diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java index 43e75585a..c65278869 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java @@ -124,7 +124,7 @@ public class GBApplication extends Application { private static SharedPreferences sharedPrefs; private static final String PREFS_VERSION = "shared_preferences_version"; //if preferences have to be migrated, increment the following and add the migration logic in migratePrefs below; see http://stackoverflow.com/questions/16397848/how-can-i-migrate-android-preferences-with-a-new-version - private static final int CURRENT_PREFS_VERSION = 28; + private static final int CURRENT_PREFS_VERSION = 29; private static final LimitedQueue mIDSenderLookup = new LimitedQueue<>(16); private static Prefs prefs; @@ -1446,6 +1446,28 @@ public class GBApplication extends Application { } } + if (oldVersion < 29) { + // Migrate HPlus 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.HPLUS) { + final SharedPreferences deviceSharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(dbDevice.getIdentifier()); + final SharedPreferences.Editor deviceSharedPrefsEdit = deviceSharedPrefs.edit(); + + deviceSharedPrefsEdit.putString("hplus_screentime", sharedPrefs.getString("hplus_screentime", "5")); + deviceSharedPrefsEdit.putBoolean("hplus_alldayhr", sharedPrefs.getBoolean("hplus_alldayhr", true)); + deviceSharedPrefsEdit.apply(); + } + } + } catch (Exception e) { + Log.w(TAG, "error acquiring DB lock"); + } + } + editor.putString(PREFS_VERSION, Integer.toString(CURRENT_PREFS_VERSION)); editor.apply(); } @@ -1457,6 +1479,10 @@ public class GBApplication extends Application { return context.getSharedPreferences("devicesettings_" + deviceIdentifier, Context.MODE_PRIVATE); } + public static Prefs getDevicePrefs(final String deviceIdentifier) { + return new Prefs(getDeviceSpecificSharedPrefs(deviceIdentifier)); + } + public static void deleteDeviceSpecificSharedPrefs(String deviceIdentifier) { if (deviceIdentifier == null || deviceIdentifier.isEmpty()) { return; 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 b2cac37b1..9816172a6 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java @@ -66,7 +66,6 @@ import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsPreferencesActivity; import nodomain.freeyourgadget.gadgetbridge.activities.discovery.DiscoveryPairingPreferenceActivity; import nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter; -import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusSettingsActivity; import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandPreferencesActivity; import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleSettingsActivity; import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.ConfigActivity; @@ -156,15 +155,6 @@ public class SettingsActivity extends AbstractSettingsActivityV2 { }); } - pref = findPreference("pref_key_hplus"); - if (pref != null) { - pref.setOnPreferenceClickListener(preference -> { - Intent enableIntent = new Intent(requireContext(), HPlusSettingsActivity.class); - startActivity(enableIntent); - return true; - }); - } - pref = findPreference("pref_key_zetime"); if (pref != null) { pref.setOnPreferenceClickListener(preference -> { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java index a3880a6ad..a8e2aec73 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java @@ -922,6 +922,7 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i setInputTypeFor(DeviceSettingsPreferenceConst.PREF_DEVICE_GPS_UPDATE_INTERVAL, InputType.TYPE_CLASS_NUMBER); setInputTypeFor(DeviceSettingsPreferenceConst.PREF_BANGLEJS_TEXT_BITMAP_SIZE, InputType.TYPE_CLASS_NUMBER); setInputTypeFor(DeviceSettingsPreferenceConst.PREF_AUTO_REPLY_INCOMING_CALL_DELAY, InputType.TYPE_CLASS_NUMBER); + setInputTypeFor("hplus_screentime", InputType.TYPE_CLASS_NUMBER); new PasswordCapabilityImpl().registerPreferences(getContext(), coordinator.getPasswordCapability(), this); new HeartRateCapability().registerPreferences(getContext(), coordinator.getHeartRateMeasurementIntervals(), this); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusCoordinator.java index 205f29e45..8c717a917 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusCoordinator.java @@ -18,11 +18,8 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.hplus; -import android.app.Activity; import android.bluetooth.le.ScanFilter; -import android.content.Context; import android.content.SharedPreferences; -import android.net.Uri; import android.os.ParcelUuid; import org.slf4j.Logger; @@ -42,16 +39,13 @@ import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity; import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator; -import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider; import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; import nodomain.freeyourgadget.gadgetbridge.entities.Device; import nodomain.freeyourgadget.gadgetbridge.entities.HPlusHealthActivitySampleDao; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; -import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample; import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser; -import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.hplus.HPlusSupport; import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs; @@ -81,36 +75,16 @@ public class HPlusCoordinator extends AbstractBLEDeviceCoordinator { return BONDING_STYLE_NONE; } - @Override - public boolean supportsCalendarEvents() { - return false; - } - @Override public boolean supportsRealtimeData() { return true; } - @Override - public boolean supportsWeather() { - return false; - } - @Override public boolean supportsFindDevice() { return true; } - @Override - public Class getPairingActivity() { - return null; - } - - @Override - public InstallHandler findInstallHandler(Uri uri, Context context) { - return null; - } - @Override public boolean supportsActivityDataFetching() { return true; @@ -126,11 +100,6 @@ public class HPlusCoordinator extends AbstractBLEDeviceCoordinator { return new HPlusHealthSampleProvider(device, session); } - @Override - public boolean supportsScreenshots(final GBDevice device) { - return false; - } - @Override public int getAlarmSlotCount(GBDevice device) { return 3; // FIXME - check the real value @@ -146,16 +115,6 @@ public class HPlusCoordinator extends AbstractBLEDeviceCoordinator { return "Zeblaze"; } - @Override - public boolean supportsAppsManagement(final GBDevice device) { - return false; - } - - @Override - public Class getAppsManagementActivity() { - return null; - } - @Override protected void deleteDevice(@NonNull GBDevice gbDevice, @NonNull Device device, @NonNull DaoSession session) throws GBException { Long deviceId = device.getId(); @@ -236,11 +195,11 @@ public class HPlusCoordinator extends AbstractBLEDeviceCoordinator { } public static byte getScreenTime(String address) { - return (byte) (prefs.getInt(HPlusConstants.PREF_HPLUS_SCREENTIME, 5) & 0xFF); + return (byte) (GBApplication.getDevicePrefs(address).getInt(HPlusConstants.PREF_HPLUS_SCREENTIME, 5) & 0xFF); } public static byte getAllDayHR(String address) { - boolean value = (prefs.getBoolean(HPlusConstants.PREF_HPLUS_ALLDAYHR, true)); + boolean value = (GBApplication.getDevicePrefs(address).getBoolean(HPlusConstants.PREF_HPLUS_ALLDAYHR, true)); if (value) { return HPlusConstants.ARG_HEARTRATE_ALLDAY_ON; @@ -310,6 +269,7 @@ public class HPlusCoordinator extends AbstractBLEDeviceCoordinator { return new int[]{ //R.xml.devicesettings_wearlocation, // disabled, since it is never used in code R.xml.devicesettings_timeformat, + R.xml.devicesettings_hplus, R.xml.devicesettings_transliteration }; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusSettingsActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusSettingsActivity.java deleted file mode 100644 index 6726bd2de..000000000 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusSettingsActivity.java +++ /dev/null @@ -1,49 +0,0 @@ -/* Copyright (C) 2023-2024 José Rebelo - - 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 . */ -package nodomain.freeyourgadget.gadgetbridge.devices.hplus; - -import android.os.Bundle; -import android.text.InputType; - -import androidx.preference.PreferenceFragmentCompat; - -import nodomain.freeyourgadget.gadgetbridge.R; -import nodomain.freeyourgadget.gadgetbridge.activities.AbstractPreferenceFragment; -import nodomain.freeyourgadget.gadgetbridge.activities.AbstractSettingsActivityV2; - -public class HPlusSettingsActivity extends AbstractSettingsActivityV2 { - @Override - protected String fragmentTag() { - return HPlusSettingsFragment.FRAGMENT_TAG; - } - - @Override - protected PreferenceFragmentCompat newFragment() { - return new HPlusSettingsFragment(); - } - - public static class HPlusSettingsFragment extends AbstractPreferenceFragment { - static final String FRAGMENT_TAG = "HPLUS_SETTINGS_FRAGMENT"; - - @Override - public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { - setPreferencesFromResource(R.xml.hplus_preferences, rootKey); - - setInputTypeFor("hplus_screentime", InputType.TYPE_CLASS_NUMBER); - } - } -} diff --git a/app/src/main/res/xml/devicesettings_hplus.xml b/app/src/main/res/xml/devicesettings_hplus.xml new file mode 100644 index 000000000..3a4a24c8e --- /dev/null +++ b/app/src/main/res/xml/devicesettings_hplus.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/app/src/main/res/xml/hplus_preferences.xml b/app/src/main/res/xml/hplus_preferences.xml deleted file mode 100644 index d37b71370..000000000 --- a/app/src/main/res/xml/hplus_preferences.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index c05ec9fd7..2476dbba0 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -285,11 +285,6 @@ android:key="pref_key_pebble" android:title="@string/pref_title_pebble_settings"> - -