Skip to content

Commit

Permalink
Respect system preference for 24 hour time
Browse files Browse the repository at this point in the history
  • Loading branch information
moezbhatti committed Jul 7, 2016
1 parent dcf9cfd commit 09a8b38
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
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;

Expand All @@ -12,13 +9,6 @@ protected void setUp() throws Exception {
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");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
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;
Expand Down Expand Up @@ -48,8 +45,7 @@ private static boolean isYesterday(long date) {
}

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", ""));
Expand Down
1 change: 0 additions & 1 deletion QKSMS/src/main/java/com/moez/QKSMS/enums/QKPreference.java
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {

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

Expand Down
2 changes: 0 additions & 2 deletions QKSMS/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@
<string name="pref_long_as_mms_summary">Send long messages as MMS instead of splitting them</string>
<string name="pref_long_as_mms_after">Send long as MMS after</string>
<string name="pref_long_as_mms_after_summary">Send long messages as MMS when they exceed the length of a number of messages</string>
<string name="pref_24h">24h time</string>
<string name="pref_24h_summary">Display timestamps in 24-hour format</string>
<string name="pref_return">Show return button</string>
<string name="pref_return_summary">Show return key on keyboard instead of Emoji button</string>
<string name="pref_text">Text</string>
Expand Down
7 changes: 0 additions & 7 deletions QKSMS/src/main/res/xml/settings_appearance.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,5 @@
android:summary="@string/pref_message_count_summary"
android:title="@string/pref_message_count"
android:widgetLayout="@layout/view_switch" />
<CheckBoxPreference
android:defaultValue="false"
android:key="pref_key_24h"
android:layout="@layout/list_item_preference"
android:summary="@string/pref_24h_summary"
android:title="@string/pref_24h"
android:widgetLayout="@layout/view_switch" />
</PreferenceCategory>
</PreferenceScreen>

0 comments on commit 09a8b38

Please sign in to comment.