PairingProgressDialog refactor

This commit is contained in:
Milos Kozak 2019-12-22 02:00:33 +01:00
parent cbfb8a6a0f
commit 88e456dd1a
6 changed files with 80 additions and 48 deletions

View file

@ -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");
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -0,0 +1,5 @@
<vector android:height="48dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="48dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M17.71,7.71L12,2h-1v7.59L6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 11,14.41L11,22h1l5.71,-5.71 -4.3,-4.29 4.3,-4.29zM13,5.83l1.88,1.88L13,9.59L13,5.83zM14.88,16.29L13,18.17v-3.76l1.88,1.88z"/>
</vector>

View file

@ -1,15 +1,45 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".plugins.pump.danaRS.activities.PairingProgressDialog" >
android:orientation="vertical"
tools:context=".plugins.pump.danaRS.dialogs.PairingProgressDialog" >
<LinearLayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:layout_gravity="center"
android:background="@color/dialog_title_background"
android:orientation="horizontal"
android:padding="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/pairing"
android:src="@drawable/ic_bluetooth_white_48dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="@string/pairing"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
<LinearLayout
android:id="@+id/spacer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp" />
<TextView
android:id="@+id/danars_pairingprogress_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -36,6 +66,5 @@
android:layout_gravity="center_horizontal"
android:layout_marginBottom="15dp"
android:text="@string/ok" />
</LinearLayout>
</FrameLayout>
</LinearLayout>

View file

@ -744,7 +744,7 @@
<string name="waitingforpairing">Waiting for pairing on pump</string>
<string name="pairingok">Pairing OK</string>
<string name="pairingtimedout">Pairing timed out</string>
<string name="pairing">PAIRING</string>
<string name="pairing">Pairing</string>
<string name="key_danars_pairingkey" translatable="false">danars_pairing_key_</string>
<string name="key_danars_address" translatable="false">danars_address</string>
<string name="key_danars_name" translatable="false">danars_name</string>