From 41588d0de310e013124b987230a6c345e3f8bf8a Mon Sep 17 00:00:00 2001 From: adbenitez Date: Wed, 4 Oct 2023 22:19:26 +0200 Subject: [PATCH] move migration to ApplicationContext --- .../thoughtcrime/securesms/ApplicationContext.java | 10 ++++++++++ .../securesms/preferences/ChatBackgroundActivity.java | 11 +---------- src/org/thoughtcrime/securesms/util/Prefs.java | 8 -------- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ApplicationContext.java b/src/org/thoughtcrime/securesms/ApplicationContext.java index da89d35a4..3cd257d4e 100644 --- a/src/org/thoughtcrime/securesms/ApplicationContext.java +++ b/src/org/thoughtcrime/securesms/ApplicationContext.java @@ -43,6 +43,7 @@ import org.thoughtcrime.securesms.notifications.NotificationCenter; import org.thoughtcrime.securesms.util.AndroidSignalProtocolLogger; import org.thoughtcrime.securesms.util.DynamicLanguage; import org.thoughtcrime.securesms.util.DynamicTheme; +import org.thoughtcrime.securesms.util.Prefs; import org.thoughtcrime.securesms.util.SignalProtocolLoggerProvider; import java.io.File; @@ -127,6 +128,15 @@ public class ApplicationContext extends MultiDexApplication { rpc.start(); + // [Migration 04/10/23] Chat Background: migrate old custom background + String backgroundImagePath = Prefs.getStringPreference(this, "pref_chat_background", ""); + if (!backgroundImagePath.isEmpty()) { + for (int accId : dcAccounts.getAll()) { + Prefs.setBackgroundImagePath(this, accId, backgroundImagePath); + } + Prefs.setStringPreference(this, "pref_chat_background", ""); + } + // set translations before starting I/O to avoid sending untranslated MDNs (issue #2288) DcHelper.setStockTranslations(this); diff --git a/src/org/thoughtcrime/securesms/preferences/ChatBackgroundActivity.java b/src/org/thoughtcrime/securesms/preferences/ChatBackgroundActivity.java index 3a66d2e54..295fe8c09 100644 --- a/src/org/thoughtcrime/securesms/preferences/ChatBackgroundActivity.java +++ b/src/org/thoughtcrime/securesms/preferences/ChatBackgroundActivity.java @@ -56,19 +56,10 @@ public class ChatBackgroundActivity extends PassphraseRequiredActionBarActivity preview = findViewById(R.id.preview); accountId = DcHelper.getContext(getApplicationContext()).getAccountId(); - // try to be backwards compatible so users don't lose already set background - String backgroundImagePath = Prefs.getBackgroundImagePathLegacy(this); - if (!backgroundImagePath.isEmpty()) { - for (int accId : DcHelper.getAccounts(getApplicationContext()).getAll()) { - Prefs.setBackgroundImagePath(this, accId, backgroundImagePath); - } - Prefs.setBackgroundImagePathLegacy(this, ""); - } - defaultButton.setOnClickListener(new DefaultClickListener()); galleryButton.setOnClickListener(new GalleryClickListener()); - backgroundImagePath = Prefs.getBackgroundImagePath(this, accountId); + String backgroundImagePath = Prefs.getBackgroundImagePath(this, accountId); if(backgroundImagePath.isEmpty()){ setDefaultLayoutBackgroundImage(); }else { diff --git a/src/org/thoughtcrime/securesms/util/Prefs.java b/src/org/thoughtcrime/securesms/util/Prefs.java index c580c02ef..0578de179 100644 --- a/src/org/thoughtcrime/securesms/util/Prefs.java +++ b/src/org/thoughtcrime/securesms/util/Prefs.java @@ -306,14 +306,6 @@ public class Prefs { // misc. - public static String getBackgroundImagePathLegacy(Context context) { - return getStringPreference(context, BACKGROUND_PREF, ""); - } - - public static void setBackgroundImagePathLegacy(Context context, String path) { - setStringPreference(context, BACKGROUND_PREF, path); - } - public static String getBackgroundImagePath(Context context, int accountId) { return getStringPreference(context, BACKGROUND_PREF+accountId, ""); }