From 68a2575a14d220ab7ba2d0cec9cae7f152de9fdb Mon Sep 17 00:00:00 2001 From: XeqtR0 <98060587+XeqtR0@users.noreply.github.com> Date: Mon, 18 Mar 2024 20:48:05 -0400 Subject: [PATCH 01/32] Stop recording immediately Now, user does not have to hold the button --- .../java/de/dennisguse/opentracks/TrackRecordingActivity.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java b/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java index 3390484d1..af9d47c6b 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java @@ -135,7 +135,7 @@ protected void onCreate(Bundle savedInstanceState) { viewBinding.trackRecordingFabAction.setImageResource(R.drawable.ic_baseline_stop_24); viewBinding.trackRecordingFabAction.setBackgroundTintList(ContextCompat.getColorStateList(this, R.color.opentracks)); viewBinding.trackRecordingFabAction.setBackgroundColor(ContextCompat.getColor(this, R.color.opentracks)); - viewBinding.trackRecordingFabAction.setOnLongClickListener((view) -> { + viewBinding.trackRecordingFabAction.setOnClickListener((view) -> { ActivityUtils.vibrate(this, 1000); trackRecordingServiceConnection.stopRecording(TrackRecordingActivity.this); Intent newIntent = IntentUtils.newIntent(TrackRecordingActivity.this, TrackStoppedActivity.class) @@ -143,9 +143,7 @@ protected void onCreate(Bundle savedInstanceState) { startActivity(newIntent); overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); finish(); - return true; }); - viewBinding.trackRecordingFabAction.setOnClickListener((view) -> Toast.makeText(TrackRecordingActivity.this, getString(R.string.hold_to_stop), Toast.LENGTH_LONG).show()); setSupportActionBar(viewBinding.bottomAppBar); } From 5bbb6b493d5e2a6ae6f1f08f191290ada5b4c0fc Mon Sep 17 00:00:00 2001 From: eehamkhan Date: Fri, 22 Mar 2024 12:06:58 -0400 Subject: [PATCH 02/32] Modified ImageView to MaterialDesign as per TODO comment --- src/main/res/layout/track_stopped.xml | 60 ++++++++++++++++++--------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/src/main/res/layout/track_stopped.xml b/src/main/res/layout/track_stopped.xml index 4aca4c419..8308df575 100644 --- a/src/main/res/layout/track_stopped.xml +++ b/src/main/res/layout/track_stopped.xml @@ -184,40 +184,62 @@ android:orientation="vertical" app:layout_constraintGuide_percent="0.5" /> - - - - + + - - + + + app:icon="@drawable/ic_button_done" + app:iconGravity="textStart" + app:iconTint="?attr/colorOnBackground" + app:iconPadding="8dp" + android:text="@string/image_stop" + android:textColor="?attr/colorOnBackground" + android:backgroundTint="?attr/colorSurface" + android:paddingStart="16dp" + android:paddingEnd="16dp"/> From 27c9ba5752416d9afd9b87c097d534b5259d8fd5 Mon Sep 17 00:00:00 2001 From: eehamkhan Date: Sat, 23 Mar 2024 11:40:26 -0400 Subject: [PATCH 03/32] Integrated pause button in the recording screen --- build.gradle | 2 +- src/main/res/drawable/ic_button_pause.xml | 9 ++++ src/main/res/layout/track_recording.xml | 12 +++++ src/main/res/layout/track_stopped.xml | 61 ++++++++--------------- src/main/res/values/strings.xml | 1 + 5 files changed, 43 insertions(+), 42 deletions(-) create mode 100644 src/main/res/drawable/ic_button_pause.xml diff --git a/build.gradle b/build.gradle index 1761f192b..52f1dc7ef 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:8.2.1' + classpath 'com.android.tools.build:gradle:8.1.4' } } diff --git a/src/main/res/drawable/ic_button_pause.xml b/src/main/res/drawable/ic_button_pause.xml new file mode 100644 index 000000000..6dfd06491 --- /dev/null +++ b/src/main/res/drawable/ic_button_pause.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/src/main/res/layout/track_recording.xml b/src/main/res/layout/track_recording.xml index 360a056dc..a40fa89ae 100644 --- a/src/main/res/layout/track_recording.xml +++ b/src/main/res/layout/track_recording.xml @@ -40,6 +40,18 @@ app:navigationIcon="@drawable/ic_logo_color_24dp" app:menu="@menu/track_record" /> + + - + - - + + - - + + + app:srcCompat="@drawable/ic_button_done" /> diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index b0f88277f..56aaad44c 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -260,6 +260,7 @@ limitations under the License. Photo marker Record Stop + Pause Discard Track From d99788dd04dba9d2d43e15cf553b2f1ea651e4c9 Mon Sep 17 00:00:00 2001 From: eehamkhan Date: Sat, 23 Mar 2024 14:58:59 -0400 Subject: [PATCH 04/32] Implemented pause functionality for Moving Time, Distance, and Speed. --- .../opentracks/TrackListActivity.java | 18 ++++++++++++ .../opentracks/TrackRecordingActivity.java | 12 ++++++-- .../services/TrackRecordingService.java | 20 +++++++++++++ .../TrackRecordingServiceConnection.java | 25 ++++++++++++---- .../GenericStatisticsViewHolder.java | 29 +++++++++++++++++++ .../res/drawable/ic_baseline_record_pause.xml | 10 +++++++ src/main/res/layout/track_recording.xml | 2 +- 7 files changed, 107 insertions(+), 9 deletions(-) create mode 100644 src/main/res/drawable/ic_baseline_record_pause.xml diff --git a/src/main/java/de/dennisguse/opentracks/TrackListActivity.java b/src/main/java/de/dennisguse/opentracks/TrackListActivity.java index dda4cb355..2719b1dda 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackListActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackListActivity.java @@ -47,6 +47,7 @@ import de.dennisguse.opentracks.data.ContentProviderUtils; import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.databinding.TrackListBinding; +import de.dennisguse.opentracks.databinding.TrackRecordingBinding; import de.dennisguse.opentracks.services.RecordingStatus; import de.dennisguse.opentracks.services.TrackRecordingService; import de.dennisguse.opentracks.services.TrackRecordingServiceConnection; @@ -79,6 +80,8 @@ public class TrackListActivity extends AbstractTrackDeleteActivity implements Co private TrackListBinding viewBinding; + private TrackRecordingBinding recordingBinding; + // Preferences private UnitSystem unitSystem = UnitSystem.defaultUnitSystem(); @@ -148,6 +151,8 @@ protected void onCreate(Bundle savedInstanceState) { requestRequiredPermissions(); + recordingBinding = TrackRecordingBinding.inflate(getLayoutInflater()); + recordingStatusConnection = new TrackRecordingServiceConnection(bindChangedCallback); viewBinding.aggregatedStatsButton.setOnClickListener((view) -> startActivity(IntentUtils.newIntent(this, AggregatedStatisticsActivity.class))); @@ -186,6 +191,19 @@ protected void onCreate(Bundle savedInstanceState) { startActivity(newIntent); }); }); + + recordingBinding.trackRecordingPause.setOnLongClickListener((view) -> { + if (!recordingStatus.isRecording()) { + return false; + } + + // Recording -> Pause + ActivityUtils.vibrate(this, 1000); + updateGpsMenuItem(true, false); + recordingBinding.trackRecordingPause.setImageResource(R.drawable.ic_baseline_record_pause); + return true; + }); + viewBinding.trackListFabAction.setOnLongClickListener((view) -> { if (!recordingStatus.isRecording()) { return false; diff --git a/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java b/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java index af9d47c6b..d0ecfd3c4 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java @@ -104,7 +104,7 @@ public class TrackRecordingActivity extends AbstractActivity implements ChooseAc } if (key == null) return; - runOnUiThread(TrackRecordingActivity.this::invalidateOptionsMenu); //TODO Should not be necessary +// runOnUiThread(TrackRecordingActivity.this::invalidateOptionsMenu); //TODO Should not be necessary }; @Override @@ -136,7 +136,7 @@ protected void onCreate(Bundle savedInstanceState) { 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); + ActivityUtils.vibrate(this, 200); trackRecordingServiceConnection.stopRecording(TrackRecordingActivity.this); Intent newIntent = IntentUtils.newIntent(TrackRecordingActivity.this, TrackStoppedActivity.class) .putExtra(TrackStoppedActivity.EXTRA_TRACK_ID, trackId); @@ -145,7 +145,13 @@ protected void onCreate(Bundle savedInstanceState) { finish(); }); - setSupportActionBar(viewBinding.bottomAppBar); + viewBinding.trackRecordingPause.setImageResource(R.drawable.ic_baseline_record_pause); + viewBinding.trackRecordingPause.setOnClickListener((view) -> { + ActivityUtils.vibrate(this, 200); + trackRecordingServiceConnection.pauseRecording(TrackRecordingActivity.this); + }); + + setSupportActionBar(viewBinding.bottomAppBar); } @Override diff --git a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java index ad2e62722..80f063d14 100644 --- a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java +++ b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java @@ -16,6 +16,8 @@ package de.dennisguse.opentracks.services; +import static java.security.AccessController.getContext; + import android.app.Service; import android.content.Intent; import android.content.SharedPreferences; @@ -26,6 +28,7 @@ import android.os.PowerManager.WakeLock; import android.util.Log; import android.util.Pair; +import android.widget.Toast; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; @@ -37,6 +40,7 @@ import java.io.StringWriter; import java.time.Duration; +import de.dennisguse.opentracks.TrackListActivity; import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.Marker; import de.dennisguse.opentracks.data.models.Track; @@ -48,6 +52,7 @@ import de.dennisguse.opentracks.settings.PreferencesUtils; import de.dennisguse.opentracks.util.PermissionRequester; import de.dennisguse.opentracks.util.SystemUtils; +import de.dennisguse.opentracks.viewmodels.GenericStatisticsViewHolder; public class TrackRecordingService extends Service implements TrackPointCreator.Callback, SharedPreferences.OnSharedPreferenceChangeListener, TrackRecordingManager.IdleObserver { @@ -187,6 +192,21 @@ public void resumeTrack(Track.Id trackId) { startRecording(); } + // TODO Verify + public void pauseRecording() { +// stopUpdateRecordingData(); + GenericStatisticsViewHolder.MovingTime.pause(); + GenericStatisticsViewHolder.Distance.pause(); + GenericStatisticsViewHolder.SpeedOrPace.pause(); + +// handler.postDelayed(updateRecordingData, RECORDING_DATA_UPDATE_INTERVAL.toMillis()); + + stopSensors(); + +// voiceAnnouncementManager.start(trackRecordingManager.getTrackStatistics()); + } + + private void startRecording() { // Update instance variables handler.postDelayed(updateRecordingData, RECORDING_DATA_UPDATE_INTERVAL.toMillis()); diff --git a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceConnection.java b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceConnection.java index 8738ac7cd..90fc060b1 100644 --- a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceConnection.java +++ b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceConnection.java @@ -24,11 +24,13 @@ import android.os.IBinder.DeathRecipient; import android.os.RemoteException; import android.util.Log; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.core.content.ContextCompat; import de.dennisguse.opentracks.BuildConfig; +import de.dennisguse.opentracks.stats.TrackStatistics; /** * Wrapper for the track recording service. @@ -89,13 +91,18 @@ public void bind(@NonNull Context context) { * Unbinds the service (but leave it running). */ //TODO This is often called for one-shot operations and should be refactored as unbinding is required. + // TEST TODO public void unbind(Context context) { - try { - context.unbindService(serviceConnection); - } catch (IllegalArgumentException e) { - // Means not bound to the service. OK to ignore. + if (trackRecordingService != null) { + try { + context.unbindService(serviceConnection); + } catch (IllegalArgumentException e) { + // Means not bound to the service. OK to ignore. + } + setTrackRecordingService(null); + } else { + Log.w(TAG, "TrackRecordingService is not bound; no need to unbind."); } - setTrackRecordingService(null); } public void stopService(Context context) { @@ -130,6 +137,14 @@ public void stopRecording(@NonNull Context context) { unbindAndStop(context); } + public void pauseRecording(@NonNull Context context) { + if (trackRecordingService == null) { + Log.e(TAG, "TrackRecordingService not connected."); + } else { + trackRecordingService.pauseRecording(); + } + } + public interface Callback { void onConnected(TrackRecordingService service, TrackRecordingServiceConnection self); } diff --git a/src/main/java/de/dennisguse/opentracks/viewmodels/GenericStatisticsViewHolder.java b/src/main/java/de/dennisguse/opentracks/viewmodels/GenericStatisticsViewHolder.java index 226a19f3c..0f606d421 100644 --- a/src/main/java/de/dennisguse/opentracks/viewmodels/GenericStatisticsViewHolder.java +++ b/src/main/java/de/dennisguse/opentracks/viewmodels/GenericStatisticsViewHolder.java @@ -3,6 +3,8 @@ import android.util.Pair; import android.view.LayoutInflater; +import java.security.AccessControlContext; + import de.dennisguse.opentracks.R; import de.dennisguse.opentracks.data.models.DistanceFormatter; import de.dennisguse.opentracks.data.models.Speed; @@ -30,8 +32,18 @@ public void configureUI(DataField dataField) { public static class Distance extends GenericStatisticsViewHolder { + private static boolean paused = false; + private static String savedTime; + + public static void pause() { + paused = true; + } + @Override public void onChanged(UnitSystem unitSystem, RecordingData data) { + if (paused) { + return; // Don't update UI if paused + } Pair valueAndUnit = DistanceFormatter.Builder() .setUnit(unitSystem) .build(getContext()).getDistanceParts(data.getTrackStatistics().getTotalDistance()); @@ -56,8 +68,17 @@ public void onChanged(UnitSystem unitSystem, RecordingData data) { public static class MovingTime extends GenericStatisticsViewHolder { + private static boolean paused = false; + private static String savedTime; + + public static void pause() { + paused = true; + } @Override public void onChanged(UnitSystem unitSystem, RecordingData data) { + if (paused) { + return; // Don't update UI if paused + } String value = StringUtils.formatElapsedTime(data.getTrackStatistics().getMovingTime()); getBinding().statsValue.setText(value); @@ -66,7 +87,12 @@ public void onChanged(UnitSystem unitSystem, RecordingData data) { } public abstract static class SpeedOrPace extends GenericStatisticsViewHolder { + private static boolean paused = false; + private static String savedTime; + public static void pause() { + paused = true; + } private final boolean reportSpeed; public SpeedOrPace(boolean reportSpeed) { @@ -75,6 +101,9 @@ public SpeedOrPace(boolean reportSpeed) { @Override public void onChanged(UnitSystem unitSystem, RecordingData data) { + if (paused) { + return; // Don't update UI if paused + } SpeedFormatter localSpeedFormatter = SpeedFormatter.Builder() .setUnit(unitSystem) .setReportSpeedOrPace(reportSpeed) diff --git a/src/main/res/drawable/ic_baseline_record_pause.xml b/src/main/res/drawable/ic_baseline_record_pause.xml new file mode 100644 index 000000000..d19183016 --- /dev/null +++ b/src/main/res/drawable/ic_baseline_record_pause.xml @@ -0,0 +1,10 @@ + + + diff --git a/src/main/res/layout/track_recording.xml b/src/main/res/layout/track_recording.xml index a40fa89ae..f51e1068c 100644 --- a/src/main/res/layout/track_recording.xml +++ b/src/main/res/layout/track_recording.xml @@ -48,7 +48,7 @@ android:layout_marginEnd="120dp" android:contentDescription="@string/image_pause" android:foreground="@drawable/ic_button_pause" - android:src="@drawable/ic_baseline_record_24" + android:src="@drawable/ic_baseline_record_pause" app:elevation="0dp" app:layout_anchor="@+id/track_recording_fab_action" /> From a114144b489340e760e13d0653d232ab0514c65c Mon Sep 17 00:00:00 2001 From: eehamkhan Date: Sat, 23 Mar 2024 17:15:36 -0400 Subject: [PATCH 05/32] Removed the stopSensors() method when pausing, as it did not allow the recording to stop without crashing once paused. --- .../dennisguse/opentracks/services/TrackRecordingService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java index 80f063d14..552f1f0df 100644 --- a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java +++ b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java @@ -201,7 +201,7 @@ public void pauseRecording() { // handler.postDelayed(updateRecordingData, RECORDING_DATA_UPDATE_INTERVAL.toMillis()); - stopSensors(); +// stopSensors(); // voiceAnnouncementManager.start(trackRecordingManager.getTrackStatistics()); } From 7c245a6a387ca1faeff45e069d9c8f37700308f5 Mon Sep 17 00:00:00 2001 From: eehamkhan Date: Sat, 23 Mar 2024 21:25:01 -0400 Subject: [PATCH 06/32] Integrated a resume button and made it show/disappear when pause/resume button clicked. --- .../opentracks/TrackRecordingActivity.java | 9 +++++++++ .../services/TrackRecordingService.java | 13 +++++++++++- .../TrackRecordingServiceConnection.java | 8 ++++++++ .../GenericStatisticsViewHolder.java | 5 +++++ .../drawable/ic_baseline_record_resume.xml | 10 ++++++++++ src/main/res/drawable/ic_button_resume.xml | 20 ++++++------------- src/main/res/layout/track_recording.xml | 15 +++++++++++++- src/main/res/values/strings.xml | 1 + 8 files changed, 65 insertions(+), 16 deletions(-) create mode 100644 src/main/res/drawable/ic_baseline_record_resume.xml diff --git a/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java b/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java index d0ecfd3c4..4178e55cd 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java @@ -149,8 +149,17 @@ protected void onCreate(Bundle savedInstanceState) { viewBinding.trackRecordingPause.setOnClickListener((view) -> { ActivityUtils.vibrate(this, 200); trackRecordingServiceConnection.pauseRecording(TrackRecordingActivity.this); + view.setVisibility(View.GONE); }); + viewBinding.trackRecordingResume.setImageResource(R.drawable.ic_button_resume); + viewBinding.trackRecordingResume.setOnClickListener((view) -> { + ActivityUtils.vibrate(this, 200); + trackRecordingServiceConnection.pauseRecording(TrackRecordingActivity.this); + viewBinding.trackRecordingPause.setVisibility(View.VISIBLE); + }); + + setSupportActionBar(viewBinding.bottomAppBar); } diff --git a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java index 552f1f0df..bafd263ee 100644 --- a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java +++ b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java @@ -192,7 +192,6 @@ public void resumeTrack(Track.Id trackId) { startRecording(); } - // TODO Verify public void pauseRecording() { // stopUpdateRecordingData(); GenericStatisticsViewHolder.MovingTime.pause(); @@ -203,6 +202,18 @@ public void pauseRecording() { // stopSensors(); +// voiceAnnouncementManager.start(trackRecordingManager.getTrackStatistics()); + } + + public void resumeRecording() { + GenericStatisticsViewHolder.MovingTime.resume(); +// GenericStatisticsViewHolder.Distance.pause(); +// GenericStatisticsViewHolder.SpeedOrPace.pause(); + +// handler.postDelayed(updateRecordingData, RECORDING_DATA_UPDATE_INTERVAL.toMillis()); + +// stopSensors(); + // voiceAnnouncementManager.start(trackRecordingManager.getTrackStatistics()); } diff --git a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceConnection.java b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceConnection.java index 90fc060b1..29447de95 100644 --- a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceConnection.java +++ b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceConnection.java @@ -145,6 +145,14 @@ public void pauseRecording(@NonNull Context context) { } } + public void resumeRecording(@NonNull Context context) { + if (trackRecordingService == null) { + Log.e(TAG, "TrackRecordingService not connected."); + } else { + trackRecordingService.resumeRecording(); + } + } + public interface Callback { void onConnected(TrackRecordingService service, TrackRecordingServiceConnection self); } diff --git a/src/main/java/de/dennisguse/opentracks/viewmodels/GenericStatisticsViewHolder.java b/src/main/java/de/dennisguse/opentracks/viewmodels/GenericStatisticsViewHolder.java index 0f606d421..2ac5da1f5 100644 --- a/src/main/java/de/dennisguse/opentracks/viewmodels/GenericStatisticsViewHolder.java +++ b/src/main/java/de/dennisguse/opentracks/viewmodels/GenericStatisticsViewHolder.java @@ -74,6 +74,10 @@ public static class MovingTime extends GenericStatisticsViewHolder { public static void pause() { paused = true; } + public static void resume() { + paused = false; + } + @Override public void onChanged(UnitSystem unitSystem, RecordingData data) { if (paused) { @@ -86,6 +90,7 @@ public void onChanged(UnitSystem unitSystem, RecordingData data) { } } + public abstract static class SpeedOrPace extends GenericStatisticsViewHolder { private static boolean paused = false; private static String savedTime; diff --git a/src/main/res/drawable/ic_baseline_record_resume.xml b/src/main/res/drawable/ic_baseline_record_resume.xml new file mode 100644 index 000000000..d19183016 --- /dev/null +++ b/src/main/res/drawable/ic_baseline_record_resume.xml @@ -0,0 +1,10 @@ + + + diff --git a/src/main/res/drawable/ic_button_resume.xml b/src/main/res/drawable/ic_button_resume.xml index 5b2a085b2..b86180f3c 100644 --- a/src/main/res/drawable/ic_button_resume.xml +++ b/src/main/res/drawable/ic_button_resume.xml @@ -4,19 +4,11 @@ android:viewportWidth="125" android:viewportHeight="125"> + android:pathData="M62.5,62.5m-62.5,0a62.5,62.5 0,1 1,125 0a62.5,62.5 0,1 1,-125 0" + android:strokeWidth="0" + android:fillColor="#ff6d00"/> - + android:pathData="M85.52,62.5l-17.53,8.97 -17.53,8.97v-35.87l17.53,8.97 17.53,8.97Z" + android:strokeWidth="0" + android:fillColor="#fff"/> diff --git a/src/main/res/layout/track_recording.xml b/src/main/res/layout/track_recording.xml index f51e1068c..4006a21dc 100644 --- a/src/main/res/layout/track_recording.xml +++ b/src/main/res/layout/track_recording.xml @@ -40,6 +40,19 @@ app:navigationIcon="@drawable/ic_logo_color_24dp" app:menu="@menu/track_record" /> + + + diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 56aaad44c..ef5646ae3 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -261,6 +261,7 @@ limitations under the License. Record Stop Pause + Resume Discard Track From e33d38c60594cf646ea12854b36cc34f9c0bab6d Mon Sep 17 00:00:00 2001 From: eehamkhan Date: Sun, 24 Mar 2024 13:51:48 -0400 Subject: [PATCH 07/32] Working on resume functionality, moving time is 4 seconds behind total time (jumps after resuming). --- .../opentracks/TrackRecordingActivity.java | 2 +- .../opentracks/stats/TrackStatistics.java | 31 +++++++++++++++++-- .../GenericStatisticsViewHolder.java | 25 +++++++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java b/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java index 4178e55cd..399d62a9a 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java @@ -155,7 +155,7 @@ protected void onCreate(Bundle savedInstanceState) { viewBinding.trackRecordingResume.setImageResource(R.drawable.ic_button_resume); viewBinding.trackRecordingResume.setOnClickListener((view) -> { ActivityUtils.vibrate(this, 200); - trackRecordingServiceConnection.pauseRecording(TrackRecordingActivity.this); + trackRecordingServiceConnection.resumeRecording(TrackRecordingActivity.this); viewBinding.trackRecordingPause.setVisibility(View.VISIBLE); }); diff --git a/src/main/java/de/dennisguse/opentracks/stats/TrackStatistics.java b/src/main/java/de/dennisguse/opentracks/stats/TrackStatistics.java index 41fa6d8e7..c0dd4c57b 100644 --- a/src/main/java/de/dennisguse/opentracks/stats/TrackStatistics.java +++ b/src/main/java/de/dennisguse/opentracks/stats/TrackStatistics.java @@ -16,6 +16,9 @@ package de.dennisguse.opentracks.stats; +import android.util.Log; +import android.widget.Toast; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; @@ -29,6 +32,7 @@ import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.TrackPoint; +import de.dennisguse.opentracks.viewmodels.GenericStatisticsViewHolder; /** * Statistical data about a {@link Track}. @@ -44,6 +48,8 @@ public class TrackStatistics { // The min and max altitude (meters) seen on this track. private final ExtremityMonitor altitudeExtremities = new ExtremityMonitor(); + public static boolean pause = false; + // The track start time. private Instant startTime; // The track stop time. @@ -63,6 +69,8 @@ public class TrackStatistics { private boolean isIdle; + public boolean resumed = false; + public TrackStatistics() { reset(); } @@ -238,7 +246,26 @@ public void setMovingTime(Duration movingTime) { } public void addMovingTime(TrackPoint trackPoint, TrackPoint lastTrackPoint) { - addMovingTime(Duration.between(lastTrackPoint.getTime(), trackPoint.getTime())); + if (pause) { + return; + } + if (resumed) { + // Calculate the elapsed time since the pause + Duration elapsedTimeSincePause = Duration.between(lastTrackPoint.getTime(), trackPoint.getTime()); + + // Update the moving time with the elapsed pause time + movingTime = movingTime.plus(elapsedTimeSincePause); + + // Reset the resumed flag + resumed = false; + } else { + // Standard moving time update logic (add the time between track points) + Duration time = Duration.between(lastTrackPoint.getTime(), trackPoint.getTime()); + if (time.isNegative()) { + throw new RuntimeException("Moving time cannot be negative"); + } + movingTime = movingTime.plus(time); + } } @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE) @@ -246,7 +273,7 @@ public void addMovingTime(Duration time) { if (time.isNegative()) { throw new RuntimeException("Moving time cannot be negative"); } - movingTime = movingTime.plus(time); + movingTime = movingTime.plus(time); } public Duration getStoppedTime() { diff --git a/src/main/java/de/dennisguse/opentracks/viewmodels/GenericStatisticsViewHolder.java b/src/main/java/de/dennisguse/opentracks/viewmodels/GenericStatisticsViewHolder.java index 2ac5da1f5..a6ae613cd 100644 --- a/src/main/java/de/dennisguse/opentracks/viewmodels/GenericStatisticsViewHolder.java +++ b/src/main/java/de/dennisguse/opentracks/viewmodels/GenericStatisticsViewHolder.java @@ -1,11 +1,15 @@ package de.dennisguse.opentracks.viewmodels; +import android.util.Log; import android.util.Pair; import android.view.LayoutInflater; +import android.widget.Toast; import java.security.AccessControlContext; +import java.time.Duration; import de.dennisguse.opentracks.R; +import de.dennisguse.opentracks.TrackRecordingActivity; import de.dennisguse.opentracks.data.models.DistanceFormatter; import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.SpeedFormatter; @@ -14,6 +18,7 @@ import de.dennisguse.opentracks.sensors.sensorData.SensorDataSet; import de.dennisguse.opentracks.services.RecordingData; import de.dennisguse.opentracks.settings.UnitSystem; +import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.ui.customRecordingLayout.DataField; import de.dennisguse.opentracks.util.StringUtils; @@ -39,6 +44,10 @@ public static void pause() { paused = true; } + public static void resume() { + paused = false; + } + @Override public void onChanged(UnitSystem unitSystem, RecordingData data) { if (paused) { @@ -69,20 +78,36 @@ public void onChanged(UnitSystem unitSystem, RecordingData data) { public static class MovingTime extends GenericStatisticsViewHolder { private static boolean paused = false; + private static boolean resume = false; + private static boolean fix = true; + + public static Duration currentTime; private static String savedTime; public static void pause() { paused = true; + TrackStatistics.pause = true; } public static void resume() { paused = false; + resume = true; } @Override public void onChanged(UnitSystem unitSystem, RecordingData data) { if (paused) { + if (fix) { + currentTime = data.getTrackStatistics().getMovingTime(); + } + fix = false; return; // Don't update UI if paused } + if (resume) { + data.getTrackStatistics().setMovingTime(currentTime); + resume = false; + TrackStatistics.pause = false; + return; + } String value = StringUtils.formatElapsedTime(data.getTrackStatistics().getMovingTime()); getBinding().statsValue.setText(value); From a5d1975084d1cae7ceb5482dfce6c5607d6e0a7f Mon Sep 17 00:00:00 2001 From: Robertmotax1 Date: Sun, 24 Mar 2024 22:06:07 -0400 Subject: [PATCH 08/32] Check if track is null (often causes error when you exit app, then try to re-open it while track is still running) --- .../fragments/StatisticsRecordedFragment.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/de/dennisguse/opentracks/fragments/StatisticsRecordedFragment.java b/src/main/java/de/dennisguse/opentracks/fragments/StatisticsRecordedFragment.java index 5c5ce6639..b1b3fcdcd 100644 --- a/src/main/java/de/dennisguse/opentracks/fragments/StatisticsRecordedFragment.java +++ b/src/main/java/de/dennisguse/opentracks/fragments/StatisticsRecordedFragment.java @@ -25,6 +25,8 @@ import android.view.View; import android.view.ViewGroup; +import android.widget.Toast; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; @@ -173,6 +175,19 @@ private void loadTrackDescription(@NonNull Track track) { } private void updateUI() { + //see if track is null + assert track != null; + + // Check if track is null + if (track == null) { + Log.e(TAG, "track cannot be null"); + Toast.makeText(getContext(), "Error: Track cannot be null. Please retry.", Toast.LENGTH_SHORT).show(); + + getActivity().finish(); + return; + } + + TrackStatistics trackStatistics = track.getTrackStatistics(); // Set total distance { From a17f24cd6f92e81d057d807d2c33cdcbf5cbf69b Mon Sep 17 00:00:00 2001 From: Robertmotax1 Date: Sun, 24 Mar 2024 22:13:14 -0400 Subject: [PATCH 09/32] Check if track is null (often causes error when you exit app, then try to re-open it while track is still running) --- .../fragments/StatisticsRecordedFragment.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/fragments/StatisticsRecordedFragment.java b/src/main/java/de/dennisguse/opentracks/fragments/StatisticsRecordedFragment.java index b1b3fcdcd..a5b8e3e9b 100644 --- a/src/main/java/de/dennisguse/opentracks/fragments/StatisticsRecordedFragment.java +++ b/src/main/java/de/dennisguse/opentracks/fragments/StatisticsRecordedFragment.java @@ -140,7 +140,7 @@ public void onDestroyView() { } public void loadStatistics() { - if (isResumed()) { + if (isResumed() && getActivity() != null) { getActivity().runOnUiThread(() -> { if (isResumed()) { Track track = contentProviderUtils.getTrack(trackId); @@ -166,6 +166,10 @@ public void loadStatistics() { } }); } + //add logs + else { + Log.w(TAG, "Activity is null when loading statistics"); + } } private void loadTrackDescription(@NonNull Track track) { @@ -175,17 +179,15 @@ private void loadTrackDescription(@NonNull Track track) { } private void updateUI() { - //see if track is null - assert track != null; - // Check if track is null +/* // Check if track is null if (track == null) { Log.e(TAG, "track cannot be null"); Toast.makeText(getContext(), "Error: Track cannot be null. Please retry.", Toast.LENGTH_SHORT).show(); getActivity().finish(); return; - } + }*/ TrackStatistics trackStatistics = track.getTrackStatistics(); From 80341e6a5808754c333c53cefb28e08cf3320032 Mon Sep 17 00:00:00 2001 From: Robertmotax1 Date: Mon, 25 Mar 2024 01:08:17 -0400 Subject: [PATCH 10/32] trying to add stop and start button --- .../dennisguse/opentracks/TrackListActivity.java | 10 ++++++---- .../opentracks/TrackRecordingActivity.java | 8 ++++++-- .../fragments/StatisticsRecordedFragment.java | 8 +++++--- .../opentracks/ui/TrackListAdapter.java | 3 ++- src/main/res/drawable/ic_button_start_arrow.xml | 14 ++++++++++++++ src/main/res/drawable/ic_button_stop.xml | 15 +++++++++++++++ src/main/res/layout/track_list.xml | 4 ++-- src/main/res/layout/track_recording.xml | 4 ++-- 8 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 src/main/res/drawable/ic_button_start_arrow.xml create mode 100644 src/main/res/drawable/ic_button_stop.xml diff --git a/src/main/java/de/dennisguse/opentracks/TrackListActivity.java b/src/main/java/de/dennisguse/opentracks/TrackListActivity.java index 2719b1dda..3811ef606 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackListActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackListActivity.java @@ -213,8 +213,9 @@ protected void onCreate(Bundle savedInstanceState) { ActivityUtils.vibrate(this, 1000); updateGpsMenuItem(false, false); recordingStatusConnection.stopRecording(TrackListActivity.this); - viewBinding.trackListFabAction.setImageResource(R.drawable.ic_baseline_record_24); - viewBinding.trackListFabAction.setBackgroundTintList(ContextCompat.getColorStateList(this, R.color.red_dark)); +/* viewBinding.trackListFabAction.setImageResource(R.drawable.ic_baseline_record_24); + viewBinding.trackListFabAction.setBackgroundTintList(ContextCompat.getColorStateList(this, R.color.red_dark));*/ + viewBinding.trackListFabAction.setImageResource(R.drawable.ic_button_start_arrow); return true; }); @@ -454,8 +455,9 @@ public void onGpsStatusChanged(GpsStatusValue newStatus) { } private void setFloatButton() { - viewBinding.trackListFabAction.setImageResource(recordingStatus.isRecording() ? R.drawable.ic_baseline_stop_24 : R.drawable.ic_baseline_record_24); - viewBinding.trackListFabAction.setBackgroundTintList(ContextCompat.getColorStateList(this, recordingStatus.isRecording() ? R.color.opentracks : R.color.red_dark)); +// viewBinding.trackListFabAction.setImageResource(recordingStatus.isRecording() ? R.drawable.ic_baseline_stop_24 : R.drawable.ic_baseline_record_24); + viewBinding.trackListFabAction.setImageResource(recordingStatus.isRecording() ? R.drawable.ic_button_stop : R.drawable.ic_button_start_arrow); +// viewBinding.trackListFabAction.setBackgroundTintList(ContextCompat.getColorStateList(this, recordingStatus.isRecording() ? R.color.opentracks : R.color.red_dark)); } private void onRecordingStatusChanged(RecordingStatus status) { diff --git a/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java b/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java index 399d62a9a..96920d883 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java @@ -132,9 +132,13 @@ protected void onCreate(Bundle savedInstanceState) { viewBinding.trackDetailActivityViewPager.setCurrentItem(savedInstanceState.getInt(CURRENT_TAB_TAG_KEY)); } - viewBinding.trackRecordingFabAction.setImageResource(R.drawable.ic_baseline_stop_24); +/* viewBinding.trackRecordingFabAction.setImageResource(R.drawable.ic_baseline_stop_24); viewBinding.trackRecordingFabAction.setBackgroundTintList(ContextCompat.getColorStateList(this, R.color.opentracks)); - viewBinding.trackRecordingFabAction.setBackgroundColor(ContextCompat.getColor(this, R.color.opentracks)); + viewBinding.trackRecordingFabAction.setBackgroundColor(ContextCompat.getColor(this, R.color.opentracks));*/ + + + viewBinding.trackRecordingFabAction.setImageResource(R.drawable.ic_button_stop); + viewBinding.trackRecordingFabAction.setOnClickListener((view) -> { ActivityUtils.vibrate(this, 200); trackRecordingServiceConnection.stopRecording(TrackRecordingActivity.this); diff --git a/src/main/java/de/dennisguse/opentracks/fragments/StatisticsRecordedFragment.java b/src/main/java/de/dennisguse/opentracks/fragments/StatisticsRecordedFragment.java index a5b8e3e9b..6de5bc487 100644 --- a/src/main/java/de/dennisguse/opentracks/fragments/StatisticsRecordedFragment.java +++ b/src/main/java/de/dennisguse/opentracks/fragments/StatisticsRecordedFragment.java @@ -32,6 +32,8 @@ import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; +import java.util.Objects; + import de.dennisguse.opentracks.R; import de.dennisguse.opentracks.TrackRecordedActivity; import de.dennisguse.opentracks.data.ContentProviderUtils; @@ -180,14 +182,14 @@ private void loadTrackDescription(@NonNull Track track) { private void updateUI() { -/* // Check if track is null + // Check if track is null if (track == null) { Log.e(TAG, "track cannot be null"); Toast.makeText(getContext(), "Error: Track cannot be null. Please retry.", Toast.LENGTH_SHORT).show(); - getActivity().finish(); + requireActivity().finish(); return; - }*/ + } TrackStatistics trackStatistics = track.getTrackStatistics(); diff --git a/src/main/java/de/dennisguse/opentracks/ui/TrackListAdapter.java b/src/main/java/de/dennisguse/opentracks/ui/TrackListAdapter.java index 50743f4f3..b252170bf 100644 --- a/src/main/java/de/dennisguse/opentracks/ui/TrackListAdapter.java +++ b/src/main/java/de/dennisguse/opentracks/ui/TrackListAdapter.java @@ -205,7 +205,8 @@ public void bind(Cursor cursor) { boolean isRecordingThisTrackRecording = trackId.equals(recordingStatus.trackId()); if (isRecordingThisTrackRecording) { - iconId = R.drawable.ic_track_recording; + //iconId = R.drawable.ic_track_recording; + iconId = R.drawable.ic_button_start_arrow; iconDesc = R.string.image_record; } diff --git a/src/main/res/drawable/ic_button_start_arrow.xml b/src/main/res/drawable/ic_button_start_arrow.xml new file mode 100644 index 000000000..e4797150b --- /dev/null +++ b/src/main/res/drawable/ic_button_start_arrow.xml @@ -0,0 +1,14 @@ + + + + diff --git a/src/main/res/drawable/ic_button_stop.xml b/src/main/res/drawable/ic_button_stop.xml new file mode 100644 index 000000000..45d5b4387 --- /dev/null +++ b/src/main/res/drawable/ic_button_stop.xml @@ -0,0 +1,15 @@ + + + + diff --git a/src/main/res/layout/track_list.xml b/src/main/res/layout/track_list.xml index 53e873f26..4f4bcb821 100644 --- a/src/main/res/layout/track_list.xml +++ b/src/main/res/layout/track_list.xml @@ -132,7 +132,7 @@ limitations under the License. android:layout_width="wrap_content" android:layout_height="wrap_content" android:contentDescription="@string/image_record" - android:src="@drawable/ic_baseline_record_24" + android:src="@drawable/ic_button_start_arrow" app:layout_anchor="@id/bottom_app_bar" /> - + \ No newline at end of file diff --git a/src/main/res/layout/track_recording.xml b/src/main/res/layout/track_recording.xml index 4006a21dc..5a39ae968 100644 --- a/src/main/res/layout/track_recording.xml +++ b/src/main/res/layout/track_recording.xml @@ -69,8 +69,8 @@ android:id="@+id/track_recording_fab_action" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:src="@drawable/ic_baseline_record_24" + android:src="@drawable/ic_button_stop" android:contentDescription="@string/image_stop" app:layout_anchor="@id/bottom_app_bar" /> - + \ No newline at end of file From d16180aa595bc32a2b7a485bbbd77f2bea24b818 Mon Sep 17 00:00:00 2001 From: Robertmotax1 Date: Mon, 25 Mar 2024 16:47:49 -0400 Subject: [PATCH 11/32] minor changes to add/stop button --- src/main/res/layout/track_list.xml | 1 + src/main/res/layout/track_recording.xml | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/res/layout/track_list.xml b/src/main/res/layout/track_list.xml index 4f4bcb821..0a32617de 100644 --- a/src/main/res/layout/track_list.xml +++ b/src/main/res/layout/track_list.xml @@ -132,6 +132,7 @@ limitations under the License. android:layout_width="wrap_content" android:layout_height="wrap_content" android:contentDescription="@string/image_record" + android:foreground="@drawable/ic_button_start_arrow" android:src="@drawable/ic_button_start_arrow" app:layout_anchor="@id/bottom_app_bar" /> diff --git a/src/main/res/layout/track_recording.xml b/src/main/res/layout/track_recording.xml index 5a39ae968..c96addfe2 100644 --- a/src/main/res/layout/track_recording.xml +++ b/src/main/res/layout/track_recording.xml @@ -69,6 +69,7 @@ android:id="@+id/track_recording_fab_action" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:foreground="@drawable/ic_button_stop" android:src="@drawable/ic_button_stop" android:contentDescription="@string/image_stop" app:layout_anchor="@id/bottom_app_bar" /> From fe96bb59add0f1dfae74b610148e11fb8fda9d15 Mon Sep 17 00:00:00 2001 From: Robertmotax1 Date: Mon, 25 Mar 2024 18:28:08 -0400 Subject: [PATCH 12/32] unsure, but another prevent nullPointer --- .../java/de/dennisguse/opentracks/TrackListActivity.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/de/dennisguse/opentracks/TrackListActivity.java b/src/main/java/de/dennisguse/opentracks/TrackListActivity.java index 3811ef606..9ad240040 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackListActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackListActivity.java @@ -158,6 +158,14 @@ protected void onCreate(Bundle savedInstanceState) { viewBinding.aggregatedStatsButton.setOnClickListener((view) -> startActivity(IntentUtils.newIntent(this, AggregatedStatisticsActivity.class))); viewBinding.sensorStartButton.setOnClickListener((view) -> { LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); + + //Check if location is actually null +/* if (locationManager == null) { + // Handle the scenario where LocationManager is null + Toast.makeText(this, "Unable to access location services.", Toast.LENGTH_SHORT).show(); + return; + }*/ + if (locationManager != null && !locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)); } else { From 87f02ca190bd7365f88916cd8211e1a659cba6ed Mon Sep 17 00:00:00 2001 From: Kevin Tran Date: Mon, 25 Mar 2024 22:43:30 -0400 Subject: [PATCH 13/32] save migrations --- .idea/migrations.xml | 10 ++++++++++ .../dennisguse/opentracks/TrackRecordedActivity.java | 1 - 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .idea/migrations.xml diff --git a/.idea/migrations.xml b/.idea/migrations.xml new file mode 100644 index 000000000..f8051a6f9 --- /dev/null +++ b/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/de/dennisguse/opentracks/TrackRecordedActivity.java b/src/main/java/de/dennisguse/opentracks/TrackRecordedActivity.java index 856a04a53..2e87054b6 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackRecordedActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackRecordedActivity.java @@ -111,7 +111,6 @@ protected void onCreate(Bundle savedInstanceState) { @Override protected void onStart() { super.onStart(); - trackDataHub.start(); } From ab27ed97f581d2de9ba53984785ec2f29f0b7be1 Mon Sep 17 00:00:00 2001 From: eehamkhan Date: Sun, 31 Mar 2024 15:11:06 -0400 Subject: [PATCH 14/32] Implemented built-in pause method instead of creating a new one. --- build.gradle | 2 +- .../opentracks/TrackListActivity.java | 2 +- .../services/TrackRecordingService.java | 24 ++++++------------- src/main/res/layout/track_recorded.xml | 1 - 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/build.gradle b/build.gradle index 3b6de8f69..d80bed607 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:8.3.1' + classpath 'com.android.tools.build:gradle:8.1.4' } } diff --git a/src/main/java/de/dennisguse/opentracks/TrackListActivity.java b/src/main/java/de/dennisguse/opentracks/TrackListActivity.java index 99c5d14be..1cabd587f 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackListActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackListActivity.java @@ -213,7 +213,7 @@ protected void onCreate(Bundle savedInstanceState) { // Recording -> Pause ActivityUtils.vibrate(this, 1000); updateGpsMenuItem(true, false); - recordingBinding.trackRecordingPause.setImageResource(R.drawable.ic_baseline_record_pause); + recordingBinding.trackRecordingPause.setImageResource(R.drawable.ic_button_pause); return true; }); diff --git a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java index bafd263ee..f7bf5369e 100644 --- a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java +++ b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java @@ -193,28 +193,18 @@ public void resumeTrack(Track.Id trackId) { } public void pauseRecording() { -// stopUpdateRecordingData(); - GenericStatisticsViewHolder.MovingTime.pause(); - GenericStatisticsViewHolder.Distance.pause(); - GenericStatisticsViewHolder.SpeedOrPace.pause(); - -// handler.postDelayed(updateRecordingData, RECORDING_DATA_UPDATE_INTERVAL.toMillis()); - -// stopSensors(); - -// voiceAnnouncementManager.start(trackRecordingManager.getTrackStatistics()); - } + // Set recording status +// updateRecordingStatus(STATUS_DEFAULT); + stopUpdateRecordingData(); - public void resumeRecording() { - GenericStatisticsViewHolder.MovingTime.resume(); +// GenericStatisticsViewHolder.TotalTime.pause(); +// GenericStatisticsViewHolder.MovingTime.pause(); // GenericStatisticsViewHolder.Distance.pause(); // GenericStatisticsViewHolder.SpeedOrPace.pause(); + } -// handler.postDelayed(updateRecordingData, RECORDING_DATA_UPDATE_INTERVAL.toMillis()); - -// stopSensors(); + public void resumeRecording() { -// voiceAnnouncementManager.start(trackRecordingManager.getTrackStatistics()); } diff --git a/src/main/res/layout/track_recorded.xml b/src/main/res/layout/track_recorded.xml index 06658308e..835b48e8a 100644 --- a/src/main/res/layout/track_recorded.xml +++ b/src/main/res/layout/track_recorded.xml @@ -47,7 +47,6 @@ limitations under the License. android:layout_height="wrap_content" android:layout_marginEnd="16dp" android:layout_marginBottom="100dp" - android:contentDescription="@string/calculate_moving_average" app:layout_anchor="@id/bottom_app_bar_layout" app:layout_anchorGravity="end|bottom" app:srcCompat="@drawable/ic_baseline_add_24" /> From 2feb8d8f97b8620a0524200f3a56103e5fcbf941 Mon Sep 17 00:00:00 2001 From: Kevin Tran Date: Sun, 31 Mar 2024 20:55:13 -0400 Subject: [PATCH 15/32] Modify UI to add 'Preferred minimum time' in Settings --- src/main/res/values/settings.xml | 20 ++++++++++++++++++++ src/main/res/values/strings.xml | 5 +++++ src/main/res/xml/settings_defaults.xml | 7 +++++++ 3 files changed, 32 insertions(+) diff --git a/src/main/res/values/settings.xml b/src/main/res/values/settings.xml index fc116b292..c199c4733 100644 --- a/src/main/res/values/settings.xml +++ b/src/main/res/values/settings.xml @@ -168,6 +168,26 @@ @string/stats_rate_pace + + timeUnits + @string/settings_stats_time_unit_five + + @string/stats_time_unit_five + @string/stats_time_unit_ten + @string/stats_time_unit_fifteen + @string/stats_time_unit_custom + + FIVE_SEC + TEN_SEC + FIFTEEN_SEC + CUSTOM + + @string/settings_stats_time_unit_five + @string/settings_stats_time_unit_ten + @string/settings_stats_time_unit_fifteen + @string/settings_stats_time_unit_custom + + statsUnits @string/stats_units_metric diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index fffff49c0..e2c945a69 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -556,6 +556,11 @@ limitations under the License. Metric (km, m) Nautical (NM, ft) Preferred units + Preferred minimum time + 5 seconds + 10 seconds + 15 seconds + Customize Public API diff --git a/src/main/res/xml/settings_defaults.xml b/src/main/res/xml/settings_defaults.xml index 778b55528..51f4a69dc 100644 --- a/src/main/res/xml/settings_defaults.xml +++ b/src/main/res/xml/settings_defaults.xml @@ -19,6 +19,13 @@ android:key="@string/stats_rate_key" android:title="@string/settings_stats_rate_title" app:useSimpleSummaryProvider="true" /> + From 4a64da1a42a0bec14e623d8e0d55b37d486aa328 Mon Sep 17 00:00:00 2001 From: Robertmotax1 Date: Mon, 1 Apr 2024 23:16:24 -0400 Subject: [PATCH 16/32] Started implementing Time Unit System, --NOTE: Needs changes among selecting multiple options --- .../settings/DefaultsSettingsFragment.java | 17 ++++++++++++ .../opentracks/settings/PreferencesUtils.java | 13 +++++++++ .../opentracks/settings/TimeUnitSystem.java | 27 +++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 src/main/java/de/dennisguse/opentracks/settings/TimeUnitSystem.java diff --git a/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java b/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java index e2f192cc4..b3b6e3908 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java +++ b/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java @@ -38,6 +38,7 @@ public void onStart() { public void onResume() { super.onResume(); PreferencesUtils.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener); + updateTimeUnits(); //Make sure that time is kept updateUnits(); } @@ -64,6 +65,22 @@ public void onDisplayPreferenceDialog(Preference preference) { super.onDisplayPreferenceDialog(preference); } + //Modify the default time units for activities + private void updateTimeUnits() { + //Acquire time units from Preferences + TimeUnitSystem time = PreferencesUtils.getTimeUnit(); + ListPreference statsTimePreferences = findPreference((getString(R.string.stats_time_units_key))); + + int entriesID = switch (time) { + case FIVE_SEC, TEN_SEC, FIFTEEN_SEC, CUSTOM -> R.array.stats_time_units_options; + }; + + String[] entries = getResources().getStringArray(entriesID); + statsTimePreferences.setEntries(entries); + + HackUtils.invalidatePreference(statsTimePreferences); + } + private void updateUnits() { UnitSystem unitSystem = PreferencesUtils.getUnitSystem(); diff --git a/src/main/java/de/dennisguse/opentracks/settings/PreferencesUtils.java b/src/main/java/de/dennisguse/opentracks/settings/PreferencesUtils.java index 531aa4fbf..65cbbe2e5 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/PreferencesUtils.java +++ b/src/main/java/de/dennisguse/opentracks/settings/PreferencesUtils.java @@ -219,6 +219,19 @@ public static UnitSystem getUnitSystem() { .orElse(UnitSystem.defaultUnitSystem()); //TODO This AGAIN defines the default } + //TODO Get time wanted + public static TimeUnitSystem getTimeUnit() { + final String STATS_TIME_UNIT_DEFAULT = resources.getString(R.string.stats_time_default); + + final String VALUE = getString(R.string.stats_time_units_key, STATS_TIME_UNIT_DEFAULT); + return Arrays.stream(TimeUnitSystem.values()) + .filter(d -> VALUE.equals(resources.getString(d.getPreferenceId(), STATS_TIME_UNIT_DEFAULT))) + .findFirst() + .orElse(TimeUnitSystem.defaultUnitSystem()); //TODO This AGAIN defines the default + } + + + public static void setUnit(UnitSystem unitSystem) { setString(R.string.stats_units_key, unitSystem.getPreferenceId()); } diff --git a/src/main/java/de/dennisguse/opentracks/settings/TimeUnitSystem.java b/src/main/java/de/dennisguse/opentracks/settings/TimeUnitSystem.java new file mode 100644 index 000000000..b99dab248 --- /dev/null +++ b/src/main/java/de/dennisguse/opentracks/settings/TimeUnitSystem.java @@ -0,0 +1,27 @@ +package de.dennisguse.opentracks.settings; + +import de.dennisguse.opentracks.R; + +public enum TimeUnitSystem { + FIVE_SEC(R.string.stats_time_unit_five), + + TEN_SEC(R.string.stats_time_unit_ten), + FIFTEEN_SEC(R.string.stats_time_unit_fifteen), + + CUSTOM(R.string.stats_time_unit_custom); // Nautical miles with feet + + private final int preference; + + TimeUnitSystem(int preference) { + this.preference = preference; + } + + public int getPreferenceId() { + return preference; + } + + @Deprecated //TODO used to initialize before loading from preferences; should be loaded first + public static TimeUnitSystem defaultUnitSystem() { + return FIVE_SEC; + } +} From db411c0392b80acf8a1dfd60ac7d7fb0444da8e8 Mon Sep 17 00:00:00 2001 From: eehamkhan Date: Tue, 2 Apr 2024 15:10:47 -0400 Subject: [PATCH 17/32] Fixed bug in pause where it would keep running in background. Moving time is paused exclusively, total time keeps running while paused. (cherry picked from commit 48f11afd9624746de87a8689cfed84e77fd2b1d9) --- .../opentracks/TrackListActivity.java | 14 ++++++++++++++ .../opentracks/TrackRecordingActivity.java | 2 +- .../services/TrackRecordingManager.java | 11 +++++++++++ .../services/TrackRecordingService.java | 18 ++++++------------ .../TrackRecordingServiceConnection.java | 5 +++-- 5 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/TrackListActivity.java b/src/main/java/de/dennisguse/opentracks/TrackListActivity.java index 1cabd587f..05f171686 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackListActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackListActivity.java @@ -232,6 +232,20 @@ protected void onCreate(Bundle savedInstanceState) { return true; }); + recordingBinding.trackRecordingPause.setOnLongClickListener((view) -> { + if (recordingStatus.isRecording()) { + return false; + } + + // Pause -> Recording + ActivityUtils.vibrate(this, 1000); + updateGpsMenuItem(true, true); + TrackRecordingServiceConnection.execute(this, (service, connection) -> { + service.resumeTrack(getRecordingTrackId()); + }); + return true; + }); + setSupportActionBar(viewBinding.trackListToolbar); adapter.setActionModeCallback(contextualActionModeCallback); } diff --git a/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java b/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java index 96920d883..5930f6df7 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java @@ -159,7 +159,7 @@ protected void onCreate(Bundle savedInstanceState) { viewBinding.trackRecordingResume.setImageResource(R.drawable.ic_button_resume); viewBinding.trackRecordingResume.setOnClickListener((view) -> { ActivityUtils.vibrate(this, 200); - trackRecordingServiceConnection.resumeRecording(TrackRecordingActivity.this); + trackRecordingServiceConnection.resumeRecording(trackId); viewBinding.trackRecordingPause.setVisibility(View.VISIBLE); }); diff --git a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingManager.java b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingManager.java index c0b299e8c..3eb7da62f 100644 --- a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingManager.java +++ b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingManager.java @@ -109,6 +109,17 @@ boolean resumeExistingTrack(@NonNull Track.Id resumeTrackId) { return true; } + void pauseCurrentTrack() { + if (trackId == null) { + Log.w(TAG, "No trackId to pause."); + return; + } + + TrackPoint segmentEnd = trackPointCreator.createSegmentEnd(); + insertTrackPoint(segmentEnd, true); + handler.removeCallbacks(ON_IDLE); + } + void endCurrentTrack() { TrackPoint segmentEnd = trackPointCreator.createSegmentEnd(); insertTrackPoint(segmentEnd, true); diff --git a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java index f7bf5369e..d5af9dd01 100644 --- a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java +++ b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java @@ -38,7 +38,11 @@ import java.io.PrintWriter; import java.io.StringWriter; +import java.text.SimpleDateFormat; import java.time.Duration; +import java.time.Instant; +import java.util.Date; +import java.util.List; import de.dennisguse.opentracks.TrackListActivity; import de.dennisguse.opentracks.data.models.Distance; @@ -50,6 +54,7 @@ import de.dennisguse.opentracks.services.handlers.GpsStatusValue; import de.dennisguse.opentracks.services.handlers.TrackPointCreator; import de.dennisguse.opentracks.settings.PreferencesUtils; +import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.util.PermissionRequester; import de.dennisguse.opentracks.util.SystemUtils; import de.dennisguse.opentracks.viewmodels.GenericStatisticsViewHolder; @@ -193,18 +198,7 @@ public void resumeTrack(Track.Id trackId) { } public void pauseRecording() { - // Set recording status -// updateRecordingStatus(STATUS_DEFAULT); - stopUpdateRecordingData(); - -// GenericStatisticsViewHolder.TotalTime.pause(); -// GenericStatisticsViewHolder.MovingTime.pause(); -// GenericStatisticsViewHolder.Distance.pause(); -// GenericStatisticsViewHolder.SpeedOrPace.pause(); - } - - public void resumeRecording() { - + trackRecordingManager.pauseCurrentTrack(); } diff --git a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceConnection.java b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceConnection.java index 29447de95..2e1b44f4a 100644 --- a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceConnection.java +++ b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceConnection.java @@ -30,6 +30,7 @@ import androidx.core.content.ContextCompat; import de.dennisguse.opentracks.BuildConfig; +import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.stats.TrackStatistics; /** @@ -145,11 +146,11 @@ public void pauseRecording(@NonNull Context context) { } } - public void resumeRecording(@NonNull Context context) { + public void resumeRecording(Track.Id trackId) { if (trackRecordingService == null) { Log.e(TAG, "TrackRecordingService not connected."); } else { - trackRecordingService.resumeRecording(); + trackRecordingService.resumeTrack(trackId); } } From 58e465eeb2055471359325d52b3d79e7aa5c16c3 Mon Sep 17 00:00:00 2001 From: eehamkhan Date: Sun, 31 Mar 2024 15:11:06 -0400 Subject: [PATCH 18/32] Implemented built-in pause method instead of creating a new one. (cherry picked from commit ab27ed97f581d2de9ba53984785ec2f29f0b7be1) --- .../opentracks/services/TrackRecordingService.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java index d5af9dd01..e5f511278 100644 --- a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java +++ b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java @@ -199,6 +199,18 @@ public void resumeTrack(Track.Id trackId) { public void pauseRecording() { trackRecordingManager.pauseCurrentTrack(); + // Set recording status +// updateRecordingStatus(STATUS_DEFAULT); + stopUpdateRecordingData(); + +// GenericStatisticsViewHolder.TotalTime.pause(); +// GenericStatisticsViewHolder.MovingTime.pause(); +// GenericStatisticsViewHolder.Distance.pause(); +// GenericStatisticsViewHolder.SpeedOrPace.pause(); + } + + public void resumeRecording() { + } From 826a6a9f3de234aba428496e472ed3bd1de65a1a Mon Sep 17 00:00:00 2001 From: eehamkhan Date: Tue, 2 Apr 2024 15:10:47 -0400 Subject: [PATCH 19/32] Added EditTextPreference and attempting to connect Default Time Units to TrackRecording.xml --- .../settings/DefaultsSettingsFragment.java | 25 ++++++++++++++++++- src/main/res/values/settings.xml | 3 ++- src/main/res/values/strings.xml | 2 ++ src/main/res/xml/settings_defaults.xml | 7 ++++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java b/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java index b3b6e3908..65434d0dc 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java +++ b/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java @@ -2,8 +2,11 @@ import android.content.SharedPreferences; import android.os.Bundle; +import android.preference.PreferenceManager; //Added for EdittextPreference + import androidx.fragment.app.DialogFragment; +import androidx.preference.EditTextPreference; import androidx.preference.ListPreference; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; @@ -70,15 +73,35 @@ private void updateTimeUnits() { //Acquire time units from Preferences TimeUnitSystem time = PreferencesUtils.getTimeUnit(); ListPreference statsTimePreferences = findPreference((getString(R.string.stats_time_units_key))); + EditTextPreference statsTimeCustom = findPreference(getString(R.string.stats_time_units_custom_key)); + //See which option is chosen int entriesID = switch (time) { - case FIVE_SEC, TEN_SEC, FIFTEEN_SEC, CUSTOM -> R.array.stats_time_units_options; + case FIVE_SEC, TEN_SEC, FIFTEEN_SEC -> R.array.stats_time_units_options; + case CUSTOM -> + R.array.stats_time_values; + }; String[] entries = getResources().getStringArray(entriesID); statsTimePreferences.setEntries(entries); + // Set summary for custom time preference + statsTimeCustom.setSummary(statsTimeCustom.getText()); + + //Validates whether the time unit saving method will work HackUtils.invalidatePreference(statsTimePreferences); + HackUtils.invalidatePreference((statsTimeCustom)) + ; + } + + //TODO implement a method where the Settings retrieve the custom time value made by the user + private String getCustomTimeValue() { + // Get the shared preferences instance + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()); + + //return custom time value input + return sharedPreferences.getString(getString(R.string.stats_time_units_custom_key),""); } private void updateUnits() { diff --git a/src/main/res/values/settings.xml b/src/main/res/values/settings.xml index c199c4733..6186e41a0 100644 --- a/src/main/res/values/settings.xml +++ b/src/main/res/values/settings.xml @@ -170,6 +170,7 @@ timeUnits + custom_timeUnits @string/settings_stats_time_unit_five @string/stats_time_unit_five @@ -185,7 +186,7 @@ @string/settings_stats_time_unit_five @string/settings_stats_time_unit_ten @string/settings_stats_time_unit_fifteen - @string/settings_stats_time_unit_custom + statsUnits diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index e2c945a69..35da5861c 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -556,6 +556,8 @@ limitations under the License. Metric (km, m) Nautical (NM, ft) Preferred units + + Preferred minimum time 5 seconds 10 seconds diff --git a/src/main/res/xml/settings_defaults.xml b/src/main/res/xml/settings_defaults.xml index 51f4a69dc..f2b507a4e 100644 --- a/src/main/res/xml/settings_defaults.xml +++ b/src/main/res/xml/settings_defaults.xml @@ -19,6 +19,7 @@ android:key="@string/stats_rate_key" android:title="@string/settings_stats_rate_title" app:useSimpleSummaryProvider="true" /> + + + From 09c3d396901b397996498ab9e5a78115a35e3b61 Mon Sep 17 00:00:00 2001 From: eehamkhan Date: Sat, 6 Apr 2024 18:33:34 -0400 Subject: [PATCH 20/32] Started implementation of the default time units backend logic. Logic will reside within the finish button. --- .../de/dennisguse/opentracks/TrackStoppedActivity.java | 7 +++++++ .../opentracks/settings/DefaultsSettingsFragment.java | 2 +- .../de/dennisguse/opentracks/settings/TimeUnitSystem.java | 2 +- src/main/res/values/settings.xml | 6 +++--- src/main/res/values/strings.xml | 2 +- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java b/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java index ddb916775..72bfeaa2e 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java @@ -7,6 +7,8 @@ import android.view.View; import android.widget.ArrayAdapter; +import androidx.preference.ListPreference; + import de.dennisguse.opentracks.data.ContentProviderUtils; import de.dennisguse.opentracks.data.models.ActivityType; import de.dennisguse.opentracks.data.models.DistanceFormatter; @@ -16,6 +18,8 @@ import de.dennisguse.opentracks.fragments.ChooseActivityTypeDialogFragment; import de.dennisguse.opentracks.services.TrackRecordingServiceConnection; import de.dennisguse.opentracks.settings.PreferencesUtils; +import de.dennisguse.opentracks.settings.TimeUnitSystem; +import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.ui.aggregatedStatistics.ConfirmDeleteDialogFragment; import de.dennisguse.opentracks.util.ExportUtils; import de.dennisguse.opentracks.util.IntentUtils; @@ -34,6 +38,8 @@ public class TrackStoppedActivity extends AbstractTrackDeleteActivity implements private boolean isDiscarding = false; + public ListPreference statsTimePreferences; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -91,6 +97,7 @@ protected void onCreate(Bundle savedInstanceState) { } viewBinding.finishButton.setOnClickListener(v -> { +// if(track.getTrackStatistics().getTotalTime() < statsTime) storeTrackMetaData(contentProviderUtils, track); ExportUtils.postWorkoutExport(this, trackId); finish(); diff --git a/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java b/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java index b3b6e3908..ae74aee57 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java +++ b/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java @@ -72,7 +72,7 @@ private void updateTimeUnits() { ListPreference statsTimePreferences = findPreference((getString(R.string.stats_time_units_key))); int entriesID = switch (time) { - case FIVE_SEC, TEN_SEC, FIFTEEN_SEC, CUSTOM -> R.array.stats_time_units_options; + case FIVE_SEC, TEN_SEC, TWENTY_SEC, CUSTOM -> R.array.stats_time_units_options; }; String[] entries = getResources().getStringArray(entriesID); diff --git a/src/main/java/de/dennisguse/opentracks/settings/TimeUnitSystem.java b/src/main/java/de/dennisguse/opentracks/settings/TimeUnitSystem.java index b99dab248..609df3247 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/TimeUnitSystem.java +++ b/src/main/java/de/dennisguse/opentracks/settings/TimeUnitSystem.java @@ -6,7 +6,7 @@ public enum TimeUnitSystem { FIVE_SEC(R.string.stats_time_unit_five), TEN_SEC(R.string.stats_time_unit_ten), - FIFTEEN_SEC(R.string.stats_time_unit_fifteen), + TWENTY_SEC(R.string.stats_time_unit_twenty), CUSTOM(R.string.stats_time_unit_custom); // Nautical miles with feet diff --git a/src/main/res/values/settings.xml b/src/main/res/values/settings.xml index c199c4733..3c2f89bee 100644 --- a/src/main/res/values/settings.xml +++ b/src/main/res/values/settings.xml @@ -174,17 +174,17 @@ @string/stats_time_unit_five @string/stats_time_unit_ten - @string/stats_time_unit_fifteen + @string/stats_time_unit_twenty @string/stats_time_unit_custom FIVE_SEC TEN_SEC - FIFTEEN_SEC + TWENTY_SEC CUSTOM @string/settings_stats_time_unit_five @string/settings_stats_time_unit_ten - @string/settings_stats_time_unit_fifteen + @string/settings_stats_time_unit_twenty @string/settings_stats_time_unit_custom diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index e2c945a69..43737eb08 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -559,7 +559,7 @@ limitations under the License. Preferred minimum time 5 seconds 10 seconds - 15 seconds + 20 seconds Customize From 8605b6bf72379c1859888d66bacc33ad3f318bb3 Mon Sep 17 00:00:00 2001 From: Kevin Tran Date: Sun, 7 Apr 2024 00:40:09 -0400 Subject: [PATCH 21/32] Implemented logic to discard record based on a default minimum time --- .../opentracks/TrackStoppedActivity.java | 121 ++++++++++-------- .../settings/DefaultsSettingsFragment.java | 7 + src/main/res/values/settings.xml | 2 +- 3 files changed, 79 insertions(+), 51 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java b/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java index 72bfeaa2e..83d7a1d2c 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java @@ -1,13 +1,15 @@ package de.dennisguse.opentracks; +import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import android.util.Log; import android.util.Pair; import android.view.View; import android.widget.ArrayAdapter; -import androidx.preference.ListPreference; +import java.time.Duration; import de.dennisguse.opentracks.data.ContentProviderUtils; import de.dennisguse.opentracks.data.models.ActivityType; @@ -18,8 +20,6 @@ import de.dennisguse.opentracks.fragments.ChooseActivityTypeDialogFragment; import de.dennisguse.opentracks.services.TrackRecordingServiceConnection; import de.dennisguse.opentracks.settings.PreferencesUtils; -import de.dennisguse.opentracks.settings.TimeUnitSystem; -import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.ui.aggregatedStatistics.ConfirmDeleteDialogFragment; import de.dennisguse.opentracks.util.ExportUtils; import de.dennisguse.opentracks.util.IntentUtils; @@ -38,8 +38,6 @@ public class TrackStoppedActivity extends AbstractTrackDeleteActivity implements private boolean isDiscarding = false; - public ListPreference statsTimePreferences; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -53,62 +51,85 @@ protected void onCreate(Bundle savedInstanceState) { ContentProviderUtils contentProviderUtils = new ContentProviderUtils(this); Track track = contentProviderUtils.getTrack(trackId); - viewBinding.trackEditName.setText(track.getName()); + SharedPreferences preferences = this.getSharedPreferences("default_time_unit", Context.MODE_PRIVATE); + int selectedTimeUnitId = preferences.getInt(getString(R.string.stats_time_units_key), R.string.stats_time_default); + int minTimeMillis = convertTimeUnitToMillis(selectedTimeUnitId); - viewBinding.trackEditActivityType.setText(track.getActivityTypeLocalized()); + Duration movingTime = track.getTrackStatistics().getMovingTime(); + long movingTimeMillis = movingTime.toMillis(); - ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, ActivityType.getLocalizedStrings(this)); - viewBinding.trackEditActivityType.setAdapter(adapter); - viewBinding.trackEditActivityType.setOnItemClickListener((parent, view, position, id) -> { - String localizedActivityType = (String) viewBinding.trackEditActivityType.getAdapter().getItem(position); - setActivityTypeIcon(ActivityType.findByLocalizedString(this, localizedActivityType)); - }); - viewBinding.trackEditActivityType.setOnFocusChangeListener((v, hasFocus) -> { - if (!hasFocus) { - String localizedActivityType = viewBinding.trackEditActivityType.getText().toString(); + if (movingTimeMillis < minTimeMillis) { + ConfirmDeleteDialogFragment.showDialog(getSupportFragmentManager(), trackId); + } else { + viewBinding.trackEditName.setText(track.getName()); + viewBinding.trackEditActivityType.setText(track.getActivityTypeLocalized()); + + ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, ActivityType.getLocalizedStrings(this)); + viewBinding.trackEditActivityType.setAdapter(adapter); + viewBinding.trackEditActivityType.setOnItemClickListener((parent, view, position, id) -> { + String localizedActivityType = (String) viewBinding.trackEditActivityType.getAdapter().getItem(position); setActivityTypeIcon(ActivityType.findByLocalizedString(this, localizedActivityType)); + }); + viewBinding.trackEditActivityType.setOnFocusChangeListener((v, hasFocus) -> { + if (!hasFocus) { + String localizedActivityType = viewBinding.trackEditActivityType.getText().toString(); + setActivityTypeIcon(ActivityType.findByLocalizedString(this, localizedActivityType)); + } + }); + + setActivityTypeIcon(track.getActivityType()); + viewBinding.trackEditActivityTypeIcon.setOnClickListener(v -> ChooseActivityTypeDialogFragment.showDialog(getSupportFragmentManager(), this, viewBinding.trackEditActivityType.getText().toString())); + + viewBinding.trackEditDescription.setText(track.getDescription()); + + viewBinding.time.setText(StringUtils.formatElapsedTime(track.getTrackStatistics().getMovingTime())); + + { + Pair parts = SpeedFormatter.Builder() + .setUnit(PreferencesUtils.getUnitSystem()) + .setReportSpeedOrPace(PreferencesUtils.isReportSpeed(track)) + .build(this) + .getSpeedParts(track.getTrackStatistics().getAverageMovingSpeed()); + viewBinding.speed.setText(parts.first); + viewBinding.speedUnit.setText(parts.second); } - }); - setActivityTypeIcon(track.getActivityType()); - viewBinding.trackEditActivityTypeIcon.setOnClickListener(v -> ChooseActivityTypeDialogFragment.showDialog(getSupportFragmentManager(), this, viewBinding.trackEditActivityType.getText().toString())); + { + Pair parts = DistanceFormatter.Builder() + .setUnit(PreferencesUtils.getUnitSystem()) + .build(this) + .getDistanceParts(track.getTrackStatistics().getTotalDistance()); + viewBinding.distance.setText(parts.first); + viewBinding.distanceUnit.setText(parts.second); + } - viewBinding.trackEditDescription.setText(track.getDescription()); + viewBinding.finishButton.setOnClickListener(v -> { + storeTrackMetaData(contentProviderUtils, track); + ExportUtils.postWorkoutExport(this, trackId); + finish(); + }); - viewBinding.time.setText(StringUtils.formatElapsedTime(track.getTrackStatistics().getMovingTime())); + viewBinding.resumeButton.setOnClickListener(v -> { + storeTrackMetaData(contentProviderUtils, track); + resumeTrackAndFinish(); + }); - { - Pair parts = SpeedFormatter.Builder() - .setUnit(PreferencesUtils.getUnitSystem()) - .setReportSpeedOrPace(PreferencesUtils.isReportSpeed(track)) - .build(this) - .getSpeedParts(track.getTrackStatistics().getAverageMovingSpeed()); - viewBinding.speed.setText(parts.first); - viewBinding.speedUnit.setText(parts.second); + viewBinding.discardButton.setOnClickListener(v -> ConfirmDeleteDialogFragment.showDialog(getSupportFragmentManager(), trackId)); } + } - { - Pair parts = DistanceFormatter.Builder() - .setUnit(PreferencesUtils.getUnitSystem()) - .build(this) - .getDistanceParts(track.getTrackStatistics().getTotalDistance()); - viewBinding.distance.setText(parts.first); - viewBinding.distanceUnit.setText(parts.second); + private int convertTimeUnitToMillis(int selectedTimeUnitId) { + int minTimeMillis; + if (selectedTimeUnitId == R.string.stats_time_unit_five) { + minTimeMillis = 5 * 1000; // 5 seconds + } else if (selectedTimeUnitId == R.string.stats_time_unit_ten) { + minTimeMillis = 10 * 1000; // 10 seconds + } else if (selectedTimeUnitId == R.string.stats_time_unit_fifteen) { + minTimeMillis = 15 * 1000; // 15 seconds + } else { + minTimeMillis = 0; // Default or custom case } - - viewBinding.finishButton.setOnClickListener(v -> { -// if(track.getTrackStatistics().getTotalTime() < statsTime) - storeTrackMetaData(contentProviderUtils, track); - ExportUtils.postWorkoutExport(this, trackId); - finish(); - }); - - viewBinding.resumeButton.setOnClickListener(v -> { - storeTrackMetaData(contentProviderUtils, track); - resumeTrackAndFinish(); - }); - - viewBinding.discardButton.setOnClickListener(v -> ConfirmDeleteDialogFragment.showDialog(getSupportFragmentManager(), trackId)); + return minTimeMillis; } private void storeTrackMetaData(ContentProviderUtils contentProviderUtils, Track track) { diff --git a/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java b/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java index ae74aee57..4c85fa553 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java +++ b/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java @@ -6,6 +6,7 @@ import androidx.fragment.app.DialogFragment; import androidx.preference.ListPreference; import androidx.preference.Preference; +import android.content.Context; import androidx.preference.PreferenceFragmentCompat; import de.dennisguse.opentracks.R; @@ -69,6 +70,12 @@ public void onDisplayPreferenceDialog(Preference preference) { private void updateTimeUnits() { //Acquire time units from Preferences TimeUnitSystem time = PreferencesUtils.getTimeUnit(); + SharedPreferences preferences = getContext().getSharedPreferences("default_time_unit", Context.MODE_PRIVATE); + SharedPreferences.Editor editor = preferences.edit(); + + editor.putInt(getString(R.string.stats_time_units_key), time.getPreferenceId()); + editor.apply(); + ListPreference statsTimePreferences = findPreference((getString(R.string.stats_time_units_key))); int entriesID = switch (time) { diff --git a/src/main/res/values/settings.xml b/src/main/res/values/settings.xml index 3c2f89bee..1498abb7f 100644 --- a/src/main/res/values/settings.xml +++ b/src/main/res/values/settings.xml @@ -170,7 +170,7 @@ timeUnits - @string/settings_stats_time_unit_five + @string/settings_stats_time_unit_ten @string/stats_time_unit_five @string/stats_time_unit_ten From ddd73b6a6478c7b91fb2c35341b6def6ee87eeaf Mon Sep 17 00:00:00 2001 From: eehamkhan Date: Sun, 7 Apr 2024 13:27:46 -0400 Subject: [PATCH 22/32] Fixed small bug, changed stats_time_unit_fifteen to stats_time_unit_twenty. Program now runs. --- .../java/de/dennisguse/opentracks/TrackStoppedActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java b/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java index 83d7a1d2c..695dd58a8 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java @@ -124,7 +124,7 @@ private int convertTimeUnitToMillis(int selectedTimeUnitId) { minTimeMillis = 5 * 1000; // 5 seconds } else if (selectedTimeUnitId == R.string.stats_time_unit_ten) { minTimeMillis = 10 * 1000; // 10 seconds - } else if (selectedTimeUnitId == R.string.stats_time_unit_fifteen) { + } else if (selectedTimeUnitId == R.string.stats_time_unit_twenty) { minTimeMillis = 15 * 1000; // 15 seconds } else { minTimeMillis = 0; // Default or custom case From a51735bfd77374e878703e8175c4b334c70fb5d5 Mon Sep 17 00:00:00 2001 From: eehamkhan Date: Sun, 7 Apr 2024 13:37:52 -0400 Subject: [PATCH 23/32] Implemented logic to get the user selection for minimum duration and turn it into an int. Comparison is then made with the total time of the track. --- .../dennisguse/opentracks/TrackStoppedActivity.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java b/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java index 695dd58a8..6f9b2fdf3 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java @@ -9,6 +9,8 @@ import android.view.View; import android.widget.ArrayAdapter; +import androidx.preference.ListPreference; + import java.time.Duration; import de.dennisguse.opentracks.data.ContentProviderUtils; @@ -37,6 +39,7 @@ public class TrackStoppedActivity extends AbstractTrackDeleteActivity implements private Track.Id trackId; private boolean isDiscarding = false; + public ListPreference statsTimePreferences; @Override protected void onCreate(Bundle savedInstanceState) { @@ -103,7 +106,16 @@ protected void onCreate(Bundle savedInstanceState) { viewBinding.distanceUnit.setText(parts.second); } + String time_setting = getString(R.string.stats_time_units_key); + String[] parts = time_setting.split("\\s+"); + String firstPart = parts[0]; + int time_key = Integer.parseInt(firstPart); + viewBinding.finishButton.setOnClickListener(v -> { + long totalTimeSeconds = track.getTrackStatistics().getTotalTime().getSeconds(); + if(totalTimeSeconds < time_key) { + // TODO implement logic to discard + } storeTrackMetaData(contentProviderUtils, track); ExportUtils.postWorkoutExport(this, trackId); finish(); From 4e28b180f08fadc3ce714645ea49664c81bfa71c Mon Sep 17 00:00:00 2001 From: Robertmotax1 Date: Sun, 7 Apr 2024 15:19:20 -0400 Subject: [PATCH 24/32] minor changes --- .../settings/DefaultsSettingsFragment.java | 15 ++++++++++----- .../opentracks/settings/TimeUnitSystem.java | 4 ++-- src/main/res/values/settings.xml | 1 + 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java b/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java index 4c85fa553..bab78ce8a 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java +++ b/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java @@ -22,6 +22,10 @@ public class DefaultsSettingsFragment extends PreferenceFragmentCompat implement if (PreferencesUtils.isKey(R.string.stats_units_key, key)) { getActivity().runOnUiThread(this::updateUnits); } + + if (PreferencesUtils.isKey(R.string.stats_time_units_key, key)) { + getActivity().runOnUiThread(this::updateTimeUnits); + } }; @Override @@ -47,6 +51,7 @@ public void onResume() { public void onPause() { super.onPause(); PreferencesUtils.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener); + } @Override @@ -70,11 +75,11 @@ public void onDisplayPreferenceDialog(Preference preference) { private void updateTimeUnits() { //Acquire time units from Preferences TimeUnitSystem time = PreferencesUtils.getTimeUnit(); - SharedPreferences preferences = getContext().getSharedPreferences("default_time_unit", Context.MODE_PRIVATE); - SharedPreferences.Editor editor = preferences.edit(); - - editor.putInt(getString(R.string.stats_time_units_key), time.getPreferenceId()); - editor.apply(); +// SharedPreferences preferences = getContext().getSharedPreferences("default_time_unit", Context.MODE_PRIVATE); +// SharedPreferences.Editor editor = preferences.edit(); +// +// editor.putInt(getString(R.string.stats_time_units_key), time.getPreferenceId()); +// editor.apply(); ListPreference statsTimePreferences = findPreference((getString(R.string.stats_time_units_key))); diff --git a/src/main/java/de/dennisguse/opentracks/settings/TimeUnitSystem.java b/src/main/java/de/dennisguse/opentracks/settings/TimeUnitSystem.java index 609df3247..0bfa18376 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/TimeUnitSystem.java +++ b/src/main/java/de/dennisguse/opentracks/settings/TimeUnitSystem.java @@ -8,7 +8,7 @@ public enum TimeUnitSystem { TEN_SEC(R.string.stats_time_unit_ten), TWENTY_SEC(R.string.stats_time_unit_twenty), - CUSTOM(R.string.stats_time_unit_custom); // Nautical miles with feet + CUSTOM(R.string.stats_time_unit_custom); private final int preference; @@ -22,6 +22,6 @@ public int getPreferenceId() { @Deprecated //TODO used to initialize before loading from preferences; should be loaded first public static TimeUnitSystem defaultUnitSystem() { - return FIVE_SEC; + return TEN_SEC; } } diff --git a/src/main/res/values/settings.xml b/src/main/res/values/settings.xml index 1498abb7f..8b1702f07 100644 --- a/src/main/res/values/settings.xml +++ b/src/main/res/values/settings.xml @@ -170,6 +170,7 @@ timeUnits + timeUnits @string/settings_stats_time_unit_ten @string/stats_time_unit_five From 1afc069fbe6d152f57149471e042884d63266cd8 Mon Sep 17 00:00:00 2001 From: eehamkhan Date: Sun, 7 Apr 2024 15:34:47 -0400 Subject: [PATCH 25/32] Made the user selection for time save. Fixed implementation for getting user selection and comparing to total track time. --- .../opentracks/TrackRecordingActivity.java | 10 ++ .../opentracks/TrackStoppedActivity.java | 153 ++++++++---------- .../settings/DefaultsSettingsFragment.java | 3 + 3 files changed, 83 insertions(+), 83 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java b/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java index 5930f6df7..904e3b9a6 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java @@ -76,6 +76,8 @@ public class TrackRecordingActivity extends AbstractActivity implements ChooseAc private RecordingStatus recordingStatus = TrackRecordingService.STATUS_DEFAULT; + public Track track; + private final TrackRecordingServiceConnection.Callback bindChangedCallback = (service, unused) -> { service.getRecordingStatusObservable() .observe(TrackRecordingActivity.this, this::onRecordingStatusChanged); @@ -142,6 +144,14 @@ protected void onCreate(Bundle savedInstanceState) { viewBinding.trackRecordingFabAction.setOnClickListener((view) -> { ActivityUtils.vibrate(this, 200); trackRecordingServiceConnection.stopRecording(TrackRecordingActivity.this); + String time_setting = getString(R.string.stats_time_units_key); + String[] parts = time_setting.split("\\s+"); + String firstPart = parts[0]; +// int time_key = Integer.parseInt(firstPart); +// long totalTimeSeconds = track.getTrackStatistics().getTotalTime().getSeconds(); +// if(totalTimeSeconds < time_key) { +// Log.i("HELLO", "HELLO"); +// } Intent newIntent = IntentUtils.newIntent(TrackRecordingActivity.this, TrackStoppedActivity.class) .putExtra(TrackStoppedActivity.EXTRA_TRACK_ID, trackId); startActivity(newIntent); diff --git a/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java b/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java index 6f9b2fdf3..0773c8ae0 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java @@ -1,18 +1,15 @@ package de.dennisguse.opentracks; -import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.os.Bundle; import android.util.Log; import android.util.Pair; import android.view.View; import android.widget.ArrayAdapter; +import android.widget.Toast; import androidx.preference.ListPreference; -import java.time.Duration; - import de.dennisguse.opentracks.data.ContentProviderUtils; import de.dennisguse.opentracks.data.models.ActivityType; import de.dennisguse.opentracks.data.models.DistanceFormatter; @@ -22,6 +19,8 @@ import de.dennisguse.opentracks.fragments.ChooseActivityTypeDialogFragment; import de.dennisguse.opentracks.services.TrackRecordingServiceConnection; import de.dennisguse.opentracks.settings.PreferencesUtils; +import de.dennisguse.opentracks.settings.TimeUnitSystem; +import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.ui.aggregatedStatistics.ConfirmDeleteDialogFragment; import de.dennisguse.opentracks.util.ExportUtils; import de.dennisguse.opentracks.util.IntentUtils; @@ -39,6 +38,7 @@ public class TrackStoppedActivity extends AbstractTrackDeleteActivity implements private Track.Id trackId; private boolean isDiscarding = false; + public ListPreference statsTimePreferences; @Override @@ -54,94 +54,69 @@ protected void onCreate(Bundle savedInstanceState) { ContentProviderUtils contentProviderUtils = new ContentProviderUtils(this); Track track = contentProviderUtils.getTrack(trackId); - SharedPreferences preferences = this.getSharedPreferences("default_time_unit", Context.MODE_PRIVATE); - int selectedTimeUnitId = preferences.getInt(getString(R.string.stats_time_units_key), R.string.stats_time_default); - int minTimeMillis = convertTimeUnitToMillis(selectedTimeUnitId); - - Duration movingTime = track.getTrackStatistics().getMovingTime(); - long movingTimeMillis = movingTime.toMillis(); + viewBinding.trackEditName.setText(track.getName()); - if (movingTimeMillis < minTimeMillis) { - ConfirmDeleteDialogFragment.showDialog(getSupportFragmentManager(), trackId); - } else { - viewBinding.trackEditName.setText(track.getName()); - viewBinding.trackEditActivityType.setText(track.getActivityTypeLocalized()); + viewBinding.trackEditActivityType.setText(track.getActivityTypeLocalized()); - ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, ActivityType.getLocalizedStrings(this)); - viewBinding.trackEditActivityType.setAdapter(adapter); - viewBinding.trackEditActivityType.setOnItemClickListener((parent, view, position, id) -> { - String localizedActivityType = (String) viewBinding.trackEditActivityType.getAdapter().getItem(position); + ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, ActivityType.getLocalizedStrings(this)); + viewBinding.trackEditActivityType.setAdapter(adapter); + viewBinding.trackEditActivityType.setOnItemClickListener((parent, view, position, id) -> { + String localizedActivityType = (String) viewBinding.trackEditActivityType.getAdapter().getItem(position); + setActivityTypeIcon(ActivityType.findByLocalizedString(this, localizedActivityType)); + }); + viewBinding.trackEditActivityType.setOnFocusChangeListener((v, hasFocus) -> { + if (!hasFocus) { + String localizedActivityType = viewBinding.trackEditActivityType.getText().toString(); setActivityTypeIcon(ActivityType.findByLocalizedString(this, localizedActivityType)); - }); - viewBinding.trackEditActivityType.setOnFocusChangeListener((v, hasFocus) -> { - if (!hasFocus) { - String localizedActivityType = viewBinding.trackEditActivityType.getText().toString(); - setActivityTypeIcon(ActivityType.findByLocalizedString(this, localizedActivityType)); - } - }); - - setActivityTypeIcon(track.getActivityType()); - viewBinding.trackEditActivityTypeIcon.setOnClickListener(v -> ChooseActivityTypeDialogFragment.showDialog(getSupportFragmentManager(), this, viewBinding.trackEditActivityType.getText().toString())); - - viewBinding.trackEditDescription.setText(track.getDescription()); - - viewBinding.time.setText(StringUtils.formatElapsedTime(track.getTrackStatistics().getMovingTime())); - - { - Pair parts = SpeedFormatter.Builder() - .setUnit(PreferencesUtils.getUnitSystem()) - .setReportSpeedOrPace(PreferencesUtils.isReportSpeed(track)) - .build(this) - .getSpeedParts(track.getTrackStatistics().getAverageMovingSpeed()); - viewBinding.speed.setText(parts.first); - viewBinding.speedUnit.setText(parts.second); } + }); - { - Pair parts = DistanceFormatter.Builder() - .setUnit(PreferencesUtils.getUnitSystem()) - .build(this) - .getDistanceParts(track.getTrackStatistics().getTotalDistance()); - viewBinding.distance.setText(parts.first); - viewBinding.distanceUnit.setText(parts.second); - } + setActivityTypeIcon(track.getActivityType()); + viewBinding.trackEditActivityTypeIcon.setOnClickListener(v -> ChooseActivityTypeDialogFragment.showDialog(getSupportFragmentManager(), this, viewBinding.trackEditActivityType.getText().toString())); - String time_setting = getString(R.string.stats_time_units_key); - String[] parts = time_setting.split("\\s+"); - String firstPart = parts[0]; - int time_key = Integer.parseInt(firstPart); - - viewBinding.finishButton.setOnClickListener(v -> { - long totalTimeSeconds = track.getTrackStatistics().getTotalTime().getSeconds(); - if(totalTimeSeconds < time_key) { - // TODO implement logic to discard - } - storeTrackMetaData(contentProviderUtils, track); - ExportUtils.postWorkoutExport(this, trackId); - finish(); - }); - - viewBinding.resumeButton.setOnClickListener(v -> { - storeTrackMetaData(contentProviderUtils, track); - resumeTrackAndFinish(); - }); - - viewBinding.discardButton.setOnClickListener(v -> ConfirmDeleteDialogFragment.showDialog(getSupportFragmentManager(), trackId)); + viewBinding.trackEditDescription.setText(track.getDescription()); + + viewBinding.time.setText(StringUtils.formatElapsedTime(track.getTrackStatistics().getMovingTime())); + + { + Pair parts = SpeedFormatter.Builder() + .setUnit(PreferencesUtils.getUnitSystem()) + .setReportSpeedOrPace(PreferencesUtils.isReportSpeed(track)) + .build(this) + .getSpeedParts(track.getTrackStatistics().getAverageMovingSpeed()); + viewBinding.speed.setText(parts.first); + viewBinding.speedUnit.setText(parts.second); } - } - private int convertTimeUnitToMillis(int selectedTimeUnitId) { - int minTimeMillis; - if (selectedTimeUnitId == R.string.stats_time_unit_five) { - minTimeMillis = 5 * 1000; // 5 seconds - } else if (selectedTimeUnitId == R.string.stats_time_unit_ten) { - minTimeMillis = 10 * 1000; // 10 seconds - } else if (selectedTimeUnitId == R.string.stats_time_unit_twenty) { - minTimeMillis = 15 * 1000; // 15 seconds - } else { - minTimeMillis = 0; // Default or custom case + { + Pair parts = DistanceFormatter.Builder() + .setUnit(PreferencesUtils.getUnitSystem()) + .build(this) + .getDistanceParts(track.getTrackStatistics().getTotalDistance()); + viewBinding.distance.setText(parts.first); + viewBinding.distanceUnit.setText(parts.second); } - return minTimeMillis; + + viewBinding.finishButton.setOnClickListener(v -> { + String time_setting = getString(R.string.stats_time_units_key); + TimeUnitSystem timeUnitSystem = PreferencesUtils.getTimeUnit(); + String[] parts = timeUnitSystem.toString().split("_"); + int time_key = convertInt(parts[0]); + long totalTimeSeconds = track.getTrackStatistics().getTotalTime().getSeconds(); + if(totalTimeSeconds < time_key) { + // TODO implement delete track + } + storeTrackMetaData(contentProviderUtils, track); + ExportUtils.postWorkoutExport(this, trackId); + finish(); + }); + + viewBinding.resumeButton.setOnClickListener(v -> { + storeTrackMetaData(contentProviderUtils, track); + resumeTrackAndFinish(); + }); + + viewBinding.discardButton.setOnClickListener(v -> ConfirmDeleteDialogFragment.showDialog(getSupportFragmentManager(), trackId)); } private void storeTrackMetaData(ContentProviderUtils contentProviderUtils, Track track) { @@ -150,6 +125,18 @@ private void storeTrackMetaData(ContentProviderUtils contentProviderUtils, Track contentProviderUtils); } + public int convertInt(String s) { + int val = 0; + if (s.equals("FIVE")) { + val = 5; + } else if (s.equals("TEN")) { + val = 10; + } else if (s.equals("TWENTY")) { + val = 20; + } + return val; + } + @Override public void onBackPressed() { if (isDiscarding) { diff --git a/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java b/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java index 4c85fa553..72b0bedc6 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java +++ b/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java @@ -22,6 +22,9 @@ public class DefaultsSettingsFragment extends PreferenceFragmentCompat implement if (PreferencesUtils.isKey(R.string.stats_units_key, key)) { getActivity().runOnUiThread(this::updateUnits); } + if (PreferencesUtils.isKey(R.string.stats_time_units_key, key)) { + getActivity().runOnUiThread(this::updateTimeUnits); + } }; @Override From 6aecfdd2677e0cfe7bcb6b5684e53add3e4b2e57 Mon Sep 17 00:00:00 2001 From: eehamkhan Date: Sun, 7 Apr 2024 15:42:39 -0400 Subject: [PATCH 26/32] Finished implementing the auto delete function depending on user input. --- .../java/de/dennisguse/opentracks/TrackStoppedActivity.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java b/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java index 0773c8ae0..ade8543ec 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java @@ -17,6 +17,7 @@ import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.databinding.TrackStoppedBinding; import de.dennisguse.opentracks.fragments.ChooseActivityTypeDialogFragment; +import de.dennisguse.opentracks.services.TrackDeleteService; import de.dennisguse.opentracks.services.TrackRecordingServiceConnection; import de.dennisguse.opentracks.settings.PreferencesUtils; import de.dennisguse.opentracks.settings.TimeUnitSystem; @@ -104,7 +105,7 @@ protected void onCreate(Bundle savedInstanceState) { int time_key = convertInt(parts[0]); long totalTimeSeconds = track.getTrackStatistics().getTotalTime().getSeconds(); if(totalTimeSeconds < time_key) { - // TODO implement delete track + onConfirmDeleteDone(trackId); } storeTrackMetaData(contentProviderUtils, track); ExportUtils.postWorkoutExport(this, trackId); From 86859b020d5a8c00c2b9c0e3235bebef40be9e09 Mon Sep 17 00:00:00 2001 From: Robertmotax1 Date: Sun, 7 Apr 2024 16:45:57 -0400 Subject: [PATCH 27/32] Add Dialog Text Box --When User selects Customize --- .../settings/DefaultsSettingsFragment.java | 55 +++++++++++++++++++ src/main/res/xml/settings_defaults.xml | 10 ++-- 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java b/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java index 72b0bedc6..58f764284 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java +++ b/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java @@ -1,17 +1,27 @@ package de.dennisguse.opentracks.settings; +import static androidx.preference.PreferenceDialogFragmentCompat.*; + +import android.app.AlertDialog; +import android.content.DialogInterface; import android.content.SharedPreferences; import android.os.Bundle; +import androidx.annotation.NonNull; import androidx.fragment.app.DialogFragment; import androidx.preference.ListPreference; import androidx.preference.Preference; import android.content.Context; +import android.text.InputType; +import android.widget.EditText; + +import androidx.preference.PreferenceDialogFragmentCompat; import androidx.preference.PreferenceFragmentCompat; import de.dennisguse.opentracks.R; import de.dennisguse.opentracks.data.models.ActivityType; import de.dennisguse.opentracks.fragments.ChooseActivityTypeDialogFragment; +import de.dennisguse.opentracks.settings.bluetooth.BluetoothLeSensorPreference; public class DefaultsSettingsFragment extends PreferenceFragmentCompat implements ChooseActivityTypeDialogFragment.ChooseActivityTypeCaller { @@ -27,9 +37,29 @@ public class DefaultsSettingsFragment extends PreferenceFragmentCompat implement } }; + + private String custom_time; //use for CUSTOM + @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(R.xml.settings_defaults); + + ListPreference statsTimeUnitsPreference = findPreference(getString(R.string.stats_time_units_key)); + + // Set up the listener + statsTimeUnitsPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(@NonNull Preference preference, Object newValue) { + if (newValue.equals("CUSTOM")) { + displayCustomInputDialog(); + // Preventthe default behavior of the ListPreference + return false; + } else { + //Allow the ListPreference to handle the change + return true; + } + } + }); } @Override @@ -116,4 +146,29 @@ public void onChooseActivityTypeDone(ActivityType activityType) { activityPreferenceDialog.updateUI(activityType); } } + + + + + //Custom Dialog + protected void displayCustomInputDialog() { + // Show dialog box for custom input + AlertDialog.Builder builder = new AlertDialog.Builder(requireContext()); + builder.setTitle("Custom Time Unit"); + + // Set the edit text box for user to enter + final EditText cus_Input = new EditText(requireContext()); + //cus_Input.setInputType(InputType.TYPE_CLASS_NUMBER); //make sure it's a number + + builder.setView(cus_Input); + + //Buttons cancel or just say ok + builder.setPositiveButton("OK", (dialog, which) -> { + custom_time = cus_Input.getText().toString(); + }); + builder.setNegativeButton("Cancel", (dialog, which) -> dialog.cancel()); + + //show final result + builder.show(); + } } diff --git a/src/main/res/xml/settings_defaults.xml b/src/main/res/xml/settings_defaults.xml index f2b507a4e..bbaf1dd53 100644 --- a/src/main/res/xml/settings_defaults.xml +++ b/src/main/res/xml/settings_defaults.xml @@ -28,11 +28,11 @@ android:title="@string/settings_stats_time_unit" app:useSimpleSummaryProvider="true" /> - + + + + + From fcd3c76d92f329e560658d969d92f36d59ebe546 Mon Sep 17 00:00:00 2001 From: eehamkhan Date: Sun, 7 Apr 2024 17:14:04 -0400 Subject: [PATCH 28/32] The last set custom time will be saved in the dialog box when user selects Custom again. --- .../settings/DefaultsSettingsFragment.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java b/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java index 58f764284..2c6b0d3b5 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java +++ b/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java @@ -17,6 +17,7 @@ import androidx.preference.PreferenceDialogFragmentCompat; import androidx.preference.PreferenceFragmentCompat; +import androidx.preference.PreferenceManager; import de.dennisguse.opentracks.R; import de.dennisguse.opentracks.data.models.ActivityType; @@ -38,7 +39,7 @@ public class DefaultsSettingsFragment extends PreferenceFragmentCompat implement }; - private String custom_time; //use for CUSTOM + private String custom_time; @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { @@ -46,13 +47,16 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { ListPreference statsTimeUnitsPreference = findPreference(getString(R.string.stats_time_units_key)); + custom_time = PreferenceManager.getDefaultSharedPreferences(requireContext()) + .getString("custom_time_unit", null); + // Set up the listener statsTimeUnitsPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(@NonNull Preference preference, Object newValue) { if (newValue.equals("CUSTOM")) { displayCustomInputDialog(); - // Preventthe default behavior of the ListPreference + // Prevent the default behavior of the ListPreference return false; } else { //Allow the ListPreference to handle the change @@ -164,11 +168,22 @@ protected void displayCustomInputDialog() { //Buttons cancel or just say ok builder.setPositiveButton("OK", (dialog, which) -> { + // Store the custom value custom_time = cus_Input.getText().toString(); + saveCustomTimeUnit(custom_time); // Call the method to persist the value }); + + if (custom_time != null) { + cus_Input.setText(custom_time); + } builder.setNegativeButton("Cancel", (dialog, which) -> dialog.cancel()); //show final result builder.show(); } + + private void saveCustomTimeUnit(String value) { + SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(requireContext()); + sharedPref.edit().putString("custom_time_unit", value).apply(); + } } From e41965cc2c711dadd77530a7553eaea5ccde57ef Mon Sep 17 00:00:00 2001 From: eehamkhan Date: Sun, 7 Apr 2024 17:32:15 -0400 Subject: [PATCH 29/32] Implemented logic for the custom time to be sent to the TrackStoppedActivity file. --- .../opentracks/TrackStoppedActivity.java | 22 ++++++++++++++----- .../settings/DefaultsSettingsFragment.java | 4 +--- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java b/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java index ade8543ec..7497b60a6 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java @@ -19,6 +19,7 @@ import de.dennisguse.opentracks.fragments.ChooseActivityTypeDialogFragment; import de.dennisguse.opentracks.services.TrackDeleteService; import de.dennisguse.opentracks.services.TrackRecordingServiceConnection; +import de.dennisguse.opentracks.settings.DefaultsSettingsFragment; import de.dennisguse.opentracks.settings.PreferencesUtils; import de.dennisguse.opentracks.settings.TimeUnitSystem; import de.dennisguse.opentracks.stats.TrackStatistics; @@ -41,6 +42,7 @@ public class TrackStoppedActivity extends AbstractTrackDeleteActivity implements private boolean isDiscarding = false; public ListPreference statsTimePreferences; + public DefaultsSettingsFragment dfs; @Override protected void onCreate(Bundle savedInstanceState) { @@ -101,11 +103,21 @@ protected void onCreate(Bundle savedInstanceState) { viewBinding.finishButton.setOnClickListener(v -> { String time_setting = getString(R.string.stats_time_units_key); TimeUnitSystem timeUnitSystem = PreferencesUtils.getTimeUnit(); - String[] parts = timeUnitSystem.toString().split("_"); - int time_key = convertInt(parts[0]); - long totalTimeSeconds = track.getTrackStatistics().getTotalTime().getSeconds(); - if(totalTimeSeconds < time_key) { - onConfirmDeleteDone(trackId); + Log.i(timeUnitSystem.toString(), timeUnitSystem.toString()); + if (time_setting.equals("CUSTOM")) { + Log.i(dfs.custom_time, dfs.custom_time); + int time_key = Integer.parseInt(dfs.custom_time); + long totalTimeSeconds = track.getTrackStatistics().getTotalTime().getSeconds(); + if(totalTimeSeconds < time_key) { + onConfirmDeleteDone(trackId); + } + } else { + String[] parts = timeUnitSystem.toString().split("_"); + int time_key = convertInt(parts[0]); + long totalTimeSeconds = track.getTrackStatistics().getTotalTime().getSeconds(); + if (totalTimeSeconds < time_key) { + onConfirmDeleteDone(trackId); + } } storeTrackMetaData(contentProviderUtils, track); ExportUtils.postWorkoutExport(this, trackId); diff --git a/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java b/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java index 2c6b0d3b5..ff09524ac 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java +++ b/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java @@ -39,7 +39,7 @@ public class DefaultsSettingsFragment extends PreferenceFragmentCompat implement }; - private String custom_time; + public String custom_time; @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { @@ -152,8 +152,6 @@ public void onChooseActivityTypeDone(ActivityType activityType) { } - - //Custom Dialog protected void displayCustomInputDialog() { // Show dialog box for custom input From 1a7cd5f39c8bad58e6a7ffd1595b68063c6c1b33 Mon Sep 17 00:00:00 2001 From: XeqtR0 <98060587+XeqtR0@users.noreply.github.com> Date: Mon, 8 Apr 2024 00:49:59 -0400 Subject: [PATCH 30/32] Display "Customize" is selected when user clicked --- .../opentracks/settings/DefaultsSettingsFragment.java | 9 ++++----- src/main/res/values/strings.xml | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java b/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java index ff09524ac..257208cad 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java +++ b/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java @@ -56,12 +56,11 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { public boolean onPreferenceChange(@NonNull Preference preference, Object newValue) { if (newValue.equals("CUSTOM")) { displayCustomInputDialog(); - // Prevent the default behavior of the ListPreference - return false; - } else { - //Allow the ListPreference to handle the change - return true; + // Update the displayed value of the ListPreference + ((ListPreference) preference).setValue(newValue.toString()); } + // Allow the ListPreference to handle the change + return true; } }); } diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index df7d9f18d..8059295cf 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -364,7 +364,7 @@ limitations under the License. All About OpenTracks Project Default Units and Activity - Preferred Units, Default Activity, Track Default Name + Preferred Units, Default Activity, Track Default Name, Preferred Minimum Time User Interface Appearance, Recording Layout, Theme From 77fa34f3bb6de3de640c395bbfb53dd4a1ecb496 Mon Sep 17 00:00:00 2001 From: c-eric <43305167+c-eric@users.noreply.github.com> Date: Mon, 8 Apr 2024 20:22:58 -0400 Subject: [PATCH 31/32] Fix custom time Resolved an issue where a track could not be deleted because the set customized time in "Preferred minimum time" always returned a null value --- .../opentracks/TrackStoppedActivity.java | 19 ++++++++++++++----- .../settings/DefaultsSettingsFragment.java | 2 ++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java b/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java index 7497b60a6..181ae9922 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java @@ -28,6 +28,7 @@ import de.dennisguse.opentracks.util.IntentUtils; import de.dennisguse.opentracks.util.StringUtils; import de.dennisguse.opentracks.util.TrackUtils; +import androidx.preference.PreferenceManager; public class TrackStoppedActivity extends AbstractTrackDeleteActivity implements ChooseActivityTypeDialogFragment.ChooseActivityTypeCaller { @@ -44,6 +45,11 @@ public class TrackStoppedActivity extends AbstractTrackDeleteActivity implements public ListPreference statsTimePreferences; public DefaultsSettingsFragment dfs; + private String getCustomTime() { + return PreferenceManager.getDefaultSharedPreferences(this) + .getString("custom_time_unit", null); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -101,14 +107,17 @@ protected void onCreate(Bundle savedInstanceState) { } viewBinding.finishButton.setOnClickListener(v -> { - String time_setting = getString(R.string.stats_time_units_key); TimeUnitSystem timeUnitSystem = PreferencesUtils.getTimeUnit(); - Log.i(timeUnitSystem.toString(), timeUnitSystem.toString()); - if (time_setting.equals("CUSTOM")) { - Log.i(dfs.custom_time, dfs.custom_time); - int time_key = Integer.parseInt(dfs.custom_time); + Log.i("timeUnitSystem", timeUnitSystem.toString()); + + String customTime = getCustomTime(); + System.out.println("CustomTime value: " + customTime); + if (customTime != null) { + System.out.println("Custom time valid"); + int time_key = Integer.parseInt(customTime); long totalTimeSeconds = track.getTrackStatistics().getTotalTime().getSeconds(); if(totalTimeSeconds < time_key) { + System.out.println("Track deleted"); onConfirmDeleteDone(trackId); } } else { diff --git a/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java b/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java index 257208cad..aa4d648a3 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java +++ b/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java @@ -182,5 +182,7 @@ protected void displayCustomInputDialog() { private void saveCustomTimeUnit(String value) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(requireContext()); sharedPref.edit().putString("custom_time_unit", value).apply(); + custom_time = value; + System.out.println("Custom Time set to: " + value); } } From 67d54fa749327e7309c291923c4301249a3a3fb2 Mon Sep 17 00:00:00 2001 From: c-eric <43305167+c-eric@users.noreply.github.com> Date: Mon, 8 Apr 2024 21:30:33 -0400 Subject: [PATCH 32/32] Minor changes --- .../java/de/dennisguse/opentracks/TrackStoppedActivity.java | 6 +----- .../opentracks/settings/DefaultsSettingsFragment.java | 6 ++++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java b/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java index 181ae9922..f4ce0047b 100644 --- a/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java +++ b/src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java @@ -45,10 +45,6 @@ public class TrackStoppedActivity extends AbstractTrackDeleteActivity implements public ListPreference statsTimePreferences; public DefaultsSettingsFragment dfs; - private String getCustomTime() { - return PreferenceManager.getDefaultSharedPreferences(this) - .getString("custom_time_unit", null); - } @Override protected void onCreate(Bundle savedInstanceState) { @@ -110,7 +106,7 @@ protected void onCreate(Bundle savedInstanceState) { TimeUnitSystem timeUnitSystem = PreferencesUtils.getTimeUnit(); Log.i("timeUnitSystem", timeUnitSystem.toString()); - String customTime = getCustomTime(); + String customTime = DefaultsSettingsFragment.getCustomTime(this); System.out.println("CustomTime value: " + customTime); if (customTime != null) { System.out.println("Custom time valid"); diff --git a/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java b/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java index aa4d648a3..c9c4001a1 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java +++ b/src/main/java/de/dennisguse/opentracks/settings/DefaultsSettingsFragment.java @@ -185,4 +185,10 @@ private void saveCustomTimeUnit(String value) { custom_time = value; System.out.println("Custom Time set to: " + value); } + + public static String getCustomTime(Context context) { + System.out.println("getCustomTime called in DefaultsSettingsFragment"); + return PreferenceManager.getDefaultSharedPreferences(context) + .getString("custom_time_unit", null); + } }