From 618be154666e0cfdaa820c28aa0e96384080a075 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 30 Dec 2021 21:35:58 +0100 Subject: [PATCH] Refactoring --- .../java/eu/faircode/email/ActivityBase.java | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityBase.java b/app/src/main/java/eu/faircode/email/ActivityBase.java index d8d714ec7c..49f7814a5d 100644 --- a/app/src/main/java/eu/faircode/email/ActivityBase.java +++ b/app/src/main/java/eu/faircode/email/ActivityBase.java @@ -201,7 +201,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc */ } - checkAuthentication(); + checkAuthentication(true); super.onCreate(savedInstanceState); } @@ -247,7 +247,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc finish(); startActivity(getIntent()); } else - checkAuthentication(); + checkAuthentication(true); } @Override @@ -257,9 +257,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc visible = false; - if (!this.getClass().equals(ActivityMain.class) && - Helper.shouldAuthenticate(this, true)) - finishAndRemoveTask(); + checkAuthentication(false); } @Override @@ -271,14 +269,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc @Override public void onUserInteraction() { Log.d("User interaction"); - - if (!this.getClass().equals(ActivityMain.class) && - Helper.shouldAuthenticate(this, false)) { - finishAndRemoveTask(); - Intent main = new Intent(this, ActivityMain.class); - main.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); - startActivity(main); - } + checkAuthentication(true); } @Override @@ -379,18 +370,21 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc super.onActivityResult(requestCode, resultCode, data); } - private void checkAuthentication() { + private void checkAuthentication(boolean auth) { if (!this.getClass().equals(ActivityMain.class) && Helper.shouldAuthenticate(this, false)) { - Intent intent = getIntent(); finishAndRemoveTask(); setResult(RESULT_CANCELED); finishAffinity(); - processStreams(intent); - Intent main = new Intent(this, ActivityMain.class) - .putExtra("intent", intent); - main.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); - startActivity(main); + + if (auth) { + Intent intent = getIntent(); + processStreams(intent); + Intent main = new Intent(this, ActivityMain.class) + .putExtra("intent", intent); + main.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + startActivity(main); + } } }