Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 09a8b386 authored by Moez Bhatti's avatar Moez Bhatti
Browse files

Respect system preference for 24 hour time

parent dcf9cfd7
Loading
Loading
Loading
Loading
+0 −10
Original line number Diff line number Diff line
package com.moez.QKSMS.common.utils;

import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.test.AndroidTestCase;
import com.moez.QKSMS.ui.settings.SettingsFragment;

import java.text.SimpleDateFormat;

@@ -12,13 +9,6 @@ public class DateFormatterTest extends AndroidTestCase {
        super.setUp();
    }

    public void test24Hours() {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
        prefs.edit().putBoolean(SettingsFragment.TIMESTAMPS_24H, true).apply();
        assertTrue(DateFormatter.accountFor24HourTime(getContext(), new SimpleDateFormat("h:mm a")).equals(new SimpleDateFormat("H:mm")));
        prefs.edit().putBoolean(SettingsFragment.TIMESTAMPS_24H, false).apply();
    }

    public void testDateSymbolsAPI(){
        assertEquals(new SimpleDateFormat("H:mm a").toPattern(), "H:mm a");
    }
+1 −5
Original line number Diff line number Diff line
package com.moez.QKSMS.common.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.text.format.DateFormat;
import android.text.format.DateUtils;
import com.moez.QKSMS.QKSMSApp;
import com.moez.QKSMS.R;
import com.moez.QKSMS.ui.settings.SettingsFragment;

import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -48,8 +45,7 @@ public abstract class DateFormatter {
    }

    public static SimpleDateFormat accountFor24HourTime(Context context, SimpleDateFormat input) { //pass in 12 hour time. If needed, change to 24 hr.
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        boolean isUsing24HourTime = prefs.getBoolean(SettingsFragment.TIMESTAMPS_24H, DateFormat.is24HourFormat(context));
        boolean isUsing24HourTime = DateFormat.is24HourFormat(context);

        if (isUsing24HourTime) {
            return new SimpleDateFormat(input.toPattern().replace('h', 'H').replaceAll(" a", ""));
+0 −1
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ public enum QKPreference {
    HIDE_AVATAR_RECEIVED("pref_key_hide_avatar_received", false),

    MESSAGE_COUNT("pref_key_message_count", false),
    TIMESTAMPS_24H("pref_key_24h", false),

    // General
    DELAYED_MESSAGING("pref_key_delayed", false),
+0 −1
Original line number Diff line number Diff line
@@ -116,7 +116,6 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
    public static final String SPLIT_COUNTER = "pref_key_split_counter";
    public static final String LONG_AS_MMS = "pref_key_long_as_mms";
    public static final String LONG_AS_MMS_AFTER = "pref_key_long_as_mms_after";
    public static final String TIMESTAMPS_24H = "pref_key_24h";
    public static final String NOTIFICATIONS = "pref_key_notifications";
    public static final String NOTIFICATION_LED = "pref_key_led";
    public static final String NOTIFICATION_LED_COLOR = "pref_key_theme_led";
+1 −1
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ public class TimePickerFragment extends DialogFragment implements TimePickerDial

        int hour = c.get(Calendar.HOUR_OF_DAY);
        int minute = c.get(Calendar.MINUTE);
        boolean isUsing24HourTime = mPrefs.getBoolean(SettingsFragment.TIMESTAMPS_24H, DateFormat.is24HourFormat(getActivity()));
        boolean isUsing24HourTime = DateFormat.is24HourFormat(getActivity());
        return new TimePickerDialog(getActivity(), this, hour, minute, isUsing24HourTime);
    }

Loading