From 02bb5bb48e8b43e0e655fb6c31875033cdcfbc50 Mon Sep 17 00:00:00 2001 From: Dennis Guse Date: Sat, 20 Jul 2019 21:09:19 +0200 Subject: [PATCH] Cleanup and default track name is location+date. --- .../settings/AdvancedSettingsActivity.java | 29 +------- .../apps/mytracks/util/DialogUtils.java | 15 ++-- .../apps/mytracks/util/PreferencesUtils.java | 68 ++++--------------- .../apps/mytracks/util/TrackNameUtils.java | 24 +++---- .../res/values/arrays_do_not_translate.xml | 5 -- src/main/res/values/do_not_translate.xml | 5 +- src/main/res/xml/settings_advanced.xml | 6 -- src/main/res/xml/settings_recording.xml | 2 +- 8 files changed, 31 insertions(+), 123 deletions(-) diff --git a/src/main/java/com/google/android/apps/mytracks/settings/AdvancedSettingsActivity.java b/src/main/java/com/google/android/apps/mytracks/settings/AdvancedSettingsActivity.java index ed7db8472..bab10c62d 100644 --- a/src/main/java/com/google/android/apps/mytracks/settings/AdvancedSettingsActivity.java +++ b/src/main/java/com/google/android/apps/mytracks/settings/AdvancedSettingsActivity.java @@ -45,10 +45,8 @@ public class AdvancedSettingsActivity extends AbstractSettingsActivity { private static final String TAG = AdvancedSettingsActivity.class.getSimpleName(); - private static final int DIALOG_CONFIRM_ALLOW_ACCESS_ID = 0; private static final int DIALOG_CONFIRM_RESET_ID = 1; - private CheckBoxPreference allowAccessCheckBoxPreference; private Preference resetPreference; private SharedPreferences sharedPreferences; @@ -90,20 +88,6 @@ public class AdvancedSettingsActivity extends AbstractSettingsActivity { setPhotoSizeSummaryAndOptions(summary, options, values); configureListPreference(preference, summary, options, values, String.valueOf(value), null); - allowAccessCheckBoxPreference = (CheckBoxPreference) findPreference( - getString(R.string.allow_access_key)); - allowAccessCheckBoxPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference pref, Object newValue) { - if ((Boolean) newValue) { - showDialog(DIALOG_CONFIRM_ALLOW_ACCESS_ID); - return false; - } else { - return true; - } - } - }); - sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); resetPreference = findPreference(getString(R.string.settings_reset_key)); @@ -133,16 +117,6 @@ public class AdvancedSettingsActivity extends AbstractSettingsActivity { @Override protected Dialog onCreateDialog(int id) { switch (id) { - case DIALOG_CONFIRM_ALLOW_ACCESS_ID: - return DialogUtils.createConfirmationDialog(this, - R.string.settings_sharing_allow_access_confirm_title, - getString(R.string.settings_sharing_allow_access_confirm_message), - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int button) { - allowAccessCheckBoxPreference.setChecked(true); - } - }); case DIALOG_CONFIRM_RESET_ID: return DialogUtils.createConfirmationDialog(this, R.string.settings_reset_confirm_title, getString(R.string.settings_reset_confirm_message), @@ -204,8 +178,7 @@ public class AdvancedSettingsActivity extends AbstractSettingsActivity { AdvancedSettingsActivity.this, R.string.settings_reset_done, Toast.LENGTH_SHORT) .show(); // Restart the settings activity so all changes are loaded - Intent intent = getIntent() - .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); + Intent intent = getIntent().addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } }); diff --git a/src/main/java/com/google/android/apps/mytracks/util/DialogUtils.java b/src/main/java/com/google/android/apps/mytracks/util/DialogUtils.java index c63d1c0de..1271c9af4 100644 --- a/src/main/java/com/google/android/apps/mytracks/util/DialogUtils.java +++ b/src/main/java/com/google/android/apps/mytracks/util/DialogUtils.java @@ -45,8 +45,7 @@ public class DialogUtils { * @param message the message * @param okListener the listener when OK is clicked */ - public static Dialog createConfirmationDialog( - final Context context, int titleId, String message, DialogInterface.OnClickListener okListener) { + public static Dialog createConfirmationDialog(final Context context, int titleId, String message, DialogInterface.OnClickListener okListener) { final AlertDialog alertDialog = new AlertDialog.Builder(context) .setCancelable(true) .setIcon(android.R.drawable.ic_dialog_alert) @@ -71,8 +70,7 @@ public class DialogUtils { * @param messageId the progress message id * @param onCancelListener the cancel listener */ - public static ProgressDialog createSpinnerProgressDialog( - Context context, int messageId, DialogInterface.OnCancelListener onCancelListener) { + public static ProgressDialog createSpinnerProgressDialog(Context context, int messageId, DialogInterface.OnCancelListener onCancelListener) { return createProgressDialog(true, context, messageId, onCancelListener); } @@ -84,8 +82,7 @@ public class DialogUtils { * @param onCancelListener the cancel listener * @param formatArgs the format arguments for the messageId */ - public static ProgressDialog createHorizontalProgressDialog(Context context, int messageId, - DialogInterface.OnCancelListener onCancelListener, Object... formatArgs) { + public static ProgressDialog createHorizontalProgressDialog(Context context, int messageId, DialogInterface.OnCancelListener onCancelListener, Object... formatArgs) { return createProgressDialog(false, context, messageId, onCancelListener, formatArgs); } @@ -98,8 +95,7 @@ public class DialogUtils { * @param onCancelListener the cancel listener * @param formatArgs the format arguments for the message id */ - private static ProgressDialog createProgressDialog(boolean spinner, final Context context, - int messageId, DialogInterface.OnCancelListener onCancelListener, Object... formatArgs) { + private static ProgressDialog createProgressDialog(boolean spinner, final Context context, int messageId, DialogInterface.OnCancelListener onCancelListener, Object... formatArgs) { final ProgressDialog progressDialog = new ProgressDialog(context); progressDialog.setCancelable(true); progressDialog.setCanceledOnTouchOutside(false); @@ -107,8 +103,7 @@ public class DialogUtils { progressDialog.setIndeterminate(true); progressDialog.setMessage(context.getString(messageId, formatArgs)); progressDialog.setOnCancelListener(onCancelListener); - progressDialog.setProgressStyle(spinner ? ProgressDialog.STYLE_SPINNER - : ProgressDialog.STYLE_HORIZONTAL); + progressDialog.setProgressStyle(spinner ? ProgressDialog.STYLE_SPINNER : ProgressDialog.STYLE_HORIZONTAL); progressDialog.setTitle(R.string.generic_progress_title); progressDialog.setOnShowListener(new DialogInterface.OnShowListener() { diff --git a/src/main/java/com/google/android/apps/mytracks/util/PreferencesUtils.java b/src/main/java/com/google/android/apps/mytracks/util/PreferencesUtils.java index 350352ec4..39e1e58a5 100644 --- a/src/main/java/com/google/android/apps/mytracks/util/PreferencesUtils.java +++ b/src/main/java/com/google/android/apps/mytracks/util/PreferencesUtils.java @@ -84,7 +84,7 @@ public class PreferencesUtils { public static final boolean STATS_SHOW_GRADE_ELEVATION_DEFAULT = false; public static final String STATS_UNITS_DEFAULT = "METRIC"; - public static final String TRACK_NAME_DEFAULT = "LOCATION"; + public static final String TRACK_NAME_DEFAULT = "DATE_ISO_8601_LOCATION"; // Track widget public static final int TRACK_WIDGET_ITEM1_DEFAULT = 3; // moving time @@ -92,9 +92,7 @@ public class PreferencesUtils { public static final int TRACK_WIDGET_ITEM3_DEFAULT = 1; // total time public static final int TRACK_WIDGET_ITEM4_DEFAULT = 2; // average speed public static final int VOICE_FREQUENCY_DEFAULT = 0; - - private static final String TAG = PreferencesUtils.class.getSimpleName(); - + private PreferencesUtils() {} /** @@ -115,8 +113,7 @@ public class PreferencesUtils { * @param defaultValue the default value */ public static boolean getBoolean(Context context, int keyId, boolean defaultValue) { - SharedPreferences sharedPreferences = context.getSharedPreferences( - Constants.SETTINGS_NAME, Context.MODE_PRIVATE); + SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); return sharedPreferences.getBoolean(getKey(context, keyId), defaultValue); } @@ -128,8 +125,7 @@ public class PreferencesUtils { * @param value the value */ public static void setBoolean(Context context, int keyId, boolean value) { - SharedPreferences sharedPreferences = context.getSharedPreferences( - Constants.SETTINGS_NAME, Context.MODE_PRIVATE); + SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); Editor editor = sharedPreferences.edit(); editor.putBoolean(getKey(context, keyId), value); editor.apply(); @@ -143,8 +139,7 @@ public class PreferencesUtils { * @param defaultValue the default value */ public static int getInt(Context context, int keyId, int defaultValue) { - SharedPreferences sharedPreferences = context.getSharedPreferences( - Constants.SETTINGS_NAME, Context.MODE_PRIVATE); + SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); return sharedPreferences.getInt(getKey(context, keyId), defaultValue); } @@ -156,8 +151,7 @@ public class PreferencesUtils { * @param value the value */ public static void setInt(Context context, int keyId, int value) { - SharedPreferences sharedPreferences = context.getSharedPreferences( - Constants.SETTINGS_NAME, Context.MODE_PRIVATE); + SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); Editor editor = sharedPreferences.edit(); editor.putInt(getKey(context, keyId), value); editor.apply(); @@ -171,8 +165,7 @@ public class PreferencesUtils { * @param defaultValue the default value */ public static float getFloat(Context context, int keyId, float defaultValue) { - SharedPreferences sharedPreferences = context.getSharedPreferences( - Constants.SETTINGS_NAME, Context.MODE_PRIVATE); + SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); return sharedPreferences.getFloat(getKey(context, keyId), defaultValue); } @@ -184,8 +177,7 @@ public class PreferencesUtils { * @param value the value */ public static void setFloat(Context context, int keyId, float value) { - SharedPreferences sharedPreferences = context.getSharedPreferences( - Constants.SETTINGS_NAME, Context.MODE_PRIVATE); + SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); Editor editor = sharedPreferences.edit(); editor.putFloat(getKey(context, keyId), value); editor.apply(); @@ -198,8 +190,7 @@ public class PreferencesUtils { * @param keyId the key id */ public static long getLong(Context context, int keyId) { - SharedPreferences sharedPreferences = context.getSharedPreferences( - Constants.SETTINGS_NAME, Context.MODE_PRIVATE); + SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); return sharedPreferences.getLong(getKey(context, keyId), -1L); } @@ -211,8 +202,7 @@ public class PreferencesUtils { * @param value the value */ public static void setLong(Context context, int keyId, long value) { - SharedPreferences sharedPreferences = context.getSharedPreferences( - Constants.SETTINGS_NAME, Context.MODE_PRIVATE); + SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); Editor editor = sharedPreferences.edit(); editor.putLong(getKey(context, keyId), value); editor.apply(); @@ -226,8 +216,7 @@ public class PreferencesUtils { * @param defaultValue default value */ public static String getString(Context context, int keyId, String defaultValue) { - SharedPreferences sharedPreferences = context.getSharedPreferences( - Constants.SETTINGS_NAME, Context.MODE_PRIVATE); + SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); return sharedPreferences.getString(getKey(context, keyId), defaultValue); } @@ -239,8 +228,7 @@ public class PreferencesUtils { * @param value the value */ public static void setString(Context context, int keyId, String value) { - SharedPreferences sharedPreferences = context.getSharedPreferences( - Constants.SETTINGS_NAME, Context.MODE_PRIVATE); + SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); Editor editor = sharedPreferences.edit(); editor.putString(getKey(context, keyId), value); editor.apply(); @@ -252,8 +240,7 @@ public class PreferencesUtils { * @param context the context */ public static boolean isMetricUnits(Context context) { - return STATS_UNITS_DEFAULT.equals( - getString(context, R.string.stats_units_key, STATS_UNITS_DEFAULT)); + return STATS_UNITS_DEFAULT.equals(getString(context, R.string.stats_units_key, STATS_UNITS_DEFAULT)); } /** @@ -263,8 +250,7 @@ public class PreferencesUtils { * @param context the context */ public static boolean isReportSpeed(Context context) { - return STATS_RATE_DEFAULT.equals( - getString(context, R.string.stats_rate_key, STATS_RATE_DEFAULT)); + return STATS_RATE_DEFAULT.equals(getString(context, R.string.stats_rate_key, STATS_RATE_DEFAULT)); } /** @@ -273,30 +259,6 @@ public class PreferencesUtils { * @param context the context */ public static boolean isChartByDistance(Context context) { - return CHART_X_AXIS_DEFAULT.equals( - getString(context, R.string.chart_x_axis_key, CHART_X_AXIS_DEFAULT)); - } - - /** - * Adds a value to a list. - * - * @param context the context - * @param keyId the key id - * @param defaultValue the default value - * @param value the value - */ - public static void addToList(Context context, int keyId, String defaultValue, String value) { - String list = getString(context, keyId, defaultValue); - if (defaultValue.equals(list)) { - setString(context, keyId, value); - return; - } - String[] items = TextUtils.split(list, ";"); - for (String item : items) { - if (value.equals(item)) { - return; - } - } - setString(context, keyId, list + ";" + value); + return CHART_X_AXIS_DEFAULT.equals(getString(context, R.string.chart_x_axis_key, CHART_X_AXIS_DEFAULT)); } } diff --git a/src/main/java/com/google/android/apps/mytracks/util/TrackNameUtils.java b/src/main/java/com/google/android/apps/mytracks/util/TrackNameUtils.java index a5bfd533d..03ce3ba46 100644 --- a/src/main/java/com/google/android/apps/mytracks/util/TrackNameUtils.java +++ b/src/main/java/com/google/android/apps/mytracks/util/TrackNameUtils.java @@ -50,26 +50,18 @@ public class TrackNameUtils { * @param startTime the track start time * @param location the track location, can be null */ - public static String getTrackName( - Context context, long trackId, long startTime, Location location) { - String trackName = PreferencesUtils.getString( - context, R.string.track_name_key, PreferencesUtils.TRACK_NAME_DEFAULT); + public static String getTrackName(Context context, long trackId, long startTime, Location location) { + String trackName = PreferencesUtils.getString(context, R.string.track_name_key, PreferencesUtils.TRACK_NAME_DEFAULT); - if (trackName.equals( - context.getString(R.string.settings_recording_track_name_location_value))) { + if (trackName.equals(context.getString(R.string.settings_recording_track_name_location_value))) { // Use the startTime if location is null - return location != null ? getReverseGeoCoding(context, location) - : StringUtils.formatDateTime(context, startTime); - } else if (trackName.equals( - context.getString(R.string.settings_recording_track_name_date_local_value))) { + return location != null ? getReverseGeoCoding(context, location) : StringUtils.formatDateTime(context, startTime); + } else if (trackName.equals(context.getString(R.string.settings_recording_track_name_date_local_value))) { return StringUtils.formatDateTime(context, startTime); - } else if (trackName.equals( - context.getString(R.string.settings_recording_track_name_date_iso_8601_value))) { + } else if (trackName.equals(context.getString(R.string.settings_recording_track_name_date_iso_8601_value))) { return new SimpleDateFormat(ISO_8601_FORMAT, Locale.US).format(startTime); - } else if (trackName.equals( - context.getString(R.string.settings_recording_track_name_date_iso_8601_location_value))) { - StringBuilder builder = new StringBuilder( - new SimpleDateFormat(ISO_8601_FORMAT, Locale.US).format(startTime)); + } else if (trackName.equals(context.getString(R.string.settings_recording_track_name_date_iso_8601_location_value))) { + StringBuilder builder = new StringBuilder(new SimpleDateFormat(ISO_8601_FORMAT, Locale.US).format(startTime)); if (location != null) { String address = getReverseGeoCoding(context, location); diff --git a/src/main/res/values/arrays_do_not_translate.xml b/src/main/res/values/arrays_do_not_translate.xml index 24db7f982..6b4f93ed8 100644 --- a/src/main/res/values/arrays_do_not_translate.xml +++ b/src/main/res/values/arrays_do_not_translate.xml @@ -197,11 +197,6 @@ limitations under the License. @string/settings_map_track_color_mode_fixed_summary @string/settings_map_track_color_mode_dynamic_summary - - @string/settings_map_track_color_mode_single_value - @string/settings_map_track_color_mode_fixed_value - @string/settings_map_track_color_mode_dynamic_value - @string/settings_recording_track_name_location_option @string/settings_recording_track_name_date_local_option diff --git a/src/main/res/values/do_not_translate.xml b/src/main/res/values/do_not_translate.xml index a460e3ca6..67f1fe830 100644 --- a/src/main/res/values/do_not_translate.xml +++ b/src/main/res/values/do_not_translate.xml @@ -21,14 +21,11 @@ limitations under the License. http://maps.google.com/mapfiles/ms/micons/ylw-pushpin.png http://maps.google.com/mapfiles/ms/micons/blue-pushpin.png My Tracks Recording Service - www.google.com/mobile/mytracks + TODO com.google.android.apps.mytracks.MYTRACKS_NOTIFICATIONS NONE RPM BPM - DYNAMIC - FIXED - SINGLE DATE_ISO_8601 DATE_ISO_8601_LOCATION DATE_LOCAL diff --git a/src/main/res/xml/settings_advanced.xml b/src/main/res/xml/settings_advanced.xml index 5e94ab4f2..e4d34d0fd 100644 --- a/src/main/res/xml/settings_advanced.xml +++ b/src/main/res/xml/settings_advanced.xml @@ -20,12 +20,6 @@ limitations under the License. android:defaultValue="1024" android:key="@string/photo_size_key" android:title="@string/settings_advanced_photo_size_title" /> -