mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-07 18:40:19 -05:00
import-log: improve operationresultparcel, add indentation
This commit is contained in:
parent
c84a1ecfff
commit
b995b836a3
@ -1,9 +1,10 @@
|
||||
package org.sufficientlysecure.keychain.pgp;
|
||||
|
||||
import android.R;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/** Represent the result of an operation.
|
||||
@ -39,20 +40,26 @@ public class OperationResultParcel implements Parcelable {
|
||||
|
||||
/** One entry in the log. */
|
||||
public static class LogEntryParcel implements Parcelable {
|
||||
final LogType mType;
|
||||
final LogLevel mLevel;
|
||||
final LogType mType;
|
||||
final String[] mParameters;
|
||||
final int mIndent;
|
||||
|
||||
public LogEntryParcel(LogType type, LogLevel level, String[] parameters) {
|
||||
mType = type;
|
||||
public LogEntryParcel(LogLevel level, LogType type, String[] parameters, int indent) {
|
||||
mLevel = level;
|
||||
mType = type;
|
||||
mParameters = parameters;
|
||||
mIndent = indent;
|
||||
}
|
||||
public LogEntryParcel(LogLevel level, LogType type, String[] parameters) {
|
||||
this(level, type, parameters, 0);
|
||||
}
|
||||
|
||||
public LogEntryParcel(Parcel source) {
|
||||
mType = LogType.values()[source.readInt()];
|
||||
mLevel = LogLevel.values()[source.readInt()];
|
||||
mType = LogType.values()[source.readInt()];
|
||||
mParameters = source.createStringArray();
|
||||
mIndent = source.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -62,9 +69,10 @@ public class OperationResultParcel implements Parcelable {
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(mType.ordinal());
|
||||
dest.writeInt(mLevel.ordinal());
|
||||
dest.writeInt(mType.ordinal());
|
||||
dest.writeStringArray(mParameters);
|
||||
dest.writeInt(mIndent);
|
||||
}
|
||||
|
||||
public static final Creator<LogEntryParcel> CREATOR = new Creator<LogEntryParcel>() {
|
||||
|
@ -29,6 +29,9 @@ import android.support.v4.util.LongSparseArray;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.OperationResultParcel;
|
||||
import org.sufficientlysecure.keychain.pgp.OperationResultParcel.LogType;
|
||||
import org.sufficientlysecure.keychain.pgp.OperationResultParcel.LogLevel;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpHelper;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
||||
@ -59,12 +62,21 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ProviderHelper {
|
||||
private Context mContext;
|
||||
private ContentResolver mContentResolver;
|
||||
private final Context mContext;
|
||||
private final ContentResolver mContentResolver;
|
||||
private final ArrayList<OperationResultParcel.LogEntryParcel> mLog;
|
||||
private int mIndent;
|
||||
|
||||
public ProviderHelper(Context context) {
|
||||
this.mContext = context;
|
||||
this.mContentResolver = context.getContentResolver();
|
||||
this(context, null, 0);
|
||||
}
|
||||
|
||||
public ProviderHelper(Context context, ArrayList<OperationResultParcel.LogEntryParcel> log,
|
||||
int indent) {
|
||||
mContext = context;
|
||||
mContentResolver = context.getContentResolver();
|
||||
mLog = log;
|
||||
mIndent = indent;
|
||||
}
|
||||
|
||||
public static class NotFoundException extends Exception {
|
||||
@ -76,6 +88,13 @@ public class ProviderHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public void log(LogLevel level, LogType type) {
|
||||
mLog.add(new OperationResultParcel.LogEntryParcel(level, type, null, mIndent));
|
||||
}
|
||||
public void log(LogLevel level, LogType type, String[] parameters) {
|
||||
mLog.add(new OperationResultParcel.LogEntryParcel(level, type, parameters, mIndent));
|
||||
}
|
||||
|
||||
// If we ever switch to api level 11, we can ditch this whole mess!
|
||||
public static final int FIELD_TYPE_NULL = 1;
|
||||
// this is called integer to stay coherent with the constants in Cursor (api level 11)
|
||||
|
Loading…
Reference in New Issue
Block a user