mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-14 11:01:06 +01:00
900511760c
- the day of week are evenly spread across the screen in the alarms detail activity - the alarms are stored in a single shared preference (as a set) NB: you'll have to reset your alarms if you used a previous version (and also manually clean the shared preferences, but this is not needed) - the list of alarms gets correctly updated after editing a specific alarm - the actionbar back button saves the alarm status, the device back button doesn't. I'm not sure if it's a bug or a feature :)
135 lines
5.0 KiB
Java
135 lines
5.0 KiB
Java
package nodomain.freeyourgadget.gadgetbridge.activities;
|
|
|
|
import android.app.Activity;
|
|
import android.os.Bundle;
|
|
import android.os.Parcelable;
|
|
import android.text.format.DateFormat;
|
|
import android.view.MenuItem;
|
|
import android.view.View;
|
|
import android.widget.CheckedTextView;
|
|
import android.widget.TimePicker;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBAlarm;
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
|
|
|
public class AlarmDetails extends Activity {
|
|
|
|
private GBAlarm alarm;
|
|
private TimePicker timePicker;
|
|
//using CheckedTextView allows for vertically aligned text
|
|
private CheckedTextView ctvSmartWakeup;
|
|
private CheckedTextView ctvMonday;
|
|
private CheckedTextView ctvTuesday;
|
|
private CheckedTextView ctvWednesday;
|
|
private CheckedTextView ctvThursday;
|
|
private CheckedTextView ctvFriday;
|
|
private CheckedTextView ctvSaturday;
|
|
private CheckedTextView ctvSunday;
|
|
|
|
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.activity_alarm_details);
|
|
|
|
Parcelable p = getIntent().getExtras().getParcelable("alarm");
|
|
alarm = (GBAlarm) p;
|
|
|
|
timePicker = (TimePicker) findViewById(R.id.alarm_time_picker);
|
|
ctvSmartWakeup = (CheckedTextView) findViewById(R.id.alarm_ctv_smart_wakeup);
|
|
ctvMonday = (CheckedTextView) findViewById(R.id.alarm_ctv_mon);
|
|
ctvTuesday = (CheckedTextView) findViewById(R.id.alarm_ctv_tue);
|
|
ctvWednesday = (CheckedTextView) findViewById(R.id.alarm_ctv_wed);
|
|
ctvThursday = (CheckedTextView) findViewById(R.id.alarm_ctv_thu);
|
|
ctvFriday = (CheckedTextView) findViewById(R.id.alarm_ctv_fri);
|
|
ctvSaturday = (CheckedTextView) findViewById(R.id.alarm_ctv_sat);
|
|
ctvSunday = (CheckedTextView) findViewById(R.id.alarm_ctv_sun);
|
|
|
|
timePicker.setIs24HourView(DateFormat.is24HourFormat(GBApplication.getContext()));
|
|
timePicker.setCurrentHour(alarm.getHour());
|
|
timePicker.setCurrentMinute(alarm.getMinute());
|
|
|
|
ctvSmartWakeup.setChecked(alarm.isSmartWakeup());
|
|
ctvSmartWakeup.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
((CheckedTextView) v).toggle();
|
|
}
|
|
});
|
|
|
|
ctvMonday.setChecked(alarm.getRepetition(GBAlarm.ALARM_MON));
|
|
ctvTuesday.setChecked(alarm.getRepetition(GBAlarm.ALARM_TUE));
|
|
ctvWednesday.setChecked(alarm.getRepetition(GBAlarm.ALARM_WED));
|
|
ctvThursday.setChecked(alarm.getRepetition(GBAlarm.ALARM_THU));
|
|
ctvFriday.setChecked(alarm.getRepetition(GBAlarm.ALARM_FRI));
|
|
ctvSaturday.setChecked(alarm.getRepetition(GBAlarm.ALARM_SAT));
|
|
ctvSunday.setChecked(alarm.getRepetition(GBAlarm.ALARM_SUN));
|
|
|
|
ctvMonday.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
((CheckedTextView) v).toggle();
|
|
}
|
|
});
|
|
ctvTuesday.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
((CheckedTextView) v).toggle();
|
|
}
|
|
});
|
|
ctvWednesday.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
((CheckedTextView) v).toggle();
|
|
}
|
|
});
|
|
ctvThursday.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
((CheckedTextView) v).toggle();
|
|
}
|
|
});
|
|
ctvFriday.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
((CheckedTextView) v).toggle();
|
|
}
|
|
});
|
|
ctvSaturday.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
((CheckedTextView) v).toggle();
|
|
}
|
|
});
|
|
ctvSunday.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
((CheckedTextView) v).toggle();
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
@Override
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
switch (item.getItemId()) {
|
|
case android.R.id.home:
|
|
// back button
|
|
updateAlarm();
|
|
finish();
|
|
return true;
|
|
}
|
|
return super.onOptionsItemSelected(item);
|
|
}
|
|
|
|
private void updateAlarm() {
|
|
alarm.setSmartWakeup(ctvSmartWakeup.isChecked());
|
|
alarm.setRepetition(ctvMonday.isChecked(), ctvTuesday.isChecked(), ctvWednesday.isChecked(), ctvThursday.isChecked(), ctvFriday.isChecked(), ctvSaturday.isChecked(), ctvSunday.isChecked());
|
|
alarm.setHour(timePicker.getCurrentHour());
|
|
alarm.setMinute(timePicker.getCurrentMinute());
|
|
alarm.store();
|
|
}
|
|
}
|