Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Group 1: Sprint 3 #191

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
68a2575
Stop recording immediately
XeqtR0 Mar 19, 2024
5bbb6b4
Modified ImageView to MaterialDesign as per TODO comment
e3ham Mar 22, 2024
c35da4b
Merge remote-tracking branch 'origin/main'
e3ham Mar 22, 2024
27c9ba5
Integrated pause button in the recording screen
e3ham Mar 23, 2024
d99788d
Implemented pause functionality for Moving Time, Distance, and Speed.
e3ham Mar 23, 2024
a114144
Removed the stopSensors() method when pausing, as it did not allow th…
e3ham Mar 23, 2024
7c245a6
Integrated a resume button and made it show/disappear when pause/resu…
e3ham Mar 24, 2024
e33d38c
Working on resume functionality, moving time is 4 seconds behind tota…
e3ham Mar 24, 2024
a5d1975
Check if track is null (often causes error when you exit app, then tr…
AevisMotax Mar 25, 2024
a17f24c
Check if track is null (often causes error when you exit app, then tr…
AevisMotax Mar 25, 2024
80341e6
trying to add stop and start button
AevisMotax Mar 25, 2024
d16180a
minor changes to add/stop button
AevisMotax Mar 25, 2024
fe96bb5
unsure, but another prevent nullPointer
AevisMotax Mar 25, 2024
87f02ca
save migrations
Mar 26, 2024
c586dde
Merge branch 'main' into main
kevinqtra Mar 26, 2024
ab27ed9
Implemented built-in pause method instead of creating a new one.
e3ham Mar 31, 2024
2feb8d8
Modify UI to add 'Preferred minimum time' in Settings
Apr 1, 2024
4a64da1
Started implementing Time Unit System,
AevisMotax Apr 2, 2024
db411c0
Fixed bug in pause where it would keep running in background. Moving …
e3ham Apr 2, 2024
58e465e
Implemented built-in pause method instead of creating a new one.
e3ham Mar 31, 2024
826a6a9
Added EditTextPreference and attempting to connect Default Time Units…
e3ham Apr 2, 2024
09c3d39
Started implementation of the default time units backend logic. Logic…
e3ham Apr 6, 2024
8605b6b
Implemented logic to discard record based on a default minimum time
kevinqtra Apr 7, 2024
ddd73b6
Fixed small bug, changed stats_time_unit_fifteen to stats_time_unit_t…
e3ham Apr 7, 2024
d8bcce0
Merge remote-tracking branch 'origin/defaultUnitTime' into defaultUni…
AevisMotax Apr 7, 2024
a51735b
Implemented logic to get the user selection for minimum duration and …
e3ham Apr 7, 2024
25f02dc
Merge remote-tracking branch 'origin/defaultUnitTime' into defaultUni…
AevisMotax Apr 7, 2024
4e28b18
minor changes
AevisMotax Apr 7, 2024
1afc069
Made the user selection for time save. Fixed implementation for getti…
e3ham Apr 7, 2024
195a0f9
Merge remote-tracking branch 'origin/defaultUnitTime' into defaultUni…
e3ham Apr 7, 2024
6aecfdd
Finished implementing the auto delete function depending on user input.
e3ham Apr 7, 2024
86859b0
Add Dialog Text Box --When User selects Customize
AevisMotax Apr 7, 2024
ef82ea1
Merge remote-tracking branch 'origin/defaultUnitTime' into defaultUni…
AevisMotax Apr 7, 2024
fcd3c76
The last set custom time will be saved in the dialog box when user se…
e3ham Apr 7, 2024
e41965c
Implemented logic for the custom time to be sent to the TrackStoppedA…
e3ham Apr 7, 2024
1a7cd5f
Display "Customize" is selected when user clicked
XeqtR0 Apr 8, 2024
77fa34f
Fix custom time
c-eric Apr 9, 2024
67d54fa
Minor changes
c-eric Apr 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

Expand Down
50 changes: 46 additions & 4 deletions src/main/java/de/dennisguse/opentracks/TrackListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -81,6 +82,8 @@ public class TrackListActivity extends AbstractTrackDeleteActivity implements Co

private TrackListBinding viewBinding;

private TrackRecordingBinding recordingBinding;

// Preferences
private UnitSystem unitSystem = UnitSystem.defaultUnitSystem();

Expand Down Expand Up @@ -150,6 +153,8 @@ protected void onCreate(Bundle savedInstanceState) {

requestRequiredPermissions();

recordingBinding = TrackRecordingBinding.inflate(getLayoutInflater());

recordingStatusConnection = new TrackRecordingServiceConnection(bindChangedCallback);

viewBinding.friendsButton.setOnClickListener((view)->startActivity(IntentUtils.newIntent(this, FriendsActivity.class)));
Expand All @@ -158,6 +163,14 @@ protected void onCreate(Bundle savedInstanceState) {
viewBinding.leaderboardButton.setOnClickListener((view) -> startActivity(IntentUtils.newIntent(this, LeaderboardActivity.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 {
Expand Down Expand Up @@ -191,6 +204,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_button_pause);
return true;
});

viewBinding.trackListFabAction.setOnLongClickListener((view) -> {
if (!recordingStatus.isRecording()) {
return false;
Expand All @@ -200,8 +226,23 @@ 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;
});

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;
});

Expand Down Expand Up @@ -441,8 +482,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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ private void saveSelectedValue(int value) {
@Override
protected void onStart() {
super.onStart();

trackDataHub.start();
}

Expand Down
43 changes: 35 additions & 8 deletions src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -104,7 +106,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
Expand Down Expand Up @@ -132,22 +134,47 @@ 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.setOnLongClickListener((view) -> {
ActivityUtils.vibrate(this, 1000);
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);
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);
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);
viewBinding.trackRecordingPause.setImageResource(R.drawable.ic_baseline_record_pause);
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.resumeRecording(trackId);
viewBinding.trackRecordingPause.setVisibility(View.VISIBLE);
});


setSupportActionBar(viewBinding.bottomAppBar);
}

@Override
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import android.util.Pair;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Toast;

import androidx.preference.ListPreference;

import de.dennisguse.opentracks.data.ContentProviderUtils;
import de.dennisguse.opentracks.data.models.ActivityType;
Expand All @@ -14,13 +17,18 @@
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.DefaultsSettingsFragment;
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;
import de.dennisguse.opentracks.util.StringUtils;
import de.dennisguse.opentracks.util.TrackUtils;
import androidx.preference.PreferenceManager;

public class TrackStoppedActivity extends AbstractTrackDeleteActivity implements ChooseActivityTypeDialogFragment.ChooseActivityTypeCaller {

Expand All @@ -34,6 +42,10 @@ public class TrackStoppedActivity extends AbstractTrackDeleteActivity implements

private boolean isDiscarding = false;

public ListPreference statsTimePreferences;
public DefaultsSettingsFragment dfs;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -91,6 +103,27 @@ protected void onCreate(Bundle savedInstanceState) {
}

viewBinding.finishButton.setOnClickListener(v -> {
TimeUnitSystem timeUnitSystem = PreferencesUtils.getTimeUnit();
Log.i("timeUnitSystem", timeUnitSystem.toString());

String customTime = DefaultsSettingsFragment.getCustomTime(this);
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 {
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);
finish();
Expand All @@ -110,6 +143,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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@
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;
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;
Expand Down Expand Up @@ -138,7 +142,7 @@ public void onDestroyView() {
}

public void loadStatistics() {
if (isResumed()) {
if (isResumed() && getActivity() != null) {
getActivity().runOnUiThread(() -> {
if (isResumed()) {
Track track = contentProviderUtils.getTrack(trackId);
Expand All @@ -164,6 +168,10 @@ public void loadStatistics() {
}
});
}
//add logs
else {
Log.w(TAG, "Activity is null when loading statistics");
}
}

private void loadTrackDescription(@NonNull Track track) {
Expand All @@ -173,6 +181,17 @@ private void loadTrackDescription(@NonNull Track track) {
}

private void updateUI() {

// 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();

requireActivity().finish();
return;
}


TrackStatistics trackStatistics = track.getTrackStatistics();
// Set total distance
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading