mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 20:59:54 +01:00
Add new UnreadMessageButton class
This commit is contained in:
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportHeight="24.0"
|
||||||
|
android:viewportWidth="24.0">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFFFF"
|
||||||
|
android:pathData="M7.41,7.84L12,12.42l4.59,-4.58L18,9.25l-6,6 -6,-6z"/>
|
||||||
|
</vector>
|
||||||
9
briar-android/src/main/res/drawable/chevron_up_white.xml
Normal file
9
briar-android/src/main/res/drawable/chevron_up_white.xml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportHeight="24.0"
|
||||||
|
android:viewportWidth="24.0">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFFFF"
|
||||||
|
android:pathData="M7.41,15.41L12,10.83l4.59,4.58L18,14l-6,-6 -6,6z"/>
|
||||||
|
</vector>
|
||||||
@@ -2,21 +2,43 @@
|
|||||||
<LinearLayout
|
<LinearLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
tools:context=".android.forum.ForumActivity">
|
tools:context=".android.forum.ForumActivity">
|
||||||
|
|
||||||
<include layout="@layout/toolbar"/>
|
<include layout="@layout/toolbar"/>
|
||||||
|
|
||||||
<org.briarproject.briar.android.view.BriarRecyclerView
|
<android.support.design.widget.CoordinatorLayout
|
||||||
android:id="@+id/list"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1">
|
||||||
app:emptyText="@string/no_forum_posts"
|
|
||||||
app:scrollToEnd="false"/>
|
<org.briarproject.briar.android.view.BriarRecyclerView
|
||||||
|
android:id="@+id/list"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:emptyText="@string/no_forum_posts"
|
||||||
|
app:scrollToEnd="false"/>
|
||||||
|
|
||||||
|
<org.briarproject.briar.android.view.UnreadMessageButton
|
||||||
|
android:id="@+id/upButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="top|right"
|
||||||
|
app:layout_anchorGravity="top|right"
|
||||||
|
app:direction="up"/>
|
||||||
|
|
||||||
|
<org.briarproject.briar.android.view.UnreadMessageButton
|
||||||
|
android:id="@+id/downButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="bottom|right"
|
||||||
|
app:layout_anchorGravity="bottom|right"
|
||||||
|
app:direction="down"/>
|
||||||
|
|
||||||
|
</android.support.design.widget.CoordinatorLayout>
|
||||||
|
|
||||||
<org.briarproject.briar.android.view.TextInputView
|
<org.briarproject.briar.android.view.TextInputView
|
||||||
android:id="@+id/text_input_container"
|
android:id="@+id/text_input_container"
|
||||||
|
|||||||
31
briar-android/src/main/res/layout/unread_message_button.xml
Normal file
31
briar-android/src/main/res/layout/unread_message_button.xml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<merge
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
tools:showIn="@layout/activity_threaded_conversation">
|
||||||
|
|
||||||
|
<android.support.design.widget.FloatingActionButton
|
||||||
|
android:id="@+id/fab"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:fabSize="mini"
|
||||||
|
app:useCompatPadding="true"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/unreadCountView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="@dimen/unread_bubble_size"
|
||||||
|
android:layout_gravity="right|top"
|
||||||
|
android:layout_marginRight="5dp"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:background="@drawable/bubble"
|
||||||
|
android:elevation="7dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:minWidth="@dimen/unread_bubble_size"
|
||||||
|
android:textColor="@color/briar_text_primary_inverse"
|
||||||
|
android:textSize="@dimen/unread_bubble_text_size"
|
||||||
|
android:textStyle="bold"
|
||||||
|
tools:text="12"/>
|
||||||
|
|
||||||
|
</merge>
|
||||||
@@ -25,4 +25,11 @@
|
|||||||
<attr name="fillHeight" format="boolean"/>
|
<attr name="fillHeight" format="boolean"/>
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
|
<declare-styleable name="UnreadMessageButton">
|
||||||
|
<attr name="direction" format="enum">
|
||||||
|
<enum name="up" value="0"/>
|
||||||
|
<enum name="down" value="1"/>
|
||||||
|
</attr>
|
||||||
|
</declare-styleable>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user