mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-30 14:02:56 +01:00
Allow to set alarms to unused when long tapping
This helps clearing up a cluttered alarms list on devices like the Mi Band 4 Difference between disabling and setting to usused: Unsused alarms cant be enabled from the Band, disabled can. Closes #1747
This commit is contained in:
parent
6e4240e61c
commit
21eada4caa
@ -15,8 +15,6 @@
|
||||
*/
|
||||
package nodomain.freeyourgadget.gadgetbridge.daogen;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import de.greenrobot.daogenerator.DaoGenerator;
|
||||
import de.greenrobot.daogenerator.Entity;
|
||||
import de.greenrobot.daogenerator.Index;
|
||||
@ -45,7 +43,7 @@ public class GBDaoGenerator {
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Schema schema = new Schema(21, MAIN_PACKAGE + ".entities");
|
||||
Schema schema = new Schema(22, MAIN_PACKAGE + ".entities");
|
||||
|
||||
Entity userAttributes = addUserAttributes(schema);
|
||||
Entity user = addUserInfo(schema, userAttributes);
|
||||
@ -378,6 +376,7 @@ public class GBDaoGenerator {
|
||||
);
|
||||
alarm.addIntProperty("hour").notNull();
|
||||
alarm.addIntProperty("minute").notNull();
|
||||
alarm.addBooleanProperty("unused").notNull();
|
||||
alarm.addToOne(user, userId);
|
||||
alarm.addToOne(device, deviceId);
|
||||
}
|
||||
|
@ -21,14 +21,15 @@ import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.adapter.GBAlarmListAdapter;
|
||||
@ -136,7 +137,7 @@ public class ConfigureAlarms extends AbstractGBActivity {
|
||||
}
|
||||
|
||||
private Alarm createDefaultAlarm(@NonNull Device device, @NonNull User user, int position) {
|
||||
return new Alarm(device.getId(), user.getId(), position, false, false,0, 6, 30);
|
||||
return new Alarm(device.getId(), user.getId(), position, false, false, 0, 6, 30, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,12 +27,13 @@ import android.widget.CompoundButton;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.cardview.widget.CardView;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.ConfigureAlarms;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||
@ -71,7 +72,7 @@ public class GBAlarmListAdapter extends RecyclerView.Adapter<GBAlarmListAdapter.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
|
||||
public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {
|
||||
|
||||
final Alarm alarm = alarmList.get(position);
|
||||
|
||||
@ -82,7 +83,7 @@ public class GBAlarmListAdapter extends RecyclerView.Adapter<GBAlarmListAdapter.
|
||||
holder.alarmDayFriday.setChecked(alarm.getRepetition(Alarm.ALARM_FRI));
|
||||
holder.alarmDaySaturday.setChecked(alarm.getRepetition(Alarm.ALARM_SAT));
|
||||
holder.alarmDaySunday.setChecked(alarm.getRepetition(Alarm.ALARM_SUN));
|
||||
|
||||
holder.container.setAlpha(alarm.getUnused() ? 0.5f : 1.0f);
|
||||
holder.isEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
@ -97,6 +98,16 @@ public class GBAlarmListAdapter extends RecyclerView.Adapter<GBAlarmListAdapter.
|
||||
((ConfigureAlarms) mContext).configureAlarm(alarm);
|
||||
}
|
||||
});
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
||||
holder.alarmTime.setText(DateTimeUtils.formatTime(alarm.getHour(), alarm.getMinute()));
|
||||
holder.isEnabled.setChecked(alarm.getEnabled());
|
||||
if (alarm.getSmartWakeup()) {
|
||||
|
@ -0,0 +1,39 @@
|
||||
/* Copyright (C) 2019 Andreas Shimokawa
|
||||
|
||||
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/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.database.schema;
|
||||
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBUpdateScript;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.AlarmDao;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.No1F1ActivitySampleDao;
|
||||
|
||||
public class GadgetbridgeUpdate_22 implements DBUpdateScript {
|
||||
@Override
|
||||
public void upgradeSchema(SQLiteDatabase db) {
|
||||
if (!DBHelper.existsColumn(AlarmDao.TABLENAME, AlarmDao.Properties.Unused.columnName, db)) {
|
||||
String ADD_COLUMN_UNUSED = "ALTER TABLE " + AlarmDao.TABLENAME + " ADD COLUMN "
|
||||
+ AlarmDao.Properties.Unused.columnName + " INTEGER NOT NULL DEFAULT 0;";
|
||||
db.execSQL(ADD_COLUMN_UNUSED);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downgradeSchema(SQLiteDatabase db) {
|
||||
}
|
||||
}
|
@ -37,6 +37,8 @@ public interface Alarm extends Serializable {
|
||||
|
||||
boolean getEnabled();
|
||||
|
||||
boolean getUnused();
|
||||
|
||||
boolean getSmartWakeup();
|
||||
|
||||
int getRepetition();
|
||||
|
@ -1487,13 +1487,17 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
|
||||
int base = 0;
|
||||
if (alarm.getEnabled()) {
|
||||
int daysMask = 0;
|
||||
if (alarm.getEnabled() && !alarm.getUnused()) {
|
||||
base = 128;
|
||||
}
|
||||
int daysMask = alarm.getRepetition();
|
||||
if (!alarm.isRepetitive()) {
|
||||
daysMask = 128;
|
||||
if (!alarm.getUnused()) {
|
||||
daysMask = alarm.getRepetition();
|
||||
if (!alarm.isRepetitive()) {
|
||||
daysMask = 128;
|
||||
}
|
||||
}
|
||||
|
||||
byte[] alarmMessage = new byte[] {
|
||||
(byte) 0x2, // TODO what is this?
|
||||
(byte) (base + alarm.getPosition()), // 128 is the base, alarm slot is added
|
||||
|
@ -48,7 +48,7 @@ public class AlarmUtils {
|
||||
* @return
|
||||
*/
|
||||
public static nodomain.freeyourgadget.gadgetbridge.model.Alarm createSingleShot(int index, boolean smartWakeup, Calendar calendar) {
|
||||
return new Alarm(-1, -1, index, true, smartWakeup, Alarm.ALARM_ONCE, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE));
|
||||
return new Alarm(-1, -1, index, true, smartWakeup, Alarm.ALARM_ONCE, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -127,7 +127,7 @@ public class AlarmUtils {
|
||||
int hour = Integer.parseInt(tokens[4]);
|
||||
int minute = Integer.parseInt(tokens[5]);
|
||||
|
||||
return new Alarm(device.getId(), user.getId(), index, enabled, smartWakeup, repetition, hour, minute);
|
||||
return new Alarm(device.getId(), user.getId(), index, enabled, smartWakeup, repetition, hour, minute, false);
|
||||
}
|
||||
|
||||
private static Comparator<Alarm> createComparator() {
|
||||
|
Loading…
Reference in New Issue
Block a user