Skip to content

Commit

Permalink
Pull Request from Group-6 (#35)
Browse files Browse the repository at this point in the history
# Thanks for your contribution.

## PLEASE REMOVE
To support us in providing a nice (and fast) open-source experience:
1. Verify that the tests are passing
2. Check that the code is properly formatted (using AndroidStudio's
autoformatter)
3. Provide write access to the
[branch](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/allowing-changes-to-a-pull-request-branch-created-from-a-fork)
4. If the PR is not ready for review, please submit it as a
[draft](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests#draft-pull-requests)
## PLEASE REMOVE

**Describe the pull request**
A clear and concise description of what the pull request changes/adds.

**Link to the the issue**
(If available): The link to the issue that this pull request solves.

**License agreement**
By opening this pull request, you are providing your contribution under
the _Apache License 2.0_ (see [LICENSE.md](LICENSE.md)).

**Note: new dependencies/libraries**
Please refrain from introducing new libraries without consulting the
team.
  • Loading branch information
OmniaAlam authored Feb 17, 2024
2 parents 222425f + 23e50cc commit 702866c
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 37 deletions.
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,4 @@ captures/
Appfile
releasePlayStore/*
Gemfile.lock
build.gradle
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.2.1'
classpath 'com.android.tools.build:gradle:8.2.2'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public record RecordingStatus(@Nullable Track.Id trackId) {

static RecordingStatus record(@NonNull Track.Id trackId) {
static RecordingStatus create(@NonNull Track.Id trackId) {
return new RecordingStatus(trackId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import androidx.core.app.JobIntentService;

import java.util.ArrayList;
import java.util.List;

import de.dennisguse.opentracks.data.ContentProviderUtils;
import de.dennisguse.opentracks.data.models.Track;
Expand All @@ -23,10 +24,10 @@ public class TrackDeleteService extends JobIntentService {

private static final String EXTRA_TRACK_IDS = "extra_track_ids";

public static void enqueue(Context context, TrackDeleteResultReceiver receiver, ArrayList<Track.Id> toBeDeleted) {
public static void enqueue(Context context, TrackDeleteResultReceiver receiver, List<Track.Id> toBeDeleted) {
Intent intent = new Intent(context, JobService.class);
intent.putExtra(EXTRA_RECEIVER, receiver);
intent.putParcelableArrayListExtra(EXTRA_TRACK_IDS, toBeDeleted);
intent.putParcelableArrayListExtra(EXTRA_TRACK_IDS, new ArrayList<>(toBeDeleted));
enqueueWork(context, TrackDeleteService.class, JOB_ID, intent);
}

Expand Down Expand Up @@ -54,10 +55,14 @@ public TrackDeleteResultReceiver(Handler handler, @NonNull Receiver receiver) {

@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
switch (resultCode) {
case RESULT_CODE_SUCCESS -> receiver.onDeleteFinished();
default -> throw new RuntimeException("Unknown resultCode.");
}

if(resultCode==RESULT_CODE_SUCCESS){
receiver.onDeleteFinished();
}
else{
throw new IllegalArgumentException("Unknown resultCode.");
}

}

public interface Receiver {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class TrackRecordingManager implements SharedPreferences.OnSharedPreferen

private static final AltitudeCorrectionManager ALTITUDE_CORRECTION_MANAGER = new AltitudeCorrectionManager();

private final Runnable ON_IDLE = this::onIdle;
private final Runnable onIdle = this::onIdle;

private final ContentProviderUtils contentProviderUtils;
private final Context context;
Expand Down Expand Up @@ -71,7 +71,7 @@ public class TrackRecordingManager implements SharedPreferences.OnSharedPreferen
Track.Id startNewTrack() {
TrackPoint segmentStartTrackPoint = trackPointCreator.createSegmentStartManual();

ZoneOffset zoneOffset = ZoneOffset.systemDefault().getRules().getOffset(segmentStartTrackPoint.getTime());
ZoneOffset zoneOffset = java.time.ZoneId.systemDefault().getRules().getOffset(segmentStartTrackPoint.getTime());
Track track = new Track(zoneOffset);
trackId = contentProviderUtils.insertTrack(track);
track.setId(trackId);
Expand Down Expand Up @@ -184,7 +184,7 @@ synchronized boolean onNewTrackPoint(@NonNull TrackPoint trackPoint) {

if (trackPoint.getType() == TrackPoint.Type.IDLE) {
insertTrackPoint(trackPoint, true);
handler.removeCallbacks(ON_IDLE);
handler.removeCallbacks(onIdle);
return true;
}
//Storing trackPoint
Expand Down Expand Up @@ -224,16 +224,16 @@ synchronized boolean onNewTrackPoint(@NonNull TrackPoint trackPoint) {
trackPoint.setType(TrackPoint.Type.SEGMENT_START_AUTOMATIC);
insertTrackPoint(trackPoint, true);

handler.removeCallbacks(ON_IDLE);
handler.postDelayed(ON_IDLE, idleDuration.toMillis());
handler.removeCallbacks(onIdle);
handler.postDelayed(onIdle, idleDuration.toMillis());
return true;
}

if (distanceToLastStoredTrackPoint.greaterOrEqualThan(recordingDistanceInterval)) {
insertTrackPoint(trackPoint, false);

handler.removeCallbacks(ON_IDLE);
handler.postDelayed(ON_IDLE, idleDuration.toMillis());
handler.removeCallbacks(onIdle);
handler.postDelayed(onIdle, idleDuration.toMillis());
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,17 @@ public TrackRecordingService getService() {
private final Runnable updateRecordingData = new Runnable() {
@Override
public void run() {
updateRecordingDataWhileRecording();
if (!isRecording()) {
Log.w(TAG, "Currently not recording; cannot update data.");
return;
}

// Compute temporary track statistics using sensorData and update time.
Pair<Track, Pair<TrackPoint, SensorDataSet>> data = trackRecordingManager.getDataForUI();

voiceAnnouncementManager.announceStatisticsIfNeeded(data.first);

recordingDataObservable.postValue(new RecordingData(data.first, data.second.first, data.second.second));

TrackRecordingService.this.handler.postDelayed(this, RECORDING_DATA_UPDATE_INTERVAL.toMillis());
}
Expand Down Expand Up @@ -169,7 +179,7 @@ public Track.Id startNewTrack() {

// Set recording status
Track.Id trackId = trackRecordingManager.startNewTrack();
updateRecordingStatus(RecordingStatus.record(trackId));
updateRecordingStatus(RecordingStatus.create(trackId));

startRecording();
return trackId;
Expand All @@ -182,7 +192,7 @@ public void resumeTrack(Track.Id trackId) {
}
Log.i(TAG, "resumeTrack");

updateRecordingStatus(RecordingStatus.record(trackId));
updateRecordingStatus(RecordingStatus.create(trackId));

startRecording();
}
Expand Down Expand Up @@ -216,7 +226,7 @@ private synchronized void startSensors() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
if (!PermissionRequester.RECORDING.hasPermission(this)) {
throw new RuntimeException("Android14: Please grant permissions LOCATION and NEARBY DEVICES (manually)");
}

}

ServiceCompat.startForeground(this, TrackRecordingServiceNotificationManager.NOTIFICATION_ID, notificationManager.setGPSonlyStarted(this), ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION + ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE);
Expand Down Expand Up @@ -291,7 +301,7 @@ public TrackPointCreator getTrackPointCreator() {
return trackPointCreator;
}

@Deprecated
@Deprecated(since = "14.0.0", forRemoval = true)
@VisibleForTesting
public TrackRecordingManager getTrackRecordingManager() {
return trackRecordingManager;
Expand All @@ -305,20 +315,6 @@ public LiveData<RecordingData> getRecordingDataObservable() {
return recordingDataObservable;
}

private void updateRecordingDataWhileRecording() {
if (!isRecording()) {
Log.w(TAG, "Currently not recording; cannot update data.");
return;
}

// Compute temporary track statistics using sensorData and update time.
Pair<Track, Pair<TrackPoint, SensorDataSet>> data = trackRecordingManager.getDataForUI();

voiceAnnouncementManager.announceStatisticsIfNeeded(data.first);

recordingDataObservable.postValue(new RecordingData(data.first, data.second.first, data.second.second));
}

public void onIdle() {
voiceAnnouncementManager.announceIdle();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ void writePace(Speed speed, StringBuilder builder, int resId, String lineBreak)
* @param lineBreak line break string
*/
@VisibleForTesting
void writeAltitude(double altitudeM, StringBuilder builder, int resId, String lineBreak) {
long altitudeInM = Math.round(altitudeM);
long altitudeInFt = Math.round(Distance.of(altitudeM).toFT());
void writeAltitude(double altitude_m, StringBuilder builder, int resId, String lineBreak) {
long altitudeInM = Math.round(altitude_m);
long altitudeInFt = Math.round(Distance.of(altitude_m).toFT());
builder.append(context.getString(resId, altitudeInM, altitudeInFt));
builder.append(lineBreak);
}
Expand Down

0 comments on commit 702866c

Please sign in to comment.