diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 391e6c674..3c30bb353 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -46,7 +46,7 @@ limitations under the License. - + diff --git a/src/main/java/de/dennisguse/opentracks/TrackListActivity.java b/src/main/java/de/dennisguse/opentracks/TrackListActivity.java index bf10ba549..c45e6ed61 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackListActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackListActivity.java @@ -123,6 +123,60 @@ public void onDestroy() { viewBinding.trackListFabAction.setVisibility(View.VISIBLE); viewBinding.bottomAppBar.performShow(true); } + + /** + * Handles a context item selection. + * + * @param itemId the menu item id + * @param longTrackIds the track ids + * @return true if handled. + */ + private boolean handleContextItem(int itemId, long... longTrackIds) { + Track.Id[] trackIds = new Track.Id[longTrackIds.length]; + for (int i = 0; i < longTrackIds.length; i++) { + trackIds[i] = new Track.Id(longTrackIds[i]); + } + + if (itemId == R.id.list_context_menu_show_on_map) { + IntentDashboardUtils.showTrackOnMap(this, false, trackIds); + return true; + } + + if (itemId == R.id.list_context_menu_share) { + Intent intent = ShareUtils.newShareFileIntent(this, trackIds); + intent = Intent.createChooser(intent, null); + startActivity(intent); + return true; + } + + if (itemId == R.id.list_context_menu_edit) { + Intent intent = IntentUtils.newIntent(this, TrackEditActivity.class) + .putExtra(TrackEditActivity.EXTRA_TRACK_ID, trackIds[0]); + startActivity(intent); + return true; + } + + if (itemId == R.id.list_context_menu_delete) { + deleteTracks(trackIds); + return true; + } + + if (itemId == R.id.list_context_menu_aggregated_stats) { + Intent intent = IntentUtils.newIntent(this, AggregatedStatisticsActivity.class) + .putParcelableArrayListExtra(AggregatedStatisticsActivity.EXTRA_TRACK_IDS, new ArrayList<>(Arrays.asList(trackIds))); + startActivity(intent); + return true; + } + + if (itemId == R.id.list_context_menu_select_all) { + for (int i = 0; i < viewBinding.trackList.getCount(); i++) { + viewBinding.trackList.setItemChecked(i, true); + } + return false; + } + + return false; + } }; private final OnSharedPreferenceChangeListener sharedPreferenceChangeListener = (sharedPreferences, key) -> { @@ -166,7 +220,7 @@ protected void onCreate(Bundle savedInstanceState) { trackRecordingServiceConnection = new TrackRecordingServiceConnection(bindChangedCallback); - viewBinding.aggregatedStatsButton.setOnClickListener((view) -> startActivity(IntentUtils.newIntent(this, AggregatedStatisticsActivity.class))); + viewBinding.aggregatedStatsButton.setOnClickListener((view) -> startActivity(IntentUtils.newIntent((ActivityUtils.ContextualActionModeCallback) this, AggregatedStatisticsActivity.class))); viewBinding.sensorStartButton.setOnClickListener((view) -> { LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); if (locationManager != null && !locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { @@ -185,12 +239,12 @@ protected void onCreate(Bundle savedInstanceState) { Track.Id trackId = new Track.Id(trackIdId); if (recordingStatus.isRecording() && trackId.equals(recordingStatus.getTrackId())) { // Is recording -> open record activity. - Intent newIntent = IntentUtils.newIntent(TrackListActivity.this, TrackRecordingActivity.class) + Intent newIntent = IntentUtils.newIntent((ActivityUtils.ContextualActionModeCallback) TrackListActivity.this, TrackRecordingActivity.class) .putExtra(TrackRecordedActivity.EXTRA_TRACK_ID, trackId); startActivity(newIntent); } else { // Not recording -> open detail activity. - Intent newIntent = IntentUtils.newIntent(TrackListActivity.this, TrackRecordedActivity.class) + Intent newIntent = IntentUtils.newIntent((ActivityUtils.ContextualActionModeCallback) TrackListActivity.this, TrackRecordedActivity.class) .putExtra(TrackRecordedActivity.EXTRA_TRACK_ID, trackId); ActivityOptions activityOptions = ActivityOptions.makeSceneTransitionAnimation( this, @@ -249,7 +303,7 @@ public void bindView(View view, Context context, Cursor cursor) { new TrackRecordingServiceConnection((service, connection) -> { Track.Id trackId = service.startNewTrack(); - Intent newIntent = IntentUtils.newIntent(TrackListActivity.this, TrackRecordingActivity.class); + Intent newIntent = IntentUtils.newIntent((ActivityUtils.ContextualActionModeCallback) TrackListActivity.this, TrackRecordingActivity.class); newIntent.putExtra(TrackRecordingActivity.EXTRA_TRACK_ID, trackId); startActivity(newIntent); @@ -343,12 +397,12 @@ public boolean onPrepareOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.track_list_markers) { - startActivity(IntentUtils.newIntent(this, MarkerListActivity.class)); + startActivity(IntentUtils.newIntent((ActivityUtils.ContextualActionModeCallback) this, MarkerListActivity.class)); return true; } if (item.getItemId() == R.id.track_list_settings) { - startActivity(IntentUtils.newIntent(this, SettingsActivity.class)); + startActivity(IntentUtils.newIntent((ActivityUtils.ContextualActionModeCallback) this, SettingsActivity.class)); return true; } @@ -360,7 +414,7 @@ public boolean onOptionsItemSelected(MenuItem item) { } if (item.getItemId() == R.id.track_list_help) { - startActivity(IntentUtils.newIntent(this, HelpActivity.class)); + startActivity(IntentUtils.newIntent((ActivityUtils.ContextualActionModeCallback) this, HelpActivity.class)); return true; } @@ -445,59 +499,7 @@ private void updateGpsMenuItem(boolean isGpsStarted, boolean isRecording) { } } - /** - * Handles a context item selection. - * - * @param itemId the menu item id - * @param longTrackIds the track ids - * @return true if handled. - */ - private boolean handleContextItem(int itemId, long... longTrackIds) { - Track.Id[] trackIds = new Track.Id[longTrackIds.length]; - for (int i = 0; i < longTrackIds.length; i++) { - trackIds[i] = new Track.Id(longTrackIds[i]); - } - - if (itemId == R.id.list_context_menu_show_on_map) { - IntentDashboardUtils.showTrackOnMap(this, false, trackIds); - return true; - } - if (itemId == R.id.list_context_menu_share) { - Intent intent = ShareUtils.newShareFileIntent(this, trackIds); - intent = Intent.createChooser(intent, null); - startActivity(intent); - return true; - } - - if (itemId == R.id.list_context_menu_edit) { - Intent intent = IntentUtils.newIntent(this, TrackEditActivity.class) - .putExtra(TrackEditActivity.EXTRA_TRACK_ID, trackIds[0]); - startActivity(intent); - return true; - } - - if (itemId == R.id.list_context_menu_delete) { - deleteTracks(trackIds); - return true; - } - - if (itemId == R.id.list_context_menu_aggregated_stats) { - Intent intent = IntentUtils.newIntent(this, AggregatedStatisticsActivity.class) - .putParcelableArrayListExtra(AggregatedStatisticsActivity.EXTRA_TRACK_IDS, new ArrayList<>(Arrays.asList(trackIds))); - startActivity(intent); - return true; - } - - if (itemId == R.id.list_context_menu_select_all) { - for (int i = 0; i < viewBinding.trackList.getCount(); i++) { - viewBinding.trackList.setItemChecked(i, true); - } - return false; - } - - return false; - } private class TrackLoaderCallBack implements LoaderManager.LoaderCallbacks { @@ -562,4 +564,4 @@ private void onRecordingStatusChanged(RecordingStatus status) { recordingStatus = status; setFloatButton(); } -} +} \ No newline at end of file diff --git a/src/main/java/de/dennisguse/opentracks/viewmodels/ClockViewHolder.java b/src/main/java/de/dennisguse/opentracks/viewmodels/ClockViewHolder.java index 9cf125c30..ef5a21d57 100644 --- a/src/main/java/de/dennisguse/opentracks/viewmodels/ClockViewHolder.java +++ b/src/main/java/de/dennisguse/opentracks/viewmodels/ClockViewHolder.java @@ -25,5 +25,8 @@ public void configureUI(DataField dataField) { @Override public void onChanged(UnitSystem unitSystem, RecordingData data) { + throw new UnsupportedOperationException(); + //We don't have enough information or context to provide a complete implementation in the base class or interface for this mothod. } + }