From fba29ddbdd0958b953d1da82cb9e22989580e804 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 17 Oct 2021 07:02:00 +0200 Subject: [PATCH] Prevent crash --- .../main/java/eu/faircode/email/FragmentSetup.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentSetup.java b/app/src/main/java/eu/faircode/email/FragmentSetup.java index 30a3f65056..2431599b49 100644 --- a/app/src/main/java/eu/faircode/email/FragmentSetup.java +++ b/app/src/main/java/eu/faircode/email/FragmentSetup.java @@ -55,6 +55,7 @@ import androidx.cardview.widget.CardView; import androidx.constraintlayout.widget.Group; import androidx.core.view.MenuCompat; import androidx.fragment.app.FragmentActivity; +import androidx.lifecycle.Lifecycle; import androidx.lifecycle.Observer; import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.preference.PreferenceManager; @@ -748,7 +749,7 @@ public class FragmentSetup extends FragmentBase { view.post(new Runnable() { @Override public void run() { - tvNoInternet.setVisibility(View.GONE); + updateInternet(true); } }); } @@ -758,10 +759,16 @@ public class FragmentSetup extends FragmentBase { view.post(new Runnable() { @Override public void run() { - tvNoInternet.setVisibility(View.VISIBLE); + updateInternet(false); } }); } + + private void updateInternet(boolean available) { + if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) + return; + tvNoInternet.setVisibility(available ? View.GONE : View.VISIBLE); + } }; public static class FragmentDialogDoze extends FragmentDialogBase {