Skip to content

Commit 3a56f1e

Browse files
committed
Sensor start: Improve G7 txid handling
1 parent 5a79416 commit 3a56f1e

File tree

6 files changed

+92
-25
lines changed

6 files changed

+92
-25
lines changed

app/src/main/java/com/eveningoutpost/dexdrip/StartNewSensor.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static com.eveningoutpost.dexdrip.Home.startWatchUpdaterService;
44
import static com.eveningoutpost.dexdrip.models.BgReading.AGE_ADJUSTMENT_TIME;
55
import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.getTransmitterID;
6+
import static com.eveningoutpost.dexdrip.ui.dialog.QuickSettingsDialogs.FINISH_ACTIVITY_ON_DIALOG_DISMISS;
67
import static com.eveningoutpost.dexdrip.xdrip.gs;
78

89
import android.app.Activity;
@@ -13,7 +14,7 @@
1314
import android.os.Build;
1415
import android.os.Bundle;
1516
import androidx.annotation.NonNull;
16-
import android.view.View;
17+
1718
import android.widget.Button;
1819
import android.widget.Toast;
1920

@@ -28,14 +29,14 @@
2829
import com.eveningoutpost.dexdrip.models.UserError.Log;
2930
import com.eveningoutpost.dexdrip.services.Ob1G5CollectionService;
3031
import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter;
31-
import com.eveningoutpost.dexdrip.utilitymodels.Experience;
3232
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
3333
import com.eveningoutpost.dexdrip.profileeditor.DatePickerFragment;
3434
import com.eveningoutpost.dexdrip.profileeditor.ProfileAdapter;
3535
import com.eveningoutpost.dexdrip.profileeditor.TimePickerFragment;
3636
import com.eveningoutpost.dexdrip.ui.dialog.G6CalibrationCodeDialog;
3737
import com.eveningoutpost.dexdrip.ui.dialog.G6EndOfLifeDialog;
3838
import com.eveningoutpost.dexdrip.utils.ActivityWithMenu;
39+
import com.eveningoutpost.dexdrip.utils.DexCollectionHelper;
3940
import com.eveningoutpost.dexdrip.utils.DexCollectionType;
4041
import com.eveningoutpost.dexdrip.utils.LocationHelper;
4142
import com.eveningoutpost.dexdrip.wearintegration.WatchUpdaterService;
@@ -58,17 +59,23 @@ public class StartNewSensor extends ActivityWithMenu {
5859
return DexTimeKeeper.getTransmitterAgeInDays(getTransmitterID());
5960
}
6061

62+
private void activitySetupView() {
63+
JoH.fixActionBar(this);
64+
setContentView(R.layout.activity_start_new_sensor);
65+
button = findViewById(R.id.startNewSensor);
66+
}
67+
6168
@Override
6269
protected void onCreate(Bundle savedInstanceState) {
6370
super.onCreate(savedInstanceState);
64-
if (DexCollectionType.getBestCollectorHardwareName().equals("G7")) {
65-
JoH.static_toast_long(getString(R.string.g7_should_start_automatically));
66-
finish();
71+
if (DexCollectionType.isG7()) {
72+
//JoH.static_toast_long(getString(R.string.g7_should_start_automatically));
73+
activitySetupView();
74+
getIntent().putExtra(FINISH_ACTIVITY_ON_DIALOG_DISMISS, true);
75+
DexCollectionHelper.assistance(this, DexCollectionType.DexcomG5);
6776
} else {
6877
if (!Sensor.isActive()) {
69-
JoH.fixActionBar(this);
70-
setContentView(R.layout.activity_start_new_sensor);
71-
button = (Button) findViewById(R.id.startNewSensor);
78+
activitySetupView();
7279
//dp = (DatePicker)findViewById(R.id.datePicker);
7380
//tp = (TimePicker)findViewById(R.id.timePicker);
7481
addListenerOnButton();
@@ -88,18 +95,16 @@ public String getMenuName() {
8895
public void addListenerOnButton() {
8996
button = (Button) findViewById(R.id.startNewSensor);
9097

91-
button.setOnClickListener(new View.OnClickListener() {
92-
public void onClick(View v) {
98+
button.setOnClickListener(v -> {
9399

94-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && DexCollectionType.hasBluetooth()) {
95-
if (!LocationHelper.locationPermission(StartNewSensor.this)) {
96-
LocationHelper.requestLocationForBluetooth(StartNewSensor.this);
97-
} else {
98-
sensorButtonClick();
99-
}
100+
if (DexCollectionType.hasBluetooth()) {
101+
if (!LocationHelper.locationPermission(StartNewSensor.this)) {
102+
LocationHelper.requestLocationForBluetooth(StartNewSensor.this);
100103
} else {
101104
sensorButtonClick();
102105
}
106+
} else {
107+
sensorButtonClick();
103108
}
104109
});
105110
}

app/src/main/java/com/eveningoutpost/dexdrip/services/Ob1G5CollectionService.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,4 +2462,19 @@ private static boolean isVolumeSilent() {
24622462
final AudioManager am = (AudioManager) xdrip.getAppContext().getSystemService(Context.AUDIO_SERVICE);
24632463
return (am.getRingerMode() != AudioManager.RINGER_MODE_NORMAL);
24642464
}
2465+
2466+
public static void clearDataWhenTransmitterIdEntered(final String txid) {
2467+
try {
2468+
UserError.Log.e(TAG, "Clearing data when new transmitter is entered: " + txid);
2469+
Ob1G5StateMachine.emptyQueue();
2470+
try {
2471+
DexSyncKeeper.clear(txid);
2472+
} catch (Exception e) {
2473+
//
2474+
}
2475+
Ob1G5CollectionService.clearPersist();
2476+
} catch (Exception e) {
2477+
UserError.Log.e(TAG, "Got error when clearing data: " + e);
2478+
}
2479+
}
24652480
}

app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/QuickSettingsDialogs.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@
22

33
import android.app.Activity;
44
import android.app.AlertDialog;
5-
import android.content.DialogInterface;
5+
import android.content.Context;
66
import android.text.InputFilter;
77
import android.view.View;
8+
import android.view.inputmethod.InputMethodManager;
89
import android.widget.CheckBox;
910
import android.widget.EditText;
1011
import android.widget.TextView;
1112

1213
import com.eveningoutpost.dexdrip.models.UserError;
1314
import com.eveningoutpost.dexdrip.R;
1415
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
16+
import com.eveningoutpost.dexdrip.watch.thinjam.BlueJayEntry;
1517

1618
// jamorham
1719

1820
public class QuickSettingsDialogs {
1921

2022
private static final String TAG = "QuickSettingsDialog";
23+
24+
public static final String FINISH_ACTIVITY_ON_DIALOG_DISMISS = "FINISH_ON_DIALOG_DISMISS";
2125
private static AlertDialog dialog;
2226

2327
public static void booleanSettingDialog(Activity activity, String setting, String title, String checkboxText, String message, final Runnable postRun) {
@@ -56,6 +60,8 @@ public static void booleanSettingDialog(Activity activity, String setting, Strin
5660
}
5761

5862
public static void textSettingDialog(Activity activity, String setting, String title, String message, int input_type, final Runnable postRun) {
63+
final boolean finishOnDismiss = activity.getIntent().getBooleanExtra(FINISH_ACTIVITY_ON_DIALOG_DISMISS, false);
64+
5965
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity);
6066

6167
final View dialogView = activity.getLayoutInflater().inflate(R.layout.dialog_text_entry, null);
@@ -92,6 +98,32 @@ public static void textSettingDialog(Activity activity, String setting, String t
9298
}
9399

94100
dialog = dialogBuilder.create();
101+
102+
// finish the holding activity when dialog is dismissed if the flag is set
103+
if (finishOnDismiss) {
104+
dialog.setOnDismissListener(d -> {
105+
// Called when the dialog is dismissed by any means
106+
activity.finish();
107+
});
108+
}
109+
110+
if (!BlueJayEntry.isNative()) {
111+
dialog.setOnShowListener(d -> {
112+
try {
113+
edt.requestFocus();
114+
edt.post(() -> {
115+
// Move cursor to end of text
116+
edt.setSelection(edt.getText().length());
117+
// show keyboard automatically
118+
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
119+
imm.showSoftInput(edt, InputMethodManager.SHOW_IMPLICIT);
120+
});
121+
} catch (Exception e) {
122+
UserError.Log.e(TAG, "Error setting input method focus: " + e);
123+
}
124+
});
125+
}
126+
95127
try {
96128
dialog.show();
97129
} catch (Exception e) {

app/src/main/java/com/eveningoutpost/dexdrip/utils/DexCollectionHelper.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.eveningoutpost.dexdrip.plugin.Dialog;
1717
import com.eveningoutpost.dexdrip.xdrip;
1818

19+
import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.clearDataWhenTransmitterIdEntered;
1920
import static com.eveningoutpost.dexdrip.ui.dialog.QuickSettingsDialogs.booleanSettingDialog;
2021
import static com.eveningoutpost.dexdrip.ui.dialog.QuickSettingsDialogs.textSettingDialog;
2122

@@ -44,13 +45,18 @@ public static void assistance(Activity activity, DexCollectionType type) {
4445
textSettingDialog(activity,
4546
pref, activity.getString(R.string.dexcom_transmitter_id),
4647
activity.getString(R.string.enter_your_transmitter_id_exactly),
47-
InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD,
48+
DexCollectionType.isG7()
49+
? InputType.TYPE_CLASS_NUMBER // g7 numbers only
50+
: InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD,
4851
() -> {
4952
// InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS does not seem functional here
5053
Pref.setString(pref, Pref.getString(pref, "").toUpperCase());
5154
if (!Dialog.askIfNeeded(activity, Pref.getString(pref, ""))) {
5255
Home.staticRefreshBGCharts();
5356
}
57+
58+
clearDataWhenTransmitterIdEntered(Pref.getString(pref, ""));
59+
5460
CollectionServiceStarter.restartCollectionServiceBackground();
5561
});
5662
break;

app/src/main/java/com/eveningoutpost/dexdrip/utils/DexCollectionType.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ public static void setDexCollectionType(DexCollectionType t) {
116116
Pref.setString(DEX_COLLECTION_METHOD, t.internalName);
117117
}
118118

119+
public static boolean isG7() {
120+
return DexCollectionType.getBestCollectorHardwareName().equals("G7");
121+
}
122+
119123
public static boolean hasBluetooth() {
120124
return usesBluetooth.contains(getDexCollectionType());
121125
}

app/src/main/java/com/eveningoutpost/dexdrip/utils/Preferences.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static com.eveningoutpost.dexdrip.EditAlertActivity.unitsConvert2Disp;
55
import static com.eveningoutpost.dexdrip.models.JoH.showNotification;
66
import static com.eveningoutpost.dexdrip.models.JoH.tolerantParseDouble;
7+
import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.clearDataWhenTransmitterIdEntered;
78
import static com.eveningoutpost.dexdrip.utilitymodels.Constants.OUT_OF_RANGE_GLUCOSE_ENTRY_ID;
89
import static com.eveningoutpost.dexdrip.utils.DexCollectionType.getBestCollectorHardwareName;
910
import static com.eveningoutpost.dexdrip.xdrip.gs;
@@ -2463,6 +2464,14 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
24632464

24642465
bindPreferenceSummaryToValue(transmitterId); // duplicated below but this sets initial value
24652466
transmitterId.getEditText().setFilters(new InputFilter[]{new InputFilter.AllCaps()}); // TODO filter O ?
2467+
transmitterId.getEditText().post(() -> {
2468+
try {
2469+
// position to end of input text
2470+
transmitterId.getEditText().setSelection(transmitterId.getEditText().getText().length());
2471+
} catch (Exception e) {
2472+
UserError.Log.d(TAG, "Could not set selection for transmitter id: " + e);
2473+
}
2474+
});
24662475
transmitterId.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
24672476
@Override
24682477
public boolean onPreferenceChange(Preference preference, Object newValue) {
@@ -2477,13 +2486,9 @@ public void run() {
24772486
//
24782487
}
24792488
Log.d(TAG, "Trying to restart collector due to tx id change");
2480-
Ob1G5StateMachine.emptyQueue();
2481-
try {
2482-
DexSyncKeeper.clear((String) newValue);
2483-
} catch (Exception e) {
2484-
//
2485-
}
2486-
Ob1G5CollectionService.clearPersist();
2489+
2490+
clearDataWhenTransmitterIdEntered((String)newValue);
2491+
24872492
CollectionServiceStarter.restartCollectionService(xdrip.getAppContext());
24882493
}
24892494
}).start();

0 commit comments

Comments
 (0)