mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 12:19:54 +01:00
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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user