mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-05-03 15:11:42 +01:00
Add trim conversations by time option.
This commit is contained in:
@@ -39,7 +39,7 @@ public class ApplicationMigrations {
|
||||
|
||||
private static final int LEGACY_CANONICAL_VERSION = 455;
|
||||
|
||||
public static final int CURRENT_VERSION = 17;
|
||||
public static final int CURRENT_VERSION = 18;
|
||||
|
||||
private static final class Version {
|
||||
static final int LEGACY = 1;
|
||||
@@ -59,6 +59,7 @@ public class ApplicationMigrations {
|
||||
static final int PIN_REMINDER = 15;
|
||||
static final int VERSIONED_PROFILE = 16;
|
||||
static final int PIN_OPT_OUT = 17;
|
||||
static final int TRIM_SETTINGS = 18;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -241,6 +242,10 @@ public class ApplicationMigrations {
|
||||
jobs.put(Version.PIN_OPT_OUT, new PinOptOutMigration());
|
||||
}
|
||||
|
||||
if (lastSeenVersion < Version.TRIM_SETTINGS) {
|
||||
jobs.put(Version.TRIM_SETTINGS, new TrimByLengthSettingsMigrationJob());
|
||||
}
|
||||
|
||||
return jobs;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package org.thoughtcrime.securesms.migrations;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
|
||||
import static org.thoughtcrime.securesms.keyvalue.SettingsValues.THREAD_TRIM_ENABLED;
|
||||
import static org.thoughtcrime.securesms.keyvalue.SettingsValues.THREAD_TRIM_LENGTH;
|
||||
|
||||
public class TrimByLengthSettingsMigrationJob extends MigrationJob {
|
||||
|
||||
private static final String TAG = Log.tag(TrimByLengthSettingsMigrationJob.class);
|
||||
|
||||
public static final String KEY = "TrimByLengthSettingsMigrationJob";
|
||||
|
||||
TrimByLengthSettingsMigrationJob() {
|
||||
this(new Parameters.Builder().build());
|
||||
}
|
||||
|
||||
private TrimByLengthSettingsMigrationJob(@NonNull Parameters parameters) {
|
||||
super(parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isUiBlocking() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
void performMigration() throws Exception {
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ApplicationDependencies.getApplication());
|
||||
if (preferences.contains(THREAD_TRIM_ENABLED)) {
|
||||
SignalStore.settings().setThreadTrimByLengthEnabled(preferences.getBoolean(THREAD_TRIM_ENABLED, false));
|
||||
//noinspection ConstantConditions
|
||||
SignalStore.settings().setThreadTrimLength(Integer.parseInt(preferences.getString(THREAD_TRIM_LENGTH, "500")));
|
||||
|
||||
preferences.edit()
|
||||
.remove(THREAD_TRIM_ENABLED)
|
||||
.remove(THREAD_TRIM_LENGTH)
|
||||
.apply();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean shouldRetry(@NonNull Exception e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull String getFactoryKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
public static class Factory implements Job.Factory<TrimByLengthSettingsMigrationJob> {
|
||||
@Override
|
||||
public @NonNull TrimByLengthSettingsMigrationJob create(@NonNull Parameters parameters, @NonNull Data data) {
|
||||
return new TrimByLengthSettingsMigrationJob(parameters);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user