From 1568b42d0d8947e643f2460ecf1c5533cd79f2ff Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Sun, 14 Mar 2021 23:18:40 -0400 Subject: [PATCH] date is locale not post, also post settings title --- .../settings/LocalePreferencesFragment.java | 45 +++++++++++++++++++ .../settings/PostPreferencesFragment.java | 45 ------------------- .../main/res/navigation/more_nav_graph.xml | 2 +- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/settings/LocalePreferencesFragment.java b/app/src/main/java/awais/instagrabber/fragments/settings/LocalePreferencesFragment.java index 2c140157..a02a8764 100644 --- a/app/src/main/java/awais/instagrabber/fragments/settings/LocalePreferencesFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/settings/LocalePreferencesFragment.java @@ -7,10 +7,15 @@ import androidx.preference.ListPreference; import androidx.preference.Preference; import androidx.preference.PreferenceScreen; +import java.text.SimpleDateFormat; +import java.util.Date; + import awais.instagrabber.R; +import awais.instagrabber.dialogs.TimeSettingsDialog; import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.LocaleUtils; import awais.instagrabber.utils.UserAgentUtils; +import awais.instagrabber.utils.Utils; import static awais.instagrabber.utils.Utils.settingsHelper; @@ -20,6 +25,7 @@ public class LocalePreferencesFragment extends BasePreferencesFragment { final Context context = getContext(); if (context == null) return; screen.addPreference(getLanguagePreference(context)); + screen.addPreference(getPostTimeFormatPreference(context)); } private Preference getLanguagePreference(@NonNull final Context context) { @@ -45,4 +51,43 @@ public class LocalePreferencesFragment extends BasePreferencesFragment { }); return preference; } + + private Preference getPostTimeFormatPreference(@NonNull final Context context) { + final Preference preference = new Preference(context); + preference.setTitle(R.string.time_settings); + preference.setSummary(Utils.datetimeParser.format(new Date())); + preference.setIconSpaceReserved(false); + preference.setOnPreferenceClickListener(preference1 -> { + new TimeSettingsDialog( + settingsHelper.getBoolean(Constants.CUSTOM_DATE_TIME_FORMAT_ENABLED), + settingsHelper.getString(Constants.CUSTOM_DATE_TIME_FORMAT), + settingsHelper.getString(Constants.DATE_TIME_SELECTION), + settingsHelper.getBoolean(Constants.SWAP_DATE_TIME_FORMAT_ENABLED), + (isCustomFormat, + formatSelection, + spTimeFormatSelectedItemPosition, + spSeparatorSelectedItemPosition, + spDateFormatSelectedItemPosition, + selectedFormat, + currentFormat, + swapDateTime) -> { + if (isCustomFormat) { + settingsHelper.putString(Constants.CUSTOM_DATE_TIME_FORMAT, formatSelection); + } else { + final String formatSelectionUpdated = spTimeFormatSelectedItemPosition + ";" + + spSeparatorSelectedItemPosition + ';' + + spDateFormatSelectedItemPosition; // time;separator;date + settingsHelper.putString(Constants.DATE_TIME_FORMAT, selectedFormat); + settingsHelper.putString(Constants.DATE_TIME_SELECTION, formatSelectionUpdated); + } + settingsHelper.putBoolean(Constants.CUSTOM_DATE_TIME_FORMAT_ENABLED, isCustomFormat); + settingsHelper.putBoolean(Constants.SWAP_DATE_TIME_FORMAT_ENABLED, swapDateTime); + Utils.datetimeParser = (SimpleDateFormat) currentFormat.clone(); + preference.setSummary(Utils.datetimeParser.format(new Date())); + } + ).show(getParentFragmentManager(), null); + return true; + }); + return preference; + } } diff --git a/app/src/main/java/awais/instagrabber/fragments/settings/PostPreferencesFragment.java b/app/src/main/java/awais/instagrabber/fragments/settings/PostPreferencesFragment.java index 3e1885e6..07012fe9 100644 --- a/app/src/main/java/awais/instagrabber/fragments/settings/PostPreferencesFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/settings/PostPreferencesFragment.java @@ -7,13 +7,8 @@ import androidx.preference.Preference; import androidx.preference.PreferenceScreen; import androidx.preference.SwitchPreferenceCompat; -import java.text.SimpleDateFormat; -import java.util.Date; - import awais.instagrabber.R; -import awais.instagrabber.dialogs.TimeSettingsDialog; import awais.instagrabber.utils.Constants; -import awais.instagrabber.utils.Utils; import static awais.instagrabber.utils.Utils.settingsHelper; @@ -25,7 +20,6 @@ public class PostPreferencesFragment extends BasePreferencesFragment { // generalCategory.addPreference(getAutoPlayVideosPreference(context)); screen.addPreference(getAlwaysMuteVideosPreference(context)); screen.addPreference(getShowCaptionPreference(context)); - screen.addPreference(getPostTimeFormatPreference(context)); } private Preference getAutoPlayVideosPreference(@NonNull final Context context) { @@ -52,43 +46,4 @@ public class PostPreferencesFragment extends BasePreferencesFragment { preference.setIconSpaceReserved(false); return preference; } - - private Preference getPostTimeFormatPreference(@NonNull final Context context) { - final Preference preference = new Preference(context); - preference.setTitle(R.string.time_settings); - preference.setSummary(Utils.datetimeParser.format(new Date())); - preference.setIconSpaceReserved(false); - preference.setOnPreferenceClickListener(preference1 -> { - new TimeSettingsDialog( - settingsHelper.getBoolean(Constants.CUSTOM_DATE_TIME_FORMAT_ENABLED), - settingsHelper.getString(Constants.CUSTOM_DATE_TIME_FORMAT), - settingsHelper.getString(Constants.DATE_TIME_SELECTION), - settingsHelper.getBoolean(Constants.SWAP_DATE_TIME_FORMAT_ENABLED), - (isCustomFormat, - formatSelection, - spTimeFormatSelectedItemPosition, - spSeparatorSelectedItemPosition, - spDateFormatSelectedItemPosition, - selectedFormat, - currentFormat, - swapDateTime) -> { - if (isCustomFormat) { - settingsHelper.putString(Constants.CUSTOM_DATE_TIME_FORMAT, formatSelection); - } else { - final String formatSelectionUpdated = spTimeFormatSelectedItemPosition + ";" - + spSeparatorSelectedItemPosition + ';' - + spDateFormatSelectedItemPosition; // time;separator;date - settingsHelper.putString(Constants.DATE_TIME_FORMAT, selectedFormat); - settingsHelper.putString(Constants.DATE_TIME_SELECTION, formatSelectionUpdated); - } - settingsHelper.putBoolean(Constants.CUSTOM_DATE_TIME_FORMAT_ENABLED, isCustomFormat); - settingsHelper.putBoolean(Constants.SWAP_DATE_TIME_FORMAT_ENABLED, swapDateTime); - Utils.datetimeParser = (SimpleDateFormat) currentFormat.clone(); - preference.setSummary(Utils.datetimeParser.format(new Date())); - } - ).show(getParentFragmentManager(), null); - return true; - }); - return preference; - } } diff --git a/app/src/main/res/navigation/more_nav_graph.xml b/app/src/main/res/navigation/more_nav_graph.xml index a5d12d2b..c0c8770c 100644 --- a/app/src/main/res/navigation/more_nav_graph.xml +++ b/app/src/main/res/navigation/more_nav_graph.xml @@ -148,5 +148,5 @@ + android:label="@string/pref_category_post" /> \ No newline at end of file