This commit adds badges to the forum list that indicate unread posts.

It does so by extending the compound view `TextAvatarView` and provides
convienient setters that take care of the required UI changes.
The new badge can also be used to indicate a problem with the forum.

Closes #408
This commit is contained in:
Torsten Grote
2016-06-01 13:39:57 -03:00
parent bba7083660
commit 5d06f42000
12 changed files with 142 additions and 58 deletions

View File

@@ -1,13 +1,13 @@
package org.briarproject.android.util;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.TextView;
import org.briarproject.R;
@@ -15,8 +15,10 @@ import de.hdodenhof.circleimageview.CircleImageView;
public class TextAvatarView extends FrameLayout {
final private AppCompatTextView textView;
final private CircleImageView backgroundView;
final private AppCompatTextView character;
final private CircleImageView background;
final private TextView badge;
private int unreadCount;
public TextAvatarView(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -25,8 +27,10 @@ public class TextAvatarView extends FrameLayout {
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater
.inflate(R.layout.text_avatar_view, this, true);
textView = (AppCompatTextView) findViewById(R.id.textAvatarView);
backgroundView = (CircleImageView) findViewById(R.id.avatarBackground);
character = (AppCompatTextView) findViewById(R.id.textAvatarView);
background = (CircleImageView) findViewById(R.id.avatarBackground);
badge = (TextView) findViewById(R.id.unreadCountView);
badge.setVisibility(INVISIBLE);
}
public TextAvatarView(Context context) {
@@ -34,7 +38,32 @@ public class TextAvatarView extends FrameLayout {
}
public void setText(String text) {
textView.setText(text);
character.setText(text);
}
public void setUnreadCount(int count) {
if (count > 0) {
this.unreadCount = count;
badge.setBackgroundResource(R.drawable.bubble);
badge.setText(String.valueOf(count));
badge.setTextColor(ContextCompat.getColor(getContext(), R.color.briar_text_primary_inverse));
badge.setVisibility(VISIBLE);
} else {
badge.setVisibility(INVISIBLE);
}
}
public void setProblem(boolean problem) {
if (problem) {
badge.setBackgroundResource(R.drawable.bubble_problem);
badge.setText("!");
badge.setTextColor(ContextCompat.getColor(getContext(), R.color.briar_primary));
badge.setVisibility(VISIBLE);
} else if (unreadCount > 0) {
setUnreadCount(unreadCount);
} else {
badge.setVisibility(INVISIBLE);
}
}
public void setBackgroundBytes(byte[] bytes) {
@@ -43,7 +72,7 @@ public class TextAvatarView extends FrameLayout {
int b = getByte(bytes, 2) * 3 / 4 + 96;
int color = Color.rgb(r, g, b);
backgroundView.setFillColor(color);
background.setFillColor(color);
}
private byte getByte(byte[] bytes, int index) {