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

add more settings migration for settings that are now per-device

This commit is contained in:
Andreas Shimokawa 2019-05-23 23:24:49 +02:00
parent e6eba8fbe0
commit d1ba702e75
2 changed files with 63 additions and 16 deletions

View File

@ -66,6 +66,7 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceService;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.service.NotificationCollectorMonitorService;
import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils;
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
@ -74,6 +75,9 @@ import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
import nodomain.freeyourgadget.gadgetbridge.util.LimitedQueue;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.AMAZFITBIP;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.AMAZFITCOR;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.AMAZFITCOR2;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.fromKey;
import static nodomain.freeyourgadget.gadgetbridge.util.GB.NOTIFICATION_CHANNEL_ID;
@ -637,28 +641,72 @@ public static String packageNameToPebbleMsgSender(String packageName) {
deviceSharedPrefsEdit.putLong("lastSyncTimeMillis", lastSyncTimeMillis);
editor.remove(preferenceKey);
}
switch (fromKey(dbDevice.getType())) {
String newLanguage = null;
Set<String> displayItems = null;
DeviceType deviceType = fromKey(dbDevice.getType());
if (deviceType == AMAZFITBIP || deviceType == AMAZFITCOR || deviceType == AMAZFITCOR2) {
int oldLanguage = prefs.getInt("amazfitbip_language", -1);
newLanguage = "auto";
String[] oldLanguageLookup = {"zh_CN", "zh_TW", "en_US", "es_ES", "ru_RU", "de_DE", "it_IT", "fr_FR", "tr_TR"};
if (oldLanguage >= 0 && oldLanguage < oldLanguageLookup.length) {
newLanguage = oldLanguageLookup[oldLanguage];
}
}
if (deviceType == AMAZFITBIP || deviceType == AMAZFITCOR) {
deviceSharedPrefsEdit.putString("disconnect_notification", prefs.getString("disconnect_notification", "off"));
deviceSharedPrefsEdit.putString("disconnect_notification_start", prefs.getString("disconnect_notification_start", "8:00"));
deviceSharedPrefsEdit.putString("disconnect_notification_end", prefs.getString("disconnect_notification_end", "22:00"));
}
switch (deviceType) {
case AMAZFITCOR:
displayItems = prefs.getStringSet("cor_display_items", null);
break;
case AMAZFITBIP:
case AMAZFITCOR2:
int oldLanguage = prefs.getInt("amazfitbip_language", -1);
String newLanguage = "auto";
String[] oldLanguageLookup = {"zh_CN", "zh_TW", "en_US", "es_ES", "ru_RU", "de_DE", "it_IT", "fr_FR", "tr_TR"};
if (oldLanguage >= 0 && oldLanguage < oldLanguageLookup.length) {
newLanguage = oldLanguageLookup[oldLanguage];
}
deviceSharedPrefsEdit.putString("language", newLanguage);
displayItems = prefs.getStringSet("bip_display_items", null);
break;
case MIBAND2:
displayItems = prefs.getStringSet("mi2_display_items", null);
deviceSharedPrefsEdit.putBoolean("mi2_enable_text_notifications", prefs.getBoolean("mi2_enable_text_notifications", true));
deviceSharedPrefsEdit.putString("mi2_dateformat", prefs.getString("mi2_dateformat", "dateformat_time"));
break;
case MIBAND3:
String language = sharedPrefs.getString("miband3_language", "auto");
deviceSharedPrefsEdit.putString("language", language);
newLanguage = prefs.getString("miband3_language", "auto");
displayItems = prefs.getStringSet("miband3_display_items", null);
deviceSharedPrefsEdit.putBoolean("swipe_unlock", prefs.getBoolean("mi3_band_screen_unlock", false));
deviceSharedPrefsEdit.putString("night_mode", prefs.getString("mi3_night_mode", "off"));
deviceSharedPrefsEdit.putString("night_mode_start", prefs.getString("mi3_night_mode_start", "16:00"));
deviceSharedPrefsEdit.putString("night_mode_end", prefs.getString("mi3_night_mode_end", "7:00"));
}
if (displayItems != null) {
deviceSharedPrefsEdit.putStringSet("display_items", displayItems);
}
if (newLanguage != null) {
deviceSharedPrefsEdit.putString("language", newLanguage);
}
}
deviceSharedPrefsEdit.apply();
}
editor.remove("miband3_language");
editor.remove("amazfitbip_language");
editor.remove("bip_display_items");
editor.remove("cor_display_items");
editor.remove("disconnect_notification");
editor.remove("disconnect_notification_start");
editor.remove("disconnect_notification_end");
editor.remove("mi2_dateformat");
editor.remove("mi2_display_items");
editor.remove("mi2_enable_text_notifications");
editor.remove("mi3_band_screen_unlock");
editor.remove("mi3_night_mode");
editor.remove("mi3_night_mode_start");
editor.remove("mi3_night_mode_end");
editor.remove("miband3_language");
} catch (Exception e) {
Log.w(TAG, "error acquiring DB lock");
}

View File

@ -29,7 +29,7 @@ import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Set;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband3.MiBand3Coordinator;
@ -40,7 +40,6 @@ import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.AmazfitBipSupport;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
public class MiBand3Support extends AmazfitBipSupport {
@ -56,8 +55,8 @@ public class MiBand3Support extends AmazfitBipSupport {
@Override
protected MiBand3Support setDisplayItems(TransactionBuilder builder) {
Prefs prefs = GBApplication.getPrefs();
Set<String> pages = prefs.getStringSet("miband3_display_items", null);
Set<String> pages = HuamiCoordinator.getDisplayItems(gbDevice.getAddress());
LOG.info("Setting display items to " + (pages == null ? "none" : pages));
byte[] command = MiBand3Service.COMMAND_CHANGE_SCREENS.clone();