From 6dd8c7a3eca34d151e2ea9720f80f2da3014ea33 Mon Sep 17 00:00:00 2001 From: Conny Duck Date: Mon, 5 Feb 2018 11:27:32 +0100 Subject: [PATCH] fixes a crash when trying to share via Tusky while not logged in --- .../java/com/keylesspalace/tusky/BaseActivity.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java b/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java index 5af788df..4b203f89 100644 --- a/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java @@ -55,9 +55,6 @@ public abstract class BaseActivity extends AppCompatActivity { protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - redirectIfNotLoggedIn(); - createMastodonApi(); - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); /* There isn't presently a way to globally change the theme of a whole application at @@ -82,6 +79,11 @@ public abstract class BaseActivity extends AppCompatActivity { } getTheme().applyStyle(style, false); + if(redirectIfNotLoggedIn()) { + return; + } + createMastodonApi(); + } @Override @@ -152,13 +154,15 @@ public abstract class BaseActivity extends AppCompatActivity { mastodonApi = retrofit.create(MastodonApi.class); } - protected void redirectIfNotLoggedIn() { + protected boolean redirectIfNotLoggedIn() { if (TuskyApplication.getAccountManager().getActiveAccount() == null) { Intent intent = new Intent(this, LoginActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); finish(); + return true; } + return false; } @Override