mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-13 03:07:32 +01:00
Improvements to how and when alarms are sent to the device
They are now sent whenever the Alarms activity is finished. Display "All alarms disabled" when no alarm is enabled. Unrelated: pass exceptions to GB.toast() where applicable.
This commit is contained in:
parent
86d17c7792
commit
4e0fed8857
@ -64,7 +64,6 @@ public class AlarmDetails extends Activity {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
// back button
|
||||
updateAlarm();
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
@ -78,4 +77,10 @@ public class AlarmDetails extends Activity {
|
||||
alarm.setMinute(timePicker.getCurrentMinute());
|
||||
alarm.store();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
updateAlarm();
|
||||
super.onPause();
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,11 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PR
|
||||
|
||||
public class ConfigureAlarms extends ListActivity {
|
||||
|
||||
private static final int REQ_CONFIGURE_ALARM = 1;
|
||||
|
||||
private GBAlarmListAdapter mGBAlarmListAdapter;
|
||||
private Set<String> preferencesAlarmListSet;
|
||||
private boolean avoidSendAlarmsToDevice;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -36,26 +39,37 @@ public class ConfigureAlarms extends ListActivity {
|
||||
if (preferencesAlarmListSet.isEmpty()) {
|
||||
//initialize the preferences
|
||||
preferencesAlarmListSet = new HashSet<>(Arrays.asList(GBAlarm.DEFAULT_ALARMS));
|
||||
sharedPrefs.edit().putStringSet(PREF_MIBAND_ALARMS, preferencesAlarmListSet).commit();
|
||||
sharedPrefs.edit().putStringSet(PREF_MIBAND_ALARMS, preferencesAlarmListSet).apply();
|
||||
}
|
||||
|
||||
mGBAlarmListAdapter = new GBAlarmListAdapter(this, preferencesAlarmListSet);
|
||||
|
||||
setListAdapter(mGBAlarmListAdapter);
|
||||
|
||||
updateAlarmsFromPrefs();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
protected void onPause() {
|
||||
if (!avoidSendAlarmsToDevice) {
|
||||
sendAlarmsToDevice();
|
||||
}
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == REQ_CONFIGURE_ALARM) {
|
||||
avoidSendAlarmsToDevice = false;
|
||||
updateAlarmsFromPrefs();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateAlarmsFromPrefs() {
|
||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
preferencesAlarmListSet = sharedPrefs.getStringSet(PREF_MIBAND_ALARMS, new HashSet<String>());
|
||||
|
||||
mGBAlarmListAdapter.setAlarmList(preferencesAlarmListSet);
|
||||
mGBAlarmListAdapter.notifyDataSetChanged();
|
||||
|
||||
sendAlarmsToDevice();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -63,7 +77,6 @@ public class ConfigureAlarms extends ListActivity {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
// back button
|
||||
sendAlarmsToDevice();
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
@ -71,10 +84,11 @@ public class ConfigureAlarms extends ListActivity {
|
||||
}
|
||||
|
||||
public void configureAlarm(GBAlarm alarm) {
|
||||
avoidSendAlarmsToDevice = true;
|
||||
Intent startIntent;
|
||||
startIntent = new Intent(getApplicationContext(), AlarmDetails.class);
|
||||
startIntent.putExtra("alarm", alarm);
|
||||
startActivity(startIntent);
|
||||
startActivityForResult(startIntent, REQ_CONFIGURE_ALARM);
|
||||
}
|
||||
|
||||
private void sendAlarmsToDevice() {
|
||||
|
@ -3,6 +3,7 @@ package nodomain.freeyourgadget.gadgetbridge.impl;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Parcel;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.HashSet;
|
||||
@ -88,7 +89,7 @@ public class GBAlarm implements Alarm {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Alarm another) {
|
||||
public int compareTo(@NonNull Alarm another) {
|
||||
if (this.getIndex() < another.getIndex()) {
|
||||
return -1;
|
||||
} else if (this.getIndex() > another.getIndex()) {
|
||||
@ -201,8 +202,7 @@ public class GBAlarm implements Alarm {
|
||||
}
|
||||
}
|
||||
newPrefs.add(this.toPreferences());
|
||||
sharedPrefs.edit().putStringSet(PREF_MIBAND_ALARMS, newPrefs).commit();
|
||||
return;
|
||||
sharedPrefs.edit().putStringSet(PREF_MIBAND_ALARMS, newPrefs).apply();
|
||||
}
|
||||
|
||||
public static final Creator CREATOR = new Creator() {
|
||||
|
@ -443,14 +443,19 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
try {
|
||||
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT);
|
||||
TransactionBuilder builder = performInitialized("Set alarm");
|
||||
boolean anyAlarmEnabled = false;
|
||||
for (Alarm alarm : alarms) {
|
||||
anyAlarmEnabled |= alarm.isEnabled();
|
||||
queueAlarm(alarm, builder, characteristic);
|
||||
}
|
||||
builder.queue(getQueue());
|
||||
Toast.makeText(getContext(), getContext().getString(R.string.user_feedback_miband_set_alarms_ok), Toast.LENGTH_SHORT).show();
|
||||
if (anyAlarmEnabled) {
|
||||
GB.toast(getContext(), getContext().getString(R.string.user_feedback_miband_set_alarms_ok), Toast.LENGTH_SHORT, GB.INFO);
|
||||
} else {
|
||||
GB.toast(getContext(), getContext().getString(R.string.user_feedback_all_alarms_disabled), Toast.LENGTH_SHORT, GB.INFO);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
Toast.makeText(getContext(), getContext().getString(R.string.user_feedback_miband_set_alarms_failed), Toast.LENGTH_LONG).show();
|
||||
LOG.error("Unable to set alarms on MI device", ex);
|
||||
GB.toast(getContext(), getContext().getString(R.string.user_feedback_miband_set_alarms_failed), Toast.LENGTH_LONG, GB.ERROR, ex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -636,7 +641,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
try {
|
||||
new UpdateFirmwareOperation(uri, this).perform();
|
||||
} catch (IOException ex) {
|
||||
GB.toast(getContext(), "Firmware cannot be installed: " + ex.getMessage(), Toast.LENGTH_LONG, GB.ERROR);
|
||||
GB.toast(getContext(), "Firmware cannot be installed: " + ex.getMessage(), Toast.LENGTH_LONG, GB.ERROR, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -207,4 +207,5 @@
|
||||
<string name="abstract_chart_fragment_kind_deep_sleep">Deep Sleep</string>
|
||||
<string name="abstract_chart_fragment_kind_not_worn">Not Worn</string>
|
||||
<string name="device_not_connected">Not connected.</string>
|
||||
<string name="user_feedback_all_alarms_disabled">All alarms disabled</string>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user