mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-18 22:57:48 +01:00
HPlus: Migrate global preferences to device-specific
This commit is contained in:
parent
4d0d9e298e
commit
9bef90a151
@ -124,7 +124,7 @@ public class GBApplication extends Application {
|
|||||||
private static SharedPreferences sharedPrefs;
|
private static SharedPreferences sharedPrefs;
|
||||||
private static final String PREFS_VERSION = "shared_preferences_version";
|
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
|
//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<Integer, String> mIDSenderLookup = new LimitedQueue<>(16);
|
private static final LimitedQueue<Integer, String> mIDSenderLookup = new LimitedQueue<>(16);
|
||||||
private static Prefs prefs;
|
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<Device> 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.putString(PREFS_VERSION, Integer.toString(CURRENT_PREFS_VERSION));
|
||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
}
|
||||||
@ -1457,6 +1479,10 @@ public class GBApplication extends Application {
|
|||||||
return context.getSharedPreferences("devicesettings_" + deviceIdentifier, Context.MODE_PRIVATE);
|
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) {
|
public static void deleteDeviceSpecificSharedPrefs(String deviceIdentifier) {
|
||||||
if (deviceIdentifier == null || deviceIdentifier.isEmpty()) {
|
if (deviceIdentifier == null || deviceIdentifier.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
@ -66,7 +66,6 @@ import nodomain.freeyourgadget.gadgetbridge.R;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsPreferencesActivity;
|
import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsPreferencesActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.discovery.DiscoveryPairingPreferenceActivity;
|
import nodomain.freeyourgadget.gadgetbridge.activities.discovery.DiscoveryPairingPreferenceActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter;
|
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.miband.MiBandPreferencesActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleSettingsActivity;
|
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleSettingsActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.ConfigActivity;
|
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");
|
pref = findPreference("pref_key_zetime");
|
||||||
if (pref != null) {
|
if (pref != null) {
|
||||||
pref.setOnPreferenceClickListener(preference -> {
|
pref.setOnPreferenceClickListener(preference -> {
|
||||||
|
@ -922,6 +922,7 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
|
|||||||
setInputTypeFor(DeviceSettingsPreferenceConst.PREF_DEVICE_GPS_UPDATE_INTERVAL, InputType.TYPE_CLASS_NUMBER);
|
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_BANGLEJS_TEXT_BITMAP_SIZE, InputType.TYPE_CLASS_NUMBER);
|
||||||
setInputTypeFor(DeviceSettingsPreferenceConst.PREF_AUTO_REPLY_INCOMING_CALL_DELAY, 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 PasswordCapabilityImpl().registerPreferences(getContext(), coordinator.getPasswordCapability(), this);
|
||||||
new HeartRateCapability().registerPreferences(getContext(), coordinator.getHeartRateMeasurementIntervals(), this);
|
new HeartRateCapability().registerPreferences(getContext(), coordinator.getHeartRateMeasurementIntervals(), this);
|
||||||
|
@ -18,11 +18,8 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
package nodomain.freeyourgadget.gadgetbridge.devices.hplus;
|
package nodomain.freeyourgadget.gadgetbridge.devices.hplus;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.bluetooth.le.ScanFilter;
|
import android.bluetooth.le.ScanFilter;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.ParcelUuid;
|
import android.os.ParcelUuid;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -42,16 +39,13 @@ import nodomain.freeyourgadget.gadgetbridge.R;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
|
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
|
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator;
|
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.HPlusHealthActivitySampleDao;
|
import nodomain.freeyourgadget.gadgetbridge.entities.HPlusHealthActivitySampleDao;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.hplus.HPlusSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.hplus.HPlusSupport;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
|
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
|
||||||
@ -81,36 +75,16 @@ public class HPlusCoordinator extends AbstractBLEDeviceCoordinator {
|
|||||||
return BONDING_STYLE_NONE;
|
return BONDING_STYLE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean supportsCalendarEvents() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsRealtimeData() {
|
public boolean supportsRealtimeData() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean supportsWeather() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsFindDevice() {
|
public boolean supportsFindDevice() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Class<? extends Activity> getPairingActivity() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InstallHandler findInstallHandler(Uri uri, Context context) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsActivityDataFetching() {
|
public boolean supportsActivityDataFetching() {
|
||||||
return true;
|
return true;
|
||||||
@ -126,11 +100,6 @@ public class HPlusCoordinator extends AbstractBLEDeviceCoordinator {
|
|||||||
return new HPlusHealthSampleProvider(device, session);
|
return new HPlusHealthSampleProvider(device, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean supportsScreenshots(final GBDevice device) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAlarmSlotCount(GBDevice device) {
|
public int getAlarmSlotCount(GBDevice device) {
|
||||||
return 3; // FIXME - check the real value
|
return 3; // FIXME - check the real value
|
||||||
@ -146,16 +115,6 @@ public class HPlusCoordinator extends AbstractBLEDeviceCoordinator {
|
|||||||
return "Zeblaze";
|
return "Zeblaze";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean supportsAppsManagement(final GBDevice device) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Class<? extends Activity> getAppsManagementActivity() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void deleteDevice(@NonNull GBDevice gbDevice, @NonNull Device device, @NonNull DaoSession session) throws GBException {
|
protected void deleteDevice(@NonNull GBDevice gbDevice, @NonNull Device device, @NonNull DaoSession session) throws GBException {
|
||||||
Long deviceId = device.getId();
|
Long deviceId = device.getId();
|
||||||
@ -236,11 +195,11 @@ public class HPlusCoordinator extends AbstractBLEDeviceCoordinator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static byte getScreenTime(String address) {
|
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) {
|
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) {
|
if (value) {
|
||||||
return HPlusConstants.ARG_HEARTRATE_ALLDAY_ON;
|
return HPlusConstants.ARG_HEARTRATE_ALLDAY_ON;
|
||||||
@ -310,6 +269,7 @@ public class HPlusCoordinator extends AbstractBLEDeviceCoordinator {
|
|||||||
return new int[]{
|
return new int[]{
|
||||||
//R.xml.devicesettings_wearlocation, // disabled, since it is never used in code
|
//R.xml.devicesettings_wearlocation, // disabled, since it is never used in code
|
||||||
R.xml.devicesettings_timeformat,
|
R.xml.devicesettings_timeformat,
|
||||||
|
R.xml.devicesettings_hplus,
|
||||||
R.xml.devicesettings_transliteration
|
R.xml.devicesettings_transliteration
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -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 <https://www.gnu.org/licenses/>. */
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
18
app/src/main/res/xml/devicesettings_hplus.xml
Normal file
18
app/src/main/res/xml/devicesettings_hplus.xml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<EditTextPreference
|
||||||
|
android:defaultValue="5"
|
||||||
|
android:icon="@drawable/ic_always_on_display"
|
||||||
|
android:key="hplus_screentime"
|
||||||
|
android:title="@string/pref_title_screentime"
|
||||||
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
|
<SwitchPreferenceCompat
|
||||||
|
android:defaultValue="true"
|
||||||
|
android:icon="@drawable/ic_heart"
|
||||||
|
android:key="hplus_alldayhr"
|
||||||
|
android:layout="@layout/preference_checkbox"
|
||||||
|
android:title="@string/prefs_title_all_day_heart_rate" />
|
||||||
|
</PreferenceScreen>
|
@ -1,23 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
|
||||||
<PreferenceCategory
|
|
||||||
android:key="pref_category_hplus_general"
|
|
||||||
android:title="@string/pref_header_general"
|
|
||||||
app:iconSpaceReserved="false">
|
|
||||||
|
|
||||||
<EditTextPreference
|
|
||||||
android:defaultValue="5"
|
|
||||||
android:key="hplus_screentime"
|
|
||||||
android:title="@string/pref_title_screentime"
|
|
||||||
app:iconSpaceReserved="false"
|
|
||||||
app:useSimpleSummaryProvider="true"/>
|
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
|
||||||
android:defaultValue="true"
|
|
||||||
android:key="hplus_alldayhr"
|
|
||||||
android:layout="@layout/preference_checkbox"
|
|
||||||
android:title="@string/prefs_title_all_day_heart_rate"
|
|
||||||
app:iconSpaceReserved="false" />
|
|
||||||
</PreferenceCategory>
|
|
||||||
</PreferenceScreen>
|
|
@ -285,11 +285,6 @@
|
|||||||
android:key="pref_key_pebble"
|
android:key="pref_key_pebble"
|
||||||
android:title="@string/pref_title_pebble_settings">
|
android:title="@string/pref_title_pebble_settings">
|
||||||
</Preference>
|
</Preference>
|
||||||
<Preference
|
|
||||||
android:icon="@drawable/ic_device_hplus"
|
|
||||||
android:key="pref_key_hplus"
|
|
||||||
android:title="@string/preferences_hplus_settings">
|
|
||||||
</Preference>
|
|
||||||
<Preference
|
<Preference
|
||||||
android:icon="@drawable/ic_device_zetime"
|
android:icon="@drawable/ic_device_zetime"
|
||||||
android:key="pref_key_zetime"
|
android:key="pref_key_zetime"
|
||||||
|
Loading…
Reference in New Issue
Block a user