Browse Source

feat: avoid wrong timestamp conversions

develop
Ezerous 3 months ago
parent
commit
ecfa4c9c5b
  1. 1
      app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java
  2. 8
      app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java
  3. 7
      app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java
  4. 19
      app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ThmmyDateTimeParser.java
  5. 3
      app/src/main/res/values/strings.xml
  6. 6
      app/src/main/res/xml-v26/app_preferences_guest.xml
  7. 6
      app/src/main/res/xml-v26/app_preferences_user.xml
  8. 6
      app/src/main/res/xml/app_preferences_guest.xml
  9. 6
      app/src/main/res/xml/app_preferences_user.xml

1
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";

8
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() {

7
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) {

19
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();
}
}

3
app/src/main/res/values/strings.xml

@ -180,6 +180,9 @@
<string name="pref_app_display_relative_time_key">pref_app_display_relative_time_key</string>
<string name="pref_title_display_relative_time">Display relative time</string>
<string name="pref_summary_display_relative_time">Considering that you haven\'t set some weird custom time format</string>
<string name="pref_app_use_greek_timezone_key">pref_app_use_greek_timezone_key</string>
<string name="pref_title_use_greek_timezone">Use Greek timezone</string>
<string name="pref_summary_use_greek_timezone">For relative time only. Disable this if you have also set a custom displayed time in your profile</string>
<string name="pref_app_display_compact_tabs_key">pref_app_display_compact_tabs_key</string>
<string name="pref_title_display_compact_tabs">Display compact tabs</string>
<string name="pref_summary_display_compact_tabs">Home screen tabs will occupy less space</string>

6
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" />
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="@string/pref_app_use_greek_timezone_key"
android:title="@string/pref_title_use_greek_timezone"
android:summary="@string/pref_summary_use_greek_timezone"
app:iconSpaceReserved="false" />
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="@string/pref_app_display_compact_tabs_key"

6
app/src/main/res/xml-v26/app_preferences_user.xml

@ -20,6 +20,12 @@
android:title="@string/pref_title_display_relative_time"
android:summary="@string/pref_summary_display_relative_time"
app:iconSpaceReserved="false" />
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="@string/pref_app_use_greek_timezone_key"
android:title="@string/pref_title_use_greek_timezone"
android:summary="@string/pref_summary_use_greek_timezone"
app:iconSpaceReserved="false" />
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="@string/pref_app_display_compact_tabs_key"

6
app/src/main/res/xml/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" />
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="@string/pref_app_use_greek_timezone_key"
android:title="@string/pref_title_use_greek_timezone"
android:summary="@string/pref_summary_use_greek_timezone"
app:iconSpaceReserved="false" />
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="@string/pref_app_display_compact_tabs_key"

6
app/src/main/res/xml/app_preferences_user.xml

@ -20,6 +20,12 @@
android:title="@string/pref_title_display_relative_time"
android:summary="@string/pref_summary_display_relative_time"
app:iconSpaceReserved="false" />
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="@string/pref_app_use_greek_timezone_key"
android:title="@string/pref_title_use_greek_timezone"
android:summary="@string/pref_summary_use_greek_timezone"
app:iconSpaceReserved="false" />
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="@string/pref_app_display_compact_tabs_key"

Loading…
Cancel
Save