work on OperationResultParcel
This commit is contained in:
@@ -55,10 +55,10 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainDatabase;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.service.results.OperationResultParcel;
|
||||
import org.sufficientlysecure.keychain.service.results.OperationResultParcel.LogLevel;
|
||||
import org.sufficientlysecure.keychain.service.results.OperationResultParcel.LogType;
|
||||
import org.sufficientlysecure.keychain.service.results.OperationResultParcel.OperationLog;
|
||||
import org.sufficientlysecure.keychain.service.results.OperationResult;
|
||||
import org.sufficientlysecure.keychain.service.results.OperationResult.LogLevel;
|
||||
import org.sufficientlysecure.keychain.service.results.OperationResult.LogType;
|
||||
import org.sufficientlysecure.keychain.service.results.OperationResult.OperationLog;
|
||||
import org.sufficientlysecure.keychain.service.results.ConsolidateResult;
|
||||
import org.sufficientlysecure.keychain.service.results.EditKeyResult;
|
||||
import org.sufficientlysecure.keychain.service.results.ImportKeyResult;
|
||||
@@ -813,9 +813,9 @@ public class KeychainIntentService extends IntentService implements Progressable
|
||||
}
|
||||
}
|
||||
|
||||
private void sendMessageToHandler(Integer arg1, OperationResultParcel data) {
|
||||
private void sendMessageToHandler(Integer arg1, OperationResult data) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable(OperationResultParcel.EXTRA_RESULT, data);
|
||||
bundle.putParcelable(OperationResult.EXTRA_RESULT, data);
|
||||
sendMessageToHandler(arg1, null, bundle);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
package org.sufficientlysecure.keychain.service.results;
|
||||
|
||||
public class ConsolidateResult extends OperationResultParcel {
|
||||
public class ConsolidateResult extends OperationResult {
|
||||
|
||||
public ConsolidateResult(int result, OperationLog log) {
|
||||
super(result, log);
|
||||
|
||||
@@ -23,7 +23,7 @@ import android.os.Parcel;
|
||||
import org.openintents.openpgp.OpenPgpMetadata;
|
||||
import org.openintents.openpgp.OpenPgpSignatureResult;
|
||||
|
||||
public class DecryptVerifyResult extends OperationResultParcel {
|
||||
public class DecryptVerifyResult extends OperationResult {
|
||||
|
||||
// the fourth bit indicates a "data pending" result! (it's also a form of non-success)
|
||||
public static final int RESULT_PENDING = RESULT_ERROR +8;
|
||||
|
||||
@@ -23,7 +23,7 @@ import android.os.Parcel;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
||||
|
||||
public class EditKeyResult extends OperationResultParcel {
|
||||
public class EditKeyResult extends OperationResult {
|
||||
|
||||
private transient UncachedKeyRing mRing;
|
||||
public final long mRingMasterKeyId;
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.ui.LogDisplayActivity;
|
||||
import org.sufficientlysecure.keychain.ui.LogDisplayFragment;
|
||||
|
||||
public class ImportKeyResult extends OperationResultParcel {
|
||||
public class ImportKeyResult extends OperationResult {
|
||||
|
||||
public final int mNewKeys, mUpdatedKeys, mBadKeys, mSecret;
|
||||
|
||||
@@ -109,7 +109,7 @@ public class ImportKeyResult extends OperationResultParcel {
|
||||
int duration, color;
|
||||
|
||||
// Not an overall failure
|
||||
if ((resultType & OperationResultParcel.RESULT_ERROR) == 0) {
|
||||
if ((resultType & OperationResult.RESULT_ERROR) == 0) {
|
||||
String withWarnings;
|
||||
|
||||
duration = Duration.EXTRA_LONG;
|
||||
|
||||
@@ -52,7 +52,7 @@ import java.util.List;
|
||||
* TODO ideally, this class should be abstract, and all actual results of a specific subclass
|
||||
*
|
||||
*/
|
||||
public class OperationResultParcel implements Parcelable {
|
||||
public abstract class OperationResult implements Parcelable {
|
||||
|
||||
public static final String EXTRA_RESULT = "operation_result";
|
||||
|
||||
@@ -71,12 +71,12 @@ public class OperationResultParcel implements Parcelable {
|
||||
/// A list of log entries tied to the operation result.
|
||||
final OperationLog mLog;
|
||||
|
||||
public OperationResultParcel(int result, OperationLog log) {
|
||||
public OperationResult(int result, OperationLog log) {
|
||||
mResult = result;
|
||||
mLog = log;
|
||||
}
|
||||
|
||||
public OperationResultParcel(Parcel source) {
|
||||
public OperationResult(Parcel source) {
|
||||
mResult = source.readInt();
|
||||
mLog = new OperationLog();
|
||||
mLog.addAll(source.createTypedArrayList(LogEntryParcel.CREATOR));
|
||||
@@ -156,25 +156,22 @@ public class OperationResultParcel implements Parcelable {
|
||||
|
||||
public SuperCardToast createNotify(final Activity activity) {
|
||||
|
||||
String str;
|
||||
int color;
|
||||
|
||||
// Take the last message as string
|
||||
String str = activity.getString(mLog.getLast().mType.getMsgId());
|
||||
|
||||
// Not an overall failure
|
||||
if (cancelled()) {
|
||||
color = Style.RED;
|
||||
str = "operation cancelled!";
|
||||
} else if (success()) {
|
||||
if (getLog().containsWarnings()) {
|
||||
color = Style.ORANGE;
|
||||
} else {
|
||||
color = Style.GREEN;
|
||||
}
|
||||
str = "operation succeeded!";
|
||||
// str = activity.getString(R.string.import_error);
|
||||
} else {
|
||||
color = Style.RED;
|
||||
str = "operation failed";
|
||||
// str = activity.getString(R.string.import_error);
|
||||
}
|
||||
|
||||
boolean button = getLog() != null && !getLog().isEmpty();
|
||||
@@ -197,7 +194,7 @@ public class OperationResultParcel implements Parcelable {
|
||||
public void onClick(View view, Parcelable token) {
|
||||
Intent intent = new Intent(
|
||||
activity, LogDisplayActivity.class);
|
||||
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, OperationResultParcel.this);
|
||||
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, OperationResult.this);
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
}
|
||||
@@ -498,6 +495,11 @@ public class OperationResultParcel implements Parcelable {
|
||||
MSG_SE_SIGCRYPTING (R.string.msg_se_sigcrypting),
|
||||
MSG_SE_SYMMETRIC (R.string.msg_se_symmetric),
|
||||
|
||||
MSG_CRT_UPLOAD_SUCCESS (R.string.msg_crt_upload_success),
|
||||
MSG_CRT_SUCCESS (R.string.msg_crt_success),
|
||||
|
||||
MSG_ACC_SAVED (R.string.api_settings_save)
|
||||
|
||||
;
|
||||
|
||||
private final int mMsgId;
|
||||
@@ -533,27 +535,17 @@ public class OperationResultParcel implements Parcelable {
|
||||
}
|
||||
}
|
||||
|
||||
public static final Creator<OperationResultParcel> CREATOR = new Creator<OperationResultParcel>() {
|
||||
public OperationResultParcel createFromParcel(final Parcel source) {
|
||||
return new OperationResultParcel(source);
|
||||
}
|
||||
|
||||
public OperationResultParcel[] newArray(final int size) {
|
||||
return new OperationResultParcel[size];
|
||||
}
|
||||
};
|
||||
|
||||
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) {
|
||||
mParcels.add(new OperationResultParcel.LogEntryParcel(level, type, indent, parameters));
|
||||
mParcels.add(new OperationResult.LogEntryParcel(level, type, indent, parameters));
|
||||
}
|
||||
|
||||
public void add(LogLevel level, LogType type, int indent) {
|
||||
mParcels.add(new OperationResultParcel.LogEntryParcel(level, type, indent, (Object[]) null));
|
||||
mParcels.add(new OperationResult.LogEntryParcel(level, type, indent, (Object[]) null));
|
||||
}
|
||||
|
||||
public boolean containsType(LogType type) {
|
||||
@@ -23,7 +23,7 @@ import android.os.Parcel;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing;
|
||||
|
||||
public class SaveKeyringResult extends OperationResultParcel {
|
||||
public class SaveKeyringResult extends OperationResult {
|
||||
|
||||
public final long mRingMasterKeyId;
|
||||
|
||||
|
||||
@@ -19,12 +19,9 @@ package org.sufficientlysecure.keychain.service.results;
|
||||
|
||||
import android.os.Parcel;
|
||||
|
||||
import org.openintents.openpgp.OpenPgpMetadata;
|
||||
import org.openintents.openpgp.OpenPgpSignatureResult;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class SignEncryptResult extends OperationResultParcel {
|
||||
public class SignEncryptResult extends OperationResult {
|
||||
|
||||
// the fourth bit indicates a "data pending" result! (it's also a form of non-success)
|
||||
public static final int RESULT_PENDING = RESULT_ERROR +8;
|
||||
|
||||
@@ -27,7 +27,7 @@ import com.github.johnpersano.supertoasts.util.Style;
|
||||
|
||||
/** This is a simple subclass meant to contain only a single log message. This log
|
||||
* message is also shown without a log button in the createNotify SuperToast. */
|
||||
public class SingletonResult extends OperationResultParcel {
|
||||
public class SingletonResult extends OperationResult {
|
||||
|
||||
/** Construct from a parcel - trivial because we have no extra data. */
|
||||
public SingletonResult(Parcel source) {
|
||||
|
||||
Reference in New Issue
Block a user