BolusProgress code cleanup

This commit is contained in:
Milos Kozak 2019-08-01 10:26:31 +02:00
parent 32ff72b620
commit b0eecac00e
3 changed files with 17 additions and 28 deletions

View file

@ -290,22 +290,6 @@ public class MainApp extends Application {
KeepAliveReceiver.cancelAlarm(this); 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() { public static Bus bus() {
return sBus; return sBus;
} }

View file

@ -4,8 +4,6 @@ package info.nightscout.androidaps.plugins.general.overview.dialogs;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.os.SystemClock; import android.os.SystemClock;
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -13,6 +11,9 @@ import android.widget.Button;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import com.squareup.otto.Subscribe; import com.squareup.otto.Subscribe;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -86,11 +87,15 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
} else { } else {
if (getDialog() != null) if (getDialog() != null)
getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
MainApp.subscribe(this);
running = true; running = true;
if (L.isEnabled(L.UI)) if (L.isEnabled(L.UI))
log.debug("onResume running"); log.debug("onResume running");
} }
try {
MainApp.bus().register(this);
} catch (IllegalArgumentException e) {
log.error("Already registered");
}
} }
@Override @Override
@ -112,11 +117,15 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
@Override @Override
public void onPause() { public void onPause() {
running = false;
super.onPause();
MainApp.unsubscribe(this);
if (L.isEnabled(L.UI)) if (L.isEnabled(L.UI))
log.debug("onPause"); log.debug("onPause");
running = false;
super.onPause();
try {
MainApp.bus().unregister(this);
} catch (IllegalArgumentException e) {
log.error("Already unregistered");
}
} }
@Override @Override
@ -196,9 +205,6 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
} }
}); });
} else {
if (L.isEnabled(L.UI))
log.debug("activity == null");
} }
}); });
t.start(); t.start();

View file

@ -15,10 +15,9 @@ public class BolusProgressHelperActivity extends AppCompatActivity {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
this.getIntent().getDoubleExtra("insulin", 0d);
BolusProgressDialog bolusProgressDialog = new BolusProgressDialog(); BolusProgressDialog bolusProgressDialog = new BolusProgressDialog();
bolusProgressDialog.setHelperActivity(this); bolusProgressDialog.setHelperActivity(this);
bolusProgressDialog.setInsulin(this.getIntent().getDoubleExtra("insulin", 0d)); bolusProgressDialog.setInsulin(getIntent().getDoubleExtra("insulin", 0d));
bolusProgressDialog.show(this.getSupportFragmentManager(), "BolusProgress"); bolusProgressDialog.show(getSupportFragmentManager(), "BolusProgress");
} }
} }