mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 19:22:14 -05:00
Reworked ImportKeysListFragment to handel exceptions, ImportKeyListLoader is temporarily disabled
This commit is contained in:
parent
9bbb286c5e
commit
5d1f61bff7
@ -27,6 +27,7 @@ import java.util.List;
|
|||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.helper.Preferences;
|
import org.sufficientlysecure.keychain.helper.Preferences;
|
||||||
|
import org.sufficientlysecure.keychain.ui.adapter.AsyncTaskResultWrapper;
|
||||||
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysAdapter;
|
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysAdapter;
|
||||||
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListEntry;
|
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListEntry;
|
||||||
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListLoader;
|
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListLoader;
|
||||||
@ -45,7 +46,7 @@ import android.widget.ListView;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class ImportKeysListFragment extends ListFragment implements
|
public class ImportKeysListFragment extends ListFragment implements
|
||||||
LoaderManager.LoaderCallbacks<List<ImportKeysListEntry>> {
|
LoaderManager.LoaderCallbacks<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> {
|
||||||
private static final String ARG_DATA_URI = "uri";
|
private static final String ARG_DATA_URI = "uri";
|
||||||
private static final String ARG_BYTES = "bytes";
|
private static final String ARG_BYTES = "bytes";
|
||||||
private static final String ARG_SERVER_QUERY = "query";
|
private static final String ARG_SERVER_QUERY = "query";
|
||||||
@ -181,12 +182,13 @@ public class ImportKeysListFragment extends ListFragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Loader<List<ImportKeysListEntry>> onCreateLoader(int id, Bundle args) {
|
public Loader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> onCreateLoader(int id, Bundle args) {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case LOADER_ID_BYTES: {
|
case LOADER_ID_BYTES: {
|
||||||
InputData inputData = getInputData(mKeyBytes, mDataUri);
|
InputData inputData = getInputData(mKeyBytes, mDataUri);
|
||||||
|
|
||||||
return new ImportKeysListLoader(mActivity, inputData);
|
//TODO Rewrite ImportKeysListLoader
|
||||||
|
//return new ImportKeysListLoader(mActivity, inputData);
|
||||||
}
|
}
|
||||||
case LOADER_ID_SERVER_QUERY: {
|
case LOADER_ID_SERVER_QUERY: {
|
||||||
return new ImportKeysListServerLoader(getActivity(), mServerQuery, mKeyServer);
|
return new ImportKeysListServerLoader(getActivity(), mServerQuery, mKeyServer);
|
||||||
@ -198,15 +200,15 @@ public class ImportKeysListFragment extends ListFragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadFinished(Loader<List<ImportKeysListEntry>> loader,
|
public void onLoadFinished(Loader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> loader,
|
||||||
List<ImportKeysListEntry> data) {
|
AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> data) {
|
||||||
// Swap the new cursor in. (The framework will take care of closing the
|
// Swap the new cursor in. (The framework will take care of closing the
|
||||||
// old cursor once we return.)
|
// old cursor once we return.)
|
||||||
|
|
||||||
Log.d(Constants.TAG, "data: " + data);
|
Log.d(Constants.TAG, "data: " + data.getResult());
|
||||||
|
|
||||||
// swap in the real data!
|
// swap in the real data!
|
||||||
mAdapter.setData(data);
|
mAdapter.setData(data.getResult());
|
||||||
mAdapter.notifyDataSetChanged();
|
mAdapter.notifyDataSetChanged();
|
||||||
|
|
||||||
setListAdapter(mAdapter);
|
setListAdapter(mAdapter);
|
||||||
@ -222,11 +224,16 @@ public class ImportKeysListFragment extends ListFragment implements
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case LOADER_ID_SERVER_QUERY:
|
case LOADER_ID_SERVER_QUERY:
|
||||||
Toast.makeText(
|
|
||||||
getActivity(), getResources().getQuantityString(R.plurals.keys_found,
|
if(data.getError() == null){
|
||||||
mAdapter.getCount(), mAdapter.getCount()),
|
Toast.makeText(
|
||||||
Toast.LENGTH_SHORT
|
getActivity(), getResources().getQuantityString(R.plurals.keys_found,
|
||||||
).show();
|
mAdapter.getCount(), mAdapter.getCount()),
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show();
|
||||||
|
} else {
|
||||||
|
Toast.makeText(getActivity(), "Server connection timed out!", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -235,7 +242,7 @@ public class ImportKeysListFragment extends ListFragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoaderReset(Loader<List<ImportKeysListEntry>> loader) {
|
public void onLoaderReset(Loader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> loader) {
|
||||||
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.
|
||||||
|
@ -28,13 +28,15 @@ import org.sufficientlysecure.keychain.util.Log;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ImportKeysListServerLoader extends AsyncTaskLoader<List<ImportKeysListEntry>> {
|
public class ImportKeysListServerLoader extends AsyncTaskLoader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> {
|
||||||
Context mContext;
|
Context mContext;
|
||||||
|
|
||||||
String mServerQuery;
|
String mServerQuery;
|
||||||
String mKeyServer;
|
String mKeyServer;
|
||||||
|
|
||||||
ArrayList<ImportKeysListEntry> data = new ArrayList<ImportKeysListEntry>();
|
//ArrayList<ImportKeysListEntry> data = new ArrayList<ImportKeysListEntry>();
|
||||||
|
ArrayList<ImportKeysListEntry> entryList = new ArrayList<ImportKeysListEntry>();
|
||||||
|
AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> entryListWrapper;
|
||||||
|
|
||||||
public ImportKeysListServerLoader(Context context, String serverQuery, String keyServer) {
|
public ImportKeysListServerLoader(Context context, String serverQuery, String keyServer) {
|
||||||
super(context);
|
super(context);
|
||||||
@ -44,15 +46,16 @@ public class ImportKeysListServerLoader extends AsyncTaskLoader<List<ImportKeysL
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ImportKeysListEntry> loadInBackground() {
|
public AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> loadInBackground() {
|
||||||
if (mServerQuery == null) {
|
if (mServerQuery == null) {
|
||||||
Log.e(Constants.TAG, "mServerQuery is null!");
|
Log.e(Constants.TAG, "mServerQuery is null!");
|
||||||
return data;
|
entryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(entryList, null);
|
||||||
|
return entryListWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
queryServer(mServerQuery, mKeyServer);
|
queryServer(mServerQuery, mKeyServer);
|
||||||
|
|
||||||
return data;
|
return entryListWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -74,7 +77,7 @@ public class ImportKeysListServerLoader extends AsyncTaskLoader<List<ImportKeysL
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deliverResult(List<ImportKeysListEntry> data) {
|
public void deliverResult(AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> data) {
|
||||||
super.deliverResult(data);
|
super.deliverResult(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,13 +90,17 @@ public class ImportKeysListServerLoader extends AsyncTaskLoader<List<ImportKeysL
|
|||||||
ArrayList<ImportKeysListEntry> searchResult = server.search(query);
|
ArrayList<ImportKeysListEntry> searchResult = server.search(query);
|
||||||
|
|
||||||
// add result to data
|
// add result to data
|
||||||
data.addAll(searchResult);
|
entryList.addAll(searchResult);
|
||||||
|
entryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(entryList, null);
|
||||||
} catch (KeyServer.InsufficientQuery e) {
|
} catch (KeyServer.InsufficientQuery e) {
|
||||||
Log.e(Constants.TAG, "InsufficientQuery", e);
|
Log.e(Constants.TAG, "InsufficientQuery", e);
|
||||||
|
entryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(entryList, e);
|
||||||
} catch (KeyServer.QueryException e) {
|
} catch (KeyServer.QueryException e) {
|
||||||
Log.e(Constants.TAG, "QueryException", e);
|
Log.e(Constants.TAG, "QueryException", e);
|
||||||
|
entryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(entryList, e);
|
||||||
} catch (KeyServer.TooManyResponses e) {
|
} catch (KeyServer.TooManyResponses e) {
|
||||||
Log.e(Constants.TAG, "TooManyResponses", e);
|
Log.e(Constants.TAG, "TooManyResponses", e);
|
||||||
|
entryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(entryList, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user