ImportKeys: Switch from ListFragment to RecyclerView
This is the first step for: - use CardView for the list - improve ImportKeysListFragment
This commit is contained in:
@@ -18,10 +18,6 @@
|
|||||||
package org.sufficientlysecure.keychain.ui;
|
package org.sufficientlysecure.keychain.ui;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
@@ -31,15 +27,17 @@ import android.os.Build;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.ListFragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.LoaderManager;
|
import android.support.v4.app.LoaderManager;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v4.content.Loader;
|
import android.support.v4.content.Loader;
|
||||||
import android.support.v4.util.LongSparseArray;
|
import android.support.v4.util.LongSparseArray;
|
||||||
import android.view.MotionEvent;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnTouchListener;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ListView;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
@@ -58,7 +56,11 @@ import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
|||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||||
|
|
||||||
public class ImportKeysListFragment extends ListFragment implements
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ImportKeysListFragment extends Fragment implements
|
||||||
LoaderManager.LoaderCallbacks<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> {
|
LoaderManager.LoaderCallbacks<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> {
|
||||||
|
|
||||||
private static final String ARG_DATA_URI = "uri";
|
private static final String ARG_DATA_URI = "uri";
|
||||||
@@ -70,16 +72,18 @@ public class ImportKeysListFragment extends ListFragment implements
|
|||||||
private static final int REQUEST_PERMISSION_READ_EXTERNAL_STORAGE = 12;
|
private static final int REQUEST_PERMISSION_READ_EXTERNAL_STORAGE = 12;
|
||||||
|
|
||||||
private Activity mActivity;
|
private Activity mActivity;
|
||||||
private ImportKeysAdapter mAdapter;
|
|
||||||
private ParcelableProxy mParcelableProxy;
|
private ParcelableProxy mParcelableProxy;
|
||||||
|
|
||||||
|
private ProgressBar mProgressBar;
|
||||||
|
private RecyclerView mRecyclerView;
|
||||||
|
private ImportKeysAdapter mAdapter;
|
||||||
|
|
||||||
private LoaderState mLoaderState;
|
private LoaderState mLoaderState;
|
||||||
|
|
||||||
private static final int LOADER_ID_BYTES = 0;
|
private static final int LOADER_ID_BYTES = 0;
|
||||||
private static final int LOADER_ID_CLOUD = 1;
|
private static final int LOADER_ID_CLOUD = 1;
|
||||||
|
|
||||||
private LongSparseArray<ParcelableKeyRing> mCachedKeyData;
|
private LongSparseArray<ParcelableKeyRing> mCachedKeyData;
|
||||||
private boolean mNonInteractive;
|
|
||||||
|
|
||||||
private boolean mShowingOrbotDialog;
|
private boolean mShowingOrbotDialog;
|
||||||
|
|
||||||
@@ -206,39 +210,26 @@ public class ImportKeysListFragment extends ListFragment implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Define Adapter and Loader on create of Activity
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
View view = inflater.inflate(R.layout.import_keys_list_fragment, container, false);
|
||||||
|
|
||||||
mActivity = getActivity();
|
mActivity = getActivity();
|
||||||
|
|
||||||
// Give some text to display if there is no data.
|
|
||||||
setEmptyText(mActivity.getString(R.string.error_nothing_import));
|
|
||||||
|
|
||||||
// Create an empty adapter we will use to display the loaded data.
|
|
||||||
mAdapter = new ImportKeysAdapter(mActivity);
|
|
||||||
setListAdapter(mAdapter);
|
|
||||||
|
|
||||||
Bundle args = getArguments();
|
Bundle args = getArguments();
|
||||||
Uri dataUri = args.getParcelable(ARG_DATA_URI);
|
Uri dataUri = args.getParcelable(ARG_DATA_URI);
|
||||||
byte[] bytes = args.getByteArray(ARG_BYTES);
|
byte[] bytes = args.getByteArray(ARG_BYTES);
|
||||||
String query = args.getString(ARG_SERVER_QUERY);
|
String query = args.getString(ARG_SERVER_QUERY);
|
||||||
mNonInteractive = args.getBoolean(ARG_NON_INTERACTIVE, false);
|
boolean nonInteractive = args.getBoolean(ARG_NON_INTERACTIVE, false);
|
||||||
|
|
||||||
getListView().setOnTouchListener(new OnTouchListener() {
|
mProgressBar = (ProgressBar) view.findViewById(R.id.progress_view);
|
||||||
@Override
|
mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(mActivity);
|
||||||
if (!mAdapter.isEmpty()) {
|
mRecyclerView.setLayoutManager(mLayoutManager);
|
||||||
mActivity.onTouchEvent(event);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
getListView().setFastScrollEnabled(true);
|
// Create an empty adapter we will use to display the loaded data.
|
||||||
|
mAdapter = new ImportKeysAdapter(mActivity, nonInteractive);
|
||||||
|
mRecyclerView.setAdapter(mAdapter);
|
||||||
|
|
||||||
if (dataUri != null || bytes != null) {
|
if (dataUri != null || bytes != null) {
|
||||||
mLoaderState = new BytesLoaderState(bytes, dataUri);
|
mLoaderState = new BytesLoaderState(bytes, dataUri);
|
||||||
@@ -252,23 +243,25 @@ public class ImportKeysListFragment extends ListFragment implements
|
|||||||
mLoaderState = new CloudLoaderState(query, cloudSearchPrefs);
|
mLoaderState = new CloudLoaderState(query, cloudSearchPrefs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataUri != null && ! checkAndRequestReadPermission(dataUri)) {
|
if (dataUri != null && !checkAndRequestReadPermission(dataUri)) {
|
||||||
return;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
restartLoaders();
|
restartLoaders();
|
||||||
|
|
||||||
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request READ_EXTERNAL_STORAGE permission on Android >= 6.0 to read content from "file" Uris.
|
* Request READ_EXTERNAL_STORAGE permission on Android >= 6.0 to read content from "file" Uris.
|
||||||
*
|
* <p/>
|
||||||
* This method returns true on Android < 6, or if permission is already granted. It
|
* This method returns true on Android < 6, or if permission is already granted. It
|
||||||
* requests the permission and returns false otherwise.
|
* requests the permission and returns false otherwise.
|
||||||
*
|
* <p/>
|
||||||
* see https://commonsware.com/blog/2015/10/07/runtime-permissions-files-action-send.html
|
* see https://commonsware.com/blog/2015/10/07/runtime-permissions-files-action-send.html
|
||||||
*/
|
*/
|
||||||
private boolean checkAndRequestReadPermission(final Uri uri) {
|
private boolean checkAndRequestReadPermission(final Uri uri) {
|
||||||
if ( ! ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
|
if (!ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,30 +305,13 @@ public class ImportKeysListFragment extends ListFragment implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
|
||||||
super.onListItemClick(l, v, position, id);
|
|
||||||
|
|
||||||
if (mNonInteractive) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Select checkbox!
|
|
||||||
// Update underlying data and notify adapter of change. The adapter will
|
|
||||||
// update the view automatically.
|
|
||||||
|
|
||||||
ImportKeysListEntry entry = mAdapter.getItem(position);
|
|
||||||
entry.setSelected(!entry.isSelected());
|
|
||||||
mAdapter.notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadNew(LoaderState loaderState) {
|
public void loadNew(LoaderState loaderState) {
|
||||||
mLoaderState = loaderState;
|
mLoaderState = loaderState;
|
||||||
|
|
||||||
if (mLoaderState instanceof BytesLoaderState) {
|
if (mLoaderState instanceof BytesLoaderState) {
|
||||||
BytesLoaderState ls = (BytesLoaderState) mLoaderState;
|
BytesLoaderState ls = (BytesLoaderState) mLoaderState;
|
||||||
|
|
||||||
if ( ls.mDataUri != null && ! checkAndRequestReadPermission(ls.mDataUri)) {
|
if (ls.mDataUri != null && !checkAndRequestReadPermission(ls.mDataUri)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -344,69 +320,67 @@ public class ImportKeysListFragment extends ListFragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void destroyLoader() {
|
public void destroyLoader() {
|
||||||
if (getLoaderManager().getLoader(LOADER_ID_BYTES) != null) {
|
LoaderManager loaderManager = getLoaderManager();
|
||||||
getLoaderManager().destroyLoader(LOADER_ID_BYTES);
|
|
||||||
|
if (loaderManager.getLoader(LOADER_ID_BYTES) != null) {
|
||||||
|
loaderManager.destroyLoader(LOADER_ID_BYTES);
|
||||||
}
|
}
|
||||||
if (getLoaderManager().getLoader(LOADER_ID_CLOUD) != null) {
|
if (loaderManager.getLoader(LOADER_ID_CLOUD) != null) {
|
||||||
getLoaderManager().destroyLoader(LOADER_ID_CLOUD);
|
loaderManager.destroyLoader(LOADER_ID_CLOUD);
|
||||||
}
|
|
||||||
if (getView() != null) {
|
|
||||||
setListShown(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void restartLoaders() {
|
private void restartLoaders() {
|
||||||
|
LoaderManager loaderManager = getLoaderManager();
|
||||||
|
|
||||||
if (mLoaderState instanceof BytesLoaderState) {
|
if (mLoaderState instanceof BytesLoaderState) {
|
||||||
// Start out with a progress indicator.
|
loaderManager.restartLoader(LOADER_ID_BYTES, null, this);
|
||||||
setListShown(false);
|
|
||||||
|
|
||||||
getLoaderManager().restartLoader(LOADER_ID_BYTES, null, this);
|
|
||||||
} else if (mLoaderState instanceof CloudLoaderState) {
|
} else if (mLoaderState instanceof CloudLoaderState) {
|
||||||
// Start out with a progress indicator.
|
loaderManager.restartLoader(LOADER_ID_CLOUD, null, this);
|
||||||
setListShown(false);
|
|
||||||
|
|
||||||
getLoaderManager().restartLoader(LOADER_ID_CLOUD, null, this);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Loader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>>
|
public Loader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> onCreateLoader(
|
||||||
onCreateLoader(int id, Bundle args) {
|
int id,
|
||||||
|
Bundle args
|
||||||
|
) {
|
||||||
|
|
||||||
|
Loader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> loader;
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case LOADER_ID_BYTES: {
|
case LOADER_ID_BYTES: {
|
||||||
return new ImportKeysListLoader(mActivity, (BytesLoaderState) mLoaderState);
|
loader = new ImportKeysListLoader(mActivity, (BytesLoaderState) mLoaderState);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case LOADER_ID_CLOUD: {
|
case LOADER_ID_CLOUD: {
|
||||||
CloudLoaderState ls = (CloudLoaderState) mLoaderState;
|
CloudLoaderState ls = (CloudLoaderState) mLoaderState;
|
||||||
return new ImportKeysListCloudLoader(getActivity(), ls.mServerQuery, ls.mCloudPrefs,
|
loader = new ImportKeysListCloudLoader(getActivity(), ls.mServerQuery,
|
||||||
mParcelableProxy);
|
ls.mCloudPrefs, mParcelableProxy);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return null;
|
loader = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (loader != null) {
|
||||||
|
mRecyclerView.setVisibility(View.GONE);
|
||||||
|
mProgressBar.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return loader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadFinished(Loader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> loader,
|
public void onLoadFinished(
|
||||||
AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> data) {
|
Loader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> loader,
|
||||||
// Swap the new cursor in. (The framework will take care of closing the
|
AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> data
|
||||||
// old cursor once we return.)
|
) {
|
||||||
|
|
||||||
Log.d(Constants.TAG, "data: " + data.getResult());
|
|
||||||
|
|
||||||
// swap in the real data!
|
|
||||||
mAdapter.setData(data.getResult());
|
mAdapter.setData(data.getResult());
|
||||||
mAdapter.notifyDataSetChanged();
|
mAdapter.notifyDataSetChanged();
|
||||||
|
|
||||||
setListAdapter(mAdapter);
|
mRecyclerView.setVisibility(View.VISIBLE);
|
||||||
|
mProgressBar.setVisibility(View.GONE);
|
||||||
// The list should now be shown.
|
|
||||||
if (isResumed()) {
|
|
||||||
setListShown(true);
|
|
||||||
} else {
|
|
||||||
setListShownNoAnimation(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// free old cached key data
|
// free old cached key data
|
||||||
mCachedKeyData = null;
|
mCachedKeyData = null;
|
||||||
@@ -414,7 +388,6 @@ public class ImportKeysListFragment extends ListFragment implements
|
|||||||
GetKeyResult getKeyResult = (GetKeyResult) data.getOperationResult();
|
GetKeyResult getKeyResult = (GetKeyResult) data.getOperationResult();
|
||||||
switch (loader.getId()) {
|
switch (loader.getId()) {
|
||||||
case LOADER_ID_BYTES:
|
case LOADER_ID_BYTES:
|
||||||
|
|
||||||
if (getKeyResult.success()) {
|
if (getKeyResult.success()) {
|
||||||
// No error
|
// No error
|
||||||
mCachedKeyData = ((ImportKeysListLoader) loader).getParcelableRings();
|
mCachedKeyData = ((ImportKeysListLoader) loader).getParcelableRings();
|
||||||
@@ -424,7 +397,6 @@ public class ImportKeysListFragment extends ListFragment implements
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case LOADER_ID_CLOUD:
|
case LOADER_ID_CLOUD:
|
||||||
|
|
||||||
if (getKeyResult.success()) {
|
if (getKeyResult.success()) {
|
||||||
// No error
|
// No error
|
||||||
} else if (getKeyResult.isPending()) {
|
} else if (getKeyResult.isPending()) {
|
||||||
@@ -488,11 +460,11 @@ public class ImportKeysListFragment extends ListFragment implements
|
|||||||
switch (loader.getId()) {
|
switch (loader.getId()) {
|
||||||
case LOADER_ID_BYTES:
|
case LOADER_ID_BYTES:
|
||||||
// Clear the data in the adapter.
|
// Clear the data in the adapter.
|
||||||
mAdapter.clear();
|
mAdapter.clearData();
|
||||||
break;
|
break;
|
||||||
case LOADER_ID_CLOUD:
|
case LOADER_ID_CLOUD:
|
||||||
// Clear the data in the adapter.
|
// Clear the data in the adapter.
|
||||||
mAdapter.clear();
|
mAdapter.clearData();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -17,16 +17,14 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.ui.adapter;
|
package org.sufficientlysecure.keychain.ui.adapter;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Build;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@@ -47,13 +45,18 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.ViewHolder> {
|
||||||
protected LayoutInflater mInflater;
|
|
||||||
protected Activity mActivity;
|
|
||||||
|
|
||||||
protected List<ImportKeysListEntry> mData;
|
private Context mContext;
|
||||||
|
private boolean mNonInteractive;
|
||||||
|
private List<ImportKeysListEntry> mData;
|
||||||
|
|
||||||
static class ViewHolder {
|
public ImportKeysAdapter(Context mContext, boolean mNonInteractive) {
|
||||||
|
this.mContext = mContext;
|
||||||
|
this.mNonInteractive = mNonInteractive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
public TextView mainUserId;
|
public TextView mainUserId;
|
||||||
public TextView mainUserIdRest;
|
public TextView mainUserIdRest;
|
||||||
public TextView keyId;
|
public TextView keyId;
|
||||||
@@ -63,38 +66,29 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
|||||||
public View userIdsDivider;
|
public View userIdsDivider;
|
||||||
public LinearLayout userIdsList;
|
public LinearLayout userIdsList;
|
||||||
public CheckBox checkBox;
|
public CheckBox checkBox;
|
||||||
}
|
|
||||||
|
|
||||||
public ImportKeysAdapter(Activity activity) {
|
public ViewHolder(View itemView) {
|
||||||
super(activity, -1);
|
super(itemView);
|
||||||
mActivity = activity;
|
|
||||||
mInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
|
||||||
public void setData(List<ImportKeysListEntry> data) {
|
|
||||||
|
|
||||||
clear();
|
|
||||||
if (data != null) {
|
|
||||||
this.mData = data;
|
|
||||||
|
|
||||||
// add data to extended ArrayAdapter
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
|
||||||
addAll(data);
|
|
||||||
} else {
|
|
||||||
for (ImportKeysListEntry entry : data) {
|
|
||||||
add(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearData() {
|
||||||
|
mData = null;
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(List<ImportKeysListEntry> data) {
|
||||||
|
this.mData = data;
|
||||||
|
}
|
||||||
|
|
||||||
public List<ImportKeysListEntry> getData() {
|
public List<ImportKeysListEntry> getData() {
|
||||||
return mData;
|
return mData;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method returns a list of all selected entries, with public keys sorted
|
/**
|
||||||
|
* This method returns a list of all selected entries, with public keys sorted
|
||||||
* before secret keys, see ImportOperation for specifics.
|
* before secret keys, see ImportOperation for specifics.
|
||||||
|
*
|
||||||
* @see ImportOperation
|
* @see ImportOperation
|
||||||
*/
|
*/
|
||||||
public ArrayList<ImportKeysListEntry> getSelectedEntries() {
|
public ArrayList<ImportKeysListEntry> getSelectedEntries() {
|
||||||
@@ -115,30 +109,27 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasStableIds() {
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
return true;
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.import_keys_list_item, parent, false);
|
||||||
|
|
||||||
|
ViewHolder vh = new ViewHolder(v);
|
||||||
|
vh.mainUserId = (TextView) v.findViewById(R.id.import_item_user_id);
|
||||||
|
vh.mainUserIdRest = (TextView) v.findViewById(R.id.import_item_user_id_email);
|
||||||
|
vh.keyId = (TextView) v.findViewById(R.id.import_item_key_id);
|
||||||
|
vh.fingerprint = (TextView) v.findViewById(R.id.import_item_fingerprint);
|
||||||
|
vh.algorithm = (TextView) v.findViewById(R.id.import_item_algorithm);
|
||||||
|
vh.status = (ImageView) v.findViewById(R.id.import_item_status);
|
||||||
|
vh.userIdsDivider = v.findViewById(R.id.import_item_status_divider);
|
||||||
|
vh.userIdsList = (LinearLayout) v.findViewById(R.id.import_item_user_ids_list);
|
||||||
|
vh.checkBox = (CheckBox) v.findViewById(R.id.import_item_selected);
|
||||||
|
|
||||||
|
return vh;
|
||||||
}
|
}
|
||||||
|
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
@Override
|
||||||
ImportKeysListEntry entry = mData.get(position);
|
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||||
Highlighter highlighter = new Highlighter(mActivity, entry.getQuery());
|
final ImportKeysListEntry entry = mData.get(position);
|
||||||
ViewHolder holder;
|
Highlighter highlighter = new Highlighter(mContext, entry.getQuery());
|
||||||
if (convertView == null) {
|
|
||||||
holder = new ViewHolder();
|
|
||||||
convertView = mInflater.inflate(R.layout.import_keys_list_item, null);
|
|
||||||
holder.mainUserId = (TextView) convertView.findViewById(R.id.import_item_user_id);
|
|
||||||
holder.mainUserIdRest = (TextView) convertView.findViewById(R.id.import_item_user_id_email);
|
|
||||||
holder.keyId = (TextView) convertView.findViewById(R.id.import_item_key_id);
|
|
||||||
holder.fingerprint = (TextView) convertView.findViewById(R.id.import_item_fingerprint);
|
|
||||||
holder.algorithm = (TextView) convertView.findViewById(R.id.import_item_algorithm);
|
|
||||||
holder.status = (ImageView) convertView.findViewById(R.id.import_item_status);
|
|
||||||
holder.userIdsDivider = convertView.findViewById(R.id.import_item_status_divider);
|
|
||||||
holder.userIdsList = (LinearLayout) convertView.findViewById(R.id.import_item_user_ids_list);
|
|
||||||
holder.checkBox = (CheckBox) convertView.findViewById(R.id.import_item_selected);
|
|
||||||
convertView.setTag(holder);
|
|
||||||
} else {
|
|
||||||
holder = (ViewHolder) convertView.getTag();
|
|
||||||
}
|
|
||||||
|
|
||||||
// main user id
|
// main user id
|
||||||
String userId = entry.getUserIds().get(0);
|
String userId = entry.getUserIds().get(0);
|
||||||
@@ -148,8 +139,7 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
|||||||
if (userIdSplit.name != null) {
|
if (userIdSplit.name != null) {
|
||||||
// show red user id if it is a secret key
|
// show red user id if it is a secret key
|
||||||
if (entry.isSecretKey()) {
|
if (entry.isSecretKey()) {
|
||||||
holder.mainUserId.setText(mActivity.getString(R.string.secret_key)
|
holder.mainUserId.setText(mContext.getString(R.string.secret_key) + " " + userIdSplit.name);
|
||||||
+ " " + userIdSplit.name);
|
|
||||||
} else {
|
} else {
|
||||||
holder.mainUserId.setText(highlighter.highlight(userIdSplit.name));
|
holder.mainUserId.setText(highlighter.highlight(userIdSplit.name));
|
||||||
}
|
}
|
||||||
@@ -165,7 +155,7 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
|||||||
holder.mainUserIdRest.setVisibility(View.GONE);
|
holder.mainUserIdRest.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.keyId.setText(KeyFormattingUtils.beautifyKeyIdWithPrefix(getContext(), entry.getKeyIdHex()));
|
holder.keyId.setText(KeyFormattingUtils.beautifyKeyIdWithPrefix(mContext, entry.getKeyIdHex()));
|
||||||
|
|
||||||
// don't show full fingerprint on key import
|
// don't show full fingerprint on key import
|
||||||
holder.fingerprint.setVisibility(View.GONE);
|
holder.fingerprint.setVisibility(View.GONE);
|
||||||
@@ -178,9 +168,9 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (entry.isRevoked()) {
|
if (entry.isRevoked()) {
|
||||||
KeyFormattingUtils.setStatusImage(getContext(), holder.status, null, State.REVOKED, R.color.key_flag_gray);
|
KeyFormattingUtils.setStatusImage(mContext, holder.status, null, State.REVOKED, R.color.key_flag_gray);
|
||||||
} else if (entry.isExpired()) {
|
} else if (entry.isExpired()) {
|
||||||
KeyFormattingUtils.setStatusImage(getContext(), holder.status, null, State.EXPIRED, R.color.key_flag_gray);
|
KeyFormattingUtils.setStatusImage(mContext, holder.status, null, State.EXPIRED, R.color.key_flag_gray);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entry.isRevoked() || entry.isExpired()) {
|
if (entry.isRevoked() || entry.isExpired()) {
|
||||||
@@ -189,9 +179,9 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
|||||||
// no more space for algorithm display
|
// no more space for algorithm display
|
||||||
holder.algorithm.setVisibility(View.GONE);
|
holder.algorithm.setVisibility(View.GONE);
|
||||||
|
|
||||||
holder.mainUserId.setTextColor(getContext().getResources().getColor(R.color.key_flag_gray));
|
holder.mainUserId.setTextColor(mContext.getResources().getColor(R.color.key_flag_gray));
|
||||||
holder.mainUserIdRest.setTextColor(getContext().getResources().getColor(R.color.key_flag_gray));
|
holder.mainUserIdRest.setTextColor(mContext.getResources().getColor(R.color.key_flag_gray));
|
||||||
holder.keyId.setTextColor(getContext().getResources().getColor(R.color.key_flag_gray));
|
holder.keyId.setTextColor(mContext.getResources().getColor(R.color.key_flag_gray));
|
||||||
} else {
|
} else {
|
||||||
holder.status.setVisibility(View.GONE);
|
holder.status.setVisibility(View.GONE);
|
||||||
holder.algorithm.setVisibility(View.VISIBLE);
|
holder.algorithm.setVisibility(View.VISIBLE);
|
||||||
@@ -199,11 +189,11 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
|||||||
if (entry.isSecretKey()) {
|
if (entry.isSecretKey()) {
|
||||||
holder.mainUserId.setTextColor(Color.RED);
|
holder.mainUserId.setTextColor(Color.RED);
|
||||||
} else {
|
} else {
|
||||||
holder.mainUserId.setTextColor(FormattingUtils.getColorFromAttr(mActivity, R.attr.colorText));
|
holder.mainUserId.setTextColor(FormattingUtils.getColorFromAttr(mContext, R.attr.colorText));
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.mainUserIdRest.setTextColor(FormattingUtils.getColorFromAttr(mActivity, R.attr.colorText));
|
holder.mainUserIdRest.setTextColor(FormattingUtils.getColorFromAttr(mContext, R.attr.colorText));
|
||||||
holder.keyId.setTextColor(FormattingUtils.getColorFromAttr(mActivity, R.attr.colorText));
|
holder.keyId.setTextColor(FormattingUtils.getColorFromAttr(mContext, R.attr.colorText));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entry.getUserIds().size() == 1) {
|
if (entry.getUserIds().size() == 1) {
|
||||||
@@ -237,31 +227,33 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
|||||||
String cUserId = pair.getKey();
|
String cUserId = pair.getKey();
|
||||||
HashSet<String> cEmails = pair.getValue();
|
HashSet<String> cEmails = pair.getValue();
|
||||||
|
|
||||||
TextView uidView = (TextView) mInflater.inflate(
|
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||||
|
|
||||||
|
TextView uidView = (TextView) inflater.inflate(
|
||||||
R.layout.import_keys_list_entry_user_id, null);
|
R.layout.import_keys_list_entry_user_id, null);
|
||||||
uidView.setText(highlighter.highlight(cUserId));
|
uidView.setText(highlighter.highlight(cUserId));
|
||||||
uidView.setPadding(0, 0, FormattingUtils.dpToPx(getContext(), 8), 0);
|
uidView.setPadding(0, 0, FormattingUtils.dpToPx(mContext, 8), 0);
|
||||||
|
|
||||||
if (entry.isRevoked() || entry.isExpired()) {
|
if (entry.isRevoked() || entry.isExpired()) {
|
||||||
uidView.setTextColor(getContext().getResources().getColor(R.color.key_flag_gray));
|
uidView.setTextColor(mContext.getResources().getColor(R.color.key_flag_gray));
|
||||||
} else {
|
} else {
|
||||||
uidView.setTextColor(FormattingUtils.getColorFromAttr(getContext(), R.attr.colorText));
|
uidView.setTextColor(FormattingUtils.getColorFromAttr(mContext, R.attr.colorText));
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.userIdsList.addView(uidView);
|
holder.userIdsList.addView(uidView);
|
||||||
|
|
||||||
for (String email : cEmails) {
|
for (String email : cEmails) {
|
||||||
TextView emailView = (TextView) mInflater.inflate(
|
TextView emailView = (TextView) inflater.inflate(
|
||||||
R.layout.import_keys_list_entry_user_id, null);
|
R.layout.import_keys_list_entry_user_id, null);
|
||||||
emailView.setPadding(
|
emailView.setPadding(
|
||||||
FormattingUtils.dpToPx(getContext(), 16), 0,
|
FormattingUtils.dpToPx(mContext, 16), 0,
|
||||||
FormattingUtils.dpToPx(getContext(), 8), 0);
|
FormattingUtils.dpToPx(mContext, 8), 0);
|
||||||
emailView.setText(highlighter.highlight(email));
|
emailView.setText(highlighter.highlight(email));
|
||||||
|
|
||||||
if (entry.isRevoked() || entry.isExpired()) {
|
if (entry.isRevoked() || entry.isExpired()) {
|
||||||
emailView.setTextColor(getContext().getResources().getColor(R.color.key_flag_gray));
|
emailView.setTextColor(mContext.getResources().getColor(R.color.key_flag_gray));
|
||||||
} else {
|
} else {
|
||||||
emailView.setTextColor(FormattingUtils.getColorFromAttr(getContext(), R.attr.colorText));
|
emailView.setTextColor(FormattingUtils.getColorFromAttr(mContext, R.attr.colorText));
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.userIdsList.addView(emailView);
|
holder.userIdsList.addView(emailView);
|
||||||
@@ -270,8 +262,19 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
holder.checkBox.setChecked(entry.isSelected());
|
holder.checkBox.setChecked(entry.isSelected());
|
||||||
|
holder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
|
if (!mNonInteractive) {
|
||||||
|
entry.setSelected(isChecked);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return convertView;
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return mData != null ? mData.size() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/progress_view"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<android.support.v7.widget.RecyclerView
|
||||||
|
android:id="@+id/recycler_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:scrollbars="vertical"
|
||||||
|
android:visibility="gone" />
|
||||||
|
</FrameLayout>
|
||||||
@@ -1,26 +1,21 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:custom="http://schemas.android.com/apk/res-auto"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:singleLine="true"
|
android:paddingBottom="4dp"
|
||||||
android:paddingLeft="8dp"
|
android:paddingLeft="8dp"
|
||||||
android:paddingRight="16dp"
|
android:paddingRight="16dp"
|
||||||
android:paddingTop="4dp"
|
android:paddingTop="4dp"
|
||||||
android:paddingBottom="4dp">
|
android:singleLine="true">
|
||||||
|
|
||||||
<CheckBox
|
<CheckBox
|
||||||
android:id="@+id/import_item_selected"
|
android:id="@+id/import_item_selected"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:paddingRight="8dp"
|
|
||||||
android:paddingTop="2dp"
|
|
||||||
android:gravity="top|center"
|
android:gravity="top|center"
|
||||||
android:clickable="false"
|
android:paddingRight="8dp"
|
||||||
android:focusable="false"
|
android:paddingTop="2dp" />
|
||||||
android:focusableInTouchMode="false" />
|
|
||||||
<!-- focusable and clickable MUST be false to handle click and longClick in ListView Activity -->
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -73,8 +68,8 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:src="@drawable/status_signature_revoked_cutout_24dp"
|
android:padding="16dp"
|
||||||
android:padding="16dp" />
|
android:src="@drawable/status_signature_revoked_cutout_24dp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/import_item_algorithm"
|
android:id="@+id/import_item_algorithm"
|
||||||
@@ -90,10 +85,10 @@
|
|||||||
android:id="@+id/import_item_status_divider"
|
android:id="@+id/import_item_status_divider"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="1dip"
|
android:layout_height="1dip"
|
||||||
android:gravity="right"
|
|
||||||
android:layout_marginBottom="2dp"
|
android:layout_marginBottom="2dp"
|
||||||
android:layout_marginTop="2dp"
|
android:layout_marginTop="2dp"
|
||||||
android:background="?android:attr/listDivider" />
|
android:background="?android:attr/listDivider"
|
||||||
|
android:gravity="right" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/import_item_user_ids_list"
|
android:id="@+id/import_item_user_ids_list"
|
||||||
@@ -106,8 +101,8 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="0000 0000 0000 0000 0000\n0000 0000 0000 0000 0000"
|
android:text="0000 0000 0000 0000 0000\n0000 0000 0000 0000 0000"
|
||||||
android:typeface="monospace"
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
android:typeface="monospace" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user