Refactor contact lists, their adapters and items

This commit is contained in:
Torsten Grote
2016-10-25 12:50:49 -02:00
parent 1e36f21cc8
commit 7191967092
19 changed files with 373 additions and 472 deletions

View File

@@ -4,8 +4,6 @@ import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;
import org.briarproject.R;
import org.briarproject.android.contact.BaseContactListAdapter;
@@ -14,16 +12,12 @@ import org.briarproject.api.contact.ContactId;
import java.util.ArrayList;
import java.util.Collection;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
class ContactSelectorAdapter
extends BaseContactListAdapter<ContactSelectorAdapter.SelectableContactHolder> {
class ContactSelectorAdapter extends
BaseContactListAdapter<SelectableContactItem, SelectableContactHolder> {
ContactSelectorAdapter(Context context,
OnItemClickListener listener) {
super(context, listener);
OnContactClickListener<SelectableContactItem> listener) {
super(context, SelectableContactItem.class, listener);
}
@Override
@@ -31,66 +25,17 @@ class ContactSelectorAdapter
int i) {
View v = LayoutInflater.from(ctx).inflate(
R.layout.list_item_selectable_contact, viewGroup, false);
return new SelectableContactHolder(v);
}
@Override
public void onBindViewHolder(SelectableContactHolder ui, int position) {
super.onBindViewHolder(ui, position);
SelectableContactListItem item =
(SelectableContactListItem) getItemAt(position);
if (item == null) return;
if (item.isSelected()) {
ui.checkBox.setChecked(true);
} else {
ui.checkBox.setChecked(false);
}
if (item.isDisabled()) {
// we share this forum already with that contact
ui.layout.setEnabled(false);
ui.shared.setVisibility(VISIBLE);
grayOutItem(ui, true);
} else {
ui.layout.setEnabled(true);
ui.shared.setVisibility(GONE);
grayOutItem(ui, false);
}
}
Collection<ContactId> getSelectedContactIds() {
Collection<ContactId> selected = new ArrayList<>();
for (int i = 0; i < items.size(); i++) {
SelectableContactListItem item =
(SelectableContactListItem) items.get(i);
SelectableContactItem item = items.get(i);
if (item.isSelected()) selected.add(item.getContact().getId());
}
return selected;
}
static class SelectableContactHolder
extends BaseContactListAdapter.BaseContactHolder {
private final CheckBox checkBox;
private final TextView shared;
private SelectableContactHolder(View v) {
super(v);
checkBox = (CheckBox) v.findViewById(R.id.checkBox);
shared = (TextView) v.findViewById(R.id.infoView);
}
}
private void grayOutItem(SelectableContactHolder ui, boolean gray) {
float alpha = gray ? 0.25f : 1f;
ui.avatar.setAlpha(alpha);
ui.name.setAlpha(alpha);
ui.checkBox.setAlpha(alpha);
}
}