rolling back code that enabled unit-changing - that caused problems
This commit is contained in:
parent
31afd893e4
commit
9e3f2b6e67
23 changed files with 106 additions and 140 deletions
0
app/src/main/java/org/y20k/trackbook/MainActivity.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/MainActivity.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/MainActivityMapFragment.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/MainActivityMapFragment.java
Normal file → Executable file
20
app/src/main/java/org/y20k/trackbook/MainActivityTrackFragment.java
Normal file → Executable file
20
app/src/main/java/org/y20k/trackbook/MainActivityTrackFragment.java
Normal file → Executable file
|
@ -55,8 +55,6 @@ import org.y20k.trackbook.core.Track;
|
|||
import org.y20k.trackbook.helpers.DialogHelper;
|
||||
import org.y20k.trackbook.helpers.DropdownAdapter;
|
||||
import org.y20k.trackbook.helpers.ExportHelper;
|
||||
import org.y20k.trackbook.helpers.LocaleUnitHelper;
|
||||
import org.y20k.trackbook.helpers.LocationHelper;
|
||||
import org.y20k.trackbook.helpers.LogHelper;
|
||||
import org.y20k.trackbook.helpers.MapHelper;
|
||||
import org.y20k.trackbook.helpers.StorageHelper;
|
||||
|
@ -372,16 +370,16 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
|
|||
}
|
||||
|
||||
// populate views
|
||||
mDistanceView.setText(LocaleUnitHelper.convertDistanceToString(mTrack.getTrackDistance()));
|
||||
mDistanceView.setText(mTrack.getTrackDistanceString());
|
||||
mStepsView.setText(stepsTaken);
|
||||
mWaypointsView.setText(String.valueOf(mTrack.getWayPoints().size()));
|
||||
mDurationView.setText(LocationHelper.convertToReadableTime(mTrack.getTrackDuration(), true));
|
||||
mDurationView.setText(mTrack.getTrackDurationString());
|
||||
mRecordingStartView.setText(recordingStart);
|
||||
mRecordingStopView.setText(recordingStop);
|
||||
mPositiveElevationView.setText(LocaleUnitHelper.convertDistanceToString(mTrack.getPositiveElevation()));
|
||||
mNegativeElevationView.setText(LocaleUnitHelper.convertDistanceToString(mTrack.getNegativeElevation()));
|
||||
mMaxAltitudeView.setText(LocaleUnitHelper.convertDistanceToString(mTrack.getMaxAltitude()));
|
||||
mMinAltitudeView.setText(LocaleUnitHelper.convertDistanceToString(mTrack.getMinAltitude()));
|
||||
mPositiveElevationView.setText(mTrack.getPositiveElevationString());
|
||||
mNegativeElevationView.setText(mTrack.getNegativeElevationString());
|
||||
mMaxAltitudeView.setText(mTrack.getMaxAltitudeString());
|
||||
mMinAltitudeView.setText(mTrack.getMinAltitudeString());
|
||||
|
||||
// show/hide elevation views depending on file format version
|
||||
if (mTrack.getTrackFormatVersion() > 1 && mTrack.getMinAltitude() > 0) {
|
||||
|
@ -513,7 +511,7 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
|
|||
int dialogNegativeButton = R.string.dialog_default_action_cancel;
|
||||
DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault());
|
||||
String recordingStartDate = df.format(mTrack.getRecordingStart());
|
||||
String dialogMessage = getString(R.string.dialog_delete_content) + " " + recordingStartDate + " | " + LocaleUnitHelper.convertDistanceToString(mTrack.getTrackDistance());
|
||||
String dialogMessage = getString(R.string.dialog_delete_content) + " " + recordingStartDate + " | " + mTrack.getTrackDistanceString();
|
||||
|
||||
// show delete dialog - results are handles by onActivityResult
|
||||
DialogFragment dialogFragment = DialogHelper.newInstance(dialogTitle, dialogMessage, dialogPositiveButton, dialogNegativeButton);
|
||||
|
@ -541,13 +539,13 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
|
|||
if (ExportHelper.gpxFileExists(mTrack)) {
|
||||
// CASE: OVERWRITE - GPX file exists
|
||||
dialogTitle = R.string.dialog_export_title_overwrite;
|
||||
dialogMessage = getString(R.string.dialog_export_content_overwrite) + " (" + recordingStartDate + " | " + LocaleUnitHelper.convertDistanceToString(mTrack.getTrackDistance()) + ")";
|
||||
dialogMessage = getString(R.string.dialog_export_content_overwrite) + " (" + recordingStartDate + " | " + mTrack.getTrackDistanceString() + ")";
|
||||
dialogPositiveButton = R.string.dialog_export_action_overwrite;
|
||||
dialogNegativeButton = R.string.dialog_default_action_cancel;
|
||||
} else {
|
||||
// CASE: EXPORT - GPX file does NOT yet exits
|
||||
dialogTitle = R.string.dialog_export_title_export;
|
||||
dialogMessage = getString(R.string.dialog_export_content_export) + " (" + recordingStartDate + " | " + LocaleUnitHelper.convertDistanceToString(mTrack.getTrackDistance()) + ")";
|
||||
dialogMessage = getString(R.string.dialog_export_content_export) + " (" + recordingStartDate + " | " + mTrack.getTrackDistanceString() + ")";
|
||||
dialogPositiveButton = R.string.dialog_export_action_export;
|
||||
dialogNegativeButton = R.string.dialog_default_action_cancel;
|
||||
}
|
||||
|
|
0
app/src/main/java/org/y20k/trackbook/Trackbook.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/Trackbook.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/TrackerService.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/TrackerService.java
Normal file → Executable file
93
app/src/main/java/org/y20k/trackbook/core/Track.java
Normal file → Executable file
93
app/src/main/java/org/y20k/trackbook/core/Track.java
Normal file → Executable file
|
@ -25,9 +25,11 @@ import org.y20k.trackbook.helpers.LocationHelper;
|
|||
import org.y20k.trackbook.helpers.TrackbookKeys;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -273,9 +275,40 @@ public class Track implements TrackbookKeys, Parcelable {
|
|||
}
|
||||
|
||||
|
||||
/* Getter track distance */
|
||||
public double getTrackDistance() {
|
||||
return (double) mWayPoints.get(mWayPoints.size()-1).getDistanceToStartingPoint();
|
||||
/* Getter for string representation of maximum altitude of recording */
|
||||
public String getMaxAltitudeString() {
|
||||
return convertDistanceToString(mMaxAltitude);
|
||||
}
|
||||
|
||||
|
||||
/* Getter for string representation of lowest altitude of recording */
|
||||
public String getMinAltitudeString() {
|
||||
return convertDistanceToString(mMinAltitude);
|
||||
}
|
||||
|
||||
|
||||
/* Getter for string representation of positive elevation of recording (cumulative altitude difference) */
|
||||
public String getPositiveElevationString() {
|
||||
return convertDistanceToString(mPositiveElevation);
|
||||
}
|
||||
|
||||
|
||||
/* Getter for string representation of negative elevation of recording (cumulative altitude difference) */
|
||||
public String getNegativeElevationString() {
|
||||
return convertDistanceToString(mNegativeElevation);
|
||||
}
|
||||
|
||||
|
||||
/* Getter for string representation of track duration */
|
||||
public String getTrackDurationString() {
|
||||
return LocationHelper.convertToReadableTime(mDuration, true);
|
||||
}
|
||||
|
||||
|
||||
/* Getter for string representation of track distance */
|
||||
public String getTrackDistanceString() {
|
||||
double trackDistance = (double) mWayPoints.get(mWayPoints.size()-1).getDistanceToStartingPoint();
|
||||
return convertDistanceToString(trackDistance);
|
||||
}
|
||||
|
||||
|
||||
|
@ -301,35 +334,35 @@ public class Track implements TrackbookKeys, Parcelable {
|
|||
// }
|
||||
|
||||
|
||||
// /* Converts a given distance value to a readable string */
|
||||
// private String convertDistanceToString(double distance) {
|
||||
// // check for locale and set unit system accordingly
|
||||
// String unit;
|
||||
// if (getUnitSystem(Locale.getDefault()) == IMPERIAL) {
|
||||
// // convert distance to feet
|
||||
// distance = distance * 3.28084f;
|
||||
// // set measurement unit
|
||||
// unit = "ft";
|
||||
// } else {
|
||||
// // set measurement unit
|
||||
// unit = "m";
|
||||
// }
|
||||
// return String.format (Locale.ENGLISH, "%.0f", distance) + unit;
|
||||
// }
|
||||
/* Converts a given distance value to a readable string */
|
||||
private String convertDistanceToString(double distance) {
|
||||
// check for locale and set unit system accordingly
|
||||
String unit;
|
||||
if (getUnitSystem(Locale.getDefault()) == IMPERIAL) {
|
||||
// convert distance to feet
|
||||
distance = distance * 3.28084f;
|
||||
// set measurement unit
|
||||
unit = "ft";
|
||||
} else {
|
||||
// set measurement unit
|
||||
unit = "m";
|
||||
}
|
||||
return String.format (Locale.ENGLISH, "%.0f", distance) + unit;
|
||||
}
|
||||
|
||||
|
||||
// /* Determines which unit system the device is using (metric or imperial) */
|
||||
// private int getUnitSystem(Locale locale) {
|
||||
// // America (US), Liberia (LR), Myanmar(MM) use the imperial system
|
||||
// List<String> imperialSystemCountries = Arrays.asList("US", "LR", "MM");
|
||||
// String countryCode = locale.getCountry();
|
||||
//
|
||||
// if (imperialSystemCountries.contains(countryCode)){
|
||||
// return IMPERIAL;
|
||||
// } else {
|
||||
// return METRIC;
|
||||
// }
|
||||
// }
|
||||
/* Determines which unit system the device is using (metric or imperial) */
|
||||
private int getUnitSystem(Locale locale) {
|
||||
// America (US), Liberia (LR), Myanmar(MM) use the imperial system
|
||||
List<String> imperialSystemCountries = Arrays.asList("US", "LR", "MM");
|
||||
String countryCode = locale.getCountry();
|
||||
|
||||
if (imperialSystemCountries.contains(countryCode)){
|
||||
return IMPERIAL;
|
||||
} else {
|
||||
return METRIC;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
|
0
app/src/main/java/org/y20k/trackbook/core/TrackBuilder.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/core/TrackBuilder.java
Normal file → Executable file
11
app/src/main/java/org/y20k/trackbook/core/TrackBundle.java
Normal file → Executable file
11
app/src/main/java/org/y20k/trackbook/core/TrackBundle.java
Normal file → Executable file
|
@ -18,7 +18,6 @@
|
|||
package org.y20k.trackbook.core;
|
||||
|
||||
import org.y20k.trackbook.helpers.LogHelper;
|
||||
import org.y20k.trackbook.helpers.TrackbookKeys;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DateFormat;
|
||||
|
@ -31,7 +30,7 @@ import java.util.Locale;
|
|||
/**
|
||||
* TrackBundle class
|
||||
*/
|
||||
public class TrackBundle implements TrackbookKeys {
|
||||
public class TrackBundle {
|
||||
|
||||
/* Define log tag */
|
||||
private static final String LOG_TAG = TrackBundle.class.getSimpleName();
|
||||
|
@ -63,13 +62,9 @@ public class TrackBundle implements TrackbookKeys {
|
|||
/* Builds a readable track name from the track's file name */
|
||||
private String buildTrackName(File file) {
|
||||
|
||||
// get file name
|
||||
// get file name without extension
|
||||
String readableTrackName = file.getName();
|
||||
|
||||
// strip extension
|
||||
if (readableTrackName.endsWith(FILE_TYPE_TRACKBOOK_EXTENSION)) {
|
||||
readableTrackName = readableTrackName.substring(0, readableTrackName.indexOf(FILE_TYPE_TRACKBOOK_EXTENSION));
|
||||
}
|
||||
readableTrackName = readableTrackName.substring(0, readableTrackName.indexOf(".trackbook"));
|
||||
|
||||
try {
|
||||
// convert file name to date
|
||||
|
|
0
app/src/main/java/org/y20k/trackbook/core/WayPoint.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/core/WayPoint.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/helpers/DialogHelper.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/helpers/DialogHelper.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/helpers/DropdownAdapter.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/helpers/DropdownAdapter.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/helpers/ExportHelper.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/helpers/ExportHelper.java
Normal file → Executable file
|
@ -1,77 +0,0 @@
|
|||
/**
|
||||
* LocaleUnitHelper.java
|
||||
* Implements the LocaleUnitHelper class
|
||||
* A LocaleUnitHelper offers helper methods for dealing with unit systems and locales
|
||||
*
|
||||
* This file is part of
|
||||
* TRACKBOOK - Movement Recorder for Android
|
||||
*
|
||||
* Copyright (c) 2016-18 - Y20K.org
|
||||
* Licensed under the MIT-License
|
||||
* http://opensource.org/licenses/MIT
|
||||
*
|
||||
* Trackbook uses osmdroid - OpenStreetMap-Tools for Android
|
||||
* https://github.com/osmdroid/osmdroid
|
||||
*/
|
||||
|
||||
package org.y20k.trackbook.helpers;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
/**
|
||||
* LocaleUnitHelper class
|
||||
*/
|
||||
public final class LocaleUnitHelper implements TrackbookKeys {
|
||||
|
||||
|
||||
/* Converts for the default locale a distance value to a readable string */
|
||||
public static String convertDistanceToString(double distance) {
|
||||
return convertDistanceToString(distance, getUnitSystem(Locale.getDefault()));
|
||||
}
|
||||
|
||||
|
||||
/* Converts for the given uni System a distance value to a readable string */
|
||||
public static String convertDistanceToString(double distance, int unitSystem) {
|
||||
// check for locale and set unit system accordingly
|
||||
String unit;
|
||||
if (unitSystem == IMPERIAL) {
|
||||
// convert distance to feet
|
||||
distance = distance * 3.28084f;
|
||||
// set measurement unit
|
||||
unit = "ft";
|
||||
} else {
|
||||
// set measurement unit
|
||||
unit = "m";
|
||||
}
|
||||
return String.format (Locale.ENGLISH, "%.0f", distance) + unit;
|
||||
}
|
||||
|
||||
|
||||
/* Determines which unit system the device is using (metric or imperial) */
|
||||
private static int getUnitSystem(Locale locale) {
|
||||
// America (US), Liberia (LR), Myanmar(MM) use the imperial system
|
||||
List<String> imperialSystemCountries = Arrays.asList("US", "LR", "MM");
|
||||
String countryCode = locale.getCountry();
|
||||
|
||||
if (imperialSystemCountries.contains(countryCode)){
|
||||
return IMPERIAL;
|
||||
} else {
|
||||
return METRIC;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Returns the opposite uni system based on the current locale */
|
||||
public static int getOppositeUnitSystem() {
|
||||
int unitSystem = getUnitSystem(Locale.getDefault());
|
||||
if (unitSystem == METRIC){
|
||||
return IMPERIAL;
|
||||
} else {
|
||||
return METRIC;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
0
app/src/main/java/org/y20k/trackbook/helpers/LocationHelper.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/helpers/LocationHelper.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/helpers/LogHelper.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/helpers/LogHelper.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/helpers/MapHelper.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/helpers/MapHelper.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/helpers/NightModeHelper.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/helpers/NightModeHelper.java
Normal file → Executable file
4
app/src/main/java/org/y20k/trackbook/helpers/NotificationHelper.java
Normal file → Executable file
4
app/src/main/java/org/y20k/trackbook/helpers/NotificationHelper.java
Normal file → Executable file
|
@ -163,8 +163,8 @@ public final class NotificationHelper implements TrackbookKeys {
|
|||
|
||||
/* Build context text for notification builder */
|
||||
private static String getContextString(Context context, Track track) {
|
||||
return context.getString(R.string.notification_content_distance) + ": " + LocaleUnitHelper.convertDistanceToString(track.getTrackDistance()) + " | " +
|
||||
context.getString(R.string.notification_content_duration) + ": " + LocationHelper.convertToReadableTime(track.getTrackDuration(), true);
|
||||
return context.getString(R.string.notification_content_distance) + ": " + track.getTrackDistanceString() + " | " +
|
||||
context.getString(R.string.notification_content_duration) + ": " + track.getTrackDurationString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
39
app/src/main/java/org/y20k/trackbook/helpers/StorageHelper.java
Normal file → Executable file
39
app/src/main/java/org/y20k/trackbook/helpers/StorageHelper.java
Normal file → Executable file
|
@ -22,6 +22,7 @@ import android.support.annotation.Nullable;
|
|||
import android.support.v4.os.EnvironmentCompat;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.gson.FieldNamingPolicy;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
|
@ -118,9 +119,7 @@ public class StorageHelper implements TrackbookKeys {
|
|||
File file = new File(mFolder.toString() + "/" + fileName);
|
||||
|
||||
// convert track to JSON
|
||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||
gsonBuilder.setDateFormat("M/d/yy hh:mm a");
|
||||
Gson gson = gsonBuilder.create();
|
||||
Gson gson = getCustomGson(true);
|
||||
String json = gson.toJson(track);
|
||||
|
||||
// write track
|
||||
|
@ -226,18 +225,25 @@ public class StorageHelper implements TrackbookKeys {
|
|||
LogHelper.v(LOG_TAG, "Loading track from external storage: " + file.toString());
|
||||
|
||||
// read until last line reached
|
||||
String line;
|
||||
String fileContent;
|
||||
String singleLine;
|
||||
StringBuilder sb = new StringBuilder("");
|
||||
while ((line = br.readLine()) != null) {
|
||||
sb.append(line);
|
||||
while ((singleLine = br.readLine()) != null) {
|
||||
sb.append(singleLine);
|
||||
sb.append("\n");
|
||||
}
|
||||
fileContent = sb.toString();
|
||||
|
||||
// prepare GsonBuilder and return Track object
|
||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||
gsonBuilder.setDateFormat("M/d/yy hh:mm a");
|
||||
Gson gson = gsonBuilder.create();
|
||||
return gson.fromJson(sb.toString(), TrackBuilder.class).toTrack();
|
||||
// identify for ugly JSON files
|
||||
boolean pretty = true;
|
||||
if (fileContent.startsWith("{\"b\"")) {
|
||||
LogHelper.w(LOG_TAG, "Trackbook file is not formatted correctly."); // todo remove
|
||||
pretty = false;
|
||||
}
|
||||
|
||||
// prepare custom Gson and return Track object
|
||||
Gson gson = getCustomGson(pretty);
|
||||
return gson.fromJson(fileContent, TrackBuilder.class).toTrack();
|
||||
|
||||
} catch (IOException e) {
|
||||
LogHelper.e(LOG_TAG, "Unable to read file from external storage: " + file.toString());
|
||||
|
@ -246,6 +252,17 @@ public class StorageHelper implements TrackbookKeys {
|
|||
}
|
||||
|
||||
|
||||
/* Creates a Gson object */
|
||||
private Gson getCustomGson(boolean pretty) {
|
||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||
gsonBuilder.setDateFormat("M/d/yy hh:mm a");
|
||||
if (pretty) {
|
||||
gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.IDENTITY);
|
||||
gsonBuilder.setPrettyPrinting();
|
||||
}
|
||||
return gsonBuilder.create();
|
||||
}
|
||||
|
||||
/* Gets most current track from directory */
|
||||
private File getMostCurrentTrack() {
|
||||
|
||||
|
|
0
app/src/main/java/org/y20k/trackbook/helpers/TrackbookKeys.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/helpers/TrackbookKeys.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/layout/DodgeAbleLayoutBehavior.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/layout/DodgeAbleLayoutBehavior.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/layout/NonSwipeableViewPager.java
Normal file → Executable file
0
app/src/main/java/org/y20k/trackbook/layout/NonSwipeableViewPager.java
Normal file → Executable file
|
@ -6,7 +6,7 @@ buildscript {
|
|||
google()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.1.1'
|
||||
classpath 'com.android.tools.build:gradle:3.1.2'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
|
|
Loading…
Reference in a new issue