Skip to content

Commit

Permalink
Group10 Pull request (#43)
Browse files Browse the repository at this point in the history
Group Folder Paths where code fix applied are :
<ul>
<li> src/main/java/de/dennisguse/opentracks/share</li>
<li> src/main/java/de/dennisguse/opentracks/util</li>
</ul>

Applied changes to remove Technical Debt and Verified the build is
working after the commits
  • Loading branch information
numanSlm authored Feb 16, 2024
2 parents bcaf676 + 9195a69 commit 222425f
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public static Distance ofCM(double distance_cm) {
return of(0.01 * distance_cm);
}

public static Distance ofDM(double distance_dm) {
return of(0.1 * distance_dm);
public static Distance ofDM(double distanceDm) {
return of(0.1 * distanceDm);
}

public static Distance one(UnitSystem unitSystem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,16 @@ void writePace(Speed speed, StringBuilder builder, int resId, String lineBreak)
}

/**
* @param altitude_M altitude_M in meters
* @param altitudeM altitudeM in meters
* @param builder StringBuilder to append
* @param resId resource id of altitude string
* @param lineBreak line break string
*/
@VisibleForTesting
void writeAltitude(double altitude_M, StringBuilder builder, int resId, String lineBreak) {
long altitude_M = Math.round(altitude_M);
long altitudeInFt = Math.round(Distance.of(altitude_M).toFT());
builder.append(context.getString(resId, altitude_M, altitudeInFt));
void writeAltitude(double altitudeM, StringBuilder builder, int resId, String lineBreak) {
long altitudeInM = Math.round(altitudeM);
long altitudeInFt = Math.round(Distance.of(altitudeM).toFT());
builder.append(context.getString(resId, altitudeInM, altitudeInFt));
builder.append(lineBreak);
}
}
23 changes: 15 additions & 8 deletions src/main/java/de/dennisguse/opentracks/share/ShareUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private ShareUtils() {
*/
public static Intent newShareFileIntent(Context context, Track.Id... trackIds) {
if (trackIds.length == 0) {
throw new RuntimeException("Need to share at least one track.");
throw new ShareUtilsException("Need to share at least one track.");
}

ContentProviderUtils contentProviderUtils = new ContentProviderUtils(context);
Expand Down Expand Up @@ -80,27 +80,34 @@ public static Intent newShareFileIntent(Context context, Track.Id... trackIds) {
@Nullable
public static Intent newShareFileIntent(Context context, Marker.Id... markerIds) {
if (markerIds.length == 0) {
throw new RuntimeException("Need to share at least one marker.");
throw new ShareUtilsException("Need to share at least one marker.");
}

String mime = null;

ContentProviderUtils contentProviderUtils = new ContentProviderUtils(context);
ArrayList<Uri> uris = new ArrayList<>();

boolean shouldbreak = false;
for (Marker.Id markerId : markerIds) {
Marker marker = contentProviderUtils.getMarker(markerId);
if (marker == null) {
Log.e(TAG, "MarkerId " + markerId.id() + " could not be resolved.");
continue;
shouldbreak = true;
}
if (marker.getPhotoURI() == null) {
else if (marker.getPhotoURI() == null) {
Log.e(TAG, "MarkerId " + markerId.id() + " has no picture.");
continue;
shouldbreak = true;
}
else{
mime = context.getContentResolver().getType(marker.getPhotoURI());
uris.add(marker.getPhotoURI());
}

mime = context.getContentResolver().getType(marker.getPhotoURI());

uris.add(marker.getPhotoURI());
if(shouldbreak){
shouldbreak = false;
continue;
}
}

if (uris.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package de.dennisguse.opentracks.share;

public class ShareUtilsException extends RuntimeException{
public ShareUtilsException (String message) { super(message);}
}
5 changes: 2 additions & 3 deletions src/main/java/de/dennisguse/opentracks/util/EGM2008Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,8 @@ public Altitude.EGM2008 correctAltitude(@NonNull Location location) {
- (int) ((-location.getLatitude() + 90) * RESOLUTION_IN_MINUTES);

// Bilinear interpolation (optimized; taken from GeopgrahicLib/Geoid.cpp)
double
a = (1 - fLongitude) * v00 + fLongitude * v01,
b = (1 - fLongitude) * v10 + fLongitude * v11;
double a = (1 - fLongitude) * v00 + fLongitude * v01;
double b = (1 - fLongitude) * v10 + fLongitude * v11;
undulationRaw = (1 - fLatitude) * a + fLatitude * b;
}
// Bilinear interpolation (not optimized)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ private void requestPermission(ActivityResultCaller context, @Nullable Runnable
ALL_PERMISSIONS = Collections.unmodifiableList(recording);
}

public final static PermissionRequester GPS = new PermissionRequester(GPS_PERMISSION);
public final static PermissionRequester BLUETOOTH = new PermissionRequester(BLUETOOTH_PERMISSIONS);
public final static PermissionRequester NOTIFICATION = new PermissionRequester(NOTIFICATION_PERMISSIONS);
public static final PermissionRequester GPS = new PermissionRequester(GPS_PERMISSION);
public static final PermissionRequester BLUETOOTH = new PermissionRequester(BLUETOOTH_PERMISSIONS);
public static final PermissionRequester NOTIFICATION = new PermissionRequester(NOTIFICATION_PERMISSIONS);

public final static PermissionRequester ALL = new PermissionRequester(ALL_PERMISSIONS);
public final static PermissionRequester RECORDING = new PermissionRequester(RECORDING_PERMISSIONS);
public static final PermissionRequester ALL = new PermissionRequester(ALL_PERMISSIONS);
public static final PermissionRequester RECORDING = new PermissionRequester(RECORDING_PERMISSIONS);

public interface RejectedCallback {
void rejected(PermissionRequester permissionRequester);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/de/dennisguse/opentracks/util/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,22 +252,22 @@ public static OffsetDateTime parseTime(String xmlDateTime) {
}

/**
* @return the formatted altitude_m (or null) and it's unit as {@link Pair}
* @return the formatted altitudeM (or null) and it's unit as {@link Pair}
*/
//TODO altitude_m should be double or a value object
public static Pair<String, String> getAltitudeParts(Context context, Float altitude_m, UnitSystem unitSystem) {
public static Pair<String, String> getAltitudeParts(Context context, Float altitudeM, UnitSystem unitSystem) {
DistanceFormatter formatter = DistanceFormatter.Builder()
.setDecimalCount(0)
.setThreshold(Double.MAX_VALUE)
.setUnit(unitSystem)
.build(context);

Distance distance = altitude_m != null ? Distance.of(altitude_m) : Distance.of((Double) null);
Distance distance = altitudeM != null ? Distance.of(altitudeM) : Distance.of((Double) null);
return formatter.getDistanceParts(distance);
}

public static String formatAltitude(Context context, Float altitude_m, UnitSystem unitSystem) {
Pair<String, String> altitudeParts = getAltitudeParts(context, altitude_m, unitSystem);
public static String formatAltitude(Context context, Float altitudeM, UnitSystem unitSystem) {
Pair<String, String> altitudeParts = getAltitudeParts(context, altitudeM, unitSystem);

return context.getString(R.string.altitude_with_unit, altitudeParts.first, altitudeParts.second);
}
Expand Down

0 comments on commit 222425f

Please sign in to comment.