2024-01-10 18:54:00 +01:00
|
|
|
/* Copyright (C) 2015-2024 Andreas Shimokawa, Arjan Schrijver, Carsten
|
|
|
|
Pfeiffer, Daniele Gobbetti
|
2017-03-10 14:53:19 +01:00
|
|
|
|
|
|
|
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
|
2024-01-10 18:54:00 +01:00
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
2015-06-24 20:14:08 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.adapter;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2017-04-08 18:44:15 +02:00
|
|
|
import android.widget.CheckedTextView;
|
2015-06-24 20:14:08 +02:00
|
|
|
import android.widget.CompoundButton;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2019-01-26 15:52:40 +01:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
2019-12-24 01:27:57 +01:00
|
|
|
|
2023-08-01 20:48:34 +02:00
|
|
|
import com.google.android.material.card.MaterialCardView;
|
2023-12-14 13:23:28 +01:00
|
|
|
import com.google.android.material.materialswitch.MaterialSwitch;
|
2023-08-01 20:48:34 +02:00
|
|
|
|
2019-12-24 01:27:57 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2015-06-24 20:14:08 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
2015-06-26 17:22:42 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.ConfigureAlarms;
|
2019-01-07 01:10:57 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.Alarm;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
2015-06-24 20:14:08 +02:00
|
|
|
|
2015-10-26 23:32:03 +01:00
|
|
|
/**
|
|
|
|
* Adapter for displaying GBAlarm instances.
|
|
|
|
*/
|
2017-04-08 18:44:15 +02:00
|
|
|
public class GBAlarmListAdapter extends RecyclerView.Adapter<GBAlarmListAdapter.ViewHolder> {
|
2015-06-24 20:14:08 +02:00
|
|
|
|
|
|
|
private final Context mContext;
|
2019-01-07 01:10:57 +01:00
|
|
|
private ArrayList<Alarm> alarmList;
|
2015-06-24 20:14:08 +02:00
|
|
|
|
2018-11-24 12:16:47 +01:00
|
|
|
public GBAlarmListAdapter(Context context) {
|
2015-06-24 20:14:08 +02:00
|
|
|
this.mContext = context;
|
2015-06-26 17:22:42 +02:00
|
|
|
}
|
|
|
|
|
2019-01-07 01:10:57 +01:00
|
|
|
public void setAlarmList(List<Alarm> alarms) {
|
|
|
|
this.alarmList = new ArrayList<>(alarms);
|
2015-06-26 17:22:42 +02:00
|
|
|
}
|
|
|
|
|
2019-01-07 01:10:57 +01:00
|
|
|
public ArrayList<Alarm> getAlarmList() {
|
|
|
|
return alarmList;
|
2015-06-26 17:22:42 +02:00
|
|
|
}
|
|
|
|
|
2019-01-07 01:10:57 +01:00
|
|
|
private void updateInDB(Alarm alarm) {
|
|
|
|
DBHelper.store(alarm);
|
2015-06-26 17:22:42 +02:00
|
|
|
}
|
|
|
|
|
2018-11-24 12:16:47 +01:00
|
|
|
@NonNull
|
2015-06-26 17:22:42 +02:00
|
|
|
@Override
|
2018-11-24 12:16:47 +01:00
|
|
|
public GBAlarmListAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
2017-04-09 16:01:48 +02:00
|
|
|
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_alarm, parent, false);
|
2018-11-24 12:16:47 +01:00
|
|
|
return new ViewHolder(view);
|
2015-06-26 17:22:42 +02:00
|
|
|
}
|
|
|
|
|
2015-06-24 20:14:08 +02:00
|
|
|
@Override
|
2019-12-24 01:27:57 +01:00
|
|
|
public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {
|
2015-06-24 20:14:08 +02:00
|
|
|
|
2019-01-07 01:10:57 +01:00
|
|
|
final Alarm alarm = alarmList.get(position);
|
2015-06-24 20:14:08 +02:00
|
|
|
|
2017-04-08 18:44:15 +02:00
|
|
|
holder.alarmDayMonday.setChecked(alarm.getRepetition(Alarm.ALARM_MON));
|
|
|
|
holder.alarmDayTuesday.setChecked(alarm.getRepetition(Alarm.ALARM_TUE));
|
|
|
|
holder.alarmDayWednesday.setChecked(alarm.getRepetition(Alarm.ALARM_WED));
|
|
|
|
holder.alarmDayThursday.setChecked(alarm.getRepetition(Alarm.ALARM_THU));
|
|
|
|
holder.alarmDayFriday.setChecked(alarm.getRepetition(Alarm.ALARM_FRI));
|
|
|
|
holder.alarmDaySaturday.setChecked(alarm.getRepetition(Alarm.ALARM_SAT));
|
|
|
|
holder.alarmDaySunday.setChecked(alarm.getRepetition(Alarm.ALARM_SUN));
|
2019-12-24 01:27:57 +01:00
|
|
|
holder.container.setAlpha(alarm.getUnused() ? 0.5f : 1.0f);
|
2017-04-08 18:44:15 +02:00
|
|
|
holder.isEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
2015-06-24 20:14:08 +02:00
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
|
alarm.setEnabled(isChecked);
|
2019-01-07 01:10:57 +01:00
|
|
|
updateInDB(alarm);
|
2015-06-24 20:14:08 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-04-08 18:44:15 +02:00
|
|
|
holder.container.setOnClickListener(new View.OnClickListener() {
|
2015-06-24 20:14:08 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-06-30 12:09:29 +02:00
|
|
|
((ConfigureAlarms) mContext).configureAlarm(alarm);
|
2015-06-24 20:14:08 +02:00
|
|
|
}
|
|
|
|
});
|
2019-12-24 01:27:57 +01:00
|
|
|
holder.container.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
alarm.setUnused(!alarm.getUnused());
|
|
|
|
holder.container.setAlpha(alarm.getUnused() ? 0.5f : 1.0f);
|
|
|
|
updateInDB(alarm);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-01-07 01:10:57 +01:00
|
|
|
holder.alarmTime.setText(DateTimeUtils.formatTime(alarm.getHour(), alarm.getMinute()));
|
|
|
|
holder.isEnabled.setChecked(alarm.getEnabled());
|
|
|
|
if (alarm.getSmartWakeup()) {
|
2017-04-08 18:44:15 +02:00
|
|
|
holder.isSmartWakeup.setVisibility(TextView.VISIBLE);
|
2015-06-24 20:14:08 +02:00
|
|
|
} else {
|
2017-04-08 18:44:15 +02:00
|
|
|
holder.isSmartWakeup.setVisibility(TextView.GONE);
|
2015-06-24 20:14:08 +02:00
|
|
|
}
|
2017-04-08 18:44:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
return alarmList.size();
|
2015-06-24 20:14:08 +02:00
|
|
|
}
|
|
|
|
|
2017-04-08 18:44:15 +02:00
|
|
|
static class ViewHolder extends RecyclerView.ViewHolder {
|
|
|
|
|
2023-08-01 20:48:34 +02:00
|
|
|
MaterialCardView container;
|
2017-04-08 18:44:15 +02:00
|
|
|
|
|
|
|
TextView alarmTime;
|
2023-12-14 13:23:28 +01:00
|
|
|
MaterialSwitch isEnabled;
|
2017-04-08 18:44:15 +02:00
|
|
|
TextView isSmartWakeup;
|
|
|
|
|
|
|
|
CheckedTextView alarmDayMonday;
|
|
|
|
CheckedTextView alarmDayTuesday;
|
|
|
|
CheckedTextView alarmDayWednesday;
|
|
|
|
CheckedTextView alarmDayThursday;
|
|
|
|
CheckedTextView alarmDayFriday;
|
|
|
|
CheckedTextView alarmDaySaturday;
|
|
|
|
CheckedTextView alarmDaySunday;
|
|
|
|
|
|
|
|
ViewHolder(View view) {
|
|
|
|
super(view);
|
|
|
|
|
2018-11-24 12:16:47 +01:00
|
|
|
container = view.findViewById(R.id.card_view);
|
2017-04-08 18:44:15 +02:00
|
|
|
|
2018-11-24 12:16:47 +01:00
|
|
|
alarmTime = view.findViewById(R.id.alarm_item_time);
|
|
|
|
isEnabled = view.findViewById(R.id.alarm_item_toggle);
|
|
|
|
isSmartWakeup = view.findViewById(R.id.alarm_smart_wakeup);
|
2017-04-08 18:44:15 +02:00
|
|
|
|
2018-11-24 12:16:47 +01:00
|
|
|
alarmDayMonday = view.findViewById(R.id.alarm_item_monday);
|
|
|
|
alarmDayTuesday = view.findViewById(R.id.alarm_item_tuesday);
|
|
|
|
alarmDayWednesday = view.findViewById(R.id.alarm_item_wednesday);
|
|
|
|
alarmDayThursday = view.findViewById(R.id.alarm_item_thursday);
|
|
|
|
alarmDayFriday = view.findViewById(R.id.alarm_item_friday);
|
|
|
|
alarmDaySaturday = view.findViewById(R.id.alarm_item_saturday);
|
|
|
|
alarmDaySunday = view.findViewById(R.id.alarm_item_sunday);
|
2015-06-24 20:14:08 +02:00
|
|
|
}
|
|
|
|
}
|
2017-04-08 18:44:15 +02:00
|
|
|
|
2015-06-24 20:14:08 +02:00
|
|
|
}
|