Merge pull request #2717 from deltachat/adb/issue-2716

allow to set chat background per-account
This commit is contained in:
Asiel Díaz Benítez
2023-10-04 17:29:41 -04:00
committed by GitHub
5 changed files with 30 additions and 14 deletions
@@ -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,16 @@ public class ApplicationContext extends MultiDexApplication {
rpc.start();
// migrating chat backgrounds, added 04/10/23, can be removed after some versions
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", "");
}
// /migrating chat backgrounds
// set translations before starting I/O to avoid sending untranslated MDNs (issue #2288)
DcHelper.setStockTranslations(this);
@@ -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)
@@ -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);
@@ -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 {
@@ -93,14 +97,14 @@ public class ChatBackgroundActivity extends PassphraseRequiredActionBarActivity
Thread thread = new Thread() {
@Override
public void run() {
String destination = context.getFilesDir().getAbsolutePath() + "/background";
Prefs.setBackgroundImagePath(context, destination);
String destination = context.getFilesDir().getAbsolutePath() + "/background."+ accountId;
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();
}
}
@@ -296,12 +296,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) {