From 279f4d668a751a7d5f1a2e66f3c8be46586c73e9 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Wed, 21 Dec 2016 18:04:05 -0200 Subject: [PATCH] Add new UnreadMessageButton class --- .../android/view/UnreadMessageButton.java | 76 +++++++++++++++++++ .../main/res/drawable/chevron_down_white.xml | 9 +++ .../main/res/drawable/chevron_up_white.xml | 9 +++ .../layout/activity_threaded_conversation.xml | 34 +++++++-- .../main/res/layout/unread_message_button.xml | 31 ++++++++ briar-android/src/main/res/values/attrs.xml | 7 ++ 6 files changed, 160 insertions(+), 6 deletions(-) create mode 100644 briar-android/src/main/java/org/briarproject/briar/android/view/UnreadMessageButton.java create mode 100644 briar-android/src/main/res/drawable/chevron_down_white.xml create mode 100644 briar-android/src/main/res/drawable/chevron_up_white.xml create mode 100644 briar-android/src/main/res/layout/unread_message_button.xml diff --git a/briar-android/src/main/java/org/briarproject/briar/android/view/UnreadMessageButton.java b/briar-android/src/main/java/org/briarproject/briar/android/view/UnreadMessageButton.java new file mode 100644 index 000000000..6e061226d --- /dev/null +++ b/briar-android/src/main/java/org/briarproject/briar/android/view/UnreadMessageButton.java @@ -0,0 +1,76 @@ +package org.briarproject.briar.android.view; + +import android.content.Context; +import android.content.res.TypedArray; +import android.support.annotation.Nullable; +import android.support.annotation.UiThread; +import android.support.design.widget.FloatingActionButton; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.widget.FrameLayout; +import android.widget.TextView; + +import org.briarproject.bramble.api.nullsafety.NotNullByDefault; +import org.briarproject.briar.R; + +@UiThread +@NotNullByDefault +public class UnreadMessageButton extends FrameLayout { + + private final static int UP = 0, DOWN = 1; + + private final FloatingActionButton fab; + private final TextView unread; + + public UnreadMessageButton(Context context) { + this(context, null); + } + + public UnreadMessageButton(Context context, @Nullable AttributeSet attrs) { + this(context, attrs, 0); + } + + public UnreadMessageButton(Context context, @Nullable AttributeSet attrs, + int defStyleAttr) { + super(context, attrs, defStyleAttr); + + LayoutInflater inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + inflater + .inflate(R.layout.unread_message_button, this, true); + + fab = (FloatingActionButton) findViewById(R.id.fab); + unread = (TextView) findViewById(R.id.unreadCountView); + + TypedArray attributes = context.obtainStyledAttributes(attrs, + R.styleable.UnreadMessageButton); + int direction = attributes + .getInteger(R.styleable.UnreadMessageButton_direction, DOWN); + setDirection(direction); + attributes.recycle(); + + setUnreadCount(0); + } + + private void setDirection(int direction) { + if (direction == UP) { + fab.setImageResource(R.drawable.chevron_up_white); + } else if (direction == DOWN) { + fab.setImageResource(R.drawable.chevron_down_white); + } else { + throw new IllegalArgumentException(); + } + } + + public void setUnreadCount(int count) { + if (count == 0) { + unread.setVisibility(INVISIBLE); + fab.hide(); + } else { + unread.setVisibility(VISIBLE); + unread.setText(String.valueOf(count)); + if (!fab.isShown()) fab.show(); + } + } + +} diff --git a/briar-android/src/main/res/drawable/chevron_down_white.xml b/briar-android/src/main/res/drawable/chevron_down_white.xml new file mode 100644 index 000000000..c7c475fea --- /dev/null +++ b/briar-android/src/main/res/drawable/chevron_down_white.xml @@ -0,0 +1,9 @@ + + + diff --git a/briar-android/src/main/res/drawable/chevron_up_white.xml b/briar-android/src/main/res/drawable/chevron_up_white.xml new file mode 100644 index 000000000..3715aa2f0 --- /dev/null +++ b/briar-android/src/main/res/drawable/chevron_up_white.xml @@ -0,0 +1,9 @@ + + + diff --git a/briar-android/src/main/res/layout/activity_threaded_conversation.xml b/briar-android/src/main/res/layout/activity_threaded_conversation.xml index 9847ed644..913a17560 100644 --- a/briar-android/src/main/res/layout/activity_threaded_conversation.xml +++ b/briar-android/src/main/res/layout/activity_threaded_conversation.xml @@ -2,21 +2,43 @@ - + android:layout_weight="1"> + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/briar-android/src/main/res/values/attrs.xml b/briar-android/src/main/res/values/attrs.xml index d28d0e3f7..6d6207cd0 100644 --- a/briar-android/src/main/res/values/attrs.xml +++ b/briar-android/src/main/res/values/attrs.xml @@ -25,4 +25,11 @@ + + + + + + + \ No newline at end of file