diff options
Diffstat (limited to 'OpenKeychain/src/main/java')
5 files changed, 147 insertions, 12 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpCertifyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpCertifyOperation.java index 2a74c8d8c..b0c801a93 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpCertifyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpCertifyOperation.java @@ -121,6 +121,7 @@ public class PgpCertifyOperation { log.add(LogType.MSG_CRT_SAVE, 2, KeyFormattingUtils.convertKeyIdToHex(certifiedKey.getMasterKeyId())); // store the signed key in our local cache + mProviderHelper.clearLog(); SaveKeyringResult result = mProviderHelper.savePublicKeyRing(certifiedKey); if (result.success()) { @@ -129,6 +130,8 @@ public class PgpCertifyOperation { log.add(LogType.MSG_CRT_WARN_SAVE_FAILED, 3); } + log.add(result, 2); + // TODO do something with import results } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java index 964c535dd..9b21b49ce 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java @@ -117,10 +117,12 @@ public class PgpImportExport { public ImportKeyResult importKeyRings(Iterator<ParcelableKeyRing> entries, int num) { updateProgress(R.string.progress_importing, 0, 100); + OperationLog log = new OperationLog(); + // If there aren't even any keys, do nothing here. if (entries == null || !entries.hasNext()) { return new ImportKeyResult( - ImportKeyResult.RESULT_FAIL_NOTHING, mProviderHelper.getLog(), 0, 0, 0, 0, + ImportKeyResult.RESULT_FAIL_NOTHING, log, 0, 0, 0, 0, new long[]{}); } @@ -156,6 +158,7 @@ public class PgpImportExport { } SaveKeyringResult result; + mProviderHelper.clearLog(); if (key.isSecret()) { result = mProviderHelper.saveSecretKeyRing(key, new ProgressScaler(mProgressable, (int)(position*progSteps), (int)((position+1)*progSteps), 100)); @@ -176,6 +179,8 @@ public class PgpImportExport { importedMasterKeyIds.add(key.getMasterKeyId()); } + log.add(result, 1); + } catch (IOException e) { Log.e(Constants.TAG, "Encountered bad key on import!", e); ++badKeys; @@ -187,7 +192,6 @@ public class PgpImportExport { position++; } - OperationLog log = mProviderHelper.getLog(); int resultType = 0; // special return case: no new keys at all if (badKeys == 0 && newKeys == 0 && oldKeys == 0) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java index 6b96a1e6e..273f9c75f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java @@ -133,6 +133,12 @@ public class ProviderHelper { } } + public void clearLog() { + if (mLog != null) { + mLog.clear(); + } + } + // 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) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResult.java index d32e3a4a9..d65a84e5b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResult.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResult.java @@ -106,7 +106,7 @@ public abstract class OperationResult implements Parcelable { mType = type; mParameters = parameters; mIndent = indent; - Log.v(Constants.TAG, "log: " + this.toString()); + Log.v(Constants.TAG, "log: " + this); } public LogEntryParcel(Parcel source) { @@ -122,6 +122,7 @@ public abstract class OperationResult implements Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(0); dest.writeInt(mType.ordinal()); dest.writeSerializable(mParameters); dest.writeInt(mIndent); @@ -129,7 +130,12 @@ public abstract class OperationResult implements Parcelable { public static final Creator<LogEntryParcel> CREATOR = new Creator<LogEntryParcel>() { public LogEntryParcel createFromParcel(final Parcel source) { - return new LogEntryParcel(source); + // Actually create LogEntryParcel or SubLogEntryParcel depending on type indicator + if (source.readInt() == 0) { + return new LogEntryParcel(source); + } else { + return new SubLogEntryParcel(source); + } } public LogEntryParcel[] newArray(final int size) { @@ -139,7 +145,7 @@ public abstract class OperationResult implements Parcelable { @Override public String toString() { - return "LogEntryParcel{" + + return getClass().getSimpleName() + "{" + "mLevel=" + mType.mLevel + ", mType=" + mType + ", mParameters=" + Arrays.toString(mParameters) + @@ -148,6 +154,42 @@ public abstract class OperationResult implements Parcelable { } } + public static class SubLogEntryParcel extends LogEntryParcel { + + OperationResult mSubResult; + + public SubLogEntryParcel(OperationResult subResult, LogType type, int indent, Object... parameters) { + super(type, indent, parameters); + mSubResult = subResult; + + Log.v(Constants.TAG, "log: " + this); + } + + public SubLogEntryParcel(Parcel source) { + super(source); + mSubResult = source.readParcelable(SubLogEntryParcel.class.getClassLoader()); + } + + public OperationResult getSubResult() { + return mSubResult; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(1); + dest.writeInt(mType.ordinal()); + dest.writeSerializable(mParameters); + dest.writeInt(mIndent); + dest.writeParcelable(mSubResult, 0); + } + + } + public SuperCardToast createNotify(final Activity activity) { int color; @@ -597,6 +639,15 @@ public abstract class OperationResult implements Parcelable { mParcels.add(new OperationResult.LogEntryParcel(type, indent, (Object[]) null)); } + public void add(OperationResult subResult, int indent) { + OperationLog subLog = subResult.getLog(); + mParcels.add(new SubLogEntryParcel(subResult, subLog.getFirst().mType, indent, subLog.getFirst().mParameters)); + } + + public void clear() { + mParcels.clear(); + } + public boolean containsType(LogType type) { for(LogEntryParcel entry : new IterableIterator<LogEntryParcel>(mParcels.iterator())) { if (entry.mType == type) { @@ -627,6 +678,13 @@ public abstract class OperationResult implements Parcelable { return mParcels.isEmpty(); } + public LogEntryParcel getFirst() { + if (mParcels.isEmpty()) { + return null; + } + return mParcels.get(0); + } + public LogEntryParcel getLast() { if (mParcels.isEmpty()) { return null; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java index 4fdfd3a21..d8a7e397d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java @@ -31,6 +31,8 @@ import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView; @@ -40,11 +42,12 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.service.results.OperationResult; import org.sufficientlysecure.keychain.service.results.OperationResult.LogEntryParcel; import org.sufficientlysecure.keychain.service.results.OperationResult.LogLevel; +import org.sufficientlysecure.keychain.service.results.OperationResult.SubLogEntryParcel; import org.sufficientlysecure.keychain.util.Log; import java.util.HashMap; -public class LogDisplayFragment extends ListFragment implements OnTouchListener { +public class LogDisplayFragment extends ListFragment implements OnTouchListener, OnItemClickListener { HashMap<LogLevel,LogAdapter> mAdapters = new HashMap<LogLevel, LogAdapter>(); LogAdapter mAdapter; @@ -89,6 +92,8 @@ public class LogDisplayFragment extends ListFragment implements OnTouchListener } }); + getListView().setOnItemClickListener(this); + getListView().setFastScrollEnabled(true); getListView().setDividerHeight(0); getListView().setOnTouchListener(this); @@ -126,6 +131,18 @@ public class LogDisplayFragment extends ListFragment implements OnTouchListener return false; } + @Override + public void onItemClick(AdapterView<?> parent, View view, int position, long id) { + LogEntryParcel parcel = mAdapter.getItem(position); + if ( ! (parcel instanceof SubLogEntryParcel)) { + return; + } + Intent intent = new Intent( + getActivity(), LogDisplayActivity.class); + intent.putExtra(LogDisplayFragment.EXTRA_RESULT, ((SubLogEntryParcel) parcel).getSubResult()); + startActivity(intent); + } + private class LogAdapter extends ArrayAdapter<LogEntryParcel> { private LayoutInflater mInflater; @@ -146,11 +163,16 @@ public class LogDisplayFragment extends ListFragment implements OnTouchListener } private class ItemHolder { - final TextView mText; - final ImageView mImg; - public ItemHolder(TextView text, ImageView image) { + final View mSecond; + final TextView mText, mSecondText; + final ImageView mImg, mSecondImg, mSub; + public ItemHolder(TextView text, ImageView image, ImageView sub, View second, TextView secondText, ImageView secondImg) { mText = text; mImg = image; + mSub = sub; + mSecond = second; + mSecondText = secondText; + mSecondImg = secondImg; } } @@ -162,13 +184,55 @@ public class LogDisplayFragment extends ListFragment implements OnTouchListener convertView = mInflater.inflate(R.layout.log_display_item, parent, false); ih = new ItemHolder( (TextView) convertView.findViewById(R.id.log_text), - (ImageView) convertView.findViewById(R.id.log_img) + (ImageView) convertView.findViewById(R.id.log_img), + (ImageView) convertView.findViewById(R.id.log_sub), + convertView.findViewById(R.id.log_second), + (TextView) convertView.findViewById(R.id.log_second_text), + (ImageView) convertView.findViewById(R.id.log_second_img) ); convertView.setTag(ih); } else { ih = (ItemHolder) convertView.getTag(); } + if (entry instanceof SubLogEntryParcel) { + ih.mSub.setVisibility(View.VISIBLE); + convertView.setClickable(false); + + OperationResult result = ((SubLogEntryParcel) entry).getSubResult(); + LogEntryParcel subEntry = result.getLog().getLast(); + if (subEntry != null) { + ih.mSecond.setVisibility(View.VISIBLE); + // special case: first parameter may be a quantity + if (subEntry.mParameters != null && subEntry.mParameters.length > 0 + && subEntry.mParameters[0] instanceof Integer) { + ih.mSecondText.setText(getResources().getQuantityString(subEntry.mType.getMsgId(), + (Integer) subEntry.mParameters[0], + subEntry.mParameters)); + } else { + ih.mSecondText.setText(getResources().getString(subEntry.mType.getMsgId(), + subEntry.mParameters)); + } + ih.mSecondText.setTextColor(subEntry.mType.mLevel == LogLevel.DEBUG ? Color.GRAY : Color.BLACK); + switch (subEntry.mType.mLevel) { + case DEBUG: ih.mSecondImg.setBackgroundColor(Color.GRAY); break; + case INFO: ih.mSecondImg.setBackgroundColor(Color.BLACK); break; + case WARN: ih.mSecondImg.setBackgroundColor(Color.YELLOW); break; + case ERROR: ih.mSecondImg.setBackgroundColor(Color.RED); break; + case START: ih.mSecondImg.setBackgroundColor(getResources().getColor(R.color.emphasis)); break; + case OK: ih.mSecondImg.setBackgroundColor(Color.GREEN); break; + case CANCELLED: ih.mSecondImg.setBackgroundColor(Color.RED); break; + } + } else { + ih.mSecond.setVisibility(View.GONE); + } + + } else { + ih.mSub.setVisibility(View.GONE); + ih.mSecond.setVisibility(View.GONE); + convertView.setClickable(true); + } + // special case: first parameter may be a quantity if (entry.mParameters != null && entry.mParameters.length > 0 && entry.mParameters[0] instanceof Integer) { @@ -179,14 +243,14 @@ public class LogDisplayFragment extends ListFragment implements OnTouchListener ih.mText.setText(getResources().getString(entry.mType.getMsgId(), entry.mParameters)); } - ih.mText.setTextColor(entry.mType.mLevel == LogLevel.DEBUG ? Color.GRAY : Color.BLACK); convertView.setPadding((entry.mIndent) * dipFactor, 0, 0, 0); + ih.mText.setTextColor(entry.mType.mLevel == LogLevel.DEBUG ? Color.GRAY : Color.BLACK); switch (entry.mType.mLevel) { case DEBUG: ih.mImg.setBackgroundColor(Color.GRAY); break; case INFO: ih.mImg.setBackgroundColor(Color.BLACK); break; case WARN: ih.mImg.setBackgroundColor(Color.YELLOW); break; case ERROR: ih.mImg.setBackgroundColor(Color.RED); break; - case START: ih.mImg.setBackgroundColor(Color.GREEN); break; + case START: ih.mImg.setBackgroundColor(getResources().getColor(R.color.emphasis)); break; case OK: ih.mImg.setBackgroundColor(Color.GREEN); break; case CANCELLED: ih.mImg.setBackgroundColor(Color.RED); break; } |