Show a bomb badge on the send button when disappearing messages is active

This commit is contained in:
Torsten Grote
2020-12-15 17:23:08 -03:00
parent 8c76db6216
commit c5669bece5
4 changed files with 51 additions and 2 deletions

View File

@@ -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)

View File

@@ -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.
* <p>
* 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);
}
}

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<solid android:color="@color/item_background_highlight" />
</shape>

View File

@@ -37,6 +37,19 @@
app:srcCompat="@drawable/social_send_now_white"
app:tint="@color/briar_accent" />
<ImageView
android:id="@+id/bombBadge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="1dp"
android:background="@drawable/bomb_badge"
android:contentDescription="@string/auto_delete_msg_contact_enabled"
android:visibility="invisible"
app:srcCompat="@drawable/ic_bomb"
app:tint="@color/color_primary"
tools:visibility="visible" />
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="@dimen/text_input_height"