From 41aab5135f49bde504e9d0fe74d5e268f36afe87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Wed, 8 May 2024 21:59:23 +0100 Subject: [PATCH] Fossil Q Hybrid: Migrate global preferences to device-specific --- app/src/main/AndroidManifest.xml | 6 +- .../gadgetbridge/GBApplication.java | 24 ++++- .../activities/SettingsActivity.java | 9 -- ...tivity.java => QHybridConfigActivity.java} | 91 +++++++++++-------- .../devices/qhybrid/QHybridCoordinator.java | 21 +++-- .../qhybrid/QHybridSettingsCustomizer.java | 60 ++++++++++++ app/src/main/res/values/strings.xml | 1 + .../devicesettings_fossilqhybrid_legacy.xml | 10 ++ app/src/main/res/xml/preferences.xml | 5 - 9 files changed, 163 insertions(+), 64 deletions(-) rename app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/{ConfigActivity.java => QHybridConfigActivity.java} (90%) create mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/QHybridSettingsCustomizer.java create mode 100644 app/src/main/res/xml/devicesettings_fossilqhybrid_legacy.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 03c1f0461..5119c8ec0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -764,15 +764,15 @@ + android:parentActivityName=".activities.devicesettings.DeviceSettingsActivity" /> + android:parentActivityName=".devices.qhybrid.QHybridConfigActivity" /> mIDSenderLookup = new LimitedQueue<>(16); private static Prefs prefs; @@ -1468,6 +1468,28 @@ public class GBApplication extends Application { } } + if (oldVersion < 30) { + // Migrate QHybrid preferences to device-specific + try (DBHandler db = acquireDB()) { + final DaoSession daoSession = db.getDaoSession(); + final List activeDevices = DBHelper.getActiveDevices(daoSession); + + for (Device dbDevice : activeDevices) { + final DeviceType deviceType = DeviceType.fromName(dbDevice.getTypeName()); + if (deviceType == DeviceType.FOSSILQHYBRID) { + final SharedPreferences deviceSharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(dbDevice.getIdentifier()); + final SharedPreferences.Editor deviceSharedPrefsEdit = deviceSharedPrefs.edit(); + + deviceSharedPrefsEdit.putInt("QHYBRID_TIME_OFFSET", sharedPrefs.getInt("QHYBRID_TIME_OFFSET", 0)); + deviceSharedPrefsEdit.putInt("QHYBRID_TIMEZONE_OFFSET", sharedPrefs.getInt("QHYBRID_TIMEZONE_OFFSET", 0)); + deviceSharedPrefsEdit.apply(); + } + } + } catch (Exception e) { + Log.w(TAG, "error acquiring DB lock"); + } + } + editor.putString(PREFS_VERSION, Integer.toString(CURRENT_PREFS_VERSION)); editor.apply(); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java index 9816172a6..a50aa013a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java @@ -68,7 +68,6 @@ import nodomain.freeyourgadget.gadgetbridge.activities.discovery.DiscoveryPairin import nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter; import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandPreferencesActivity; import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleSettingsActivity; -import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.ConfigActivity; import nodomain.freeyourgadget.gadgetbridge.devices.zetime.ZeTimePreferenceActivity; import nodomain.freeyourgadget.gadgetbridge.externalevents.TimeChangeReceiver; import nodomain.freeyourgadget.gadgetbridge.model.Weather; @@ -138,14 +137,6 @@ public class SettingsActivity extends AbstractSettingsActivityV2 { }); } - pref = findPreference("pref_key_qhybrid"); - if (pref != null) { - pref.setOnPreferenceClickListener(preference -> { - startActivity(new Intent(requireContext(), ConfigActivity.class)); - return true; - }); - } - pref = findPreference("pref_key_pebble"); if (pref != null) { pref.setOnPreferenceClickListener(preference -> { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/ConfigActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/QHybridConfigActivity.java similarity index 90% rename from app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/ConfigActivity.java rename to app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/QHybridConfigActivity.java index 9e62fd4b6..0b769bdb7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/ConfigActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/QHybridConfigActivity.java @@ -80,7 +80,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.foss import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.buttonconfig.ConfigPayload; import nodomain.freeyourgadget.gadgetbridge.util.GB; -public class ConfigActivity extends AbstractGBActivity { +public class QHybridConfigActivity extends AbstractGBActivity { PackageAdapter adapter; ArrayList list; PackageConfigHelper helper; @@ -97,45 +97,53 @@ public class ConfigActivity extends AbstractGBActivity { @Override protected void onCreate(Bundle savedInstanceState) { + device = getIntent().getParcelableExtra(GBDevice.EXTRA_DEVICE); + super.onCreate(savedInstanceState); + if (device == null) { + GB.toast(this, "Device is null", Toast.LENGTH_LONG, GB.ERROR); + finish(); + return; + } + setContentView(R.layout.activity_qhybrid_settings); findViewById(R.id.buttonOverwriteButtons).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_OVERWRITE_BUTTONS)); + LocalBroadcastManager.getInstance(QHybridConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_OVERWRITE_BUTTONS)); } }); - prefs = getSharedPreferences(getPackageName(), MODE_PRIVATE); + prefs = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()); timeOffsetView = findViewById(R.id.qhybridTimeOffset); timeOffsetView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { int timeOffset = prefs.getInt("QHYBRID_TIME_OFFSET", 0); - LinearLayout layout2 = new LinearLayout(ConfigActivity.this); + LinearLayout layout2 = new LinearLayout(QHybridConfigActivity.this); layout2.setOrientation(LinearLayout.HORIZONTAL); - final NumberPicker hourPicker = new NumberPicker(ConfigActivity.this); + final NumberPicker hourPicker = new NumberPicker(QHybridConfigActivity.this); hourPicker.setMinValue(0); hourPicker.setMaxValue(23); hourPicker.setValue(timeOffset / 60); - final NumberPicker minPicker = new NumberPicker(ConfigActivity.this); + final NumberPicker minPicker = new NumberPicker(QHybridConfigActivity.this); minPicker.setMinValue(0); minPicker.setMaxValue(59); minPicker.setValue(timeOffset % 60); layout2.addView(hourPicker); - TextView tw = new TextView(ConfigActivity.this); + TextView tw = new TextView(QHybridConfigActivity.this); tw.setText(":"); layout2.addView(tw); layout2.addView(minPicker); layout2.setGravity(Gravity.CENTER); - new MaterialAlertDialogBuilder(ConfigActivity.this) + new MaterialAlertDialogBuilder(QHybridConfigActivity.this) .setTitle(getString(R.string.qhybrid_offset_time_by)) .setView(layout2) .setPositiveButton("ok", new DialogInterface.OnClickListener() { @@ -143,7 +151,7 @@ public class ConfigActivity extends AbstractGBActivity { public void onClick(DialogInterface dialogInterface, int i) { prefs.edit().putInt("QHYBRID_TIME_OFFSET", hourPicker.getValue() * 60 + minPicker.getValue()).apply(); updateTimeOffset(); - LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE)); + LocalBroadcastManager.getInstance(QHybridConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE)); GB.toast(getString(R.string.qhybrid_changes_delay_prompt), Toast.LENGTH_SHORT, GB.INFO); } }) @@ -159,28 +167,28 @@ public class ConfigActivity extends AbstractGBActivity { @Override public void onClick(View view) { int timeOffset = prefs.getInt("QHYBRID_TIMEZONE_OFFSET", 0); - LinearLayout layout2 = new LinearLayout(ConfigActivity.this); + LinearLayout layout2 = new LinearLayout(QHybridConfigActivity.this); layout2.setOrientation(LinearLayout.HORIZONTAL); - final NumberPicker hourPicker = new NumberPicker(ConfigActivity.this); + final NumberPicker hourPicker = new NumberPicker(QHybridConfigActivity.this); hourPicker.setMinValue(0); hourPicker.setMaxValue(23); hourPicker.setValue(timeOffset / 60); - final NumberPicker minPicker = new NumberPicker(ConfigActivity.this); + final NumberPicker minPicker = new NumberPicker(QHybridConfigActivity.this); minPicker.setMinValue(0); minPicker.setMaxValue(59); minPicker.setValue(timeOffset % 60); layout2.addView(hourPicker); - TextView tw = new TextView(ConfigActivity.this); + TextView tw = new TextView(QHybridConfigActivity.this); tw.setText(":"); layout2.addView(tw); layout2.addView(minPicker); layout2.setGravity(Gravity.CENTER); - new MaterialAlertDialogBuilder(ConfigActivity.this) + new MaterialAlertDialogBuilder(QHybridConfigActivity.this) .setTitle(getString(R.string.qhybrid_offset_timezone)) .setView(layout2) .setPositiveButton("ok", new DialogInterface.OnClickListener() { @@ -188,7 +196,7 @@ public class ConfigActivity extends AbstractGBActivity { public void onClick(DialogInterface dialogInterface, int i) { prefs.edit().putInt("QHYBRID_TIMEZONE_OFFSET", hourPicker.getValue() * 60 + minPicker.getValue()).apply(); updateTimezoneOffset(); - LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE_TIMEZONE)); + LocalBroadcastManager.getInstance(QHybridConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE_TIMEZONE)); GB.toast(getString(R.string.qhybrid_changes_delay_prompt), Toast.LENGTH_SHORT, GB.INFO); } }) @@ -215,7 +223,7 @@ public class ConfigActivity extends AbstractGBActivity { appList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(final AdapterView adapterView, View view, final int i, long l) { - PopupMenu menu = new PopupMenu(ConfigActivity.this, view); + PopupMenu menu = new PopupMenu(QHybridConfigActivity.this, view); menu.getMenu().add(0, 0, 0, "edit"); menu.getMenu().add(0, 1, 1, "delete"); menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @@ -223,7 +231,7 @@ public class ConfigActivity extends AbstractGBActivity { public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case 0: { - TimePicker picker = new TimePicker(ConfigActivity.this, (NotificationConfiguration) adapterView.getItemAtPosition(i)); + TimePicker picker = new TimePicker(QHybridConfigActivity.this, (NotificationConfiguration) adapterView.getItemAtPosition(i)); picker.finishListener = new TimePicker.OnFinishListener() { @Override public void onFinish(boolean success, NotificationConfiguration config) { @@ -231,7 +239,7 @@ public class ConfigActivity extends AbstractGBActivity { if (success) { try { helper.saveNotificationConfiguration(config); - LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_NOTIFICATION_CONFIG_CHANGED)); + LocalBroadcastManager.getInstance(QHybridConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_NOTIFICATION_CONFIG_CHANGED)); } catch (Exception e) { GB.toast("error saving notification", Toast.LENGTH_SHORT, GB.ERROR, e); } @@ -257,7 +265,7 @@ public class ConfigActivity extends AbstractGBActivity { case 1: { try { helper.deleteNotificationConfiguration((NotificationConfiguration) adapterView.getItemAtPosition(i)); - LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_NOTIFICATION_CONFIG_CHANGED)); + LocalBroadcastManager.getInstance(QHybridConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_NOTIFICATION_CONFIG_CHANGED)); } catch (Exception e) { GB.toast("error deleting setting", Toast.LENGTH_SHORT, GB.ERROR, e); } @@ -278,7 +286,7 @@ public class ConfigActivity extends AbstractGBActivity { public void onItemClick(AdapterView adapterView, View view, int i, long l) { Intent notificationIntent = new Intent(QHybridSupport.QHYBRID_COMMAND_NOTIFICATION); notificationIntent.putExtra("CONFIG", (NotificationConfiguration) adapterView.getItemAtPosition(i)); - LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(notificationIntent); + LocalBroadcastManager.getInstance(QHybridConfigActivity.this).sendBroadcast(notificationIntent); } }); SeekBar vibeBar = findViewById(R.id.vibrationStrengthBar); @@ -302,22 +310,15 @@ public class ConfigActivity extends AbstractGBActivity { device.addDeviceInfo(new GenericItem(QHybridSupport.ITEM_VIBRATION_STRENGTH, values[progress])); Intent intent = new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE_SETTINGS); intent.putExtra("EXTRA_SETTING", QHybridSupport.ITEM_VIBRATION_STRENGTH); - LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(intent); + LocalBroadcastManager.getInstance(QHybridConfigActivity.this).sendBroadcast(intent); } }); - // NOTE: this code always selects the first connected Q Hybrid device - // because currently this class is unable to handle multiple - // connected Q Hybrid devices - List devices = GBApplication.app().getDeviceManager().getSelectedDevices(); - for(GBDevice candidate : devices){ - if (candidate.getType() == DeviceType.FOSSILQHYBRID && candidate.getFirmwareVersion().charAt(2) == '0') { - device = candidate; - updateSettings(); - return; - } + if (device.getType() == DeviceType.FOSSILQHYBRID && device.isInitialized() && device.getFirmwareVersion().charAt(2) == '0') { + updateSettings(); + } else { + setSettingsError(getString(R.string.watch_not_connected)); } - setSettingsError(getString(R.string.watch_not_connected)); } private void updateTimeOffset() { @@ -362,7 +363,7 @@ public class ConfigActivity extends AbstractGBActivity { device.addDeviceInfo(new GenericItem(QHybridSupport.ITEM_STEP_GOAL, t)); Intent intent = new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE_SETTINGS); intent.putExtra("EXTRA_SETTING", QHybridSupport.ITEM_STEP_GOAL); - LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(intent); + LocalBroadcastManager.getInstance(QHybridConfigActivity.this).sendBroadcast(intent); updateSettings(); } ((InputMethodManager) getApplicationContext().getSystemService(Activity.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0); @@ -390,7 +391,7 @@ public class ConfigActivity extends AbstractGBActivity { @Override public void onCheckedChanged(CompoundButton buttonView, boolean checked) { if (!device.getDeviceInfo(QHybridSupport.ITEM_STEP_GOAL).getDetails().equals("1000000")) { - new MaterialAlertDialogBuilder(ConfigActivity.this) + new MaterialAlertDialogBuilder(QHybridConfigActivity.this) .setMessage(getString(R.string.qhybrid_prompt_million_steps)) .setPositiveButton("ok", null) .show(); @@ -400,7 +401,7 @@ public class ConfigActivity extends AbstractGBActivity { device.addDeviceInfo(new GenericItem(QHybridSupport.ITEM_USE_ACTIVITY_HAND, String.valueOf(checked))); Intent intent = new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE_SETTINGS); intent.putExtra("EXTRA_SETTING", QHybridSupport.ITEM_USE_ACTIVITY_HAND); - LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(intent); + LocalBroadcastManager.getInstance(QHybridConfigActivity.this).sendBroadcast(intent); } }); } else { @@ -440,7 +441,7 @@ public class ConfigActivity extends AbstractGBActivity { for (int i = 0; i < buttonConfig.length(); i++) { final int currentIndex = i; String configName = buttonConfig.getString(i); - TextView buttonTextView = new TextView(ConfigActivity.this); + TextView buttonTextView = new TextView(QHybridConfigActivity.this); buttonTextView.setTextSize(20); try { ConfigPayload payload = ConfigPayload.valueOf(configName); @@ -452,7 +453,7 @@ public class ConfigActivity extends AbstractGBActivity { buttonTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - AlertDialog dialog = new MaterialAlertDialogBuilder(ConfigActivity.this) + AlertDialog dialog = new MaterialAlertDialogBuilder(QHybridConfigActivity.this) .setItems(names, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { @@ -465,7 +466,7 @@ public class ConfigActivity extends AbstractGBActivity { updateSettings(); Intent buttonIntent = new Intent(QHybridSupport.QHYBRID_COMMAND_OVERWRITE_BUTTONS); buttonIntent.putExtra(FossilWatchAdapter.ITEM_BUTTONS, buttonConfig.toString()); - LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(buttonIntent); + LocalBroadcastManager.getInstance(QHybridConfigActivity.this).sendBroadcast(buttonIntent); } catch (JSONException e) { GB.log("error", GB.ERROR, e); } @@ -547,6 +548,16 @@ public class ConfigActivity extends AbstractGBActivity { super.onActivityResult(requestCode, resultCode, data); } + @Override + public boolean onOptionsItemSelected(@NonNull final MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + this.onBackPressed(); + return true; + } + + return super.onOptionsItemSelected(item); + } private void setSettingsError(final String error) { runOnUiThread(new Runnable() { @@ -575,13 +586,13 @@ public class ConfigActivity extends AbstractGBActivity { NotificationConfiguration settings = getItem(position); if (settings == null) { - Button addButton = new Button(ConfigActivity.this); + Button addButton = new Button(QHybridConfigActivity.this); addButton.setText("+"); addButton.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); addButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - startActivityForResult(new Intent(ConfigActivity.this, QHybridAppChoserActivity.class), REQUEST_CODE_ADD_APP); + startActivityForResult(new Intent(QHybridConfigActivity.this, QHybridAppChoserActivity.class), REQUEST_CODE_ADD_APP); } }); return addButton; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/QHybridCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/QHybridCoordinator.java index 751e8bdf0..debff2c5e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/QHybridCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/QHybridCoordinator.java @@ -41,10 +41,12 @@ import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.activities.appmanager.AppManagerActivity; import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettings; +import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsCustomizer; import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsScreen; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider; +import nodomain.freeyourgadget.gadgetbridge.devices.cmfwatchpro.CmfWatchProSettingsCustomizer; import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; import nodomain.freeyourgadget.gadgetbridge.entities.Device; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; @@ -150,7 +152,7 @@ public class QHybridCoordinator extends AbstractBLEDeviceCoordinator { @Override public int getCannedRepliesSlotCount(final GBDevice device) { - if (isHybridHR()) { + if (isHybridHR(device)) { return 16; } @@ -159,17 +161,17 @@ public class QHybridCoordinator extends AbstractBLEDeviceCoordinator { @Override public boolean supportsAlarmTitle(GBDevice device) { - return isHybridHR(); + return isHybridHR(device); } @Override public boolean supportsAlarmDescription(GBDevice device) { - return isHybridHR(); + return isHybridHR(device); } @Override public boolean supportsHeartRateMeasurement(GBDevice device) { - return this.isHybridHR(); + return isHybridHR(device); } @Override @@ -189,7 +191,7 @@ public class QHybridCoordinator extends AbstractBLEDeviceCoordinator { @Override public Class getAppsManagementActivity() { - return isHybridHR() ? AppManagerActivity.class : ConfigActivity.class; + return isHybridHR() ? AppManagerActivity.class : QHybridConfigActivity.class; } @Override @@ -249,7 +251,8 @@ public class QHybridCoordinator extends AbstractBLEDeviceCoordinator { @Override public DeviceSpecificSettings getDeviceSpecificSettings(final GBDevice device) { final DeviceSpecificSettings deviceSpecificSettings = new DeviceSpecificSettings(); - if (!isHybridHR()) { + if (!isHybridHR(device)) { + deviceSpecificSettings.addRootScreen(R.xml.devicesettings_fossilqhybrid_legacy); return deviceSpecificSettings; } final List generic = deviceSpecificSettings.addRootScreen(DeviceSpecificSettingsScreen.GENERIC); @@ -280,6 +283,11 @@ public class QHybridCoordinator extends AbstractBLEDeviceCoordinator { return deviceSpecificSettings; } + @Override + public DeviceSpecificSettingsCustomizer getDeviceSpecificSettingsCustomizer(final GBDevice device) { + return new QHybridSettingsCustomizer(); + } + @NonNull @Override public Class getDeviceSupportClass() { @@ -293,6 +301,7 @@ public class QHybridCoordinator extends AbstractBLEDeviceCoordinator { }; } + @Deprecated // we should use the isHybridHR(GBDevice) instead of iterating every single device private boolean isHybridHR() { List devices = GBApplication.app().getDeviceManager().getSelectedDevices(); for(GBDevice device : devices){ diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/QHybridSettingsCustomizer.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/QHybridSettingsCustomizer.java new file mode 100644 index 000000000..eb3b0f0d6 --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/QHybridSettingsCustomizer.java @@ -0,0 +1,60 @@ +package nodomain.freeyourgadget.gadgetbridge.devices.qhybrid; + +import android.content.Intent; +import android.os.Parcel; + +import androidx.annotation.NonNull; +import androidx.preference.Preference; + +import java.util.Collections; +import java.util.Set; + +import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsCustomizer; +import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsHandler; +import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; +import nodomain.freeyourgadget.gadgetbridge.util.Prefs; + +public class QHybridSettingsCustomizer implements DeviceSpecificSettingsCustomizer { + @Override + public void onPreferenceChange(final Preference preference, final DeviceSpecificSettingsHandler handler) { + } + + @Override + public void customizeSettings(final DeviceSpecificSettingsHandler handler, final Prefs prefs) { + final Preference pref = handler.findPreference("pref_key_qhybrid_legacy"); + if (pref != null) { + pref.setOnPreferenceClickListener(preference -> { + final Intent intent = new Intent(handler.getContext(), QHybridConfigActivity.class); + intent.putExtra(GBDevice.EXTRA_DEVICE, handler.getDevice()); + handler.getContext().startActivity(intent); + return true; + }); + } + } + + @Override + public Set getPreferenceKeysWithSummary() { + return Collections.emptySet(); + } + + public static final Creator CREATOR = new Creator() { + @Override + public QHybridSettingsCustomizer createFromParcel(final Parcel in) { + return new QHybridSettingsCustomizer(); + } + + @Override + public QHybridSettingsCustomizer[] newArray(final int size) { + return new QHybridSettingsCustomizer[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(@NonNull final Parcel dest, final int flags) { + } +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 883414852..768ea9123 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1612,6 +1612,7 @@ Cards MI AI Q Hybrid Settings + Legacy settings for Q Hybrid watches Music More NFC diff --git a/app/src/main/res/xml/devicesettings_fossilqhybrid_legacy.xml b/app/src/main/res/xml/devicesettings_fossilqhybrid_legacy.xml new file mode 100644 index 000000000..aeed1ab0a --- /dev/null +++ b/app/src/main/res/xml/devicesettings_fossilqhybrid_legacy.xml @@ -0,0 +1,10 @@ + + + + + + diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 2476dbba0..3e1b6812b 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -270,11 +270,6 @@ android:title="@string/preferences_category_device_specific_settings" app:iconSpaceReserved="false"> - -