aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2014-06-10 16:24:04 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2014-06-10 16:24:04 +0200
commitf38556cab1215f1e49f2e6c2e90627a4c00b02d5 (patch)
treec30678966b139ffa7b0a464ee82bc970e4648d57 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java
parente41e6ea0deec06703c5b9c80e429aff8ab110534 (diff)
downloadopen-keychain-f38556cab1215f1e49f2e6c2e90627a4c00b02d5.tar.gz
open-keychain-f38556cab1215f1e49f2e6c2e90627a4c00b02d5.tar.bz2
open-keychain-f38556cab1215f1e49f2e6c2e90627a4c00b02d5.zip
import-log: switch to flags instead of statuses for result int
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java91
1 files changed, 45 insertions, 46 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java
index 61d7e7949..3ff4f9887 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java
@@ -378,55 +378,54 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O
final ImportResult result =
returnData.<ImportResult>getParcelable(KeychainIntentService.RESULT);
- String str = "";
- boolean hasWarnings = result.getLog().containsWarnings();
- int duration = 0, color = hasWarnings ? Style.ORANGE : Style.GREEN;
- String withWarnings = hasWarnings
- ? getResources().getString(R.string.with_warnings) : "";
-
- switch(result.getResult()) {
- case ImportResult.RESULT_OK_NEWKEYS:
- if (!hasWarnings) {
- duration = SuperToast.Duration.LONG;
- }
- str = getResources().getQuantityString(
- R.plurals.keys_added, result.mNewKeys, result.mNewKeys, withWarnings);
- break;
+ int resultType = result.getResult();
- case ImportResult.RESULT_OK_UPDATED:
- if (!hasWarnings) {
- duration = SuperToast.Duration.LONG;
- }
- str = getResources().getQuantityString(
- R.plurals.keys_updated, result.mNewKeys, result.mNewKeys, withWarnings);
- break;
+ String str;
+ int duration, color;
- case ImportResult.RESULT_OK_BOTHKEYS:
- if (!hasWarnings) {
- duration = SuperToast.Duration.LONG;
- }
- str = getResources().getQuantityString(
- R.plurals.keys_added_and_updated_1, result.mNewKeys, result.mNewKeys);
- str += getResources().getQuantityString(
- R.plurals.keys_added_and_updated_2, result.mUpdatedKeys, result.mUpdatedKeys, withWarnings);
- break;
+ // Not an overall failure
+ if ((resultType & ImportResult.RESULT_ERROR) == 0) {
+ String withWarnings;
- case ImportResult.RESULT_PARTIAL_WITH_ERRORS:
- str = "partial with errors";
+ // Any warnings?
+ if ((resultType & ImportResult.RESULT_WITH_WARNINGS) > 0) {
+ duration = 0;
color = Style.ORANGE;
- break;
-
- case ImportResult.RESULT_FAIL_ERROR:
- str = "fail error";
- color = Style.RED;
- break;
-
- case ImportResult.RESULT_FAIL_NOTHING:
- str = getString(R.string.no_keys_added_or_updated);
+ withWarnings = getResources().getString(R.string.import_with_warnings);
+ } else {
+ duration = SuperToast.Duration.LONG;
+ color = Style.GREEN;
+ withWarnings = "";
+ }
+
+ // New and updated keys
+ if (result.isOkBoth()) {
+ str = getResources().getQuantityString(
+ R.plurals.import_keys_added_and_updated_1, result.mNewKeys, result.mNewKeys);
+ str += getResources().getQuantityString(
+ R.plurals.import_keys_added_and_updated_2, result.mUpdatedKeys, result.mUpdatedKeys, withWarnings);
+ } else if (result.isOkNew()) {
+ str = getResources().getQuantityString(
+ R.plurals.import_keys_added, result.mNewKeys, result.mNewKeys, withWarnings);
+ } else if (result.isOkUpdated()) {
+ str = getResources().getQuantityString(
+ R.plurals.import_keys_updated, result.mUpdatedKeys, result.mUpdatedKeys, withWarnings);
+ } else {
+ duration = 0;
color = Style.RED;
- break;
-
+ str = "internal error";
+ }
+
+ } else {
+ duration = 0;
+ color = Style.RED;
+ if (result.isFailNothing()) {
+ str = getString(R.string.import_error_nothing);
+ } else {
+ str = getString(R.string.import_error);
+ }
}
+
SuperCardToast toast = new SuperCardToast(ImportKeysActivity.this,
SuperToast.Type.BUTTON, Style.getStyle(color, SuperToast.Animations.POPUP));
toast.setText(str);
@@ -434,9 +433,9 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O
toast.setIndeterminate(duration == 0);
toast.setSwipeToDismiss(true);
toast.setButtonIcon(R.drawable.ic_action_view_as_list,
- getResources().getString(R.string.view_log));
- toast.setButtonTextColor(R.color.emphasis_dark);
- toast.setTextColor(R.color.emphasis_dark);
+ getResources().getString(R.string.import_view_log));
+ toast.setButtonTextColor(getResources().getColor(R.color.black));
+ toast.setTextColor(getResources().getColor(R.color.black));
toast.setOnClickWrapper(new OnClickWrapper("supercardtoast",
new SuperToast.OnClickListener() {
@Override