From 0c7dba6d43d382325969cfb5b269548a31bb3122 Mon Sep 17 00:00:00 2001 From: Jake McGinty Date: Thu, 2 Apr 2015 17:16:55 -0700 Subject: [PATCH] Pass MasterSecret into pref fragments Fixes #2868 Closes #2870 // FREEBIE --- .../ApplicationPreferencesActivity.java | 18 +++++------------- .../AdvancedPreferenceFragment.java | 7 +++++-- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java index 558b18c5ee..cef095caec 100644 --- a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java +++ b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java @@ -69,16 +69,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA @Override protected void onCreate(Bundle icicle, @NonNull MasterSecret masterSecret) { this.getSupportActionBar().setDisplayHomeAsUpEnabled(true); - - Bundle fragmentArgs = new Bundle(); - Fragment fragment = new ApplicationPreferenceFragment(); - - fragmentArgs.putParcelable("master_secret", masterSecret); - fragment.setArguments(fragmentArgs); - - getSupportFragmentManager().beginTransaction() - .replace(android.R.id.content, fragment) - .commit(); + initFragment(android.R.id.content, new ApplicationPreferenceFragment(), masterSecret); } @Override @@ -185,10 +176,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA fragment = new NotificationsPreferenceFragment(); break; case PREFERENCE_CATEGORY_APP_PROTECTION: - Bundle args = new Bundle(); - args.putParcelable("master_secret", masterSecret); fragment = new AppProtectionPreferenceFragment(); - fragment.setArguments(args); break; case PREFERENCE_CATEGORY_APPEARANCE: fragment = new AppearancePreferenceFragment(); @@ -203,6 +191,10 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA throw new AssertionError(); } + Bundle args = new Bundle(); + args.putParcelable("master_secret", masterSecret); + fragment.setArguments(args); + FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(android.R.id.content, fragment); diff --git a/src/org/thoughtcrime/securesms/preferences/AdvancedPreferenceFragment.java b/src/org/thoughtcrime/securesms/preferences/AdvancedPreferenceFragment.java index 29b97163ab..982f8b25ad 100644 --- a/src/org/thoughtcrime/securesms/preferences/AdvancedPreferenceFragment.java +++ b/src/org/thoughtcrime/securesms/preferences/AdvancedPreferenceFragment.java @@ -22,6 +22,7 @@ import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.RegistrationActivity; import org.thoughtcrime.securesms.contacts.ContactAccessor; import org.thoughtcrime.securesms.contacts.ContactIdentityManager; +import org.thoughtcrime.securesms.crypto.MasterSecret; import org.thoughtcrime.securesms.push.TextSecureCommunicationFactory; import org.thoughtcrime.securesms.util.ProgressDialogAsyncTask; import org.thoughtcrime.securesms.util.TextSecurePreferences; @@ -39,9 +40,12 @@ public class AdvancedPreferenceFragment extends PreferenceFragment { private static final int PICK_IDENTITY_CONTACT = 1; + private MasterSecret masterSecret; + @Override public void onCreate(Bundle paramBundle) { super.onCreate(paramBundle); + masterSecret = getArguments().getParcelable("master_secret"); addPreferencesFromResource(R.xml.preferences_advanced); initializePushMessagingToggle(); @@ -186,12 +190,11 @@ public class AdvancedPreferenceFragment extends PreferenceFragment { builder.show(); } else { Intent nextIntent = new Intent(getActivity(), ApplicationPreferencesActivity.class); - nextIntent.putExtra("master_secret", getActivity().getIntent().getParcelableExtra("master_secret")); Intent intent = new Intent(getActivity(), RegistrationActivity.class); intent.putExtra("cancel_button", true); intent.putExtra("next_intent", nextIntent); - intent.putExtra("master_secret", getActivity().getIntent().getParcelableExtra("master_secret")); + intent.putExtra("master_secret", masterSecret); startActivity(intent); }