From 9843bafafdcec1721b5715440011e5f7b72ac583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ha=C3=9F?= Date: Mon, 3 Mar 2014 09:35:05 +0100 Subject: Added handler for FileHasNoContent exception, some clean up --- .../keychain/ui/ImportKeysListFragment.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'OpenPGP-Keychain/src') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java index 1118f0264..abc594b39 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java @@ -219,27 +219,34 @@ public class ImportKeysListFragment extends ListFragment implements } else { setListShownNoAnimation(true); } + + Exception error = data.getError(); + switch (loader.getId()) { case LOADER_ID_BYTES: + error = data.getError(); + + if(error instanceof ImportKeysListLoader.FileHasNoContent) { + AppMsg.makeText(getActivity(), R.string.error_import_file_no_content, + AppMsg.STYLE_ALERT).show(); + } break; case LOADER_ID_SERVER_QUERY: - Exception error = data.getError(); - - if(error == null){ + if(error == null) { AppMsg.makeText( getActivity(), getResources().getQuantityString(R.plurals.keys_found, mAdapter.getCount(), mAdapter.getCount()), AppMsg.STYLE_INFO ).show(); - } else if(error instanceof KeyServer.InsufficientQuery){ + } else if(error instanceof KeyServer.InsufficientQuery) { AppMsg.makeText(getActivity(), R.string.error_keyserver_insufficient_query, AppMsg.STYLE_ALERT).show(); - }else if(error instanceof KeyServer.QueryException){ + } else if(error instanceof KeyServer.QueryException) { AppMsg.makeText(getActivity(), R.string.error_keyserver_query, AppMsg.STYLE_ALERT).show(); - }else if(error instanceof KeyServer.TooManyResponses){ + } else if(error instanceof KeyServer.TooManyResponses) { AppMsg.makeText(getActivity(), R.string.error_keyserver_too_many_responses, AppMsg.STYLE_ALERT).show(); } -- cgit v1.2.3 From f484122c353aa66dbc1a3a776163eaa28d70e4d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ha=C3=9F?= Date: Mon, 3 Mar 2014 09:36:10 +0100 Subject: Added exception for empty files --- .../keychain/ui/adapter/ImportKeysListLoader.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'OpenPGP-Keychain/src') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java index 29e418db7..bc8e4d050 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java @@ -33,7 +33,14 @@ import org.sufficientlysecure.keychain.util.PositionAwareInputStream; import android.content.Context; import android.support.v4.content.AsyncTaskLoader; +import com.devspark.appmsg.AppMsg; + public class ImportKeysListLoader extends AsyncTaskLoader>> { + + public static class FileHasNoContent extends Exception { + + } + Context mContext; InputData mInputData; @@ -92,6 +99,9 @@ public class ImportKeysListLoader extends AsyncTaskLoader 0) { + isEmpty = false; InputStream in = PGPUtil.getDecoderStream(bufferedInput); PGPObjectFactory objectFactory = new PGPObjectFactory(in); @@ -120,7 +131,12 @@ public class ImportKeysListLoader extends AsyncTaskLoader>(data, new FileHasNoContent()); } } -- cgit v1.2.3 From 6362b2de94c43eca9562af832fa0cfa77d93fbe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ha=C3=9F?= Date: Mon, 3 Mar 2014 09:36:40 +0100 Subject: Added FileHasNoContent string --- OpenPGP-Keychain/src/main/res/values/strings.xml | 1 + 1 file changed, 1 insertion(+) (limited to 'OpenPGP-Keychain/src') diff --git a/OpenPGP-Keychain/src/main/res/values/strings.xml b/OpenPGP-Keychain/src/main/res/values/strings.xml index 91359701f..e8dc05f3b 100644 --- a/OpenPGP-Keychain/src/main/res/values/strings.xml +++ b/OpenPGP-Keychain/src/main/res/values/strings.xml @@ -289,6 +289,7 @@ Insufficient server query Querying keyserver failed Too many responses + File has no content Please delete it from the \'My Keys\' screen! Please delete them from the \'My Keys\' screen! -- cgit v1.2.3 From ec8a3469fff2718e47f6214f5364a13d84664967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ha=C3=9F?= Date: Mon, 3 Mar 2014 15:07:07 +0100 Subject: Little fixes --- .../java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java | 1 - .../sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'OpenPGP-Keychain/src') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java index abc594b39..009c26ce5 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java @@ -224,7 +224,6 @@ public class ImportKeysListFragment extends ListFragment implements switch (loader.getId()) { case LOADER_ID_BYTES: - error = data.getError(); if(error instanceof ImportKeysListLoader.FileHasNoContent) { AppMsg.makeText(getActivity(), R.string.error_import_file_no_content, diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java index bc8e4d050..19b17468b 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java @@ -131,7 +131,7 @@ public class ImportKeysListLoader extends AsyncTaskLoader Date: Mon, 3 Mar 2014 20:42:38 +0100 Subject: Added handling for other exceptions in the ImportListLoader. --- .../keychain/ui/ImportKeysListFragment.java | 9 ++++++++ .../keychain/ui/adapter/ImportKeysListLoader.java | 25 ++++++++++++++++++---- OpenPGP-Keychain/src/main/res/values/strings.xml | 5 +++++ 3 files changed, 35 insertions(+), 4 deletions(-) (limited to 'OpenPGP-Keychain/src') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java index 009c26ce5..06925e5fa 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java @@ -228,6 +228,15 @@ public class ImportKeysListFragment extends ListFragment implements if(error instanceof ImportKeysListLoader.FileHasNoContent) { AppMsg.makeText(getActivity(), R.string.error_import_file_no_content, AppMsg.STYLE_ALERT).show(); + } else if(error instanceof ImportKeysListLoader.NonPGPPart) { + AppMsg.makeText(getActivity(), + ((ImportKeysListLoader.NonPGPPart) error).getCount() + " " + getResources(). + getQuantityString(R.plurals.error_import_non_pgp_part, + ((ImportKeysListLoader.NonPGPPart) error).getCount()), + new AppMsg.Style(AppMsg.LENGTH_LONG, R.color.confirm)).show(); + } else { + AppMsg.makeText(getActivity(), R.string.error_generic_report_bug, + new AppMsg.Style(AppMsg.LENGTH_LONG, R.color.alert)).show(); } break; diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java index 19b17468b..98884689c 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java @@ -20,7 +20,6 @@ package org.sufficientlysecure.keychain.ui.adapter; import java.io.BufferedInputStream; import java.io.InputStream; import java.util.ArrayList; -import java.util.List; import org.spongycastle.openpgp.PGPKeyRing; import org.spongycastle.openpgp.PGPObjectFactory; @@ -33,14 +32,22 @@ import org.sufficientlysecure.keychain.util.PositionAwareInputStream; import android.content.Context; import android.support.v4.content.AsyncTaskLoader; -import com.devspark.appmsg.AppMsg; - public class ImportKeysListLoader extends AsyncTaskLoader>> { public static class FileHasNoContent extends Exception { } + public static class NonPGPPart extends Exception { + private int count; + public NonPGPPart(int count) { + this.count = count; + } + public int getCount() { + return count; + } + } + Context mContext; InputData mInputData; @@ -101,6 +108,7 @@ public class ImportKeysListLoader extends AsyncTaskLoader>(data, e); + nonPGPcounter = 0; } if(isEmpty) { Log.e(Constants.TAG, "File has no content!", new FileHasNoContent()); - entryListWrapper = new AsyncTaskResultWrapper>(data, new FileHasNoContent()); + entryListWrapper = new AsyncTaskResultWrapper> + (data, new FileHasNoContent()); + } + + if(nonPGPcounter > 0) { + entryListWrapper = new AsyncTaskResultWrapper> + (data, new NonPGPPart(nonPGPcounter)); } } diff --git a/OpenPGP-Keychain/src/main/res/values/strings.xml b/OpenPGP-Keychain/src/main/res/values/strings.xml index e8dc05f3b..14ed7c7da 100644 --- a/OpenPGP-Keychain/src/main/res/values/strings.xml +++ b/OpenPGP-Keychain/src/main/res/values/strings.xml @@ -290,10 +290,15 @@ Querying keyserver failed Too many responses File has no content + A generic error occurred, please create a new bug report for OpenKeychain. Please delete it from the \'My Keys\' screen! Please delete them from the \'My Keys\' screen! + + part of the loaded file is a valid OpenPGP object but not a OpenPGP key + parts of the loaded file are valid OpenPGP objects but not OpenPGP keys + done. -- cgit v1.2.3 From a12b67c538a1934a35c45fbed3569056a786df67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ha=C3=9F?= Date: Tue, 4 Mar 2014 13:56:46 +0100 Subject: Added exception is null option to display nothing if no error occured --- .../sufficientlysecure/keychain/ui/ImportKeysListFragment.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'OpenPGP-Keychain/src') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java index 06925e5fa..a6917d6f4 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java @@ -225,14 +225,16 @@ public class ImportKeysListFragment extends ListFragment implements switch (loader.getId()) { case LOADER_ID_BYTES: - if(error instanceof ImportKeysListLoader.FileHasNoContent) { + if(error == null){ + // No error + } else if(error instanceof ImportKeysListLoader.FileHasNoContent) { AppMsg.makeText(getActivity(), R.string.error_import_file_no_content, AppMsg.STYLE_ALERT).show(); - } else if(error instanceof ImportKeysListLoader.NonPGPPart) { + } else if(error instanceof ImportKeysListLoader.NonPgpPart) { AppMsg.makeText(getActivity(), - ((ImportKeysListLoader.NonPGPPart) error).getCount() + " " + getResources(). + ((ImportKeysListLoader.NonPgpPart) error).getCount() + " " + getResources(). getQuantityString(R.plurals.error_import_non_pgp_part, - ((ImportKeysListLoader.NonPGPPart) error).getCount()), + ((ImportKeysListLoader.NonPgpPart) error).getCount()), new AppMsg.Style(AppMsg.LENGTH_LONG, R.color.confirm)).show(); } else { AppMsg.makeText(getActivity(), R.string.error_generic_report_bug, -- cgit v1.2.3 From 106027a7cd43001a2f9e620ee13ef60d39074c41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ha=C3=9F?= Date: Tue, 4 Mar 2014 13:58:26 +0100 Subject: Fixed some naming --- .../keychain/ui/adapter/ImportKeysListLoader.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'OpenPGP-Keychain/src') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java index 98884689c..7ca7bc998 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java @@ -38,9 +38,9 @@ public class ImportKeysListLoader extends AsyncTaskLoader>(data, e); - nonPGPcounter = 0; + nonPgpCounter = 0; } if(isEmpty) { @@ -151,9 +151,9 @@ public class ImportKeysListLoader extends AsyncTaskLoader 0) { + if(nonPgpCounter > 0) { entryListWrapper = new AsyncTaskResultWrapper> - (data, new NonPGPPart(nonPGPcounter)); + (data, new NonPgpPart(nonPgpCounter)); } } -- cgit v1.2.3