diff --git a/briar-android/res/drawable/bubble.xml b/briar-android/res/drawable/bubble.xml index 9b7f37f9f..a00f451ed 100644 --- a/briar-android/res/drawable/bubble.xml +++ b/briar-android/res/drawable/bubble.xml @@ -8,7 +8,8 @@ + android:right="@dimen/unread_bubble_padding_horizontal" + android:bottom="1px"/> diff --git a/briar-android/res/drawable/bubble_problem.xml b/briar-android/res/drawable/bubble_problem.xml new file mode 100644 index 000000000..9d27c9596 --- /dev/null +++ b/briar-android/res/drawable/bubble_problem.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + diff --git a/briar-android/res/layout/list_item_available_forum.xml b/briar-android/res/layout/list_item_available_forum.xml index ca9158af1..536d983e2 100644 --- a/briar-android/res/layout/list_item_available_forum.xml +++ b/briar-android/res/layout/list_item_available_forum.xml @@ -11,8 +11,8 @@ + android:layout_centerVertical="true" + android:layout_marginRight="@dimen/listitem_horizontal_margin"/> + tools:text="This is a name of a forum"/> + tools:text="1337 posts"/> - + diff --git a/briar-android/res/layout/text_avatar_view.xml b/briar-android/res/layout/text_avatar_view.xml index f9eebbbdf..211d0f000 100644 --- a/briar-android/res/layout/text_avatar_view.xml +++ b/briar-android/res/layout/text_avatar_view.xml @@ -2,14 +2,15 @@ + xmlns:tools="http://schemas.android.com/tools" + tools:showIn="@layout/list_item_forum"> @@ -18,13 +19,28 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" + android:layout_marginRight="@dimen/listitem_picture_frame_offset" + android:layout_marginTop="@dimen/listitem_picture_frame_offset" android:maxLength="1" android:shadowColor="@color/forum_avatar_shadow" android:shadowDx="0" android:shadowDy="1.5" android:shadowRadius="1.5" android:textColor="@color/briar_text_primary_inverse" - android:textSize="30sp" + android:textSize="@dimen/avatar_text_size" tools:text="T"/> + + diff --git a/briar-android/res/values/color.xml b/briar-android/res/values/color.xml index 14a0938bb..8a44a58f3 100644 --- a/briar-android/res/values/color.xml +++ b/briar-android/res/values/color.xml @@ -30,7 +30,7 @@ @color/briar_primary #ffffff #333333 - #333333 + #FF78909C #06b9ff #ff0000 diff --git a/briar-android/res/values/dimens.xml b/briar-android/res/values/dimens.xml index 942a2d5bf..6ebd250eb 100644 --- a/briar-android/res/values/dimens.xml +++ b/briar-android/res/values/dimens.xml @@ -27,11 +27,13 @@ 68dp 48dp 23dp - 50dp + 53dp + 2dp 40dp 32dp 48dp 2dp + 30sp 12sp 2dp diff --git a/briar-android/res/values/strings.xml b/briar-android/res/values/strings.xml index 1e1e8e28c..c74ee87fd 100644 --- a/briar-android/res/values/strings.xml +++ b/briar-android/res/values/strings.xml @@ -81,12 +81,15 @@ Leave Forum Left Forum Sharing Status - No posts - no unread posts + No posts %d unread post %d unread posts + + %d post + %d posts + New Forum Choose a name for your forum: Create Forum diff --git a/briar-android/src/org/briarproject/android/forum/ForumListAdapter.java b/briar-android/src/org/briarproject/android/forum/ForumListAdapter.java index de53aab8d..34f27ebcf 100644 --- a/briar-android/src/org/briarproject/android/forum/ForumListAdapter.java +++ b/briar-android/src/org/briarproject/android/forum/ForumListAdapter.java @@ -19,10 +19,12 @@ import org.briarproject.api.sync.GroupId; import java.util.Collection; +import static android.view.View.GONE; +import static android.view.View.VISIBLE; import static org.briarproject.android.BriarActivity.GROUP_ID; import static org.briarproject.android.forum.ForumActivity.FORUM_NAME; -public class ForumListAdapter extends +class ForumListAdapter extends RecyclerView.Adapter { private SortedList forums = new SortedList<>( @@ -76,7 +78,7 @@ public class ForumListAdapter extends private final Context ctx; - public ForumListAdapter(Context ctx) { + ForumListAdapter(Context ctx) { this.ctx = ctx; } @@ -94,31 +96,36 @@ public class ForumListAdapter extends // Avatar ui.avatar.setText(item.getForum().getName().substring(0, 1)); ui.avatar.setBackgroundBytes(item.getForum().getId().getBytes()); + ui.avatar.setUnreadCount(item.getUnreadCount()); // Forum Name ui.name.setText(item.getForum().getName()); - // Unread Count - int unread = item.getUnreadCount(); - if (unread > 0) { + // Post Count + int postCount = item.getPostCount(); + if (postCount > 0) { ui.unread.setText(ctx.getResources() - .getQuantityString(R.plurals.unread_posts, unread, unread)); + .getQuantityString(R.plurals.forum_posts, postCount, + postCount)); ui.unread.setTextColor( - ContextCompat.getColor(ctx, R.color.briar_button_positive)); + ContextCompat + .getColor(ctx, R.color.briar_text_secondary)); } else { - ui.unread.setText(ctx.getString(R.string.no_unread_posts)); + ui.avatar.setProblem(true); + ui.unread.setText(ctx.getString(R.string.forum_no_posts)); ui.unread.setTextColor( - ContextCompat.getColor(ctx, R.color.briar_text_secondary)); + ContextCompat + .getColor(ctx, R.color.briar_text_tertiary)); } - // Date or "No Posts" + // Date if (item.isEmpty()) { - ui.date.setVisibility(View.GONE); + ui.date.setVisibility(GONE); } else { long timestamp = item.getTimestamp(); ui.date.setText( DateUtils.getRelativeTimeSpanString(ctx, timestamp)); - ui.date.setVisibility(View.VISIBLE); + ui.date.setVisibility(VISIBLE); } // Open Forum on Click @@ -158,7 +165,7 @@ public class ForumListAdapter extends forums.addAll(items); } - public void updateItem(ForumListItem item) { + void updateItem(ForumListItem item) { ForumListItem oldItem = getItem(item.getForum().getGroup().getId()); int position = forums.indexOf(oldItem); forums.updateItemAt(position, item); @@ -176,7 +183,7 @@ public class ForumListAdapter extends return forums.size() == 0; } - protected static class ForumViewHolder extends RecyclerView.ViewHolder { + static class ForumViewHolder extends RecyclerView.ViewHolder { private final ViewGroup layout; private final TextAvatarView avatar; @@ -184,7 +191,7 @@ public class ForumListAdapter extends private final TextView unread; private final TextView date; - public ForumViewHolder(View v) { + ForumViewHolder(View v) { super(v); layout = (ViewGroup) v; diff --git a/briar-android/src/org/briarproject/android/forum/ForumListFragment.java b/briar-android/src/org/briarproject/android/forum/ForumListFragment.java index 9c3207983..afe61864a 100644 --- a/briar-android/src/org/briarproject/android/forum/ForumListFragment.java +++ b/briar-android/src/org/briarproject/android/forum/ForumListFragment.java @@ -14,8 +14,6 @@ import android.view.View; import android.view.ViewGroup; import org.briarproject.R; -import org.briarproject.android.ActivityComponent; -import org.briarproject.android.AndroidComponent; import org.briarproject.android.fragment.BaseEventFragment; import org.briarproject.android.util.BriarRecyclerView; import org.briarproject.api.db.DbException; diff --git a/briar-android/src/org/briarproject/android/forum/ForumListItem.java b/briar-android/src/org/briarproject/android/forum/ForumListItem.java index f6e55a8a1..88a710d4e 100644 --- a/briar-android/src/org/briarproject/android/forum/ForumListItem.java +++ b/briar-android/src/org/briarproject/android/forum/ForumListItem.java @@ -9,6 +9,7 @@ class ForumListItem { private final Forum forum; private final boolean empty; + private final int postCount; private final long timestamp; private final int unread; @@ -16,6 +17,7 @@ class ForumListItem { this.forum = forum; empty = headers.isEmpty(); if (empty) { + postCount = 0; timestamp = 0; unread = 0; } else { @@ -29,6 +31,7 @@ class ForumListItem { } if (!h.isRead()) unread++; } + this.postCount = headers.size(); this.timestamp = newest.getTimestamp(); this.unread = unread; } @@ -42,6 +45,10 @@ class ForumListItem { return empty; } + int getPostCount() { + return postCount; + } + long getTimestamp() { return timestamp; } diff --git a/briar-android/src/org/briarproject/android/util/TextAvatarView.java b/briar-android/src/org/briarproject/android/util/TextAvatarView.java index 721fc5e91..cc4ab9148 100644 --- a/briar-android/src/org/briarproject/android/util/TextAvatarView.java +++ b/briar-android/src/org/briarproject/android/util/TextAvatarView.java @@ -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) {