From d65c45f96ae420df321d7a5a15b65e6d42efc621 Mon Sep 17 00:00:00 2001 From: adbenitez Date: Wed, 4 Oct 2023 16:33:23 +0200 Subject: [PATCH] allow to set chat background per-account --- .../securesms/ConversationActivity.java | 3 ++- .../AppearancePreferenceFragment.java | 4 ++-- .../preferences/ChatBackgroundActivity.java | 16 ++++++++++------ src/org/thoughtcrime/securesms/util/Prefs.java | 8 ++++---- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ConversationActivity.java b/src/org/thoughtcrime/securesms/ConversationActivity.java index 03449391b..1ef3ca8bd 100644 --- a/src/org/thoughtcrime/securesms/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationActivity.java @@ -858,7 +858,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity } private void initializeBackground() { - String backgroundImagePath = Prefs.getBackgroundImagePath(this); + String backgroundImagePath = Prefs.getBackgroundImagePath(this, dcContext.getAccountId()); Drawable background; if(!backgroundImagePath.isEmpty()) { background = Drawable.createFromPath(backgroundImagePath); @@ -892,6 +892,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity AccountManager.getInstance().switchAccount(context, accountId); dcContext = context.dcContext; fragment.dcContext = context.dcContext; + initializeBackground(); } chatId = getIntent().getIntExtra(CHAT_ID_EXTRA, -1); if(chatId == DcChat.DC_CHAT_NO_CHAT) diff --git a/src/org/thoughtcrime/securesms/preferences/AppearancePreferenceFragment.java b/src/org/thoughtcrime/securesms/preferences/AppearancePreferenceFragment.java index 944a464e9..5372c10e3 100644 --- a/src/org/thoughtcrime/securesms/preferences/AppearancePreferenceFragment.java +++ b/src/org/thoughtcrime/securesms/preferences/AppearancePreferenceFragment.java @@ -46,7 +46,7 @@ public class AppearancePreferenceFragment extends ListSummaryPreferenceFragment public void onResume() { super.onResume(); ((ApplicationPreferencesActivity) getActivity()).getSupportActionBar().setTitle(R.string.pref_appearance); - String imagePath = Prefs.getBackgroundImagePath(getContext()); + String imagePath = Prefs.getBackgroundImagePath(getContext(), dcContext.getAccountId()); String backgroundString; if(imagePath.isEmpty()){ backgroundString = this.getString(R.string.def); @@ -75,7 +75,7 @@ public class AppearancePreferenceFragment extends ListSummaryPreferenceFragment int themeIndex = Arrays.asList(themeEntryValues).indexOf(Prefs.getTheme(context)); if (themeIndex == -1) themeIndex = 0; - String imagePath = Prefs.getBackgroundImagePath(context); + String imagePath = Prefs.getBackgroundImagePath(context, DcHelper.getContext(context).getAccountId()); String backgroundString; if(imagePath.isEmpty()){ backgroundString = context.getString(R.string.def); diff --git a/src/org/thoughtcrime/securesms/preferences/ChatBackgroundActivity.java b/src/org/thoughtcrime/securesms/preferences/ChatBackgroundActivity.java index 4baf8f09f..1718ccccd 100644 --- a/src/org/thoughtcrime/securesms/preferences/ChatBackgroundActivity.java +++ b/src/org/thoughtcrime/securesms/preferences/ChatBackgroundActivity.java @@ -23,6 +23,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy; import org.thoughtcrime.securesms.ApplicationPreferencesActivity; import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity; import org.thoughtcrime.securesms.R; +import org.thoughtcrime.securesms.connect.DcHelper; import org.thoughtcrime.securesms.mms.AttachmentManager; import org.thoughtcrime.securesms.mms.GlideApp; import org.thoughtcrime.securesms.util.DynamicTheme; @@ -44,6 +45,8 @@ public class ChatBackgroundActivity extends PassphraseRequiredActionBarActivity Uri imageUri; Boolean imageUpdate = false; + private int accountId; + @Override protected void onCreate(Bundle savedInstanceState, boolean ready) { setContentView(R.layout.activity_select_chat_background); @@ -51,11 +54,12 @@ public class ChatBackgroundActivity extends PassphraseRequiredActionBarActivity defaultButton = findViewById(R.id.set_default_button); galleryButton = findViewById(R.id.from_gallery_button); preview = findViewById(R.id.preview); + accountId = DcHelper.getContext(getApplicationContext()).getAccountId(); defaultButton.setOnClickListener(new DefaultClickListener()); galleryButton.setOnClickListener(new GalleryClickListener()); - String backgroundImagePath = Prefs.getBackgroundImagePath(this); + String backgroundImagePath = Prefs.getBackgroundImagePath(this, accountId); if(backgroundImagePath.isEmpty()){ setDefaultLayoutBackgroundImage(); }else { @@ -94,13 +98,13 @@ public class ChatBackgroundActivity extends PassphraseRequiredActionBarActivity @Override public void run() { String destination = context.getFilesDir().getAbsolutePath() + "/background"; - Prefs.setBackgroundImagePath(context, destination); + Prefs.setBackgroundImagePath(context, accountId, destination); scaleAndSaveImage(context, destination); } }; thread.start(); } else { - Prefs.setBackgroundImagePath(context, ""); + Prefs.setBackgroundImagePath(context, accountId, ""); } } finish(); @@ -133,15 +137,15 @@ public class ChatBackgroundActivity extends PassphraseRequiredActionBarActivity scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 85, outStream); } catch (InterruptedException e) { e.printStackTrace(); - Prefs.setBackgroundImagePath(context, ""); + Prefs.setBackgroundImagePath(context, accountId, ""); showBackgroundSaveError(); } catch (ExecutionException e) { e.printStackTrace(); - Prefs.setBackgroundImagePath(context, ""); + Prefs.setBackgroundImagePath(context, accountId, ""); showBackgroundSaveError(); } catch (FileNotFoundException e) { e.printStackTrace(); - Prefs.setBackgroundImagePath(context, ""); + Prefs.setBackgroundImagePath(context, accountId, ""); showBackgroundSaveError(); } } diff --git a/src/org/thoughtcrime/securesms/util/Prefs.java b/src/org/thoughtcrime/securesms/util/Prefs.java index c127de055..0578de179 100644 --- a/src/org/thoughtcrime/securesms/util/Prefs.java +++ b/src/org/thoughtcrime/securesms/util/Prefs.java @@ -306,12 +306,12 @@ public class Prefs { // misc. - public static String getBackgroundImagePath(Context context) { - return getStringPreference(context, BACKGROUND_PREF, ""); + public static String getBackgroundImagePath(Context context, int accountId) { + return getStringPreference(context, BACKGROUND_PREF+accountId, ""); } - public static void setBackgroundImagePath(Context context, String path) { - setStringPreference(context, BACKGROUND_PREF, path); + public static void setBackgroundImagePath(Context context, int accountId, String path) { + setStringPreference(context, BACKGROUND_PREF+accountId, path); } public static boolean isSystemEmojiPreferred(Context context) {