2015-06-24 20:14:08 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.activities;
|
|
|
|
|
2015-06-26 17:22:42 +02:00
|
|
|
import android.app.ListActivity;
|
2015-06-24 20:14:08 +02:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.preference.PreferenceManager;
|
2015-06-26 17:22:42 +02:00
|
|
|
import android.view.MenuItem;
|
2015-06-24 20:14:08 +02:00
|
|
|
|
2015-06-26 17:22:42 +02:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
2015-06-24 20:14:08 +02:00
|
|
|
|
2015-08-21 00:58:18 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
2015-08-04 01:01:14 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
|
2015-08-03 23:09:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBAlarm;
|
2015-06-24 20:14:08 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.adapter.GBAlarmListAdapter;
|
|
|
|
|
2015-08-03 23:09:49 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_ALARMS;
|
2015-06-24 20:14:08 +02:00
|
|
|
|
|
|
|
|
2015-06-26 17:22:42 +02:00
|
|
|
public class ConfigureAlarms extends ListActivity {
|
2015-06-24 20:14:08 +02:00
|
|
|
|
|
|
|
private GBAlarmListAdapter mGBAlarmListAdapter;
|
2015-06-26 17:22:42 +02:00
|
|
|
private Set<String> preferencesAlarmListSet;
|
2015-06-24 20:14:08 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2015-06-26 17:22:42 +02:00
|
|
|
|
2015-06-24 20:14:08 +02:00
|
|
|
setContentView(R.layout.activity_configure_alarms);
|
|
|
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
|
|
|
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
2015-06-26 17:22:42 +02:00
|
|
|
preferencesAlarmListSet = sharedPrefs.getStringSet(PREF_MIBAND_ALARMS, new HashSet<String>());
|
|
|
|
if (preferencesAlarmListSet.isEmpty()) {
|
|
|
|
//initialize the preferences
|
|
|
|
preferencesAlarmListSet = new HashSet<>(Arrays.asList(GBAlarm.DEFAULT_ALARMS));
|
|
|
|
sharedPrefs.edit().putStringSet(PREF_MIBAND_ALARMS, preferencesAlarmListSet).commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
mGBAlarmListAdapter = new GBAlarmListAdapter(this, preferencesAlarmListSet);
|
|
|
|
|
|
|
|
setListAdapter(mGBAlarmListAdapter);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
|
|
|
|
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
preferencesAlarmListSet = sharedPrefs.getStringSet(PREF_MIBAND_ALARMS, new HashSet<String>());
|
|
|
|
|
|
|
|
mGBAlarmListAdapter.setAlarmList(preferencesAlarmListSet);
|
|
|
|
mGBAlarmListAdapter.notifyDataSetChanged();
|
|
|
|
|
|
|
|
sendAlarmsToDevice();
|
2015-06-24 20:14:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-26 17:22:42 +02:00
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case android.R.id.home:
|
|
|
|
// back button
|
|
|
|
sendAlarmsToDevice();
|
|
|
|
finish();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void configureAlarm(GBAlarm alarm) {
|
|
|
|
Intent startIntent;
|
|
|
|
startIntent = new Intent(getApplicationContext(), AlarmDetails.class);
|
|
|
|
startIntent.putExtra("alarm", alarm);
|
|
|
|
startActivity(startIntent);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void sendAlarmsToDevice() {
|
2015-08-21 00:58:18 +02:00
|
|
|
GBApplication.deviceService().onSetAlarms(mGBAlarmListAdapter.getAlarmList());
|
2015-06-24 20:14:08 +02:00
|
|
|
}
|
|
|
|
}
|