mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-06-21 04:20:27 +02:00
The code basically works, but there a lot of things to fix / improve. * The alarms are stored to and read from the Shared Preferences, but there is no persistence within the app (basically they are read and stored at every access) * The alarm list is not updated when coming back from the alarm detail view (probably related to the point above), but the actual alarm is * The alarms preference names is sometimes built by concatenating strings, which is not really safe * There is no check in the alarm constructor whether the stored string is a valid alarm representation * Even though only 3 alarms can be stored on the device, we could have more in the app and let the user choose which to sync * In the alarm detail view XML some material* drawables are used, it's possible that these break on android version < 5 * ...
56 lines
2.2 KiB
Java
56 lines
2.2 KiB
Java
package nodomain.freeyourgadget.gadgetbridge.activities;
|
|
|
|
import android.content.Intent;
|
|
import android.content.SharedPreferences;
|
|
import android.os.Bundle;
|
|
import android.app.Activity;
|
|
import android.preference.PreferenceManager;
|
|
import android.widget.ListView;
|
|
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.BluetoothCommunicationService;
|
|
import nodomain.freeyourgadget.gadgetbridge.GBAlarm;
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
|
import nodomain.freeyourgadget.gadgetbridge.adapter.GBAlarmListAdapter;
|
|
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.PREF_MIBAND_ALARM1;
|
|
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.PREF_MIBAND_ALARM2;
|
|
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.PREF_MIBAND_ALARM3;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
|
|
public class ConfigureAlarms extends Activity {
|
|
|
|
ListView alarmListView;
|
|
private GBAlarmListAdapter mGBAlarmListAdapter;
|
|
|
|
final List<GBAlarm> alarmList = new ArrayList<>();
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.activity_configure_alarms);
|
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
//The GBAlarm class initializes the sharedPrefs values if they're missing, no need to handle it here
|
|
alarmList.add(new GBAlarm(sharedPrefs.getString(PREF_MIBAND_ALARM1, GBAlarm.DEFAULT_ALARM1)));
|
|
alarmList.add(new GBAlarm(sharedPrefs.getString(PREF_MIBAND_ALARM2, GBAlarm.DEFAULT_ALARM2)));
|
|
alarmList.add(new GBAlarm(sharedPrefs.getString(PREF_MIBAND_ALARM3, GBAlarm.DEFAULT_ALARM3)));
|
|
|
|
alarmListView = (ListView) findViewById(R.id.alarmListView);
|
|
mGBAlarmListAdapter = new GBAlarmListAdapter(this, alarmList);
|
|
alarmListView.setAdapter(this.mGBAlarmListAdapter);
|
|
}
|
|
|
|
@Override
|
|
protected void onDestroy() {
|
|
super.onDestroy();
|
|
Intent startIntent = new Intent(ConfigureAlarms.this, BluetoothCommunicationService.class);
|
|
startIntent.setAction(BluetoothCommunicationService.ACTION_SET_ALARMS);
|
|
startService(startIntent);
|
|
}
|
|
}
|