From b0eecac00e300066781d6b0ed57292f381abb200 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 1 Aug 2019 10:26:31 +0200 Subject: [PATCH] BolusProgress code cleanup --- .../info/nightscout/androidaps/MainApp.java | 16 ------------- .../overview/dialogs/BolusProgressDialog.java | 24 ++++++++++++------- .../dialogs/BolusProgressHelperActivity.java | 5 ++-- 3 files changed, 17 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 734962e5dd..dd51afbec5 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -290,22 +290,6 @@ public class MainApp extends Application { KeepAliveReceiver.cancelAlarm(this); } - public static void subscribe(Object subscriber) { - try { - bus().register(subscriber); - } catch (IllegalArgumentException e) { - // already registered - } - } - - public static void unsubscribe(Object subscriber) { - try { - bus().unregister(subscriber); - } catch (IllegalArgumentException e) { - // already unregistered - } - } - public static Bus bus() { return sBus; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/BolusProgressDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/BolusProgressDialog.java index 3876250308..04da9761a3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/BolusProgressDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/BolusProgressDialog.java @@ -4,8 +4,6 @@ package info.nightscout.androidaps.plugins.general.overview.dialogs; import android.app.Activity; import android.os.Bundle; import android.os.SystemClock; -import androidx.annotation.NonNull; -import androidx.fragment.app.DialogFragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -13,6 +11,9 @@ import android.widget.Button; import android.widget.ProgressBar; import android.widget.TextView; +import androidx.annotation.NonNull; +import androidx.fragment.app.DialogFragment; + import com.squareup.otto.Subscribe; import org.slf4j.Logger; @@ -86,11 +87,15 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL } else { if (getDialog() != null) getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - MainApp.subscribe(this); running = true; if (L.isEnabled(L.UI)) log.debug("onResume running"); } + try { + MainApp.bus().register(this); + } catch (IllegalArgumentException e) { + log.error("Already registered"); + } } @Override @@ -112,11 +117,15 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL @Override public void onPause() { - running = false; - super.onPause(); - MainApp.unsubscribe(this); if (L.isEnabled(L.UI)) log.debug("onPause"); + running = false; + super.onPause(); + try { + MainApp.bus().unregister(this); + } catch (IllegalArgumentException e) { + log.error("Already unregistered"); + } } @Override @@ -196,9 +205,6 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL log.error("Unhandled exception", e); } }); - } else { - if (L.isEnabled(L.UI)) - log.debug("activity == null"); } }); t.start(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/BolusProgressHelperActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/BolusProgressHelperActivity.java index 7ca19d0334..a18f9bbb18 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/BolusProgressHelperActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/BolusProgressHelperActivity.java @@ -15,10 +15,9 @@ public class BolusProgressHelperActivity extends AppCompatActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - this.getIntent().getDoubleExtra("insulin", 0d); BolusProgressDialog bolusProgressDialog = new BolusProgressDialog(); bolusProgressDialog.setHelperActivity(this); - bolusProgressDialog.setInsulin(this.getIntent().getDoubleExtra("insulin", 0d)); - bolusProgressDialog.show(this.getSupportFragmentManager(), "BolusProgress"); + bolusProgressDialog.setInsulin(getIntent().getDoubleExtra("insulin", 0d)); + bolusProgressDialog.show(getSupportFragmentManager(), "BolusProgress"); } }