From 669991727900953abaff35f0cabb13427485b62a Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 5 Oct 2014 11:10:40 +0200 Subject: [PATCH] add support for second line in log view --- .../keychain/pgp/PgpCertifyOperation.java | 3 + .../keychain/provider/ProviderHelper.java | 6 ++ .../keychain/ui/LogDisplayFragment.java | 49 +++++++++-- .../src/main/res/layout/log_display_item.xml | 87 +++++++++++++------ 4 files changed, 112 insertions(+), 33 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/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/ui/LogDisplayFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java index 3cc16bd93..d8a7e397d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java @@ -163,12 +163,16 @@ public class LogDisplayFragment extends ListFragment implements OnTouchListener, } private class ItemHolder { - final TextView mText; - final ImageView mImg, mSub; - public ItemHolder(TextView text, ImageView image, ImageView sub) { + 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; } } @@ -181,7 +185,10 @@ public class LogDisplayFragment extends ListFragment implements OnTouchListener, ih = new ItemHolder( (TextView) convertView.findViewById(R.id.log_text), (ImageView) convertView.findViewById(R.id.log_img), - (ImageView) convertView.findViewById(R.id.log_sub) + (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 { @@ -191,8 +198,38 @@ public class LogDisplayFragment extends ListFragment implements OnTouchListener, 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); } @@ -206,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; } diff --git a/OpenKeychain/src/main/res/layout/log_display_item.xml b/OpenKeychain/src/main/res/layout/log_display_item.xml index 9efe9cf64..d3938aaf0 100644 --- a/OpenKeychain/src/main/res/layout/log_display_item.xml +++ b/OpenKeychain/src/main/res/layout/log_display_item.xml @@ -1,37 +1,70 @@ - + - + - + + + + + + + android:id="@+id/log_second" + android:layout_marginLeft="8dip"> + + + + + \ No newline at end of file