Use FAB for new identity action
This commit is contained in:
@@ -19,7 +19,7 @@ import i2p.bote.email.EmailIdentity;
|
||||
public class IdentityAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
private Context mCtx;
|
||||
private List<EmailIdentity> mIdentities;
|
||||
private IdentityListFragment.IdentityListListener mListener;
|
||||
private IdentityListFragment.OnIdentitySelectedListener mListener;
|
||||
|
||||
public static class SimpleViewHolder extends RecyclerView.ViewHolder {
|
||||
public SimpleViewHolder(View itemView) {
|
||||
@@ -38,7 +38,7 @@ public class IdentityAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||
}
|
||||
}
|
||||
|
||||
public IdentityAdapter(Context context, IdentityListFragment.IdentityListListener listener) {
|
||||
public IdentityAdapter(Context context, IdentityListFragment.OnIdentitySelectedListener listener) {
|
||||
mCtx = context;
|
||||
mListener = listener;
|
||||
setHasStableIds(true);
|
||||
@@ -56,8 +56,8 @@ public class IdentityAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (position == 0)
|
||||
return R.layout.listitem_text;
|
||||
if (mIdentities == null || mIdentities.isEmpty())
|
||||
return R.layout.listitem_empty;
|
||||
|
||||
return R.layout.listitem_identity;
|
||||
}
|
||||
@@ -80,20 +80,14 @@ public class IdentityAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
switch (holder.getItemViewType()) {
|
||||
case R.layout.listitem_text:
|
||||
case R.layout.listitem_empty:
|
||||
((TextView) holder.itemView).setText(
|
||||
mCtx.getResources().getString(R.string.new_identity));
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mListener.onNewIdentity();
|
||||
}
|
||||
});
|
||||
mCtx.getResources().getString(R.string.no_identities));
|
||||
break;
|
||||
|
||||
case R.layout.listitem_identity:
|
||||
final IdentityViewHolder cvh = (IdentityViewHolder) holder;
|
||||
EmailIdentity identity = mIdentities.get(position - 1);
|
||||
EmailIdentity identity = mIdentities.get(position);
|
||||
|
||||
String pic = identity.getPictureBase64();
|
||||
if (pic != null && !pic.isEmpty())
|
||||
@@ -108,7 +102,7 @@ public class IdentityAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||
cvh.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mListener.onIdentitySelected(mIdentities.get(cvh.getAdapterPosition() - 1));
|
||||
mListener.onIdentitySelected(mIdentities.get(cvh.getAdapterPosition()));
|
||||
}
|
||||
});
|
||||
break;
|
||||
@@ -121,14 +115,17 @@ public class IdentityAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||
// Return the size of the dataset (invoked by the layout manager)
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mIdentities.size() + 1;
|
||||
if (mIdentities == null || mIdentities.isEmpty())
|
||||
return 1;
|
||||
|
||||
return mIdentities.size();
|
||||
}
|
||||
|
||||
public long getItemId(int position) {
|
||||
if (position == 0)
|
||||
if (mIdentities == null || mIdentities.isEmpty())
|
||||
return 0;
|
||||
|
||||
EmailIdentity identity = mIdentities.get(position - 1);
|
||||
EmailIdentity identity = mIdentities.get(position);
|
||||
return identity.getHash().hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import i2p.bote.android.R;
|
||||
import i2p.bote.email.EmailIdentity;
|
||||
|
||||
public class IdentityListActivity extends BoteActivityBase implements
|
||||
IdentityListFragment.IdentityListListener {
|
||||
IdentityListFragment.OnIdentitySelectedListener {
|
||||
static final int ALTER_IDENTITY_LIST = 1;
|
||||
|
||||
@Override
|
||||
@@ -32,12 +32,6 @@ public class IdentityListActivity extends BoteActivityBase implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNewIdentity() {
|
||||
Intent i = new Intent(this, EditIdentityActivity.class);
|
||||
startActivityForResult(i, ALTER_IDENTITY_LIST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIdentitySelected(EmailIdentity identity) {
|
||||
Intent i = new Intent(this, ViewIdentityActivity.class);
|
||||
@@ -50,7 +44,7 @@ public class IdentityListActivity extends BoteActivityBase implements
|
||||
if (requestCode == ALTER_IDENTITY_LIST) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
IdentityListFragment f = (IdentityListFragment) getSupportFragmentManager().findFragmentById(R.id.container);
|
||||
f.updateContactList();
|
||||
f.updateIdentityList();
|
||||
}
|
||||
} else {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
@@ -15,7 +15,6 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.google.zxing.integration.android.IntentIntegrator;
|
||||
import com.pnikosis.materialishprogress.ProgressWheel;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -24,7 +23,6 @@ import java.util.Collection;
|
||||
|
||||
import i2p.bote.I2PBote;
|
||||
import i2p.bote.android.R;
|
||||
import i2p.bote.android.addressbook.EditContactActivity;
|
||||
import i2p.bote.android.util.AuthenticatedFragment;
|
||||
import i2p.bote.android.util.BetterAsyncTaskLoader;
|
||||
import i2p.bote.android.widget.DividerItemDecoration;
|
||||
@@ -34,13 +32,14 @@ import i2p.bote.fileencryption.PasswordException;
|
||||
|
||||
public class IdentityListFragment extends AuthenticatedFragment implements
|
||||
LoaderManager.LoaderCallbacks<Collection<EmailIdentity>> {
|
||||
IdentityListListener mCallback;
|
||||
OnIdentitySelectedListener mCallback;
|
||||
private LoadingRecyclerView mIdentitiesList;
|
||||
private IdentityAdapter mAdapter;
|
||||
|
||||
private View mNewIdentity;
|
||||
|
||||
// Container Activity must implement this interface
|
||||
public interface IdentityListListener {
|
||||
void onNewIdentity();
|
||||
public interface OnIdentitySelectedListener {
|
||||
void onIdentitySelected(EmailIdentity identity);
|
||||
}
|
||||
|
||||
@@ -51,7 +50,7 @@ public class IdentityListFragment extends AuthenticatedFragment implements
|
||||
// This makes sure that the container activity has implemented
|
||||
// the callback interface. If not, it throws an exception
|
||||
try {
|
||||
mCallback = (IdentityListListener) activity;
|
||||
mCallback = (OnIdentitySelectedListener) activity;
|
||||
} catch (ClassCastException e) {
|
||||
throw new ClassCastException(activity.toString()
|
||||
+ " must implement OnIdentitySelectedListener");
|
||||
@@ -75,6 +74,14 @@ public class IdentityListFragment extends AuthenticatedFragment implements
|
||||
ProgressWheel loading = (ProgressWheel) v.findViewById(R.id.loading);
|
||||
mIdentitiesList.setLoadingView(empty, loading);
|
||||
|
||||
mNewIdentity = v.findViewById(R.id.action_new_identity);
|
||||
mNewIdentity.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
startNewIdentity();
|
||||
}
|
||||
});
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -119,6 +126,7 @@ public class IdentityListFragment extends AuthenticatedFragment implements
|
||||
boolean passwordRequired = I2PBote.getInstance().isPasswordRequired();
|
||||
menu.findItem(R.id.export_identities).setVisible(!passwordRequired);
|
||||
menu.findItem(R.id.import_identities).setVisible(!passwordRequired);
|
||||
mNewIdentity.setVisibility(passwordRequired ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -139,17 +147,12 @@ public class IdentityListFragment extends AuthenticatedFragment implements
|
||||
}
|
||||
}
|
||||
|
||||
private void startNewContact() {
|
||||
Intent nci = new Intent(getActivity(), EditContactActivity.class);
|
||||
getActivity().startActivityForResult(nci, IdentityListActivity.ALTER_IDENTITY_LIST);
|
||||
private void startNewIdentity() {
|
||||
Intent nii = new Intent(getActivity(), EditIdentityActivity.class);
|
||||
getActivity().startActivityForResult(nii, IdentityListActivity.ALTER_IDENTITY_LIST);
|
||||
}
|
||||
|
||||
private void startScanQrCode() {
|
||||
IntentIntegrator integrator = new IntentIntegrator(getActivity());
|
||||
integrator.initiateScan(IntentIntegrator.QR_CODE_TYPES);
|
||||
}
|
||||
|
||||
protected void updateContactList() {
|
||||
protected void updateIdentityList() {
|
||||
getLoaderManager().restartLoader(0, null, this);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +1,46 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<i2p.bote.android.widget.LoadingRecyclerView
|
||||
android:id="@+id/identities_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="vertical"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/empty"
|
||||
<FrameLayout
|
||||
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:matProg_barColor="@color/accent"
|
||||
app:matProg_progressIndeterminate="true"/>
|
||||
</RelativeLayout>
|
||||
</FrameLayout>
|
||||
<i2p.bote.android.widget.LoadingRecyclerView
|
||||
android:id="@+id/identities_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:matProg_barColor="@color/accent"
|
||||
app:matProg_progressIndeterminate="true"/>
|
||||
</RelativeLayout>
|
||||
</FrameLayout>
|
||||
|
||||
<net.i2p.android.ext.floatingactionbutton.AddFloatingActionButton
|
||||
android:id="@+id/action_new_identity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_marginBottom="@dimen/listitem_horizontal_margin"
|
||||
android:layout_marginEnd="@dimen/listitem_horizontal_margin"
|
||||
android:layout_marginRight="@dimen/listitem_horizontal_margin"
|
||||
app:fab_colorNormal="@color/accent"
|
||||
app:fab_colorPressed="@color/accent_dark"/>
|
||||
</RelativeLayout>
|
||||
@@ -226,6 +226,7 @@
|
||||
<string name="remove_password_info">To remove the password, leave the \'New password\' fields blank.</string>
|
||||
<string name="password_changed">Password changed successfully</string>
|
||||
<string name="pref_title_identities">Identities</string>
|
||||
<string name="no_identities">No identities</string>
|
||||
<string name="new_identity">New identity…</string>
|
||||
<string name="edit_identity">Edit identity</string>
|
||||
<string name="title_new_identity">New identity</string>
|
||||
|
||||
Reference in New Issue
Block a user