Allow user-selected backup time.

main
Nicholas 2023-01-25 08:55:33 -05:00 zatwierdzone przez Greyson Parrelli
rodzic a7d9bd944b
commit 8dd1d3bdeb
5 zmienionych plików z 95 dodań i 1 usunięć

Wyświetl plik

@ -50,6 +50,8 @@ public final class SettingsValues extends SignalStoreValues {
public static final String PREFER_SYSTEM_EMOJI = "settings.use.system.emoji";
public static final String ENTER_KEY_SENDS = "settings.enter.key.sends";
public static final String BACKUPS_ENABLED = "settings.backups.enabled";
public static final String BACKUPS_SCHEDULE_HOUR = "settings.backups.schedule.hour";
public static final String BACKUPS_SCHEDULE_MINUTE = "settings.backups.schedule.minute";
public static final String SMS_DELIVERY_REPORTS_ENABLED = "settings.sms.delivery.reports.enabled";
public static final String WIFI_CALLING_COMPATIBILITY_MODE_ENABLED = "settings.wifi.calling.compatibility.mode.enabled";
public static final String MESSAGE_NOTIFICATIONS_ENABLED = "settings.message.notifications.enabled";
@ -263,6 +265,19 @@ public final class SettingsValues extends SignalStoreValues {
putBoolean(BACKUPS_ENABLED, backupEnabled);
}
public int getBackupHour() {
return getInteger(BACKUPS_SCHEDULE_HOUR, 2);
}
public int getBackupMinute() {
return getInteger(BACKUPS_SCHEDULE_MINUTE, 0);
}
public void setBackupSchedule(int hour, int minute) {
putInteger(BACKUPS_SCHEDULE_HOUR, hour);
putInteger(BACKUPS_SCHEDULE_MINUTE, minute);
}
public boolean isSmsDeliveryReportsEnabled() {
return getBoolean(SMS_DELIVERY_REPORTS_ENABLED, TextSecurePreferences.isSmsDeliveryReportsEnabled(ApplicationDependencies.getApplication()));
}

Wyświetl plik

@ -2,11 +2,14 @@ package org.thoughtcrime.securesms.preferences;
import android.Manifest;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.text.method.LinkMovementMethod;
import android.util.TimeUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -19,6 +22,9 @@ import androidx.annotation.RequiresApi;
import androidx.core.text.HtmlCompat;
import androidx.fragment.app.Fragment;
import com.google.android.material.timepicker.MaterialTimePicker;
import com.google.android.material.timepicker.TimeFormat;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
@ -32,10 +38,14 @@ import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.jobs.LocalBackupJob;
import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.permissions.Permissions;
import org.thoughtcrime.securesms.service.LocalBackupListener;
import org.thoughtcrime.securesms.util.BackupUtil;
import org.thoughtcrime.securesms.util.JavaTimeExtensionsKt;
import org.thoughtcrime.securesms.util.StorageUtil;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import java.text.NumberFormat;
import java.time.LocalTime;
import java.util.Locale;
import java.util.Objects;
@ -48,6 +58,8 @@ public class BackupsPreferenceFragment extends Fragment {
private View create;
private View folder;
private View verify;
private View timer;
private TextView timeLabel;
private TextView toggle;
private TextView info;
private TextView summary;
@ -67,6 +79,8 @@ public class BackupsPreferenceFragment extends Fragment {
create = view.findViewById(R.id.fragment_backup_create);
folder = view.findViewById(R.id.fragment_backup_folder);
verify = view.findViewById(R.id.fragment_backup_verify);
timer = view.findViewById(R.id.fragment_backup_time);
timeLabel = view.findViewById(R.id.fragment_backup_time_value);
toggle = view.findViewById(R.id.fragment_backup_toggle);
info = view.findViewById(R.id.fragment_backup_info);
summary = view.findViewById(R.id.fragment_backup_create_summary);
@ -77,6 +91,7 @@ public class BackupsPreferenceFragment extends Fragment {
toggle.setOnClickListener(unused -> onToggleClicked());
create.setOnClickListener(unused -> onCreateClicked());
verify.setOnClickListener(unused -> BackupDialog.showVerifyBackupPassphraseDialog(requireContext()));
timer.setOnClickListener(unused -> pickTime());
formatter.setMinimumFractionDigits(1);
formatter.setMaximumFractionDigits(1);
@ -243,6 +258,25 @@ public class BackupsPreferenceFragment extends Fragment {
LocalBackupJob.enqueue(true);
}
private void pickTime() {
int timeFormat = DateFormat.is24HourFormat(requireContext()) ? TimeFormat.CLOCK_24H : TimeFormat.CLOCK_12H;
final MaterialTimePicker timePickerFragment = new MaterialTimePicker.Builder()
.setTimeFormat(timeFormat)
.setHour(SignalStore.settings().getBackupHour())
.setMinute(SignalStore.settings().getBackupMinute())
.setTitleText("Set Backup Time")
.build();
timePickerFragment.addOnPositiveButtonClickListener(v -> {
int hour = timePickerFragment.getHour();
int minute = timePickerFragment.getMinute();
SignalStore.settings().setBackupSchedule(hour, minute);
updateTimeLabel();
TextSecurePreferences.setNextBackupTime(requireContext(), 0);
LocalBackupListener.schedule(requireContext());
});
timePickerFragment.show(getChildFragmentManager(), "TIME_PICKER");
}
private void onCreateClickedLegacy() {
Permissions.with(this)
.request(Manifest.permission.WRITE_EXTERNAL_STORAGE)
@ -255,10 +289,19 @@ public class BackupsPreferenceFragment extends Fragment {
.execute();
}
private void updateTimeLabel() {
final int backupHour = SignalStore.settings().getBackupHour();
final int backupMinute = SignalStore.settings().getBackupMinute();
LocalTime time = LocalTime.of(backupHour, backupMinute);
timeLabel.setText(JavaTimeExtensionsKt.formatHours(time, requireContext()));
}
private void setBackupsEnabled() {
toggle.setText(R.string.BackupsPreferenceFragment__turn_off);
create.setVisibility(View.VISIBLE);
verify.setVisibility(View.VISIBLE);
timer.setVisibility(View.VISIBLE);
updateTimeLabel();
setBackupFolderName();
}
@ -267,6 +310,7 @@ public class BackupsPreferenceFragment extends Fragment {
create.setVisibility(View.GONE);
folder.setVisibility(View.GONE);
verify.setVisibility(View.GONE);
timer.setVisibility(View.GONE);
ApplicationDependencies.getJobManager().cancelAllInQueue(LocalBackupJob.QUEUE);
}
}

Wyświetl plik

@ -50,7 +50,9 @@ public class LocalBackupListener extends PersistentAlarmManagerListener {
nextTime = System.currentTimeMillis() + INTERVAL;
} else {
LocalDateTime now = LocalDateTime.now();
LocalDateTime next = now.withHour(2).withMinute(0).withSecond(0);
int hour = SignalStore.settings().getBackupHour();
int minute = SignalStore.settings().getBackupMinute();
LocalDateTime next = now.withHour(hour).withMinute(minute).withSecond(0);
if (now.getHour() >= 2) {
next = next.plusDays(1);
}

Wyświetl plik

@ -117,6 +117,37 @@
android:textColor="@color/signal_text_secondary" />
</LinearLayout>
<LinearLayout
android:id="@+id/fragment_backup_time"
android:layout_width="match_parent"
android:layout_height="?attr/listPreferredItemHeightLarge"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:orientation="vertical"
android:visibility="gone"
tools:visibility="visible">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="@string/BackupsPreferenceFragment__backup_time"
android:textAppearance="@style/Signal.Text.Body"
android:textColor="@color/signal_text_primary" />
<TextView
android:id="@+id/fragment_backup_time_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:textAppearance="@style/Signal.Text.Preview"
android:textColor="@color/signal_text_secondary"
tools:text="3:00" />
</LinearLayout>
<LinearLayout
android:id="@+id/fragment_backup_verify"
android:layout_width="match_parent"

Wyświetl plik

@ -595,6 +595,8 @@
<string name="BackupsPreferenceFragment__create_backup">Create backup</string>
<string name="BackupsPreferenceFragment__last_backup">Last backup: %1$s</string>
<string name="BackupsPreferenceFragment__backup_folder">Backup folder</string>
<!-- Title for a preference item allowing the user to selected the hour of the day when their chats are backed up. -->
<string name="BackupsPreferenceFragment__backup_time">Backup time</string>
<string name="BackupsPreferenceFragment__verify_backup_passphrase">Verify backup passphrase</string>
<string name="BackupsPreferenceFragment__test_your_backup_passphrase">Test your backup passphrase and verify that it matches</string>
<string name="BackupsPreferenceFragment__turn_on">Turn on</string>