2019-02-13 20:43:30 +01:00
|
|
|
/* Copyright (C) 2015-2019 Andreas Shimokawa, Carsten Pfeiffer, Daniele
|
2017-03-10 14:53:19 +01:00
|
|
|
Gobbetti, Lem Dulfo
|
|
|
|
|
|
|
|
This file is part of Gadgetbridge.
|
|
|
|
|
|
|
|
Gadgetbridge is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Gadgetbridge is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
2015-06-24 20:14:08 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.activities;
|
|
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.text.format.DateFormat;
|
2015-06-26 17:22:42 +02:00
|
|
|
import android.view.MenuItem;
|
2017-01-26 20:55:00 +01:00
|
|
|
import android.view.View;
|
2017-04-09 16:01:48 +02:00
|
|
|
import android.widget.CheckedTextView;
|
2015-06-24 20:14:08 +02:00
|
|
|
import android.widget.TimePicker;
|
|
|
|
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
2019-01-07 01:10:57 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
2017-01-26 20:55:00 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
2019-01-07 01:10:57 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.Alarm;
|
2019-01-26 15:52:40 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
2019-01-07 01:10:57 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.AlarmUtils;
|
2017-01-26 20:55:00 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
2015-06-24 20:14:08 +02:00
|
|
|
|
2017-09-03 01:02:31 +02:00
|
|
|
public class AlarmDetails extends AbstractGBActivity {
|
2015-06-24 20:14:08 +02:00
|
|
|
|
2019-01-07 01:10:57 +01:00
|
|
|
private Alarm alarm;
|
2015-06-24 20:14:08 +02:00
|
|
|
private TimePicker timePicker;
|
2017-04-09 16:01:48 +02:00
|
|
|
private CheckedTextView cbSmartWakeup;
|
|
|
|
private CheckedTextView cbMonday;
|
|
|
|
private CheckedTextView cbTuesday;
|
|
|
|
private CheckedTextView cbWednesday;
|
|
|
|
private CheckedTextView cbThursday;
|
|
|
|
private CheckedTextView cbFriday;
|
|
|
|
private CheckedTextView cbSaturday;
|
|
|
|
private CheckedTextView cbSunday;
|
2017-01-26 20:55:00 +01:00
|
|
|
private GBDevice device;
|
2015-06-24 20:14:08 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_alarm_details);
|
|
|
|
|
2019-01-07 01:10:57 +01:00
|
|
|
alarm = (Alarm) getIntent().getSerializableExtra(nodomain.freeyourgadget.gadgetbridge.model.Alarm.EXTRA_ALARM);
|
2017-01-26 20:55:00 +01:00
|
|
|
device = getIntent().getParcelableExtra(GBDevice.EXTRA_DEVICE);
|
2015-06-25 14:34:21 +02:00
|
|
|
|
2018-08-17 00:13:14 +02:00
|
|
|
timePicker = findViewById(R.id.alarm_time_picker);
|
|
|
|
cbSmartWakeup = findViewById(R.id.alarm_cb_smart_wakeup);
|
|
|
|
cbMonday = findViewById(R.id.alarm_cb_monday);
|
|
|
|
cbTuesday = findViewById(R.id.alarm_cb_tuesday);
|
|
|
|
cbWednesday = findViewById(R.id.alarm_cb_wednesday);
|
|
|
|
cbThursday = findViewById(R.id.alarm_cb_thursday);
|
|
|
|
cbFriday = findViewById(R.id.alarm_cb_friday);
|
|
|
|
cbSaturday = findViewById(R.id.alarm_cb_saturday);
|
|
|
|
cbSunday = findViewById(R.id.alarm_cb_sunday);
|
2017-04-09 16:01:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
cbSmartWakeup.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View v) {
|
|
|
|
((CheckedTextView) v).toggle();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
cbMonday.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View v) {
|
|
|
|
((CheckedTextView) v).toggle();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
cbTuesday.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View v) {
|
|
|
|
((CheckedTextView) v).toggle();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
cbWednesday.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View v) {
|
|
|
|
((CheckedTextView) v).toggle();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
cbThursday.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View v) {
|
|
|
|
((CheckedTextView) v).toggle();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
cbFriday.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View v) {
|
|
|
|
((CheckedTextView) v).toggle();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
cbSaturday.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View v) {
|
|
|
|
((CheckedTextView) v).toggle();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
cbSunday.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View v) {
|
|
|
|
((CheckedTextView) v).toggle();
|
|
|
|
}
|
|
|
|
});
|
2015-06-25 14:34:21 +02:00
|
|
|
|
|
|
|
timePicker.setIs24HourView(DateFormat.is24HourFormat(GBApplication.getContext()));
|
|
|
|
timePicker.setCurrentHour(alarm.getHour());
|
|
|
|
timePicker.setCurrentMinute(alarm.getMinute());
|
|
|
|
|
2019-01-07 01:10:57 +01:00
|
|
|
cbSmartWakeup.setChecked(alarm.getSmartWakeup());
|
2017-01-26 20:55:00 +01:00
|
|
|
int smartAlarmVisibility = supportsSmartWakeup() ? View.VISIBLE : View.GONE;
|
|
|
|
cbSmartWakeup.setVisibility(smartAlarmVisibility);
|
2015-06-25 14:34:21 +02:00
|
|
|
|
2019-01-07 01:10:57 +01:00
|
|
|
cbMonday.setChecked(alarm.getRepetition(Alarm.ALARM_MON));
|
|
|
|
cbTuesday.setChecked(alarm.getRepetition(Alarm.ALARM_TUE));
|
|
|
|
cbWednesday.setChecked(alarm.getRepetition(Alarm.ALARM_WED));
|
|
|
|
cbThursday.setChecked(alarm.getRepetition(Alarm.ALARM_THU));
|
|
|
|
cbFriday.setChecked(alarm.getRepetition(Alarm.ALARM_FRI));
|
|
|
|
cbSaturday.setChecked(alarm.getRepetition(Alarm.ALARM_SAT));
|
|
|
|
cbSunday.setChecked(alarm.getRepetition(Alarm.ALARM_SUN));
|
2015-06-24 20:14:08 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-01-26 20:55:00 +01:00
|
|
|
private boolean supportsSmartWakeup() {
|
|
|
|
if (device != null) {
|
|
|
|
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
|
|
|
|
return coordinator.supportsSmartWakeup(device);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
finish();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateAlarm() {
|
2017-03-26 17:57:03 +02:00
|
|
|
alarm.setSmartWakeup(supportsSmartWakeup() && cbSmartWakeup.isChecked());
|
2019-01-07 01:10:57 +01:00
|
|
|
int repetitionMask = AlarmUtils.createRepetitionMassk(cbMonday.isChecked(), cbTuesday.isChecked(), cbWednesday.isChecked(), cbThursday.isChecked(), cbFriday.isChecked(), cbSaturday.isChecked(), cbSunday.isChecked());
|
|
|
|
alarm.setRepetition(repetitionMask);
|
2015-06-24 20:14:08 +02:00
|
|
|
alarm.setHour(timePicker.getCurrentHour());
|
|
|
|
alarm.setMinute(timePicker.getCurrentMinute());
|
2019-01-07 01:10:57 +01:00
|
|
|
DBHelper.store(alarm);
|
2015-06-24 20:14:08 +02:00
|
|
|
}
|
2015-10-18 23:52:59 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
|
|
|
updateAlarm();
|
|
|
|
super.onPause();
|
|
|
|
}
|
2015-06-24 20:14:08 +02:00
|
|
|
}
|