From 88e456dd1ac200c4045b3f3f57b7485b6a2d66ea Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 22 Dec 2019 02:00:33 +0100 Subject: [PATCH] PairingProgressDialog refactor --- .../activities/PairingHelperActivity.java | 16 ------- .../activities/PairingHelperActivity.kt | 16 +++++++ .../PairingProgressDialog.java | 48 +++++++++---------- .../res/drawable/ic_bluetooth_white_48dp.xml | 5 ++ .../layout/danars_pairingprogressdialog.xml | 41 +++++++++++++--- app/src/main/res/values/strings.xml | 2 +- 6 files changed, 80 insertions(+), 48 deletions(-) delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.kt rename app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/{activities => dialogs}/PairingProgressDialog.java (75%) create mode 100644 app/src/main/res/drawable/ic_bluetooth_white_48dp.xml diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.java deleted file mode 100644 index 5be6d7fbd1..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.java +++ /dev/null @@ -1,16 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.danaRS.activities; - -import android.os.Bundle; - -import info.nightscout.androidaps.activities.NoSplashAppCompatActivity; - -public class PairingHelperActivity extends NoSplashAppCompatActivity { - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - PairingProgressDialog bolusProgressDialog = new PairingProgressDialog(); - bolusProgressDialog.setHelperActivity(this); - bolusProgressDialog.show(this.getSupportFragmentManager(), "PairingProgress"); - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.kt new file mode 100644 index 0000000000..ba73e1b368 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingHelperActivity.kt @@ -0,0 +1,16 @@ +package info.nightscout.androidaps.plugins.pump.danaRS.activities + +import android.content.pm.ActivityInfo +import android.os.Bundle +import info.nightscout.androidaps.activities.NoSplashAppCompatActivity +import info.nightscout.androidaps.plugins.pump.danaRS.dialogs.PairingProgressDialog + +class PairingHelperActivity : NoSplashAppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + PairingProgressDialog() + .setHelperActivity(this) + .show(supportFragmentManager, "PairingProgress") + requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; + } +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingProgressDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/dialogs/PairingProgressDialog.java similarity index 75% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingProgressDialog.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/dialogs/PairingProgressDialog.java index afb5e86387..bad9e98112 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/activities/PairingProgressDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/dialogs/PairingProgressDialog.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.pump.danaRS.activities; +package info.nightscout.androidaps.plugins.pump.danaRS.dialogs; import android.app.Activity; @@ -8,6 +8,8 @@ import android.os.HandlerThread; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.Window; +import android.view.WindowManager; import android.widget.Button; import android.widget.ProgressBar; import android.widget.TextView; @@ -17,23 +19,22 @@ import androidx.fragment.app.DialogFragment; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.plugins.bus.RxBus; +import info.nightscout.androidaps.plugins.pump.danaRS.activities.PairingHelperActivity; import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPairingSuccess; import info.nightscout.androidaps.utils.FabricPrivacy; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.schedulers.Schedulers; -public class PairingProgressDialog extends DialogFragment implements View.OnClickListener { +public class PairingProgressDialog extends DialogFragment { private CompositeDisposable disposable = new CompositeDisposable(); - TextView statusView; - ProgressBar progressBar; - Button button; - PairingHelperActivity helperActivity; + private TextView statusView; + private ProgressBar progressBar; + private Button button; + private PairingHelperActivity helperActivity; - static int secondsPassed = 0; - public static boolean pairingEnded = false; - public static boolean running = true; + private static boolean pairingEnded = false; private static Handler sHandler; private static HandlerThread sHandlerThread; @@ -46,7 +47,6 @@ public class PairingProgressDialog extends DialogFragment implements View.OnClic sHandlerThread.start(); sHandler = new Handler(sHandlerThread.getLooper()); } - secondsPassed = 0; } @@ -54,17 +54,21 @@ public class PairingProgressDialog extends DialogFragment implements View.OnClic public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.danars_pairingprogressdialog, container, false); - getDialog().setTitle(MainApp.gs(R.string.pairing)); - statusView = (TextView) view.findViewById(R.id.danars_pairingprogress_status); - progressBar = (ProgressBar) view.findViewById(R.id.danars_pairingprogress_progressbar); - button = (Button) view.findViewById(R.id.ok); + + 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(this); - setCancelable(false); + button.setOnClickListener(v -> dismiss()); sHandler.post(() -> { for (int i = 0; i < 20; i++) { @@ -110,8 +114,8 @@ public class PairingProgressDialog extends DialogFragment implements View.OnClic .observeOn(Schedulers.io()) .subscribe(event -> pairingEnded = true, FabricPrivacy::logException) ); - running = true; if (pairingEnded) dismiss(); + getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); } @Override @@ -126,16 +130,10 @@ public class PairingProgressDialog extends DialogFragment implements View.OnClic public void onPause() { super.onPause(); disposable.clear(); - running = false; } - public void setHelperActivity(PairingHelperActivity activity) { + public PairingProgressDialog setHelperActivity(PairingHelperActivity activity) { this.helperActivity = activity; - } - - @Override - public void onClick(View v) { - running = false; - dismiss(); + return this; } } diff --git a/app/src/main/res/drawable/ic_bluetooth_white_48dp.xml b/app/src/main/res/drawable/ic_bluetooth_white_48dp.xml new file mode 100644 index 0000000000..f5f2fa4797 --- /dev/null +++ b/app/src/main/res/drawable/ic_bluetooth_white_48dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/danars_pairingprogressdialog.xml b/app/src/main/res/layout/danars_pairingprogressdialog.xml index a94aba0b67..496c4a90f6 100644 --- a/app/src/main/res/layout/danars_pairingprogressdialog.xml +++ b/app/src/main/res/layout/danars_pairingprogressdialog.xml @@ -1,15 +1,45 @@ - + android:orientation="vertical" + tools:context=".plugins.pump.danaRS.dialogs.PairingProgressDialog" > - + android:layout_gravity="center" + android:background="@color/dialog_title_background" + android:orientation="horizontal" + android:padding="5dp"> + + + + + + + + - - + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3ac1016070..17c491aa74 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -744,7 +744,7 @@ Waiting for pairing on pump Pairing OK Pairing timed out - PAIRING + Pairing danars_pairing_key_ danars_address danars_name