be backwards compatible

also fix bug: save custom wallpaper in different file per account
This commit is contained in:
adbenitez
2023-10-04 20:10:03 +02:00
parent d65c45f96a
commit e6e92f60e8
2 changed files with 19 additions and 2 deletions
@@ -56,10 +56,19 @@ 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());
String backgroundImagePath = Prefs.getBackgroundImagePath(this, accountId);
backgroundImagePath = Prefs.getBackgroundImagePath(this, accountId);
if(backgroundImagePath.isEmpty()){
setDefaultLayoutBackgroundImage();
}else {
@@ -97,7 +106,7 @@ public class ChatBackgroundActivity extends PassphraseRequiredActionBarActivity
Thread thread = new Thread() {
@Override
public void run() {
String destination = context.getFilesDir().getAbsolutePath() + "/background";
String destination = context.getFilesDir().getAbsolutePath() + "/background."+ accountId;
Prefs.setBackgroundImagePath(context, accountId, destination);
scaleAndSaveImage(context, destination);
}
@@ -306,6 +306,14 @@ 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, "");
}