Show warning dialog when auto-delete timer has changed since starting to compose message

This commit is contained in:
Torsten Grote
2021-01-04 14:54:42 -03:00
parent b02629bf34
commit 0d3f531545
3 changed files with 39 additions and 0 deletions

View File

@@ -174,6 +174,7 @@ public class TextAttachmentController extends TextSendController
private void onNewUris(boolean restart, List<Uri> newUris) {
if (newUris.isEmpty()) return;
if (loadingUris) throw new AssertionError();
if (textIsEmpty) onStartingMessage();
loadingUris = true;
if (newUris.size() > MAX_ATTACHMENTS_PER_MESSAGE) {
newUris = newUris.subList(0, MAX_ATTACHMENTS_PER_MESSAGE);

View File

@@ -16,6 +16,7 @@ import java.util.List;
import androidx.annotation.CallSuper;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import androidx.appcompat.app.AlertDialog;
import static com.google.android.material.snackbar.Snackbar.LENGTH_SHORT;
import static java.util.Collections.emptyList;
@@ -32,6 +33,7 @@ public class TextSendController implements TextInputListener {
protected boolean textIsEmpty = true;
private boolean ready = true;
private long currentTimer = NO_AUTO_DELETE_TIMER;
private long expectedTimer = NO_AUTO_DELETE_TIMER;
private final CharSequence defaultHint;
private final boolean allowEmptyText;
@@ -49,6 +51,7 @@ public class TextSendController implements TextInputListener {
@Override
public void onTextIsEmptyChanged(boolean isEmpty) {
textIsEmpty = isEmpty;
if (!isEmpty) onStartingMessage();
updateViewState();
}
@@ -59,6 +62,15 @@ public class TextSendController implements TextInputListener {
}
}
/**
* Call whenever the user starts a new message,
* either by entering text or adding an attachment.
* This updates the expected auto-delete timer to the current value.
*/
protected void onStartingMessage() {
expectedTimer = currentTimer;
}
public void setReady(boolean ready) {
this.ready = ready;
updateViewState();
@@ -111,6 +123,11 @@ public class TextSendController implements TextInputListener {
LENGTH_SHORT).show();
return false;
}
if (expectedTimer != currentTimer) {
boolean enabled = currentTimer != NO_AUTO_DELETE_TIMER;
showTimerChangedDialog(enabled);
return false;
}
return ready && (canSendEmptyText() || !textIsEmpty);
}
@@ -118,6 +135,23 @@ public class TextSendController implements TextInputListener {
return allowEmptyText;
}
private void showTimerChangedDialog(boolean enabled) {
Context ctx = textInput.getContext();
int message =
enabled ? R.string.auto_delete_changed_warning_message_enabled :
R.string.auto_delete_changed_warning_message_disabled;
new AlertDialog.Builder(ctx, R.style.BriarDialogTheme)
.setTitle(R.string.auto_delete_changed_warning_title)
.setMessage(message)
.setPositiveButton(R.string.auto_delete_changed_warning_send,
(dialog, which) -> {
expectedTimer = currentTimer;
onSendEvent();
})
.setNegativeButton(R.string.cancel, null)
.show();
}
@Nullable
public Parcelable onSaveInstanceState(@Nullable Parcelable superState) {
return superState;

View File

@@ -176,6 +176,10 @@
<!-- The second placeholder at the end will add "Tap to learn more." -->
<string name="auto_delete_msg_contact_disabled">%1$s\'s messages will not disappear. %2$s</string>
<string name="tap_to_learn_more">Tap to learn more.</string>
<string name="auto_delete_changed_warning_title">Disappearing messages changed</string>
<string name="auto_delete_changed_warning_message_enabled">Since you started composing your message, disappearing messages have been enabled.</string>
<string name="auto_delete_changed_warning_message_disabled">Since you started composing your message, disappearing messages have been disabled.</string>
<string name="auto_delete_changed_warning_send">Send anyway</string>
<string name="delete_all_messages">Delete all messages</string>
<string name="dialog_title_delete_all_messages">Confirm Message Deletion</string>
<string name="dialog_message_delete_all_messages">Are you sure that you want to delete all messages?</string>