mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user