From 05885c6a719f8adc1512df698006ec33ccb236ea Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 1 Nov 2019 18:20:28 +0100 Subject: [PATCH] Refactoring --- .../java/eu/faircode/email/ActivityBase.java | 24 ++++++++++--------- .../java/eu/faircode/email/FragmentBase.java | 5 +--- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityBase.java b/app/src/main/java/eu/faircode/email/ActivityBase.java index 6b3f77b61c..13a7704b95 100644 --- a/app/src/main/java/eu/faircode/email/ActivityBase.java +++ b/app/src/main/java/eu/faircode/email/ActivityBase.java @@ -161,10 +161,8 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc public void onUserInteraction() { Log.i("User interaction"); - if (!this.getClass().equals(ActivityMain.class) && Helper.shouldAuthenticate(this)) { - finishAndRemoveTask(); - startActivity(new Intent(this, ActivityMain.class)); - } + if (!this.getClass().equals(ActivityMain.class) && Helper.shouldAuthenticate(this)) + restart(null); } @Override @@ -205,13 +203,8 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc } private void checkAuthentication() { - if (!this.getClass().equals(ActivityMain.class) && Helper.shouldAuthenticate(this)) { - Intent intent = getIntent(); - finishAndRemoveTask(); - startActivity( - new Intent(this, ActivityMain.class) - .putExtra("intent", intent)); - } + if (!this.getClass().equals(ActivityMain.class) && Helper.shouldAuthenticate(this)) + restart(getIntent()); } @Override @@ -282,6 +275,15 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc } } + protected void restart(Intent intent) { + Intent main = new Intent(this, ActivityMain.class); + if (intent != null) + main.putExtra("intent", intent); + main.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + startActivity(main); + finishAndRemoveTask(); + } + protected boolean backHandled() { for (IBackPressedListener listener : backPressedListeners) if (listener.onBackPressed()) diff --git a/app/src/main/java/eu/faircode/email/FragmentBase.java b/app/src/main/java/eu/faircode/email/FragmentBase.java index 9f17e0128b..488d49020c 100644 --- a/app/src/main/java/eu/faircode/email/FragmentBase.java +++ b/app/src/main/java/eu/faircode/email/FragmentBase.java @@ -116,10 +116,7 @@ public class FragmentBase extends Fragment { } protected void restart() { - Intent intent = new Intent(getContext(), ActivityMain.class); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); - startActivity(intent); - Runtime.getRuntime().exit(0); + ((ActivityBase) getActivity()).restart(null); } @Override