From af9a981de5e32b5b9e065e39ea617b0086fb8b7b Mon Sep 17 00:00:00 2001 From: pranjalesh <31514465+pranjalesh@users.noreply.github.com> Date: Mon, 27 Nov 2023 17:16:34 -0500 Subject: [PATCH] bug fixes --- .../opentracks/TrackRecordingActivity.java | 117 ++++-------------- 1 file changed, 22 insertions(+), 95 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java b/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java index af8b529bb..754eebce3 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java @@ -5,15 +5,14 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.os.Build; import android.os.Bundle; +import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.WindowManager; -import android.widget.Button; import android.widget.Toast; import androidx.annotation.NonNull; -import androidx.appcompat.widget.SearchView; import androidx.core.content.ContextCompat; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; @@ -113,44 +112,30 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); contentProviderUtils = new ContentProviderUtils(this); - if(getIntent().getParcelableExtra(EXTRA_TRACK_ID)!=null){ - trackId = getIntent().getParcelableExtra(EXTRA_TRACK_ID); - trackRecordingServiceConnection = new TrackRecordingServiceConnection(bindChangedCallback); + trackId = getIntent().getParcelableExtra(EXTRA_TRACK_ID); + if (trackId == null) { + throw new RuntimeException("TrackId is mandatory"); + } + if (contentProviderUtils.getTrack(trackId) == null) { + Log.w(TAG, "TrackId does not exists."); + finish(); } - -// if (trackId == null) { -// throw new RuntimeException("TrackId is mandatory"); -// } -// if (contentProviderUtils.getTrack(trackId) == null) { -// Log.w(TAG, "TrackId does not exists."); -// finish(); -// } - - + trackRecordingServiceConnection = new TrackRecordingServiceConnection(bindChangedCallback); trackDataHub = new TrackDataHub(this); CustomFragmentPagerAdapter pagerAdapter = new CustomFragmentPagerAdapter(this); viewBinding.trackDetailActivityViewPager.setAdapter(pagerAdapter); -// new TabLayoutMediator(viewBinding.trackDetailActivityTablayout, viewBinding.trackDetailActivityViewPager, -// (tab, position) -> tab.setText(pagerAdapter.getPageTitle(position))).attach(); -// if (savedInstanceState != null) { -// viewBinding.trackDetailActivityViewPager.setCurrentItem(savedInstanceState.getInt(CURRENT_TAB_TAG_KEY)); -// } - - if(getIntent().getParcelableExtra(EXTRA_TRACK_ID)!=null){ - viewBinding.trackRecordingFabAction.setImageResource(R.drawable.stop); - }else{ - viewBinding.trackRecordingFabAction.setImageResource(R.drawable.start); + new TabLayoutMediator(viewBinding.trackDetailActivityTablayout, viewBinding.trackDetailActivityViewPager, + (tab, position) -> tab.setText(pagerAdapter.getPageTitle(position))).attach(); + if (savedInstanceState != null) { + viewBinding.trackDetailActivityViewPager.setCurrentItem(savedInstanceState.getInt(CURRENT_TAB_TAG_KEY)); } - // viewBinding.holdToStopButton.setImageResource(R.drawable.ic_baseline_stop_24); - // viewBinding.holdToStopButton.setBackgroundTintList(ContextCompat.getColorStateList(this, R.color.opentracks)); - // viewBinding.holdToStopButton.setBackgroundColor(ContextCompat.getColor(this, R.color.opentracks)); +// viewBinding.holdToStopButton.setImageResource(R.drawable.ic_baseline_stop_24); +// viewBinding.holdToStopButton.setBackgroundTintList(ContextCompat.getColorStateList(this, R.color.opentracks)); +// viewBinding.holdToStopButton.setBackgroundColor(ContextCompat.getColor(this, R.color.opentracks)); viewBinding.holdToStopButton.setOnLongClickListener((view) -> { - viewBinding.trackRecordingFabAction.setBackgroundTintList(ContextCompat.getColorStateList(this, R.color.opentracks)); - viewBinding.trackRecordingFabAction.setBackgroundColor(ContextCompat.getColor(this, R.color.opentracks)); - viewBinding.trackRecordingFabAction.setOnClickListener((view) -> { ActivityUtils.vibrate(this, 1000); trackRecordingServiceConnection.stopRecording(TrackRecordingActivity.this); Intent newIntent = IntentUtils.newIntent(TrackRecordingActivity.this, TrackStoppedActivity.class) @@ -158,47 +143,14 @@ protected void onCreate(Bundle savedInstanceState) { startActivity(newIntent); overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); finish(); + return true; }); - viewBinding.holdToStopButton.setOnClickListener((view) -> Toast.makeText(TrackRecordingActivity.this, getString(R.string.hold_to_pause), Toast.LENGTH_LONG).show()); + viewBinding.holdToStopButton.setOnClickListener((view) -> Toast.makeText(TrackRecordingActivity.this, getString(R.string.hold_to_stop), Toast.LENGTH_LONG).show()); viewBinding.bottomAppBar.setNavigationIcon(R.drawable.ic_baseline_arrow_back_24); setSupportActionBar(viewBinding.bottomAppBar); - setSupportActionBar(viewBinding.trackListToolbar); - viewBinding.trackRecordingFabAction.setOnClickListener(v -> startRecording(pagerAdapter)); - - viewBinding.trackRecordingFabAction.setOnLongClickListener((view) -> { - ActivityUtils.vibrate(this, 1000); - trackRecordingServiceConnection.stopRecording(TrackRecordingActivity.this); - Intent newIntent = IntentUtils.newIntent(TrackRecordingActivity.this, TrackStoppedActivity.class) - .putExtra(TrackStoppedActivity.EXTRA_TRACK_ID, trackId); - startActivity(newIntent); - overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); - finish(); - return true; - }); - } - void startRecording(CustomFragmentPagerAdapter pagerAdapter) { - if (recordingStatus.isRecording()) { - Toast.makeText(TrackRecordingActivity.this, getString(R.string.hold_to_stop), Toast.LENGTH_LONG).show(); - return; - } - // Not Recording -> Recording - // updateGpsMenuItem(false, true); - new TrackRecordingServiceConnection((service, connection) -> { - trackId = service.startNewTrack(); - trackRecordingServiceConnection = new TrackRecordingServiceConnection(bindChangedCallback); - trackRecordingServiceConnection.startConnection(this); - }).startAndBind(this, true); - new TabLayoutMediator(viewBinding.trackDetailActivityTablayout, viewBinding.trackDetailActivityViewPager, - (tab, position) -> tab.setText(pagerAdapter.getPageTitle(position))).attach(); - viewBinding.bottomAppBar.setVisibility(View.VISIBLE); - - viewBinding.trackRecordingFabAction.setImageResource(R.drawable.stop); - - - } @Override public void onAttachedToWindow() { setLockscreenPolicy(); @@ -256,10 +208,7 @@ protected void onStart() { PreferencesUtils.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener); - if (trackRecordingServiceConnection != null) { - trackRecordingServiceConnection.startConnection(this); - } - + trackRecordingServiceConnection.startConnection(this); trackDataHub.start(); } @@ -276,10 +225,7 @@ protected void onResume() { trackDataHub.setRecordingStatus(recordingStatus); } - if (trackRecordingServiceConnection != null) { - trackRecordingServiceConnection.startAndBindWithCallback(this); - } - + trackRecordingServiceConnection.startAndBindWithCallback(this); } @Override @@ -288,19 +234,11 @@ protected void onSaveInstanceState(@NonNull Bundle outState) { outState.putInt(CURRENT_TAB_TAG_KEY, viewBinding.trackDetailActivityViewPager.getCurrentItem()); } - @Override - protected void onPause() { - super.onPause(); - if (trackRecordingServiceConnection != null) { - trackRecordingServiceConnection.unbind(this); - } - } - @Override protected void onStop() { super.onStop(); PreferencesUtils.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener); - + trackRecordingServiceConnection.unbind(this); trackDataHub.stop(); } @@ -319,7 +257,7 @@ protected View getRootView() { @Override public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.track_menu_custom, menu); + getMenuInflater().inflate(R.menu.track_record, menu); return super.onCreateOptionsMenu(menu); } @@ -367,17 +305,6 @@ public boolean onOptionsItemSelected(MenuItem item) { return true; } - if (item.getItemId() == R.id.track_list_settings) { - startActivity(IntentUtils.newIntent(this, SettingsActivity.class)); - return true; - } - - - if (item.getItemId() == R.id.track_list_help) { - startActivity(IntentUtils.newIntent(this, HelpActivity.class)); - return true; - } - return super.onOptionsItemSelected(item); }