From c5669bece5d4b068dd90ddf45c470ffcf928cad9 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Tue, 15 Dec 2020 17:23:08 -0300 Subject: [PATCH] Show a bomb badge on the send button when disappearing messages is active --- .../briar/android/view/CompositeSendButton.java | 15 +++++++++++++-- .../briar/android/view/TextSendController.java | 12 ++++++++++++ .../src/main/res/drawable/bomb_badge.xml | 13 +++++++++++++ .../res/layout/view_composite_send_button.xml | 13 +++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 briar-android/src/main/res/drawable/bomb_badge.xml diff --git a/briar-android/src/main/java/org/briarproject/briar/android/view/CompositeSendButton.java b/briar-android/src/main/java/org/briarproject/briar/android/view/CompositeSendButton.java index 273a250c5..11ed0adfc 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/view/CompositeSendButton.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/view/CompositeSendButton.java @@ -5,6 +5,7 @@ import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.FrameLayout; +import android.widget.ImageView; import android.widget.ProgressBar; import org.briarproject.briar.R; @@ -19,9 +20,10 @@ import static java.util.Objects.requireNonNull; public class CompositeSendButton extends FrameLayout { private final AppCompatImageButton sendButton, imageButton; + private final ImageView bombBadge; private final ProgressBar progressBar; - private boolean hasImageSupport = false; + private boolean hasImageSupport = false, bombVisible = false; public CompositeSendButton(@NonNull Context context, @Nullable AttributeSet attrs) { @@ -32,6 +34,7 @@ public class CompositeSendButton extends FrameLayout { sendButton = findViewById(R.id.sendButton); imageButton = findViewById(R.id.imageButton); + bombBadge = findViewById(R.id.bombBadge); progressBar = findViewById(R.id.progressBar); } @@ -71,6 +74,11 @@ public class CompositeSendButton extends FrameLayout { return hasImageSupport; } + public void setBombVisible(boolean visible) { + bombVisible = visible; + bombBadge.setVisibility(visible ? VISIBLE : INVISIBLE); + } + public void showImageButton(boolean showImageButton, boolean sendEnabled) { if (showImageButton) { imageButton.setVisibility(VISIBLE); @@ -78,6 +86,7 @@ public class CompositeSendButton extends FrameLayout { sendButton.clearAnimation(); sendButton.animate().alpha(0f).withEndAction(() -> { sendButton.setVisibility(INVISIBLE); + bombBadge.setVisibility(INVISIBLE); imageButton.setEnabled(true); }).start(); imageButton.clearAnimation(); @@ -88,7 +97,9 @@ public class CompositeSendButton extends FrameLayout { sendButton.setEnabled(sendEnabled); imageButton.setEnabled(false); sendButton.clearAnimation(); - sendButton.animate().alpha(1f).start(); + sendButton.animate().alpha(1f).withEndAction(() -> { + if (bombVisible) bombBadge.setVisibility(VISIBLE); + }).start(); imageButton.clearAnimation(); imageButton.animate().alpha(0f).withEndAction(() -> imageButton.setVisibility(INVISIBLE) diff --git a/briar-android/src/main/java/org/briarproject/briar/android/view/TextSendController.java b/briar-android/src/main/java/org/briarproject/briar/android/view/TextSendController.java index 2e510132b..886a0a44b 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/view/TextSendController.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/view/TextSendController.java @@ -7,6 +7,7 @@ import com.google.android.material.snackbar.Snackbar; import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.briar.R; +import org.briarproject.briar.android.conversation.ConversationActivity; import org.briarproject.briar.android.view.EmojiTextInputView.TextInputListener; import org.briarproject.briar.api.attachment.AttachmentHeader; @@ -60,15 +61,26 @@ public class TextSendController implements TextInputListener { updateViewState(); } + /** + * Sets the current auto delete timer and updates the UI accordingly. + *

+ * Attention: Works only in {@link ConversationActivity}. + */ public void setAutoDeleteTimer(long timer) { + // this will need to be adapted when other screens + // besides the private conversation use auto delete timers + CompositeSendButton sendButton = + (CompositeSendButton) compositeSendButton; // update hint if (timer == NO_AUTO_DELETE_TIMER) { textInput.setHint(defaultHint); + sendButton.setBombVisible(false); } else { // this might need to be adapted when other screens // besides the private conversation use auto delete timers defaultHint = textInput.getHint(); textInput.setHint(R.string.message_hint_auto_delete); + sendButton.setBombVisible(true); } } diff --git a/briar-android/src/main/res/drawable/bomb_badge.xml b/briar-android/src/main/res/drawable/bomb_badge.xml new file mode 100644 index 000000000..c3bf3da45 --- /dev/null +++ b/briar-android/src/main/res/drawable/bomb_badge.xml @@ -0,0 +1,13 @@ + + + + + + + + diff --git a/briar-android/src/main/res/layout/view_composite_send_button.xml b/briar-android/src/main/res/layout/view_composite_send_button.xml index b72677e71..01b474b85 100644 --- a/briar-android/src/main/res/layout/view_composite_send_button.xml +++ b/briar-android/src/main/res/layout/view_composite_send_button.xml @@ -37,6 +37,19 @@ app:srcCompat="@drawable/social_send_now_white" app:tint="@color/briar_accent" /> + +