Commit 9318a50c authored by str4d's avatar str4d

Migrate LocalAuthorSpinnerAdapter to XML, add identicons

parent 35c59fdb
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical">
<im.delight.android.identicons.SymmetricIdenticon
android:id="@+id/identiconView"
android:layout_width="@dimen/dropdown_picture_size"
android:layout_height="@dimen/dropdown_picture_size"/>
<TextView
android:id="@+id/nameView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_medium"
android:layout_marginStart="@dimen/margin_medium"
android:ellipsize="end"
android:singleLine="true"
android:textSize="@dimen/text_size_medium"
tools:text="This is a name of an author. It can be quite long."/>
</LinearLayout>
\ No newline at end of file
......@@ -26,4 +26,6 @@
<dimen name="listitem_height_one_line_avatar">56dp</dimen>
<dimen name="dropdown_picture_size">32dp</dimen>
</resources>
package org.briarproject.android.identity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
......@@ -8,14 +9,14 @@ import android.widget.SpinnerAdapter;
import android.widget.TextView;
import org.briarproject.R;
import org.briarproject.android.util.LayoutUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import static android.text.TextUtils.TruncateAt.END;
import im.delight.android.identicons.IdenticonView;
import static org.briarproject.android.identity.LocalAuthorItem.ANONYMOUS;
import static org.briarproject.android.identity.LocalAuthorItem.NEW;
......@@ -49,17 +50,32 @@ implements SpinnerAdapter {
@Override
public View getDropDownView(int position, View convertView,
ViewGroup parent) {
TextView name = new TextView(ctx);
name.setTextSize(18);
name.setSingleLine();
name.setEllipsize(END);
int pad = LayoutUtils.getPadding(ctx);
name.setPadding(pad, pad, pad, pad);
View view;
if (convertView == null) {
LayoutInflater inflater =
(LayoutInflater) ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.dropdown_author, parent, false);
} else
view = convertView;
TextView name = (TextView) view.findViewById(R.id.nameView);
IdenticonView identicon =
(IdenticonView) view.findViewById(R.id.identiconView);
LocalAuthorItem item = getItem(position);
if (item == ANONYMOUS) name.setText(R.string.anonymous);
else if (item == NEW) name.setText(R.string.new_identity_item);
else name.setText(item.getLocalAuthor().getName());
return name;
if (item == ANONYMOUS) {
name.setText(R.string.anonymous);
identicon.setVisibility(View.INVISIBLE);
} else if (item == NEW) {
name.setText(R.string.new_identity_item);
identicon.setVisibility(View.INVISIBLE);
} else {
name.setText(item.getLocalAuthor().getName());
identicon.setVisibility(View.VISIBLE);
identicon.show(item.getLocalAuthor().getId().getBytes());
}
return view;
}
public LocalAuthorItem getItem(int position) {
......@@ -78,15 +94,7 @@ implements SpinnerAdapter {
}
public View getView(int position, View convertView, ViewGroup parent) {
TextView name = new TextView(ctx);
name.setTextSize(18);
name.setSingleLine();
name.setEllipsize(END);
LocalAuthorItem item = getItem(position);
if (item == ANONYMOUS) name.setText(R.string.anonymous);
else if (item == NEW) name.setText(R.string.new_identity_item);
else name.setText(item.getLocalAuthor().getName());
return name;
return getDropDownView(position, convertView, parent);
}
@Override
......
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