mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 13:19:52 +01:00
Removed the 'new identity' item from the spinner - find a better way.
Returning null from getItem() was causing too many problems, and the item was triggering onItemSelected() before the other items had been loaded.
This commit is contained in:
@@ -1,76 +1,40 @@
|
|||||||
package net.sf.briar.android;
|
package net.sf.briar.android;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import net.sf.briar.R;
|
import net.sf.briar.R;
|
||||||
import net.sf.briar.api.Author;
|
|
||||||
import net.sf.briar.api.LocalAuthor;
|
import net.sf.briar.api.LocalAuthor;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.BaseAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.SpinnerAdapter;
|
import android.widget.SpinnerAdapter;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class LocalAuthorSpinnerAdapter extends BaseAdapter
|
public class LocalAuthorSpinnerAdapter extends ArrayAdapter<LocalAuthor>
|
||||||
implements SpinnerAdapter {
|
implements SpinnerAdapter {
|
||||||
|
|
||||||
private final Context ctx;
|
|
||||||
private final List<LocalAuthor> list = new ArrayList<LocalAuthor>();
|
|
||||||
|
|
||||||
public LocalAuthorSpinnerAdapter(Context ctx) {
|
public LocalAuthorSpinnerAdapter(Context ctx) {
|
||||||
this.ctx = ctx;
|
super(ctx, android.R.layout.simple_spinner_item,
|
||||||
}
|
new ArrayList<LocalAuthor>());
|
||||||
|
|
||||||
public void add(LocalAuthor a) {
|
|
||||||
list.add(a);
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clear() {
|
|
||||||
list.clear();
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCount() {
|
|
||||||
return list.size() + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalAuthor getItem(int position) {
|
|
||||||
if(position == list.size()) return null;
|
|
||||||
return list.get(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getItemId(int position) {
|
|
||||||
return android.R.layout.simple_spinner_item;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sort(Comparator<Author> comparator) {
|
|
||||||
Collections.sort(list, comparator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
Log.i("Briar", "getView: " + position);
|
TextView name = new TextView(getContext());
|
||||||
TextView name = new TextView(ctx);
|
|
||||||
name.setTextSize(18);
|
name.setTextSize(18);
|
||||||
name.setMaxLines(1);
|
name.setMaxLines(1);
|
||||||
Resources res = ctx.getResources();
|
Resources res = getContext().getResources();
|
||||||
int pad = res.getInteger(R.integer.spinner_padding);
|
int pad = res.getInteger(R.integer.spinner_padding);
|
||||||
name.setPadding(pad, pad, pad, pad);
|
name.setPadding(pad, pad, pad, pad);
|
||||||
if(position == list.size()) name.setText(R.string.create_identity_item);
|
name.setText(getItem(position).getName());
|
||||||
else name.setText(list.get(position).getName());
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getDropDownView(int position, View convertView,
|
public View getDropDownView(int position, View convertView,
|
||||||
ViewGroup parent) {
|
ViewGroup parent) {
|
||||||
Log.i("Briar", "getDropDownView: " + position);
|
|
||||||
return getView(position, convertView, parent);
|
return getView(position, convertView, parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user