Loading and empty views for address book
This commit is contained in:
@@ -16,6 +16,7 @@ import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
|
||||
import com.google.zxing.integration.android.IntentIntegrator;
|
||||
import com.pnikosis.materialishprogress.ProgressWheel;
|
||||
|
||||
import java.util.SortedSet;
|
||||
|
||||
@@ -24,13 +25,14 @@ import i2p.bote.android.R;
|
||||
import i2p.bote.android.util.AuthenticatedFragment;
|
||||
import i2p.bote.android.util.BetterAsyncTaskLoader;
|
||||
import i2p.bote.android.widget.DividerItemDecoration;
|
||||
import i2p.bote.android.widget.LoadingRecyclerView;
|
||||
import i2p.bote.fileencryption.PasswordException;
|
||||
import i2p.bote.packet.dht.Contact;
|
||||
|
||||
public class AddressBookFragment extends AuthenticatedFragment implements
|
||||
LoaderManager.LoaderCallbacks<SortedSet<Contact>> {
|
||||
OnContactSelectedListener mCallback;
|
||||
private RecyclerView mContactsList;
|
||||
private LoadingRecyclerView mContactsList;
|
||||
private ContactAdapter mAdapter;
|
||||
|
||||
private View mPromotedActions;
|
||||
@@ -66,7 +68,10 @@ public class AddressBookFragment extends AuthenticatedFragment implements
|
||||
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View v = inflater.inflate(R.layout.fragment_list_contacts, container, false);
|
||||
|
||||
mContactsList = (RecyclerView) v.findViewById(R.id.contacts_list);
|
||||
mContactsList = (LoadingRecyclerView) v.findViewById(R.id.contacts_list);
|
||||
View empty = v.findViewById(R.id.empty);
|
||||
ProgressWheel loading = (ProgressWheel) v.findViewById(R.id.loading);
|
||||
mContactsList.setLoadingView(empty, loading);
|
||||
mPromotedActions = v.findViewById(R.id.promoted_actions);
|
||||
|
||||
ImageButton b = (ImageButton) v.findViewById(R.id.action_new_contact);
|
||||
@@ -100,7 +105,7 @@ public class AddressBookFragment extends AuthenticatedFragment implements
|
||||
mContactsList.setLayoutManager(mLayoutManager);
|
||||
|
||||
// Set the adapter for the list view
|
||||
mAdapter = new ContactAdapter(mCallback);
|
||||
mAdapter = new ContactAdapter(getActivity(), mCallback);
|
||||
mContactsList.setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package i2p.bote.android.addressbook;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -15,23 +16,32 @@ import i2p.bote.android.R;
|
||||
import i2p.bote.android.util.BoteHelper;
|
||||
import i2p.bote.packet.dht.Contact;
|
||||
|
||||
public class ContactAdapter extends RecyclerView.Adapter<ContactAdapter.ViewHolder> {
|
||||
public class ContactAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
private Context mCtx;
|
||||
private List<Contact> mContacts;
|
||||
private AddressBookFragment.OnContactSelectedListener mListener;
|
||||
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
public static class SimpleViewHolder extends RecyclerView.ViewHolder {
|
||||
public SimpleViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ContactViewHolder extends RecyclerView.ViewHolder {
|
||||
public ImageView mPicture;
|
||||
public TextView mName;
|
||||
|
||||
public ViewHolder(View itemView) {
|
||||
public ContactViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
mPicture = (ImageView) itemView.findViewById(R.id.contact_picture);
|
||||
mName = (TextView) itemView.findViewById(R.id.contact_name);
|
||||
}
|
||||
}
|
||||
|
||||
public ContactAdapter(AddressBookFragment.OnContactSelectedListener listener) {
|
||||
public ContactAdapter(Context context, AddressBookFragment.OnContactSelectedListener listener) {
|
||||
mCtx = context;
|
||||
mListener = listener;
|
||||
setHasStableIds(true);
|
||||
}
|
||||
|
||||
public void setContacts(SortedSet<Contact> contacts) {
|
||||
@@ -44,43 +54,78 @@ public class ContactAdapter extends RecyclerView.Adapter<ContactAdapter.ViewHold
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (mContacts == null || mContacts.isEmpty())
|
||||
return R.layout.listitem_empty;
|
||||
|
||||
return R.layout.listitem_contact;
|
||||
}
|
||||
|
||||
// Create new views (invoked by the layout manager)
|
||||
@Override
|
||||
public ContactAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
|
||||
int viewType) {
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent,
|
||||
int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.listitem_contact, parent, false);
|
||||
return new ViewHolder(v);
|
||||
.inflate(viewType, parent, false);
|
||||
switch (viewType) {
|
||||
case R.layout.listitem_contact:
|
||||
return new ContactViewHolder(v);
|
||||
default:
|
||||
return new SimpleViewHolder(v);
|
||||
}
|
||||
}
|
||||
|
||||
// Replace the contents of a view (invoked by the layout manager)
|
||||
@Override
|
||||
public void onBindViewHolder(final ViewHolder holder, int position) {
|
||||
Contact contact = mContacts.get(position);
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
switch (holder.getItemViewType()) {
|
||||
case R.layout.listitem_empty:
|
||||
((TextView) holder.itemView).setText(
|
||||
mCtx.getResources().getString(R.string.address_book_empty));
|
||||
break;
|
||||
|
||||
String pic = contact.getPictureBase64();
|
||||
if (pic != null && !pic.isEmpty())
|
||||
holder.mPicture.setImageBitmap(BoteHelper.decodePicture(pic));
|
||||
else {
|
||||
ViewGroup.LayoutParams lp = holder.mPicture.getLayoutParams();
|
||||
holder.mPicture.setImageBitmap(BoteHelper.getIdenticonForAddress(contact.getBase64Dest(), lp.width, lp.height));
|
||||
case R.layout.listitem_contact:
|
||||
final ContactViewHolder cvh = (ContactViewHolder) holder;
|
||||
Contact contact = mContacts.get(position);
|
||||
|
||||
String pic = contact.getPictureBase64();
|
||||
if (pic != null && !pic.isEmpty())
|
||||
cvh.mPicture.setImageBitmap(BoteHelper.decodePicture(pic));
|
||||
else {
|
||||
ViewGroup.LayoutParams lp = cvh.mPicture.getLayoutParams();
|
||||
cvh.mPicture.setImageBitmap(BoteHelper.getIdenticonForAddress(contact.getBase64Dest(), lp.width, lp.height));
|
||||
}
|
||||
|
||||
cvh.mName.setText(contact.getName());
|
||||
|
||||
cvh.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mListener.onContactSelected(mContacts.get(cvh.getPosition()));
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
holder.mName.setText(contact.getName());
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mListener.onContactSelected(mContacts.get(holder.getPosition()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Return the size of the dataset (invoked by the layout manager)
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (mContacts != null)
|
||||
return mContacts.size();
|
||||
return 0;
|
||||
if (mContacts == null || mContacts.isEmpty())
|
||||
return 1;
|
||||
|
||||
return mContacts.size();
|
||||
}
|
||||
|
||||
public long getItemId(int position) {
|
||||
if (mContacts == null || mContacts.isEmpty())
|
||||
return 0;
|
||||
|
||||
Contact contact = mContacts.get(position);
|
||||
return contact.getDestination().getHash().hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,31 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/contacts_list"
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="vertical"/>
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<i2p.bote.android.widget.LoadingRecyclerView
|
||||
android:id="@+id/contacts_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="vertical"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/empty"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.pnikosis.materialishprogress.ProgressWheel
|
||||
android:id="@+id/loading"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="80dp"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_centerVertical="true"
|
||||
app:barColor="@color/accent"
|
||||
app:progressIndeterminate="true"/>
|
||||
</RelativeLayout>
|
||||
</FrameLayout>
|
||||
|
||||
<net.i2p.android.ext.floatingactionbutton.FloatingActionsMenu
|
||||
android:id="@+id/promoted_actions"
|
||||
|
||||
Reference in New Issue
Block a user