diff options
author | mar-v-in <github@rvin.mooo.com> | 2014-07-31 23:19:01 +0200 |
---|---|---|
committer | mar-v-in <github@rvin.mooo.com> | 2014-07-31 23:19:01 +0200 |
commit | eae7c711a3f588a24ef621a8b82bcd793bcb7e70 (patch) | |
tree | 6c1017380b9234a193cfc6c6460ebfd44923837d /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java | |
parent | 0c7eea225b7c04549e92c8c7729bf0e7a04aa5c7 (diff) | |
parent | 50aea621ba4de844cf6eee077d1f5b14d0247f14 (diff) | |
download | open-keychain-eae7c711a3f588a24ef621a8b82bcd793bcb7e70.tar.gz open-keychain-eae7c711a3f588a24ef621a8b82bcd793bcb7e70.tar.bz2 open-keychain-eae7c711a3f588a24ef621a8b82bcd793bcb7e70.zip |
Merge branch 'master' into improve-file-more
Conflicts:
.gitmodules
OpenKeychain/build.gradle
OpenKeychain/src/main/AndroidManifest.xml
OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java
OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFileFragment.java
OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptMessageFragment.java
OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptAsymmetricFragment.java
OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFileFragment.java
OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptMessageFragment.java
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java | 138 |
1 files changed, 128 insertions, 10 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java index 6bf6b655d..c27b3f6da 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java @@ -1,14 +1,27 @@ package org.sufficientlysecure.keychain.service; +import android.app.Activity; +import android.content.Intent; import android.os.Parcel; import android.os.Parcelable; +import android.view.View; + +import com.github.johnpersano.supertoasts.SuperCardToast; +import com.github.johnpersano.supertoasts.SuperToast; +import com.github.johnpersano.supertoasts.util.OnClickWrapper; +import com.github.johnpersano.supertoasts.util.Style; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.ui.LogDisplayActivity; +import org.sufficientlysecure.keychain.ui.LogDisplayFragment; import org.sufficientlysecure.keychain.util.IterableIterator; import org.sufficientlysecure.keychain.util.Log; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; /** Represent the result of an operation. * @@ -21,6 +34,9 @@ import java.util.ArrayList; * */ public class OperationResultParcel implements Parcelable { + + public static final String EXTRA_RESULT = "operation_result"; + /** Holds the overall result, the number specifying varying degrees of success. The first bit * is 0 on overall success, 1 on overall failure. All other bits may be used for more specific * conditions. */ @@ -67,9 +83,7 @@ public class OperationResultParcel implements Parcelable { mType = type; mParameters = parameters; mIndent = indent; - } - public LogEntryParcel(LogLevel level, LogType type, Object... parameters) { - this(level, type, 0, parameters); + Log.v(Constants.TAG, "log: " + this.toString()); } public LogEntryParcel(Parcel source) { @@ -102,6 +116,77 @@ public class OperationResultParcel implements Parcelable { } }; + @Override + public String toString() { + return "LogEntryParcel{" + + "mLevel=" + mLevel + + ", mType=" + mType + + ", mParameters=" + Arrays.toString(mParameters) + + ", mIndent=" + mIndent + + '}'; + } + } + + public SuperCardToast createNotify(final Activity activity) { + + int resultType = getResult(); + + String str; + int duration, color; + + // Not an overall failure + if ((resultType & OperationResultParcel.RESULT_ERROR) == 0) { + + if (getLog().containsWarnings()) { + duration = 0; + color = Style.ORANGE; + } else { + duration = SuperToast.Duration.LONG; + color = Style.GREEN; + } + + str = "operation succeeded!"; + // str = activity.getString(R.string.import_error); + + } else { + + duration = 0; + color = Style.RED; + + str = "operation failed"; + // str = activity.getString(R.string.import_error); + + } + + boolean button = getLog() != null && !getLog().isEmpty(); + SuperCardToast toast = new SuperCardToast(activity, + button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD, + Style.getStyle(color, SuperToast.Animations.POPUP)); + toast.setText(str); + toast.setDuration(duration); + toast.setIndeterminate(duration == 0); + toast.setSwipeToDismiss(true); + // If we have a log and it's non-empty, show a View Log button + if (button) { + toast.setButtonIcon(R.drawable.ic_action_view_as_list, + activity.getResources().getString(R.string.view_log)); + toast.setButtonTextColor(activity.getResources().getColor(R.color.black)); + toast.setTextColor(activity.getResources().getColor(R.color.black)); + toast.setOnClickWrapper(new OnClickWrapper("supercardtoast", + new SuperToast.OnClickListener() { + @Override + public void onClick(View view, Parcelable token) { + Intent intent = new Intent( + activity, LogDisplayActivity.class); + intent.putExtra(LogDisplayFragment.EXTRA_RESULT, OperationResultParcel.this); + activity.startActivity(intent); + } + } + )); + } + + return toast; + } /** This is an enum of all possible log events. @@ -123,6 +208,8 @@ public class OperationResultParcel implements Parcelable { */ public static enum LogType { + INTERNAL_ERROR (R.string.internal_error), + // import public MSG_IP(R.string.msg_ip), MSG_IP_APPLY_BATCH (R.string.msg_ip_apply_batch), @@ -193,6 +280,7 @@ public class OperationResultParcel implements Parcelable { MSG_KC_REVOKE_BAD_LOCAL (R.string.msg_kc_revoke_bad_local), MSG_KC_REVOKE_BAD_TIME (R.string.msg_kc_revoke_bad_time), MSG_KC_REVOKE_BAD_TYPE (R.string.msg_kc_revoke_bad_type), + MSG_KC_REVOKE_BAD_TYPE_UID (R.string.msg_kc_revoke_bad_type_uid), MSG_KC_REVOKE_BAD (R.string.msg_kc_revoke_bad), MSG_KC_REVOKE_DUP (R.string.msg_kc_revoke_dup), MSG_KC_SUB (R.string.msg_kc_sub), @@ -224,6 +312,7 @@ public class OperationResultParcel implements Parcelable { MSG_KC_UID_NO_CERT (R.string.msg_kc_uid_no_cert), MSG_KC_UID_REVOKE_DUP (R.string.msg_kc_uid_revoke_dup), MSG_KC_UID_REVOKE_OLD (R.string.msg_kc_uid_revoke_old), + MSG_KC_UID_REMOVE (R.string.msg_kc_uid_remove), // keyring consolidation @@ -233,9 +322,17 @@ public class OperationResultParcel implements Parcelable { MSG_MG_HETEROGENEOUS (R.string.msg_mg_heterogeneous), MSG_MG_NEW_SUBKEY (R.string.msg_mg_new_subkey), MSG_MG_FOUND_NEW (R.string.msg_mg_found_new), + MSG_MG_UNCHANGED (R.string.msg_mg_unchanged), // secret key create - MSG_CR_ERROR_NO_MASTER (R.string.msg_mr), + MSG_CR (R.string.msg_cr), + MSG_CR_ERROR_NO_MASTER (R.string.msg_cr_error_no_master), + MSG_CR_ERROR_NO_USER_ID (R.string.msg_cr_error_no_user_id), + MSG_CR_ERROR_NO_CERTIFY (R.string.msg_cr_error_no_certify), + MSG_CR_ERROR_KEYSIZE_512 (R.string.msg_cr_error_keysize_512), + MSG_CR_ERROR_UNKNOWN_ALGO (R.string.msg_cr_error_unknown_algo), + MSG_CR_ERROR_INTERNAL_PGP (R.string.msg_cr_error_internal_pgp), + MSG_CR_ERROR_MASTER_ELGAMAL (R.string.msg_cr_error_master_elgamal), // secret key modify MSG_MF (R.string.msg_mr), @@ -243,10 +340,13 @@ public class OperationResultParcel implements Parcelable { MSG_MF_ERROR_FINGERPRINT (R.string.msg_mf_error_fingerprint), MSG_MF_ERROR_KEYID (R.string.msg_mf_error_keyid), MSG_MF_ERROR_INTEGRITY (R.string.msg_mf_error_integrity), + MSG_MF_ERROR_NOEXIST_PRIMARY (R.string.msg_mf_error_noexist_primary), MSG_MF_ERROR_REVOKED_PRIMARY (R.string.msg_mf_error_revoked_primary), MSG_MF_ERROR_PGP (R.string.msg_mf_error_pgp), MSG_MF_ERROR_SIG (R.string.msg_mf_error_sig), MSG_MF_PASSPHRASE (R.string.msg_mf_passphrase), + MSG_MF_PRIMARY_REPLACE_OLD (R.string.msg_mf_primary_replace_old), + MSG_MF_PRIMARY_NEW (R.string.msg_mf_primary_new), MSG_MF_SUBKEY_CHANGE (R.string.msg_mf_subkey_change), MSG_MF_SUBKEY_MISSING (R.string.msg_mf_subkey_missing), MSG_MF_SUBKEY_NEW_ID (R.string.msg_mf_subkey_new_id), @@ -257,6 +357,7 @@ public class OperationResultParcel implements Parcelable { MSG_MF_UID_ADD (R.string.msg_mf_uid_add), MSG_MF_UID_PRIMARY (R.string.msg_mf_uid_primary), MSG_MF_UID_REVOKE (R.string.msg_mf_uid_revoke), + MSG_MF_UID_ERROR_EMPTY (R.string.msg_mf_uid_error_empty), MSG_MF_UNLOCK_ERROR (R.string.msg_mf_unlock_error), MSG_MF_UNLOCK (R.string.msg_mf_unlock), ; @@ -288,7 +389,7 @@ public class OperationResultParcel implements Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(mResult); - dest.writeTypedList(mLog); + dest.writeTypedList(mLog.toList()); } public static final Creator<OperationResultParcel> CREATOR = new Creator<OperationResultParcel>() { @@ -301,20 +402,21 @@ public class OperationResultParcel implements Parcelable { } }; - public static class OperationLog extends ArrayList<LogEntryParcel> { + public static class OperationLog implements Iterable<LogEntryParcel> { + + private final List<LogEntryParcel> mParcels = new ArrayList<LogEntryParcel>(); /// Simple convenience method public void add(LogLevel level, LogType type, int indent, Object... parameters) { - Log.d(Constants.TAG, type.toString()); - add(new OperationResultParcel.LogEntryParcel(level, type, indent, parameters)); + mParcels.add(new OperationResultParcel.LogEntryParcel(level, type, indent, parameters)); } public void add(LogLevel level, LogType type, int indent) { - add(new OperationResultParcel.LogEntryParcel(level, type, indent, (Object[]) null)); + mParcels.add(new OperationResultParcel.LogEntryParcel(level, type, indent, (Object[]) null)); } public boolean containsWarnings() { - for(LogEntryParcel entry : new IterableIterator<LogEntryParcel>(iterator())) { + for(LogEntryParcel entry : new IterableIterator<LogEntryParcel>(mParcels.iterator())) { if (entry.mLevel == LogLevel.WARN || entry.mLevel == LogLevel.ERROR) { return true; } @@ -322,6 +424,22 @@ public class OperationResultParcel implements Parcelable { return false; } + public void addAll(List<LogEntryParcel> parcels) { + mParcels.addAll(parcels); + } + + public List<LogEntryParcel> toList() { + return mParcels; + } + + public boolean isEmpty() { + return mParcels.isEmpty(); + } + + @Override + public Iterator<LogEntryParcel> iterator() { + return mParcels.iterator(); + } } } |