diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java index 40fab7a7..b16a750a 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java @@ -11,6 +11,7 @@ public class SettingsActivity extends BaseActivity { public static final String DEFAULT_HOME_TAB = "pref_app_main_default_tab_key"; public static final String DISPLAY_COMPACT_TABS = "pref_app_display_compact_tabs_key"; public static final String DISPLAY_RELATIVE_TIME = "pref_app_display_relative_time_key"; + public static final String USE_GREEK_TIMEZONE = "pref_app_use_greek_timezone_key"; public static final String NOTIFICATION_LED_KEY = "pref_notification_led_enable_key"; public static final String NOTIFICATION_VIBRATION_KEY = "pref_notification_vibration_enable_key"; public static final String POSTING_APP_SIGNATURE_ENABLE_KEY = "pref_posting_app_signature_enable_key"; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java index 355fa8eb..efd0dccf 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java @@ -66,7 +66,9 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared defaultHomeTabValues.add("0"); defaultHomeTabValues.add("1"); - if (isLoggedIn = BaseApplication.getInstance().getSessionManager().isLoggedIn()) { + isLoggedIn = BaseApplication.getInstance().getSessionManager().isLoggedIn(); + + if (isLoggedIn) { defaultHomeTabEntries.add(UNREAD); defaultHomeTabValues.add("2"); } @@ -228,6 +230,10 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared && BaseApplication.getInstance().isDisplayCompactTabsEnabled() != sharedPreferences.getBoolean(key, false)) { displayRestartAppToTakeEffectToast(); } + else if (key.equals(getString(R.string.pref_app_use_greek_timezone_key)) + && BaseApplication.getInstance().isUseGreekTimezoneEnabled() != sharedPreferences.getBoolean(key, false)) { + displayRestartAppToTakeEffectToast(); + } } private void displayRestartAppToTakeEffectToast() { diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java index 228b67d3..42715f5e 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java @@ -2,6 +2,7 @@ package gr.thmmy.mthmmy.base; import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.DISPLAY_COMPACT_TABS; import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.DISPLAY_RELATIVE_TIME; +import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.USE_GREEK_TIMEZONE; import static gr.thmmy.mthmmy.activities.upload.UploadActivity.firebaseConfigUploadsCoursesKey; import static gr.thmmy.mthmmy.utils.io.ResourceUtils.readJSONResourceToString; @@ -71,6 +72,7 @@ public class BaseApplication extends Application implements Executor{ private boolean displayRelativeTime; private boolean displayCompactTabs; + private boolean useGreekTimezone; //Display Metrics private static float widthDp; @@ -115,6 +117,7 @@ public class BaseApplication extends Application implements Executor{ displayRelativeTime = settingsSharedPrefs.getBoolean(DISPLAY_RELATIVE_TIME, true); displayCompactTabs = settingsSharedPrefs.getBoolean(DISPLAY_COMPACT_TABS, true); + useGreekTimezone = settingsSharedPrefs.getBoolean(USE_GREEK_TIMEZONE, true); } private void initFirebase(SharedPreferences settingsSharedPrefs) { @@ -263,6 +266,10 @@ public class BaseApplication extends Application implements Executor{ return displayCompactTabs; } + public boolean isUseGreekTimezoneEnabled() { + return useGreekTimezone; + } + //-------------------- Firebase -------------------- public void logFirebaseAnalyticsEvent(String event, Bundle params) { diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ThmmyDateTimeParser.java b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ThmmyDateTimeParser.java index cfc40ae2..66660163 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ThmmyDateTimeParser.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ThmmyDateTimeParser.java @@ -45,7 +45,16 @@ public class ThmmyDateTimeParser { public static String convertToTimestamp(String thmmyDateTime) { Timber.v("Will attempt to convert %s to timestamp.", thmmyDateTime); String originalDateTime = thmmyDateTime; - DateTimeZone dtz = getDtz(); + + DateTimeZone dtz; + + // This was added for people who briefly travelled abroad and didn't change the displayed time in their profile settings + final boolean useeGreekTimezone = BaseApplication.getInstance().isUseGreekTimezoneEnabled(); + + if(useeGreekTimezone) + dtz = DateTimeZone.forID("Europe/Athens"); + else + dtz = DateTimeZone.getDefault(); // Remove any unnecessary "Today at" strings thmmyDateTime = purifyTodayDateTime(thmmyDateTime); @@ -112,12 +121,4 @@ public class ThmmyDateTimeParser { private static String removeSeconds(String dateTime) { return dateTime.replaceAll("(.*):\\d+($|\\s.*)", "$1$2"); } - - @VisibleForTesting - private static DateTimeZone getDtz() { - if (!BaseApplication.getInstance().getSessionManager().isLoggedIn()) - return DateTimeZone.forID("Europe/Athens"); - else - return DateTimeZone.getDefault(); - } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a51c55e6..bd2180ea 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -180,6 +180,9 @@ pref_app_display_relative_time_key Display relative time Considering that you haven\'t set some weird custom time format + pref_app_use_greek_timezone_key + Use Greek timezone + For relative time only. Disable this if you have also set a custom displayed time in your profile pref_app_display_compact_tabs_key Display compact tabs Home screen tabs will occupy less space diff --git a/app/src/main/res/xml-v26/app_preferences_guest.xml b/app/src/main/res/xml-v26/app_preferences_guest.xml index f366c6e0..58794266 100644 --- a/app/src/main/res/xml-v26/app_preferences_guest.xml +++ b/app/src/main/res/xml-v26/app_preferences_guest.xml @@ -20,6 +20,12 @@ android:title="@string/pref_title_display_relative_time" android:summary="@string/pref_summary_display_relative_time" app:iconSpaceReserved="false" /> + + + +