improve PairingProgressDialog

This commit is contained in:
Milos Kozak 2020-03-24 21:00:43 +01:00
parent b872b82cd9
commit d1d49a8db2
4 changed files with 76 additions and 39 deletions

View file

@ -81,7 +81,9 @@
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".plugins.pump.danaRS.activities.PairingHelperActivity" /> <activity
android:name=".plugins.pump.danaRS.activities.PairingHelperActivity"
android:launchMode="singleTask" />
<activity android:name=".historyBrowser.HistoryBrowseActivity" /> <activity android:name=".historyBrowser.HistoryBrowseActivity" />
<activity android:name=".activities.SurveyActivity" /> <activity android:name=".activities.SurveyActivity" />
<activity android:name=".activities.StatsActivity" /> <activity android:name=".activities.StatsActivity" />

View file

@ -33,6 +33,7 @@ import info.nightscout.androidaps.plugins.profile.local.LocalProfileFragment
import info.nightscout.androidaps.plugins.profile.ns.NSProfileFragment import info.nightscout.androidaps.plugins.profile.ns.NSProfileFragment
import info.nightscout.androidaps.plugins.pump.combo.ComboFragment import info.nightscout.androidaps.plugins.pump.combo.ComboFragment
import info.nightscout.androidaps.plugins.pump.danaR.DanaRFragment import info.nightscout.androidaps.plugins.pump.danaR.DanaRFragment
import info.nightscout.androidaps.plugins.pump.danaRS.dialogs.PairingProgressDialog
import info.nightscout.androidaps.plugins.pump.insight.LocalInsightFragment import info.nightscout.androidaps.plugins.pump.insight.LocalInsightFragment
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicFragment import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicFragment
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpFragment import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpFragment
@ -83,6 +84,7 @@ abstract class FragmentsModule {
@ContributesAndroidInjector abstract fun contributesVirtualPumpFragment(): VirtualPumpFragment @ContributesAndroidInjector abstract fun contributesVirtualPumpFragment(): VirtualPumpFragment
@ContributesAndroidInjector abstract fun contributesPairingProgressDialog(): PairingProgressDialog
@ContributesAndroidInjector abstract fun contributesBolusProgressDialog(): BolusProgressDialog @ContributesAndroidInjector abstract fun contributesBolusProgressDialog(): BolusProgressDialog
@ContributesAndroidInjector abstract fun contributesCalibrationDialog(): CalibrationDialog @ContributesAndroidInjector abstract fun contributesCalibrationDialog(): CalibrationDialog
@ContributesAndroidInjector abstract fun contributesCarbsDialog(): CarbsDialog @ContributesAndroidInjector abstract fun contributesCarbsDialog(): CarbsDialog

View file

@ -1,18 +1,32 @@
package info.nightscout.androidaps.plugins.pump.danaRS.activities package info.nightscout.androidaps.plugins.pump.danaRS.activities
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Intent
import android.content.pm.ActivityInfo import android.content.pm.ActivityInfo
import android.os.Bundle import android.os.Bundle
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity import info.nightscout.androidaps.activities.NoSplashAppCompatActivity
import info.nightscout.androidaps.plugins.pump.danaRS.dialogs.PairingProgressDialog import info.nightscout.androidaps.plugins.pump.danaRS.dialogs.PairingProgressDialog
class PairingHelperActivity : NoSplashAppCompatActivity() { class PairingHelperActivity : NoSplashAppCompatActivity() {
var dialog: PairingProgressDialog? = null
@SuppressLint("SourceLockedOrientationActivity") @SuppressLint("SourceLockedOrientationActivity")
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
PairingProgressDialog() dialog = PairingProgressDialog()
.setHelperActivity(this) .setHelperActivity(this)
.show(supportFragmentManager, "PairingProgress") dialog?.show(supportFragmentManager, "PairingProgress")
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
} }
override fun onDestroy() {
super.onDestroy()
dialog = null
}
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
dialog?.resetToNewPairing()
}
} }

View file

@ -14,19 +14,25 @@ import android.widget.Button;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import androidx.fragment.app.DialogFragment; import javax.inject.Inject;
import info.nightscout.androidaps.MainApp; import dagger.android.support.DaggerDialogFragment;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.pump.danaRS.activities.PairingHelperActivity; import info.nightscout.androidaps.plugins.pump.danaRS.activities.PairingHelperActivity;
import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPairingSuccess; import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPairingSuccess;
import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
public class PairingProgressDialog extends DialogFragment { public class PairingProgressDialog extends DaggerDialogFragment {
@Inject ResourceHelper resourceHelper;
@Inject RxBusWrapper rxBus;
@Inject FabricPrivacy fabricPrivacy;
private CompositeDisposable disposable = new CompositeDisposable(); private CompositeDisposable disposable = new CompositeDisposable();
private TextView statusView; private TextView statusView;
@ -36,41 +42,21 @@ public class PairingProgressDialog extends DialogFragment {
private static boolean pairingEnded = false; private static boolean pairingEnded = false;
private static Handler sHandler; private static Handler handler;
private static HandlerThread sHandlerThread; private static HandlerThread handlerThread;
private static Runnable runnable;
public PairingProgressDialog() { public PairingProgressDialog() {
super(); super();
// Required empty public constructor // Required empty public constructor
if (sHandlerThread == null) { if (handlerThread == null) {
sHandlerThread = new HandlerThread(PairingProgressDialog.class.getSimpleName()); handlerThread = new HandlerThread(PairingProgressDialog.class.getSimpleName());
sHandlerThread.start(); handlerThread.start();
sHandler = new Handler(sHandlerThread.getLooper()); handler = new Handler(handlerThread.getLooper());
} }
}
runnable = () -> {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.danars_pairingprogressdialog, container, false);
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
setCancelable(false);
getDialog().setCanceledOnTouchOutside(false);
statusView = view.findViewById(R.id.danars_pairingprogress_status);
progressBar = view.findViewById(R.id.danars_pairingprogress_progressbar);
button = view.findViewById(R.id.ok);
progressBar.setMax(100);
progressBar.setProgress(0);
statusView.setText(MainApp.gs(R.string.waitingforpairing));
button.setVisibility(View.GONE);
button.setOnClickListener(v -> dismiss());
sHandler.post(() -> {
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
if (pairingEnded) { if (pairingEnded) {
Activity activity = getActivity(); Activity activity = getActivity();
@ -102,17 +88,36 @@ public class PairingProgressDialog extends DialogFragment {
button.setVisibility(View.VISIBLE); button.setVisibility(View.VISIBLE);
}); });
} }
}); };
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.danars_pairingprogressdialog, container, false);
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
setCancelable(false);
getDialog().setCanceledOnTouchOutside(false);
statusView = view.findViewById(R.id.danars_pairingprogress_status);
progressBar = view.findViewById(R.id.danars_pairingprogress_progressbar);
button = view.findViewById(R.id.ok);
setViews();
return view; return view;
} }
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
disposable.add(RxBus.Companion.getINSTANCE() disposable.add(rxBus
.toObservable(EventDanaRSPairingSuccess.class) .toObservable(EventDanaRSPairingSuccess.class)
.observeOn(Schedulers.io()) .observeOn(Schedulers.io())
.subscribe(event -> pairingEnded = true, exception -> FabricPrivacy.getInstance().logException(exception)) .subscribe(event -> pairingEnded = true, fabricPrivacy::logException)
); );
if (pairingEnded) dismiss(); if (pairingEnded) dismiss();
getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
@ -132,6 +137,20 @@ public class PairingProgressDialog extends DialogFragment {
disposable.clear(); disposable.clear();
} }
private void setViews() {
progressBar.setMax(100);
progressBar.setProgress(0);
statusView.setText(resourceHelper.gs(R.string.waitingforpairing));
button.setVisibility(View.GONE);
button.setOnClickListener(v -> dismiss());
handler.post(runnable);
}
public void resetToNewPairing() {
handler.removeCallbacks(runnable);
setViews();
}
public PairingProgressDialog setHelperActivity(PairingHelperActivity activity) { public PairingProgressDialog setHelperActivity(PairingHelperActivity activity) {
this.helperActivity = activity; this.helperActivity = activity;
return this; return this;