Hide the last N reserved alarm slots from the Alarm activity.

The original values remain stored in the preferences, they are just not available to the user anymore, further they are not sent to the device.
This commit is contained in:
Daniele Gobbetti
2015-12-17 17:02:00 +01:00
parent 0dda5c214b
commit 78cd11ad93
2 changed files with 7 additions and 2 deletions
@@ -14,6 +14,7 @@ import java.util.Set;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.adapter.GBAlarmListAdapter;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
import nodomain.freeyourgadget.gadgetbridge.impl.GBAlarm;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_ALARMS;
@@ -67,8 +68,9 @@ public class ConfigureAlarms extends ListActivity {
private void updateAlarmsFromPrefs() {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
preferencesAlarmListSet = sharedPrefs.getStringSet(PREF_MIBAND_ALARMS, new HashSet<String>());
int reservedSlots = Integer.parseInt(sharedPrefs.getString(MiBandConst.PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR, "0"));
mGBAlarmListAdapter.setAlarmList(preferencesAlarmListSet);
mGBAlarmListAdapter.setAlarmList(preferencesAlarmListSet, reservedSlots);
mGBAlarmListAdapter.notifyDataSetChanged();
}
@@ -49,7 +49,7 @@ public class GBAlarmListAdapter extends ArrayAdapter<GBAlarm> {
Collections.sort(alarmList);
}
public void setAlarmList(Set<String> preferencesAlarmListSet) {
public void setAlarmList(Set<String> preferencesAlarmListSet, int reservedSlots) {
alarmList = new ArrayList<>();
for (String alarmString : preferencesAlarmListSet) {
@@ -57,6 +57,9 @@ public class GBAlarmListAdapter extends ArrayAdapter<GBAlarm> {
}
Collections.sort(alarmList);
//cannot do this earlier because the Set is not guaranteed to be in order by ID
alarmList.subList(alarmList.size() - reservedSlots, alarmList.size()).clear();
}
public ArrayList<? extends Alarm> getAlarmList() {