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()) {
|
switch (item.getItemId()) {
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
// back button
|
// back button
|
||||||
updateAlarm();
|
|
||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -78,4 +77,10 @@ public class AlarmDetails extends Activity {
|
|||||||
alarm.setMinute(timePicker.getCurrentMinute());
|
alarm.setMinute(timePicker.getCurrentMinute());
|
||||||
alarm.store();
|
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 {
|
public class ConfigureAlarms extends ListActivity {
|
||||||
|
|
||||||
|
private static final int REQ_CONFIGURE_ALARM = 1;
|
||||||
|
|
||||||
private GBAlarmListAdapter mGBAlarmListAdapter;
|
private GBAlarmListAdapter mGBAlarmListAdapter;
|
||||||
private Set<String> preferencesAlarmListSet;
|
private Set<String> preferencesAlarmListSet;
|
||||||
|
private boolean avoidSendAlarmsToDevice;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -36,26 +39,37 @@ public class ConfigureAlarms extends ListActivity {
|
|||||||
if (preferencesAlarmListSet.isEmpty()) {
|
if (preferencesAlarmListSet.isEmpty()) {
|
||||||
//initialize the preferences
|
//initialize the preferences
|
||||||
preferencesAlarmListSet = new HashSet<>(Arrays.asList(GBAlarm.DEFAULT_ALARMS));
|
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);
|
mGBAlarmListAdapter = new GBAlarmListAdapter(this, preferencesAlarmListSet);
|
||||||
|
|
||||||
setListAdapter(mGBAlarmListAdapter);
|
setListAdapter(mGBAlarmListAdapter);
|
||||||
|
updateAlarmsFromPrefs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onPause() {
|
||||||
super.onResume();
|
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);
|
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
preferencesAlarmListSet = sharedPrefs.getStringSet(PREF_MIBAND_ALARMS, new HashSet<String>());
|
preferencesAlarmListSet = sharedPrefs.getStringSet(PREF_MIBAND_ALARMS, new HashSet<String>());
|
||||||
|
|
||||||
mGBAlarmListAdapter.setAlarmList(preferencesAlarmListSet);
|
mGBAlarmListAdapter.setAlarmList(preferencesAlarmListSet);
|
||||||
mGBAlarmListAdapter.notifyDataSetChanged();
|
mGBAlarmListAdapter.notifyDataSetChanged();
|
||||||
|
|
||||||
sendAlarmsToDevice();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -63,7 +77,6 @@ public class ConfigureAlarms extends ListActivity {
|
|||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
// back button
|
// back button
|
||||||
sendAlarmsToDevice();
|
|
||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -71,10 +84,11 @@ public class ConfigureAlarms extends ListActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void configureAlarm(GBAlarm alarm) {
|
public void configureAlarm(GBAlarm alarm) {
|
||||||
|
avoidSendAlarmsToDevice = true;
|
||||||
Intent startIntent;
|
Intent startIntent;
|
||||||
startIntent = new Intent(getApplicationContext(), AlarmDetails.class);
|
startIntent = new Intent(getApplicationContext(), AlarmDetails.class);
|
||||||
startIntent.putExtra("alarm", alarm);
|
startIntent.putExtra("alarm", alarm);
|
||||||
startActivity(startIntent);
|
startActivityForResult(startIntent, REQ_CONFIGURE_ALARM);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendAlarmsToDevice() {
|
private void sendAlarmsToDevice() {
|
||||||
|
@ -3,6 +3,7 @@ package nodomain.freeyourgadget.gadgetbridge.impl;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -88,7 +89,7 @@ public class GBAlarm implements Alarm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Alarm another) {
|
public int compareTo(@NonNull Alarm another) {
|
||||||
if (this.getIndex() < another.getIndex()) {
|
if (this.getIndex() < another.getIndex()) {
|
||||||
return -1;
|
return -1;
|
||||||
} else if (this.getIndex() > another.getIndex()) {
|
} else if (this.getIndex() > another.getIndex()) {
|
||||||
@ -201,8 +202,7 @@ public class GBAlarm implements Alarm {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
newPrefs.add(this.toPreferences());
|
newPrefs.add(this.toPreferences());
|
||||||
sharedPrefs.edit().putStringSet(PREF_MIBAND_ALARMS, newPrefs).commit();
|
sharedPrefs.edit().putStringSet(PREF_MIBAND_ALARMS, newPrefs).apply();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Creator CREATOR = new Creator() {
|
public static final Creator CREATOR = new Creator() {
|
||||||
|
@ -443,14 +443,19 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
|||||||
try {
|
try {
|
||||||
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT);
|
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT);
|
||||||
TransactionBuilder builder = performInitialized("Set alarm");
|
TransactionBuilder builder = performInitialized("Set alarm");
|
||||||
|
boolean anyAlarmEnabled = false;
|
||||||
for (Alarm alarm : alarms) {
|
for (Alarm alarm : alarms) {
|
||||||
|
anyAlarmEnabled |= alarm.isEnabled();
|
||||||
queueAlarm(alarm, builder, characteristic);
|
queueAlarm(alarm, builder, characteristic);
|
||||||
}
|
}
|
||||||
builder.queue(getQueue());
|
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) {
|
} catch (IOException ex) {
|
||||||
Toast.makeText(getContext(), getContext().getString(R.string.user_feedback_miband_set_alarms_failed), Toast.LENGTH_LONG).show();
|
GB.toast(getContext(), getContext().getString(R.string.user_feedback_miband_set_alarms_failed), Toast.LENGTH_LONG, GB.ERROR, ex);
|
||||||
LOG.error("Unable to set alarms on MI device", ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -636,7 +641,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
|||||||
try {
|
try {
|
||||||
new UpdateFirmwareOperation(uri, this).perform();
|
new UpdateFirmwareOperation(uri, this).perform();
|
||||||
} catch (IOException ex) {
|
} 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_deep_sleep">Deep Sleep</string>
|
||||||
<string name="abstract_chart_fragment_kind_not_worn">Not Worn</string>
|
<string name="abstract_chart_fragment_kind_not_worn">Not Worn</string>
|
||||||
<string name="device_not_connected">Not connected.</string>
|
<string name="device_not_connected">Not connected.</string>
|
||||||
|
<string name="user_feedback_all_alarms_disabled">All alarms disabled</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user