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.DialogHelper;
|
||||||
import org.y20k.trackbook.helpers.DropdownAdapter;
|
import org.y20k.trackbook.helpers.DropdownAdapter;
|
||||||
import org.y20k.trackbook.helpers.ExportHelper;
|
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.LogHelper;
|
||||||
import org.y20k.trackbook.helpers.MapHelper;
|
import org.y20k.trackbook.helpers.MapHelper;
|
||||||
import org.y20k.trackbook.helpers.StorageHelper;
|
import org.y20k.trackbook.helpers.StorageHelper;
|
||||||
|
@ -372,16 +370,16 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
|
||||||
}
|
}
|
||||||
|
|
||||||
// populate views
|
// populate views
|
||||||
mDistanceView.setText(LocaleUnitHelper.convertDistanceToString(mTrack.getTrackDistance()));
|
mDistanceView.setText(mTrack.getTrackDistanceString());
|
||||||
mStepsView.setText(stepsTaken);
|
mStepsView.setText(stepsTaken);
|
||||||
mWaypointsView.setText(String.valueOf(mTrack.getWayPoints().size()));
|
mWaypointsView.setText(String.valueOf(mTrack.getWayPoints().size()));
|
||||||
mDurationView.setText(LocationHelper.convertToReadableTime(mTrack.getTrackDuration(), true));
|
mDurationView.setText(mTrack.getTrackDurationString());
|
||||||
mRecordingStartView.setText(recordingStart);
|
mRecordingStartView.setText(recordingStart);
|
||||||
mRecordingStopView.setText(recordingStop);
|
mRecordingStopView.setText(recordingStop);
|
||||||
mPositiveElevationView.setText(LocaleUnitHelper.convertDistanceToString(mTrack.getPositiveElevation()));
|
mPositiveElevationView.setText(mTrack.getPositiveElevationString());
|
||||||
mNegativeElevationView.setText(LocaleUnitHelper.convertDistanceToString(mTrack.getNegativeElevation()));
|
mNegativeElevationView.setText(mTrack.getNegativeElevationString());
|
||||||
mMaxAltitudeView.setText(LocaleUnitHelper.convertDistanceToString(mTrack.getMaxAltitude()));
|
mMaxAltitudeView.setText(mTrack.getMaxAltitudeString());
|
||||||
mMinAltitudeView.setText(LocaleUnitHelper.convertDistanceToString(mTrack.getMinAltitude()));
|
mMinAltitudeView.setText(mTrack.getMinAltitudeString());
|
||||||
|
|
||||||
// show/hide elevation views depending on file format version
|
// show/hide elevation views depending on file format version
|
||||||
if (mTrack.getTrackFormatVersion() > 1 && mTrack.getMinAltitude() > 0) {
|
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;
|
int dialogNegativeButton = R.string.dialog_default_action_cancel;
|
||||||
DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault());
|
DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault());
|
||||||
String recordingStartDate = df.format(mTrack.getRecordingStart());
|
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
|
// show delete dialog - results are handles by onActivityResult
|
||||||
DialogFragment dialogFragment = DialogHelper.newInstance(dialogTitle, dialogMessage, dialogPositiveButton, dialogNegativeButton);
|
DialogFragment dialogFragment = DialogHelper.newInstance(dialogTitle, dialogMessage, dialogPositiveButton, dialogNegativeButton);
|
||||||
|
@ -541,13 +539,13 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
|
||||||
if (ExportHelper.gpxFileExists(mTrack)) {
|
if (ExportHelper.gpxFileExists(mTrack)) {
|
||||||
// CASE: OVERWRITE - GPX file exists
|
// CASE: OVERWRITE - GPX file exists
|
||||||
dialogTitle = R.string.dialog_export_title_overwrite;
|
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;
|
dialogPositiveButton = R.string.dialog_export_action_overwrite;
|
||||||
dialogNegativeButton = R.string.dialog_default_action_cancel;
|
dialogNegativeButton = R.string.dialog_default_action_cancel;
|
||||||
} else {
|
} else {
|
||||||
// CASE: EXPORT - GPX file does NOT yet exits
|
// CASE: EXPORT - GPX file does NOT yet exits
|
||||||
dialogTitle = R.string.dialog_export_title_export;
|
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;
|
dialogPositiveButton = R.string.dialog_export_action_export;
|
||||||
dialogNegativeButton = R.string.dialog_default_action_cancel;
|
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 org.y20k.trackbook.helpers.TrackbookKeys;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -273,9 +275,40 @@ public class Track implements TrackbookKeys, Parcelable {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Getter track distance */
|
/* Getter for string representation of maximum altitude of recording */
|
||||||
public double getTrackDistance() {
|
public String getMaxAltitudeString() {
|
||||||
return (double) mWayPoints.get(mWayPoints.size()-1).getDistanceToStartingPoint();
|
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 */
|
/* Converts a given distance value to a readable string */
|
||||||
// private String convertDistanceToString(double distance) {
|
private String convertDistanceToString(double distance) {
|
||||||
// // check for locale and set unit system accordingly
|
// check for locale and set unit system accordingly
|
||||||
// String unit;
|
String unit;
|
||||||
// if (getUnitSystem(Locale.getDefault()) == IMPERIAL) {
|
if (getUnitSystem(Locale.getDefault()) == IMPERIAL) {
|
||||||
// // convert distance to feet
|
// convert distance to feet
|
||||||
// distance = distance * 3.28084f;
|
distance = distance * 3.28084f;
|
||||||
// // set measurement unit
|
// set measurement unit
|
||||||
// unit = "ft";
|
unit = "ft";
|
||||||
// } else {
|
} else {
|
||||||
// // set measurement unit
|
// set measurement unit
|
||||||
// unit = "m";
|
unit = "m";
|
||||||
// }
|
}
|
||||||
// return String.format (Locale.ENGLISH, "%.0f", distance) + unit;
|
return String.format (Locale.ENGLISH, "%.0f", distance) + unit;
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
|
||||||
// /* Determines which unit system the device is using (metric or imperial) */
|
/* Determines which unit system the device is using (metric or imperial) */
|
||||||
// private int getUnitSystem(Locale locale) {
|
private int getUnitSystem(Locale locale) {
|
||||||
// // America (US), Liberia (LR), Myanmar(MM) use the imperial system
|
// America (US), Liberia (LR), Myanmar(MM) use the imperial system
|
||||||
// List<String> imperialSystemCountries = Arrays.asList("US", "LR", "MM");
|
List<String> imperialSystemCountries = Arrays.asList("US", "LR", "MM");
|
||||||
// String countryCode = locale.getCountry();
|
String countryCode = locale.getCountry();
|
||||||
//
|
|
||||||
// if (imperialSystemCountries.contains(countryCode)){
|
if (imperialSystemCountries.contains(countryCode)){
|
||||||
// return IMPERIAL;
|
return IMPERIAL;
|
||||||
// } else {
|
} else {
|
||||||
// return METRIC;
|
return METRIC;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@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;
|
package org.y20k.trackbook.core;
|
||||||
|
|
||||||
import org.y20k.trackbook.helpers.LogHelper;
|
import org.y20k.trackbook.helpers.LogHelper;
|
||||||
import org.y20k.trackbook.helpers.TrackbookKeys;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
|
@ -31,7 +30,7 @@ import java.util.Locale;
|
||||||
/**
|
/**
|
||||||
* TrackBundle class
|
* TrackBundle class
|
||||||
*/
|
*/
|
||||||
public class TrackBundle implements TrackbookKeys {
|
public class TrackBundle {
|
||||||
|
|
||||||
/* Define log tag */
|
/* Define log tag */
|
||||||
private static final String LOG_TAG = TrackBundle.class.getSimpleName();
|
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 */
|
/* Builds a readable track name from the track's file name */
|
||||||
private String buildTrackName(File file) {
|
private String buildTrackName(File file) {
|
||||||
|
|
||||||
// get file name
|
// get file name without extension
|
||||||
String readableTrackName = file.getName();
|
String readableTrackName = file.getName();
|
||||||
|
readableTrackName = readableTrackName.substring(0, readableTrackName.indexOf(".trackbook"));
|
||||||
// strip extension
|
|
||||||
if (readableTrackName.endsWith(FILE_TYPE_TRACKBOOK_EXTENSION)) {
|
|
||||||
readableTrackName = readableTrackName.substring(0, readableTrackName.indexOf(FILE_TYPE_TRACKBOOK_EXTENSION));
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// convert file name to date
|
// 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 */
|
/* Build context text for notification builder */
|
||||||
private static String getContextString(Context context, Track track) {
|
private static String getContextString(Context context, Track track) {
|
||||||
return context.getString(R.string.notification_content_distance) + ": " + LocaleUnitHelper.convertDistanceToString(track.getTrackDistance()) + " | " +
|
return context.getString(R.string.notification_content_distance) + ": " + track.getTrackDistanceString() + " | " +
|
||||||
context.getString(R.string.notification_content_duration) + ": " + LocationHelper.convertToReadableTime(track.getTrackDuration(), true);
|
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.support.v4.os.EnvironmentCompat;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.google.gson.FieldNamingPolicy;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
|
|
||||||
|
@ -118,9 +119,7 @@ public class StorageHelper implements TrackbookKeys {
|
||||||
File file = new File(mFolder.toString() + "/" + fileName);
|
File file = new File(mFolder.toString() + "/" + fileName);
|
||||||
|
|
||||||
// convert track to JSON
|
// convert track to JSON
|
||||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
Gson gson = getCustomGson(true);
|
||||||
gsonBuilder.setDateFormat("M/d/yy hh:mm a");
|
|
||||||
Gson gson = gsonBuilder.create();
|
|
||||||
String json = gson.toJson(track);
|
String json = gson.toJson(track);
|
||||||
|
|
||||||
// write track
|
// write track
|
||||||
|
@ -226,18 +225,25 @@ public class StorageHelper implements TrackbookKeys {
|
||||||
LogHelper.v(LOG_TAG, "Loading track from external storage: " + file.toString());
|
LogHelper.v(LOG_TAG, "Loading track from external storage: " + file.toString());
|
||||||
|
|
||||||
// read until last line reached
|
// read until last line reached
|
||||||
String line;
|
String fileContent;
|
||||||
|
String singleLine;
|
||||||
StringBuilder sb = new StringBuilder("");
|
StringBuilder sb = new StringBuilder("");
|
||||||
while ((line = br.readLine()) != null) {
|
while ((singleLine = br.readLine()) != null) {
|
||||||
sb.append(line);
|
sb.append(singleLine);
|
||||||
sb.append("\n");
|
sb.append("\n");
|
||||||
}
|
}
|
||||||
|
fileContent = sb.toString();
|
||||||
|
|
||||||
// prepare GsonBuilder and return Track object
|
// identify for ugly JSON files
|
||||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
boolean pretty = true;
|
||||||
gsonBuilder.setDateFormat("M/d/yy hh:mm a");
|
if (fileContent.startsWith("{\"b\"")) {
|
||||||
Gson gson = gsonBuilder.create();
|
LogHelper.w(LOG_TAG, "Trackbook file is not formatted correctly."); // todo remove
|
||||||
return gson.fromJson(sb.toString(), TrackBuilder.class).toTrack();
|
pretty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// prepare custom Gson and return Track object
|
||||||
|
Gson gson = getCustomGson(pretty);
|
||||||
|
return gson.fromJson(fileContent, TrackBuilder.class).toTrack();
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogHelper.e(LOG_TAG, "Unable to read file from external storage: " + file.toString());
|
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 */
|
/* Gets most current track from directory */
|
||||||
private File getMostCurrentTrack() {
|
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()
|
google()
|
||||||
}
|
}
|
||||||
dependencies {
|
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
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
|
|
Loading…
Reference in a new issue