Skip to content

Commit dcca107

Browse files
committed
2 parents 2ae3730 + 2379f08 commit dcca107

File tree

6 files changed

+142
-90
lines changed

6 files changed

+142
-90
lines changed

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
import android.app.AlertDialog;
44
import android.app.TimePickerDialog;
55
import android.content.Context;
6+
import android.content.Intent;
67
import android.content.SharedPreferences;
8+
import android.media.RingtoneManager;
9+
import android.net.Uri;
710
import android.os.Bundle;
811
import android.preference.PreferenceManager;
912
import android.text.format.DateFormat;
1013
import android.view.View;
14+
import android.widget.Button;
1115
import android.widget.CheckBox;
1216
import android.widget.CompoundButton;
1317
import android.widget.EditText;
@@ -16,17 +20,23 @@
1620
import android.widget.TimePicker;
1721

1822
import com.eveningoutpost.dexdrip.models.AlertType;
23+
import com.eveningoutpost.dexdrip.models.UserError;
1924
import com.eveningoutpost.dexdrip.services.MissedReadingService;
25+
import com.eveningoutpost.dexdrip.utilitymodels.AlertPlayer;
26+
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
2027
import com.eveningoutpost.dexdrip.utils.ActivityWithMenu;
2128

2229

2330
public class MissedReadingActivity extends ActivityWithMenu {
2431
public static String menu_name = "Missed reading";
2532
private Context mContext;
33+
private Button buttonalertMp3;
2634

2735
private CheckBox checkboxEnableAlert;
2836
private CheckBox checkboxAllDay;
2937
private CheckBox checkboxEnableReraise;
38+
private String audioPath; // Local representation of the path to the sound file
39+
private EditText alertMp3File; // Sound file title
3040

3141
private LinearLayout layoutTimeBetween;
3242
private LinearLayout timeInstructions;
@@ -49,6 +59,8 @@ public class MissedReadingActivity extends ActivityWithMenu {
4959
private int endHour = 23;
5060
private int endMinute = 59;
5161
private int missedMinutes = 59;
62+
private final static String TAG = AlertPlayer.class.getSimpleName();
63+
EditAlertActivity editAlert = new EditAlertActivity();
5264

5365

5466
@Override
@@ -59,9 +71,18 @@ protected void onCreate(Bundle savedInstanceState) {
5971

6072
viewTimeStart = (TextView) findViewById(R.id.missed_reading_time_start);
6173
viewTimeEnd = (TextView) findViewById(R.id.missed_reading_time_end);
74+
buttonalertMp3 = (Button)findViewById(R.id.Button_mra_mp3_file);
6275
checkboxAllDay = (CheckBox) findViewById(R.id.missed_reading_all_day);
6376
checkboxEnableAlert = (CheckBox) findViewById(R.id.missed_reading_enable_alert);
6477
checkboxEnableReraise = (CheckBox) findViewById(R.id.missed_reading_enable_alerts_reraise);
78+
/** xDrip used to use the other alerts sound file for the missed readings alert.
79+
* To avoid causing an unexpected behavior for a previous user of xDrip, the missed reading alert
80+
* by default uses the same sound file as the other alerts alert.
81+
**/
82+
if (Pref.getString("bg_missed_alerts_sound", null) == null) { // If missed reading sound file has never been set
83+
Pref.setString("bg_missed_alerts_sound", Pref.getString("other_alerts_sound", "content://settings/system/alarm_alert")); // Set it to the other alerts sound
84+
}
85+
alertMp3File = (EditText) findViewById(R.id.bg_missed_alerts_sound);
6586

6687
layoutTimeBetween = (LinearLayout) findViewById(R.id.missed_reading_time_between);
6788
timeInstructions = (LinearLayout) findViewById(R.id.missed_reading_instructions);
@@ -83,6 +104,7 @@ protected void onCreate(Bundle savedInstanceState) {
83104
boolean enableAlert = prefs.getBoolean("bg_missed_alerts",false);
84105
boolean allDay = prefs.getBoolean("missed_readings_all_day",true);
85106
boolean enableReraise = prefs.getBoolean("bg_missed_alerts_enable_alerts_reraise",false);
107+
audioPath = Pref.getString("bg_missed_alerts_sound", null);
86108

87109
checkboxAllDay.setChecked(allDay);
88110
checkboxEnableAlert.setChecked(enableAlert);
@@ -95,9 +117,15 @@ protected void onCreate(Bundle savedInstanceState) {
95117
bgMissedMinutes.setText(prefs.getString("bg_missed_minutes", "30"));
96118
bgMissedSnoozeMin.setText("" + MissedReadingService.getOtherAlertSnoozeMinutes(prefs, "bg_missed_alerts"));
97119
bgMissedReraiseSec.setText(prefs.getString("bg_missed_alerts_reraise_sec", "60"));
120+
if (!audioPath.equals("")) {
121+
alertMp3File.setText(editAlert.shortPath(audioPath));
122+
} else {
123+
alertMp3File.setText("Silent");
124+
}
98125

99126
addListenerOnButtons();
100127
enableAllControls();
128+
alertMp3File.setKeyListener(null);
101129
}
102130

103131
@Override
@@ -225,6 +253,35 @@ public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinut
225253
viewTimeEnd.setOnClickListener(endTimeListener);
226254
timeInstructionsEnd.setOnClickListener(endTimeListener);
227255

256+
buttonalertMp3.setOnClickListener(new View.OnClickListener() {
257+
public void onClick(View v) {
258+
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
259+
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
260+
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
261+
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
262+
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALL);
263+
startActivityForResult(intent, 999);
264+
AlertDialog dialog = builder.create();
265+
dialog.show();
266+
}
267+
}); //- See more at: http://blog.kerul.net/2011/12/pick-file-using-intentactiongetcontent.html#sthash.c8xtIr1Y.dpuf
268+
269+
270+
}
271+
272+
public void onActivityResult(int requestCode, int resultCode, Intent data) {
273+
if (resultCode == RESULT_OK) {
274+
Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
275+
if (uri != null) {
276+
audioPath = uri.toString();
277+
alertMp3File.setText(editAlert.shortPath(audioPath));
278+
} else {
279+
audioPath = "";
280+
alertMp3File.setText("Silent");
281+
}
282+
UserError.Log.d(TAG, "Selected sound path: " + audioPath);
283+
Pref.setString("bg_missed_alerts_sound", audioPath); // Update the sound file preference
284+
}
228285
}
229286

230287
public void setTimeRanges() {

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

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,25 @@ public class QuickSettingsDialogs {
2020
private static final String TAG = "QuickSettingsDialog";
2121
private static AlertDialog dialog;
2222

23-
2423
public static void booleanSettingDialog(Activity activity, String setting, String title, String checkboxText, String message, final Runnable postRun) {
2524
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity);
2625

2726
final View dialogView = activity.getLayoutInflater().inflate(R.layout.dialog_checkbox, null);
2827
dialogBuilder.setView(dialogView);
2928

30-
final CheckBox cb = (CheckBox) dialogView.findViewById(R.id.dialogCheckbox);
29+
final CheckBox cb = dialogView.findViewById(R.id.dialogCheckbox);
3130
cb.setText(checkboxText);
3231
cb.setChecked(Pref.getBooleanDefaultFalse(setting));
3332

34-
final TextView tv = (TextView) dialogView.findViewById(R.id.dialogCheckboxTextView);
33+
final TextView tv = dialogView.findViewById(R.id.dialogCheckboxTextView);
3534
dialogBuilder.setTitle(title);
3635
tv.setText(message);
37-
dialogBuilder.setPositiveButton(R.string.done, new DialogInterface.OnClickListener() {
38-
public void onClick(DialogInterface dialog, int whichButton) {
39-
Pref.setBoolean(setting, cb.isChecked());
40-
if (postRun != null) postRun.run();
41-
}
36+
dialogBuilder.setPositiveButton(R.string.done, (dialog, whichButton) -> {
37+
Pref.setBoolean(setting, cb.isChecked());
38+
if (postRun != null) postRun.run();
4239
});
43-
dialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
44-
public void onClick(DialogInterface dialog, int whichButton) {
45-
if (postRun != null) postRun.run();
46-
}
40+
dialogBuilder.setNegativeButton(R.string.cancel, (dialog, whichButton) -> {
41+
if (postRun != null) postRun.run();
4742
});
4843

4944
try {
@@ -60,14 +55,13 @@ public void onClick(DialogInterface dialog, int whichButton) {
6055
}
6156
}
6257

63-
6458
public static void textSettingDialog(Activity activity, String setting, String title, String message, int input_type, final Runnable postRun) {
6559
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity);
6660

6761
final View dialogView = activity.getLayoutInflater().inflate(R.layout.dialog_text_entry, null);
6862
dialogBuilder.setView(dialogView);
6963

70-
final EditText edt = (EditText) dialogView.findViewById(R.id.dialogTextEntryeditText);
64+
final EditText edt = dialogView.findViewById(R.id.dialogTextEntryeditText);
7165

7266
if (input_type != 0) {
7367
edt.setInputType(input_type);
@@ -77,23 +71,18 @@ public static void textSettingDialog(Activity activity, String setting, String t
7771
edt.setFilters(new InputFilter[]{new InputFilter.AllCaps()});
7872
}
7973

80-
8174
edt.setText(Pref.getString(setting, ""));
8275

83-
final TextView tv = (TextView) dialogView.findViewById(R.id.dialogTextEntryTextView);
76+
final TextView tv = dialogView.findViewById(R.id.dialogTextEntryTextView);
8477
dialogBuilder.setTitle(title);
8578
tv.setText(message);
86-
dialogBuilder.setPositiveButton(R.string.done, new DialogInterface.OnClickListener() {
87-
public void onClick(DialogInterface dialog, int whichButton) {
88-
final String text = edt.getText().toString().trim();
89-
Pref.setString(setting, text);
90-
if (postRun != null) postRun.run();
91-
}
79+
dialogBuilder.setPositiveButton(R.string.done, (dialog, whichButton) -> {
80+
final String text = edt.getText().toString().trim();
81+
Pref.setString(setting, text);
82+
if (postRun != null) postRun.run();
9283
});
93-
dialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
94-
public void onClick(DialogInterface dialog, int whichButton) {
95-
if (postRun != null) postRun.run();
96-
}
84+
dialogBuilder.setNegativeButton(R.string.cancel, (dialog, whichButton) -> {
85+
if (postRun != null) postRun.run();
9786
});
9887

9988
try {
@@ -110,9 +99,7 @@ public void onClick(DialogInterface dialog, int whichButton) {
11099
}
111100
}
112101

113-
114102
public static boolean isDialogShowing() {
115103
return (dialog != null) && dialog.isShowing();
116104
}
117-
118105
}

app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Notifications.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,8 +902,9 @@ public static void bgUnclearAlert(Context context) {
902902
}
903903

904904
public static void bgMissedAlert(Context context) {
905-
long otherAlertReraiseSec = MissedReadingService.getOtherAlertReraiseSec(context, "bg_missed_alerts");
906-
OtherAlert(context, "bg_missed_alerts", context.getString(R.string.bg_reading_missed) + " (@" + JoH.hourMinuteString() + ")", missedAlertNotificationId, NotificationChannels.BG_MISSED_ALERT_CHANNEL, true, otherAlertReraiseSec);
905+
final String type = "bg_missed_alerts";
906+
long otherAlertReraiseSec = MissedReadingService.getOtherAlertReraiseSec(context, type);
907+
OtherAlert(context, type, context.getString(R.string.bg_reading_missed) + " (@" + JoH.hourMinuteString() + ")", missedAlertNotificationId, NotificationChannels.BG_MISSED_ALERT_CHANNEL, true, otherAlertReraiseSec);
907908
}
908909

909910
public static void ob1SessionRestartRequested() {

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

Lines changed: 21 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,13 @@ public static void assistance(Activity activity, DexCollectionType type) {
4545
pref, activity.getString(R.string.dexcom_transmitter_id),
4646
activity.getString(R.string.enter_your_transmitter_id_exactly),
4747
InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD,
48-
new Runnable() {
49-
@Override
50-
public void run() {
51-
// InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS does not seem functional here
52-
Pref.setString(pref, Pref.getString(pref, "").toUpperCase());
53-
if (!Dialog.askIfNeeded(activity, Pref.getString(pref, ""))) {
54-
Home.staticRefreshBGCharts();
55-
}
56-
CollectionServiceStarter.restartCollectionServiceBackground();
48+
() -> {
49+
// InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS does not seem functional here
50+
Pref.setString(pref, Pref.getString(pref, "").toUpperCase());
51+
if (!Dialog.askIfNeeded(activity, Pref.getString(pref, ""))) {
52+
Home.staticRefreshBGCharts();
5753
}
54+
CollectionServiceStarter.restartCollectionServiceBackground();
5855
});
5956
break;
6057

@@ -63,12 +60,7 @@ public void run() {
6360
"dex_txid", activity.getString(R.string.dexcom_transmitter_id),
6461
activity.getString(R.string.enter_your_transmitter_id_exactly),
6562
InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD,
66-
new Runnable() {
67-
@Override
68-
public void run() {
69-
bluetoothScanIfNeeded();
70-
}
71-
});
63+
DexCollectionHelper::bluetoothScanIfNeeded);
7264
break;
7365

7466

@@ -77,12 +69,9 @@ public void run() {
7769
"nsfollow_url", "Nightscout Follow URL",
7870
"Web address for following",
7971
InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD,
80-
new Runnable() {
81-
@Override
82-
public void run() {
83-
Home.staticRefreshBGCharts();
84-
CollectionServiceStarter.restartCollectionServiceBackground();
85-
}
72+
() -> {
73+
Home.staticRefreshBGCharts();
74+
CollectionServiceStarter.restartCollectionServiceBackground();
8675
});
8776
break;
8877

@@ -91,48 +80,25 @@ public void run() {
9180
"shfollow_user", "Dex Share Username",
9281
"Enter Share Follower Username",
9382
InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS,
94-
new Runnable() {
95-
@Override
96-
public void run() {
97-
textSettingDialog(activity,
98-
"shfollow_pass", "Dex Share Password",
99-
"Enter Share Follower Password",
100-
InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD,
101-
new Runnable() {
102-
@Override
103-
public void run() {
104-
booleanSettingDialog(activity,
105-
"dex_share_us_acct", "Select Servers", "My account is on USA servers", "Select whether using USA or rest-of-world account", new Runnable() {
106-
@Override
107-
public void run() {
108-
Home.staticRefreshBGCharts();
109-
ShareFollowService.resetInstanceAndInvalidateSession();
110-
CollectionServiceStarter.restartCollectionServiceBackground();
111-
}
112-
});
113-
}
114-
});
115-
}
116-
});
83+
() -> textSettingDialog(activity,
84+
"shfollow_pass", "Dex Share Password",
85+
"Enter Share Follower Password",
86+
InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD,
87+
() -> booleanSettingDialog(activity,
88+
"dex_share_us_acct", "Select Servers", "My account is on USA servers", "Select whether using USA or rest-of-world account",
89+
() -> {
90+
Home.staticRefreshBGCharts();
91+
ShareFollowService.resetInstanceAndInvalidateSession();
92+
CollectionServiceStarter.restartCollectionServiceBackground();
93+
})));
11794
break;
11895

119-
12096
case LimiTTer:
121-
bluetoothScanIfNeeded();
122-
break;
123-
12497
case BluetoothWixel:
125-
bluetoothScanIfNeeded();
126-
break;
127-
12898
case DexcomShare:
129-
bluetoothScanIfNeeded();
130-
break;
131-
13299
case Medtrum:
133100
bluetoothScanIfNeeded();
134101
break;
135-
136102
case LibreReceiver:
137103
Home.staticRefreshBGChartsOnIdle();
138104
break;
@@ -191,15 +157,11 @@ public void run() {
191157
// TODO Helper apps not installed? Prompt for installation
192158

193159
}
194-
195-
196160
}
197161

198162
public static void bluetoothScanIfNeeded() {
199163
if (ActiveBluetoothDevice.first() == null) {
200164
xdrip.getAppContext().startActivity(new Intent(xdrip.getAppContext(), BluetoothScan.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
201165
}
202166
}
203-
204-
205167
}

0 commit comments

Comments
 (0)