PairingProgressDialog refactor
This commit is contained in:
parent
cbfb8a6a0f
commit
88e456dd1a
6 changed files with 80 additions and 48 deletions
|
@ -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");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.danaRS.activities;
|
package info.nightscout.androidaps.plugins.pump.danaRS.dialogs;
|
||||||
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
@ -8,6 +8,8 @@ import android.os.HandlerThread;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.Window;
|
||||||
|
import android.view.WindowManager;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
@ -17,23 +19,22 @@ import androidx.fragment.app.DialogFragment;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
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.plugins.pump.danaRS.events.EventDanaRSPairingSuccess;
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||||
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 implements View.OnClickListener {
|
public class PairingProgressDialog extends DialogFragment {
|
||||||
private CompositeDisposable disposable = new CompositeDisposable();
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
TextView statusView;
|
private TextView statusView;
|
||||||
ProgressBar progressBar;
|
private ProgressBar progressBar;
|
||||||
Button button;
|
private Button button;
|
||||||
PairingHelperActivity helperActivity;
|
private PairingHelperActivity helperActivity;
|
||||||
|
|
||||||
static int secondsPassed = 0;
|
private static boolean pairingEnded = false;
|
||||||
public static boolean pairingEnded = false;
|
|
||||||
public static boolean running = true;
|
|
||||||
|
|
||||||
private static Handler sHandler;
|
private static Handler sHandler;
|
||||||
private static HandlerThread sHandlerThread;
|
private static HandlerThread sHandlerThread;
|
||||||
|
@ -46,7 +47,6 @@ public class PairingProgressDialog extends DialogFragment implements View.OnClic
|
||||||
sHandlerThread.start();
|
sHandlerThread.start();
|
||||||
sHandler = new Handler(sHandlerThread.getLooper());
|
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,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.danars_pairingprogressdialog, container, false);
|
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);
|
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
||||||
progressBar = (ProgressBar) view.findViewById(R.id.danars_pairingprogress_progressbar);
|
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
||||||
button = (Button) view.findViewById(R.id.ok);
|
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.setMax(100);
|
||||||
progressBar.setProgress(0);
|
progressBar.setProgress(0);
|
||||||
statusView.setText(MainApp.gs(R.string.waitingforpairing));
|
statusView.setText(MainApp.gs(R.string.waitingforpairing));
|
||||||
button.setVisibility(View.GONE);
|
button.setVisibility(View.GONE);
|
||||||
button.setOnClickListener(this);
|
button.setOnClickListener(v -> dismiss());
|
||||||
setCancelable(false);
|
|
||||||
|
|
||||||
sHandler.post(() -> {
|
sHandler.post(() -> {
|
||||||
for (int i = 0; i < 20; i++) {
|
for (int i = 0; i < 20; i++) {
|
||||||
|
@ -110,8 +114,8 @@ public class PairingProgressDialog extends DialogFragment implements View.OnClic
|
||||||
.observeOn(Schedulers.io())
|
.observeOn(Schedulers.io())
|
||||||
.subscribe(event -> pairingEnded = true, FabricPrivacy::logException)
|
.subscribe(event -> pairingEnded = true, FabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
running = true;
|
|
||||||
if (pairingEnded) dismiss();
|
if (pairingEnded) dismiss();
|
||||||
|
getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -126,16 +130,10 @@ public class PairingProgressDialog extends DialogFragment implements View.OnClic
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
disposable.clear();
|
disposable.clear();
|
||||||
running = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHelperActivity(PairingHelperActivity activity) {
|
public PairingProgressDialog setHelperActivity(PairingHelperActivity activity) {
|
||||||
this.helperActivity = activity;
|
this.helperActivity = activity;
|
||||||
}
|
return this;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
running = false;
|
|
||||||
dismiss();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
5
app/src/main/res/drawable/ic_bluetooth_white_48dp.xml
Normal file
5
app/src/main/res/drawable/ic_bluetooth_white_48dp.xml
Normal 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>
|
|
@ -1,13 +1,43 @@
|
||||||
<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"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="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_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
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
|
<TextView
|
||||||
android:id="@+id/danars_pairingprogress_status"
|
android:id="@+id/danars_pairingprogress_status"
|
||||||
|
@ -36,6 +66,5 @@
|
||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
android:layout_marginBottom="15dp"
|
android:layout_marginBottom="15dp"
|
||||||
android:text="@string/ok" />
|
android:text="@string/ok" />
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</FrameLayout>
|
</LinearLayout>
|
||||||
|
|
|
@ -744,7 +744,7 @@
|
||||||
<string name="waitingforpairing">Waiting for pairing on pump</string>
|
<string name="waitingforpairing">Waiting for pairing on pump</string>
|
||||||
<string name="pairingok">Pairing OK</string>
|
<string name="pairingok">Pairing OK</string>
|
||||||
<string name="pairingtimedout">Pairing timed out</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_pairingkey" translatable="false">danars_pairing_key_</string>
|
||||||
<string name="key_danars_address" translatable="false">danars_address</string>
|
<string name="key_danars_address" translatable="false">danars_address</string>
|
||||||
<string name="key_danars_name" translatable="false">danars_name</string>
|
<string name="key_danars_name" translatable="false">danars_name</string>
|
||||||
|
|
Loading…
Reference in a new issue