mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-23 10:20:25 +01:00
Add trim conversations by time option.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package org.thoughtcrime.securesms.keyvalue;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public enum KeepMessagesDuration {
|
||||
FOREVER(0, R.string.preferences_storage__forever, Long.MAX_VALUE),
|
||||
ONE_YEAR(1, R.string.preferences_storage__one_year, TimeUnit.DAYS.toMillis(365)),
|
||||
SIX_MONTHS(2, R.string.preferences_storage__six_months, TimeUnit.DAYS.toMillis(183)),
|
||||
THIRTY_DAYS(3, R.string.preferences_storage__thirty_days, TimeUnit.DAYS.toMillis(30));
|
||||
|
||||
private final int id;
|
||||
private final int stringResource;
|
||||
private final long duration;
|
||||
|
||||
KeepMessagesDuration(int id, @StringRes int stringResource, long duration) {
|
||||
this.id = id;
|
||||
this.stringResource = stringResource;
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public @StringRes int getStringResource() {
|
||||
return stringResource;
|
||||
}
|
||||
|
||||
public long getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
static @NonNull KeepMessagesDuration fromId(int id) {
|
||||
return values()[id];
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,11 @@ import androidx.annotation.NonNull;
|
||||
|
||||
public final class SettingsValues extends SignalStoreValues {
|
||||
|
||||
public static final String LINK_PREVIEWS = "settings.link_previews";
|
||||
public static final String LINK_PREVIEWS = "settings.link_previews";
|
||||
public static final String KEEP_MESSAGES_DURATION = "settings.keep_messages_duration";
|
||||
|
||||
public static final String THREAD_TRIM_LENGTH = "pref_trim_length";
|
||||
public static final String THREAD_TRIM_ENABLED = "pref_trim_threads";
|
||||
|
||||
SettingsValues(@NonNull KeyValueStore store) {
|
||||
super(store);
|
||||
@@ -24,4 +28,29 @@ public final class SettingsValues extends SignalStoreValues {
|
||||
public void setLinkPreviewsEnabled(boolean enabled) {
|
||||
putBoolean(LINK_PREVIEWS, enabled);
|
||||
}
|
||||
|
||||
public @NonNull KeepMessagesDuration getKeepMessagesDuration() {
|
||||
return KeepMessagesDuration.fromId(getInteger(KEEP_MESSAGES_DURATION, 0));
|
||||
}
|
||||
|
||||
public void setKeepMessagesForDuration(@NonNull KeepMessagesDuration duration) {
|
||||
putInteger(KEEP_MESSAGES_DURATION, duration.getId());
|
||||
}
|
||||
|
||||
public boolean isTrimByLengthEnabled() {
|
||||
return getBoolean(THREAD_TRIM_ENABLED, false);
|
||||
}
|
||||
|
||||
public void setThreadTrimByLengthEnabled(boolean enabled) {
|
||||
putBoolean(THREAD_TRIM_ENABLED, enabled);
|
||||
}
|
||||
|
||||
public int getThreadTrimLength() {
|
||||
return getInteger(THREAD_TRIM_LENGTH, 500);
|
||||
}
|
||||
|
||||
public void setThreadTrimLength(int length) {
|
||||
putInteger(THREAD_TRIM_LENGTH, length);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user