1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-23 02:16:48 +01:00

Moyoung: Add option for letting the device follow the phone DND setting

This commit is contained in:
Arjan Schrijver 2024-09-21 22:41:32 +02:00
parent a586a9af52
commit 504faf6db0
5 changed files with 30 additions and 3 deletions

View File

@ -226,6 +226,7 @@ public class DeviceSettingsPreferenceConst {
public static final String PREF_DO_NOT_DISTURB_LIFT_WRIST = "do_not_disturb_lift_wrist";
public static final String PREF_DO_NOT_DISTURB_NOT_WEAR = "do_not_disturb_not_wear";
public static final String PREF_DO_NOT_DISTURB_BOOL = "do_not_disturb_on_off";
public static final String PREF_DO_NOT_DISTURB_FOLLOW_PHONE = "do_not_disturb_follow_phone";
public static final String PREF_DO_NOT_DISTURB_OFF = "off";
public static final String PREF_DO_NOT_DISTURB_AUTOMATIC = "automatic";
public static final String PREF_DO_NOT_DISTURB_ALWAYS = "always";

View File

@ -572,6 +572,7 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
addPreferenceHandlerFor(PREF_DO_NOT_DISTURB_LIFT_WRIST);
addPreferenceHandlerFor(PREF_DO_NOT_DISTURB_NOT_WEAR);
addPreferenceHandlerFor(PREF_DO_NOT_DISTURB_BOOL);
addPreferenceHandlerFor(PREF_DO_NOT_DISTURB_FOLLOW_PHONE);
addPreferenceHandlerFor(PREF_FIND_PHONE);
addPreferenceHandlerFor(PREF_FIND_PHONE_DURATION);
addPreferenceHandlerFor(PREF_AUTOLIGHT);

View File

@ -204,7 +204,7 @@ public abstract class AbstractMoyoungDeviceCoordinator extends AbstractBLEDevice
generic.add(R.xml.devicesettings_moyoung_watchface);
generic.add(R.xml.devicesettings_liftwrist_display);
// generic.add(R.xml.devicesettings_donotdisturb_no_auto); // not supported by Colmi i28 Ultra
generic.add(R.xml.devicesettings_donotdisturb_on_off);
generic.add(R.xml.devicesettings_donotdisturb_on_off_follow);
generic.add(R.xml.devicesettings_world_clocks);
generic.add(R.xml.devicesettings_sync_calendar);
final List<Integer> health = deviceSpecificSettings.addRootScreen(DeviceSpecificSettingsScreen.HEALTH);

View File

@ -18,8 +18,8 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.moyoung;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.os.Handler;
import android.text.format.DateFormat;
import android.util.Pair;
@ -81,7 +81,6 @@ import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.settings.MoyoungSett
import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.settings.MoyoungSettingTimeRange;
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary;
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummaryDao;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
import nodomain.freeyourgadget.gadgetbridge.entities.MoyoungActivitySample;
import nodomain.freeyourgadget.gadgetbridge.entities.MoyoungBloodPressureSample;
@ -1409,6 +1408,24 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
onAbortHeartRateTest();
}
@Override
public void onChangePhoneSilentMode(int ringerMode) {
Prefs prefs = getDevicePrefs();
if (!prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_FOLLOW_PHONE, false)) {
return;
}
LOG.info("Phone ringer mode changed to {}, changing on device too", ringerMode);
switch (ringerMode) {
case AudioManager.RINGER_MODE_NORMAL:
case AudioManager.RINGER_MODE_VIBRATE:
sendSetting(getSetting("DO_NOT_DISTURB_ONOFF"), false);
break;
case AudioManager.RINGER_MODE_SILENT:
sendSetting(getSetting("DO_NOT_DISTURB_ONOFF"), true);
break;
}
}
@Override
public void onFindDevice(boolean start) {
if (start)

View File

@ -9,4 +9,12 @@
android:title="@string/mi2_prefs_do_not_disturb"
android:summary="@string/mi2_prefs_do_not_disturb_summary" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:icon="@drawable/ic_action_find_lost_device"
android:key="do_not_disturb_follow_phone"
android:layout="@layout/preference_checkbox"
android:title="@string/pref_dnd_follow_phone_title"
android:summary="@string/pref_dnd_follow_phone_summary" />
</androidx.preference.PreferenceScreen>