1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-11 20:49:25 +01:00

Xiaomi: Add camera remote preference

This commit is contained in:
José Rebelo 2023-12-10 13:24:35 +00:00
parent a3e2997f26
commit bf9a5d90d4
2 changed files with 40 additions and 3 deletions

View File

@ -431,9 +431,9 @@ public abstract class XiaomiCoordinator extends AbstractBLEDeviceCoordinator {
if (getContactsSlotCount(device) > 0) { if (getContactsSlotCount(device) > 0) {
settings.add(R.xml.devicesettings_contacts); settings.add(R.xml.devicesettings_contacts);
} }
// TODO not implemented if (supports(device, FEAT_CAMERA_REMOTE)) { if (supports(device, FEAT_CAMERA_REMOTE)) {
// TODO not implemented settings.add(R.xml.devicesettings_camera_remote); settings.add(R.xml.devicesettings_camera_remote);
// TODO not implemented } }
if (supports(device, FEAT_DEVICE_ACTIONS)) { if (supports(device, FEAT_DEVICE_ACTIONS)) {
settings.add(R.xml.devicesettings_device_actions); settings.add(R.xml.devicesettings_device_actions);
} }

View File

@ -103,6 +103,7 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
getSupport().sendCommand("get battery state", COMMAND_TYPE, CMD_BATTERY); getSupport().sendCommand("get battery state", COMMAND_TYPE, CMD_BATTERY);
getSupport().sendCommand("get password", COMMAND_TYPE, CMD_PASSWORD_GET); getSupport().sendCommand("get password", COMMAND_TYPE, CMD_PASSWORD_GET);
getSupport().sendCommand("get display items", COMMAND_TYPE, CMD_DISPLAY_ITEMS_GET); getSupport().sendCommand("get display items", COMMAND_TYPE, CMD_DISPLAY_ITEMS_GET);
getSupport().sendCommand("get camera remote", COMMAND_TYPE, CMD_CAMERA_REMOTE_GET);
} }
@Override @Override
@ -129,6 +130,12 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
case CMD_PASSWORD_GET: case CMD_PASSWORD_GET:
handlePassword(cmd.getSystem().getPassword()); handlePassword(cmd.getSystem().getPassword());
return; return;
case CMD_PASSWORD_GET:
handleCameraRemote(cmd.getSystem().getCamera());
return;
case CMD_CAMERA_REMOTE_SET:
LOG.debug("Got camera remote set ack, status={}", cmd.getStatus());
return;
case CMD_FIND_PHONE: case CMD_FIND_PHONE:
LOG.debug("Got find phone: {}", cmd.getSystem().getFindDevice()); LOG.debug("Got find phone: {}", cmd.getSystem().getFindDevice());
final GBDeviceEventFindPhone findPhoneEvent = new GBDeviceEventFindPhone(); final GBDeviceEventFindPhone findPhoneEvent = new GBDeviceEventFindPhone();
@ -160,6 +167,9 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
@Override @Override
public boolean onSendConfiguration(final String config, final Prefs prefs) { public boolean onSendConfiguration(final String config, final Prefs prefs) {
switch (config) { switch (config) {
case DeviceSettingsPreferenceConst.PREF_CAMERA_REMOTE:
setCameraRemoteConfig();
return true;
case DeviceSettingsPreferenceConst.PREF_LANGUAGE: case DeviceSettingsPreferenceConst.PREF_LANGUAGE:
setLanguage(); setLanguage();
return true; return true;
@ -340,6 +350,33 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
getSupport().evaluateGBDeviceEvent(eventUpdatePreferences); getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
} }
private void handleCameraRemote(final XiaomiProto.Camera camera) {
LOG.debug("Got camera remote enabled={}", camera.getEnabled());
final GBDeviceEventUpdatePreferences eventUpdatePreferences = new GBDeviceEventUpdatePreferences()
.withPreference(XiaomiPreferences.FEAT_CAMERA_REMOTE, true)
.withPreference(DeviceSettingsPreferenceConst.PREF_CAMERA_REMOTE, camera.getEnabled());
getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
}
private void setCameraRemoteConfig() {
final boolean enabled = getDevicePrefs().getBoolean(DeviceSettingsPreferenceConst.PREF_CAMERA_REMOTE, false);
LOG.debug("Set camera remote enabled={}", enabled);
getSupport().sendCommand(
"set camera remote",
XiaomiProto.Command.newBuilder()
.setType(COMMAND_TYPE)
.setSubtype(CMD_CAMERA_REMOTE_SET)
.setSystem(XiaomiProto.System.newBuilder().setCamera(
XiaomiProto.Camera.newBuilder().setEnabled(enabled)
))
.build()
);
}
private void setDisplayItems() { private void setDisplayItems() {
final Prefs prefs = getDevicePrefs(); final Prefs prefs = getDevicePrefs();
final List<String> allScreens = new ArrayList<>(prefs.getList(DeviceSettingsUtils.getPrefPossibleValuesKey(HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE), Collections.emptyList())); final List<String> allScreens = new ArrayList<>(prefs.getList(DeviceSettingsUtils.getPrefPossibleValuesKey(HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE), Collections.emptyList()));