From 6e15db6004d057085ee037bc24e0465bad57f06d Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 6 May 2019 10:48:14 +0200 Subject: [PATCH] Prevent crash --- .../main/java/eu/faircode/email/ActivitySetup.java | 13 +++++++++++++ .../eu/faircode/email/FragmentOptionsGeneral.java | 8 ++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivitySetup.java b/app/src/main/java/eu/faircode/email/ActivitySetup.java index 538e0e5975..972541f0ec 100644 --- a/app/src/main/java/eu/faircode/email/ActivitySetup.java +++ b/app/src/main/java/eu/faircode/email/ActivitySetup.java @@ -109,6 +109,7 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On static final String ACTION_EDIT_ACCOUNT = BuildConfig.APPLICATION_ID + ".EDIT_ACCOUNT"; static final String ACTION_EDIT_IDENTITY = BuildConfig.APPLICATION_ID + ".EDIT_IDENTITY"; + static final String ACTION_SHOW_PRO = BuildConfig.APPLICATION_ID + ".SHOW_PRO"; @Override protected void onCreate(Bundle savedInstanceState) { @@ -302,6 +303,7 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On IntentFilter iff = new IntentFilter(); iff.addAction(ACTION_EDIT_ACCOUNT); iff.addAction(ACTION_EDIT_IDENTITY); + iff.addAction(ACTION_SHOW_PRO); lbm.registerReceiver(receiver, iff); } @@ -906,6 +908,15 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On fragmentTransaction.commit(); } + private void onShowPro(Intent intent) { + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + getSupportFragmentManager().popBackStack("pro", FragmentManager.POP_BACK_STACK_INCLUSIVE); + + FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); + fragmentTransaction.replace(R.id.content_frame, new FragmentPro()).addToBackStack("pro"); + fragmentTransaction.commit(); + } + BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -913,6 +924,8 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On onEditAccount(intent); else if (ACTION_EDIT_IDENTITY.equals(intent.getAction())) onEditIdentity(intent); + else if (ACTION_SHOW_PRO.equals(intent.getAction())) + onShowPro(intent); } }; } diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsGeneral.java b/app/src/main/java/eu/faircode/email/FragmentOptionsGeneral.java index cd95fe8b14..9f6fef8b8d 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsGeneral.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsGeneral.java @@ -22,6 +22,7 @@ package eu.faircode.email; import android.app.Dialog; import android.app.TimePickerDialog; import android.content.Context; +import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.text.format.DateFormat; @@ -38,7 +39,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.SwitchCompat; import androidx.fragment.app.DialogFragment; -import androidx.fragment.app.FragmentTransaction; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.preference.PreferenceManager; import java.text.SimpleDateFormat; @@ -116,9 +117,8 @@ public class FragmentOptionsGeneral extends FragmentBase implements SharedPrefer ServiceSynchronize.reschedule(getContext()); } else { swSchedule.setChecked(false); - FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); - fragmentTransaction.replace(R.id.content_frame, new FragmentPro()).addToBackStack("pro"); - fragmentTransaction.commit(); + LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext()); + lbm.sendBroadcast(new Intent(ActivityView.ACTION_SHOW_PRO)); } } else { prefs.edit().putBoolean("schedule", false).apply();