From f07ce7b1f11edf37f9d2483122a641e6d16613e5 Mon Sep 17 00:00:00 2001 From: Mateo Hernandez Date: Sat, 15 Apr 2017 11:58:26 -0500 Subject: [PATCH] Move SMS/MMS pref hiding logic to onCreate Closes #6528 // FREEBIE --- .../preferences/SmsMmsPreferenceFragment.java | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/org/thoughtcrime/securesms/preferences/SmsMmsPreferenceFragment.java b/src/org/thoughtcrime/securesms/preferences/SmsMmsPreferenceFragment.java index 5fe97930b1..5d1e317633 100644 --- a/src/org/thoughtcrime/securesms/preferences/SmsMmsPreferenceFragment.java +++ b/src/org/thoughtcrime/securesms/preferences/SmsMmsPreferenceFragment.java @@ -31,6 +31,8 @@ public class SmsMmsPreferenceFragment extends CorrectedPreferenceFragment { this.findPreference(MMS_PREF) .setOnPreferenceClickListener(new ApnPreferencesClickListener()); + + initializePlatformSpecificOptions(); } @Override @@ -38,7 +40,7 @@ public class SmsMmsPreferenceFragment extends CorrectedPreferenceFragment { super.onResume(); ((ApplicationPreferencesActivity) getActivity()).getSupportActionBar().setTitle(R.string.preferences__sms_mms); - initializePlatformSpecificOptions(); + initializeDefaultPreference(); } private void initializePlatformSpecificOptions() { @@ -51,18 +53,6 @@ public class SmsMmsPreferenceFragment extends CorrectedPreferenceFragment { if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) { if (allSmsPreference != null) preferenceScreen.removePreference(allSmsPreference); if (allMmsPreference != null) preferenceScreen.removePreference(allMmsPreference); - - if (Util.isDefaultSmsProvider(getActivity())) { - defaultPreference.setIntent(new Intent(Settings.ACTION_WIRELESS_SETTINGS)); - defaultPreference.setTitle(getString(R.string.ApplicationPreferencesActivity_sms_enabled)); - defaultPreference.setSummary(getString(R.string.ApplicationPreferencesActivity_touch_to_change_your_default_sms_app)); - } else { - Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT); - intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, getActivity().getPackageName()); - defaultPreference.setIntent(intent); - defaultPreference.setTitle(getString(R.string.ApplicationPreferencesActivity_sms_disabled)); - defaultPreference.setSummary(getString(R.string.ApplicationPreferencesActivity_touch_to_make_signal_your_default_sms_app)); - } } else if (defaultPreference != null) { preferenceScreen.removePreference(defaultPreference); } @@ -72,6 +62,23 @@ public class SmsMmsPreferenceFragment extends CorrectedPreferenceFragment { } } + private void initializeDefaultPreference() { + if (VERSION.SDK_INT < VERSION_CODES.KITKAT) return; + + Preference defaultPreference = findPreference(KITKAT_DEFAULT_PREF); + if (Util.isDefaultSmsProvider(getActivity())) { + defaultPreference.setIntent(new Intent(Settings.ACTION_WIRELESS_SETTINGS)); + defaultPreference.setTitle(getString(R.string.ApplicationPreferencesActivity_sms_enabled)); + defaultPreference.setSummary(getString(R.string.ApplicationPreferencesActivity_touch_to_change_your_default_sms_app)); + } else { + Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT); + intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, getActivity().getPackageName()); + defaultPreference.setIntent(intent); + defaultPreference.setTitle(getString(R.string.ApplicationPreferencesActivity_sms_disabled)); + defaultPreference.setSummary(getString(R.string.ApplicationPreferencesActivity_touch_to_make_signal_your_default_sms_app)); + } + } + private class ApnPreferencesClickListener implements Preference.OnPreferenceClickListener { @Override