Forum Avatars using the first letter of the forum and color from group

Also prevents the snackbar from hiding the bottom of the list.

Closes #337
parent 3193b736
<?xml version="1.0" encoding="utf-8"?>
<org.briarproject.android.util.BriarRecyclerView
android:id="@+id/forumList"
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent">
<org.briarproject.android.util.BriarRecyclerView
android:id="@+id/forumList"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="org.briarproject.android.util.BriarRecyclerViewBehavior"/>
</android.support.design.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
......@@ -9,6 +10,15 @@
android:paddingTop="@dimen/listitem_horizontal_margin"
android:background="?attr/selectableItemBackground">
<org.briarproject.android.util.TextAvatarView
android:id="@+id/avatarView"
android:layout_height="@dimen/avatar_forum_size"
android:layout_width="@dimen/avatar_forum_size"
android:layout_marginRight="@dimen/listitem_horizontal_margin"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
/>
<TextView
android:id="@+id/forumNameView"
android:layout_width="wrap_content"
......@@ -16,21 +26,23 @@
android:maxLines="2"
android:textColor="@color/briar_text_primary"
android:textSize="@dimen/text_size_medium"
tools:text="This is a name of a forum"/>
tools:text="This is a name of a forum"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/avatarView"
android:layout_toEndOf="@+id/avatarView"/>
<TextView
android:id="@+id/unreadView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/forumNameView"
android:layout_toLeftOf="@+id/dateView"
android:paddingTop="@dimen/margin_medium"
android:paddingBottom="@dimen/listitem_horizontal_margin"
android:textColor="@color/briar_text_secondary"
android:textSize="@dimen/text_size_small"
android:text="@string/no_unread_posts"/>
android:text="@string/no_unread_posts"
android:layout_below="@+id/forumNameView"
android:layout_toRightOf="@+id/avatarView"
android:layout_toEndOf="@+id/avatarView"/>
<TextView
android:id="@+id/dateView"
......
<?xml version="1.0" encoding="utf-8"?>
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/avatarBackground"
android:layout_width="@dimen/avatar_forum_size"
android:layout_height="@dimen/avatar_forum_size"
android:layout_gravity="center"
android:src="@android:color/transparent"
app:civ_fill_color="@color/briar_button_positive"
app:civ_border_color="@color/briar_primary"
app:civ_border_width="@dimen/avatar_border_width"/>
<android.support.v7.widget.AppCompatTextView
android:id="@+id/textAvatarView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
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"
tools:text="T"/>
</merge>
......@@ -18,7 +18,7 @@
<color name="horizontal_border">#CCCCCC</color>
<color name="forums_available_background">@color/briar_gold</color>
<color name="no_private_messages">#AAAAAA</color>
<color name="no_posts">#AAAAAA</color>
<color name="forum_avatar_shadow">#b3b3b3</color>
<color name="briar_primary">@color/briar_blue</color>
<color name="briar_primary_dark">@color/briar_blue_dark</color>
......
......@@ -28,6 +28,7 @@
<dimen name="listitem_picture_size">48dp</dimen>
<dimen name="listitem_selectable_picture_size">40dp</dimen>
<dimen name="dropdown_picture_size">32dp</dimen>
<dimen name="avatar_forum_size">48dp</dimen>
<dimen name="avatar_border_width">1dp</dimen>
<dimen name="message_bubble_margin_tail">14dp</dimen>
......
......@@ -13,6 +13,7 @@ import android.view.ViewGroup;
import android.widget.TextView;
import org.briarproject.R;
import org.briarproject.android.util.TextAvatarView;
import org.briarproject.api.forum.Forum;
import org.briarproject.api.sync.GroupId;
......@@ -91,6 +92,8 @@ public class ForumListAdapter extends
final ForumListItem item = getItem(position);
// TODO add avatar. See #337
ui.avatar.setText(item.getForum().getName().substring(0, 1));
ui.avatar.setBackgroundBytes(item.getForum().getId().getBytes());
// Forum Name
ui.name.setText(item.getForum().getName());
......@@ -176,6 +179,7 @@ public class ForumListAdapter extends
protected static class ForumViewHolder extends RecyclerView.ViewHolder {
private final ViewGroup layout;
private final TextAvatarView avatar;
private final TextView name;
private final TextView unread;
private final TextView date;
......@@ -184,6 +188,7 @@ public class ForumListAdapter extends
super(v);
layout = (ViewGroup) v;
avatar = (TextAvatarView) v.findViewById(R.id.avatarView);
name = (TextView) v.findViewById(R.id.forumNameView);
unread = (TextView) v.findViewById(R.id.unreadView);
date = (TextView) v.findViewById(R.id.dateView);
......
......@@ -83,7 +83,7 @@ public class ForumListFragment extends BaseEventFragment implements
list.setAdapter(adapter);
list.setEmptyText(getString(R.string.no_forums));
snackbar = Snackbar.make(contentView, "", LENGTH_INDEFINITE);
snackbar = Snackbar.make(list, "", LENGTH_INDEFINITE);
snackbar.getView().setBackgroundResource(R.color.briar_primary);
snackbar.setAction(R.string.show_forums, this);
snackbar.setActionTextColor(ContextCompat
......
package org.briarproject.android.util;
import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.util.AttributeSet;
import android.view.View;
public class BriarRecyclerViewBehavior
extends CoordinatorLayout.Behavior<BriarRecyclerView> {
public BriarRecyclerViewBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent,
BriarRecyclerView child, View dependency) {
// FIXME the below code works, but does not reset margin when snackbar is dismissed
/*
int margin = 0;
if (dependency.isShown()) margin = dependency.getHeight();
// set snackbar height as bottom margin if it is shown
CoordinatorLayout.LayoutParams params =
(CoordinatorLayout.LayoutParams) child.getLayoutParams();
params.setMargins(0, 0, 0, margin);
child.setLayoutParams(params);
child.scrollToPosition(0);
*/
return true;
}
@Override
public boolean layoutDependsOn(CoordinatorLayout parent,
BriarRecyclerView child, View dependency) {
// we only want to trigger the change
// only when the changes is from a snackbar
return dependency instanceof Snackbar.SnackbarLayout;
}
}
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.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import org.briarproject.R;
import de.hdodenhof.circleimageview.CircleImageView;
public class TextAvatarView extends FrameLayout {
final private AppCompatTextView textView;
final private CircleImageView backgroundView;
public TextAvatarView(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater inflater = (LayoutInflater) context
.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);
}
public TextAvatarView(Context context) {
this(context, null);
}
public void setText(String text) {
textView.setText(text);
}
public void setBackgroundBytes(byte[] bytes) {
int r = getByte(bytes, 0) * 3 / 4 + 96;
int g = getByte(bytes, 1) * 3 / 4 + 96;
int b = getByte(bytes, 2) * 3 / 4 + 96;
int color = Color.rgb(r, g, b);
backgroundView.setFillColor(color);
}
private byte getByte(byte[] bytes, int index) {
if (bytes == null) {
return -128;
} else {
return bytes[index % bytes.length];
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment