aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2015-09-11 03:08:53 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2015-09-11 03:08:53 +0200
commitcdf67c3296b9a7aadf3528ed3eed29cdac752dde (patch)
tree58204c1f0f01036c62ddcfef6a6e7fbb0d5bf264 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java
parentb76aa7fe11f953d10688fbc01daa65676448c78a (diff)
downloadopen-keychain-cdf67c3296b9a7aadf3528ed3eed29cdac752dde.tar.gz
open-keychain-cdf67c3296b9a7aadf3528ed3eed29cdac752dde.tar.bz2
open-keychain-cdf67c3296b9a7aadf3528ed3eed29cdac752dde.zip
share rather than save log files (OKC-01-015)
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java80
1 files changed, 63 insertions, 17 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java
index 6e9aca30d..41691933e 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java
@@ -20,6 +20,7 @@ package org.sufficientlysecure.keychain.operations.results;
import android.app.Activity;
import android.content.Intent;
+import android.content.res.Resources;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
@@ -52,6 +53,8 @@ import java.util.List;
*/
public abstract class OperationResult implements Parcelable {
+ final static String INDENTATION_WHITESPACE = " ";
+
public static final String EXTRA_RESULT = "operation_result";
/**
@@ -166,6 +169,27 @@ public abstract class OperationResult implements Parcelable {
", mIndent=" + mIndent +
'}';
}
+
+ StringBuilder getPrintableLogEntry(Resources resources, int indent) {
+
+ StringBuilder result = new StringBuilder();
+ int padding = mIndent +indent;
+ if (padding > INDENTATION_WHITESPACE.length()) {
+ padding = INDENTATION_WHITESPACE.length();
+ }
+ result.append(INDENTATION_WHITESPACE, 0, padding);
+ result.append(LOG_LEVEL_NAME[mType.mLevel.ordinal()]).append(' ');
+
+ // special case: first parameter may be a quantity
+ if (mParameters != null && mParameters.length > 0 && mParameters[0] instanceof Integer) {
+ result.append(resources.getQuantityString(mType.getMsgId(), (Integer) mParameters[0], mParameters));
+ } else {
+ result.append(resources.getString(mType.getMsgId(), mParameters));
+ }
+
+ return result;
+ }
+
}
public static class SubLogEntryParcel extends LogEntryParcel {
@@ -202,6 +226,17 @@ public abstract class OperationResult implements Parcelable {
dest.writeParcelable(mSubResult, 0);
}
+ @Override
+ StringBuilder getPrintableLogEntry(Resources resources, int indent) {
+
+ LogEntryParcel subEntry = mSubResult.getLog().getLast();
+ if (subEntry != null) {
+ return subEntry.getPrintableLogEntry(resources, mIndent +indent);
+ } else {
+ return super.getPrintableLogEntry(resources, indent);
+ }
+ }
+
}
public Showable createNotify(final Activity activity) {
@@ -245,15 +280,15 @@ public abstract class OperationResult implements Parcelable {
}
return Notify.create(activity, logText, Notify.LENGTH_LONG, style,
- new ActionListener() {
- @Override
- public void onAction() {
- Intent intent = new Intent(
- activity, LogDisplayActivity.class);
- intent.putExtra(LogDisplayFragment.EXTRA_RESULT, OperationResult.this);
- activity.startActivity(intent);
- }
- }, R.string.snackbar_details);
+ new ActionListener() {
+ @Override
+ public void onAction() {
+ Intent intent = new Intent(
+ activity, LogDisplayActivity.class);
+ intent.putExtra(LogDisplayFragment.EXTRA_RESULT, OperationResult.this);
+ activity.startActivity(intent);
+ }
+ }, R.string.snackbar_details);
}
@@ -803,14 +838,7 @@ public abstract class OperationResult implements Parcelable {
MSG_LV_FETCH_ERROR_URL (LogLevel.ERROR, R.string.msg_lv_fetch_error_url),
MSG_LV_FETCH_ERROR_IO (LogLevel.ERROR, R.string.msg_lv_fetch_error_io),
MSG_LV_FETCH_ERROR_FORMAT(LogLevel.ERROR, R.string.msg_lv_fetch_error_format),
- MSG_LV_FETCH_ERROR_NOTHING (LogLevel.ERROR, R.string.msg_lv_fetch_error_nothing),
-
- //export log
- MSG_EXPORT_LOG(LogLevel.START,R.string.msg_export_log_start),
- MSG_EXPORT_LOG_EXPORT_ERROR_NO_FILE(LogLevel.ERROR,R.string.msg_export_log_error_no_file),
- MSG_EXPORT_LOG_EXPORT_ERROR_FOPEN(LogLevel.ERROR,R.string.msg_export_log_error_fopen),
- MSG_EXPORT_LOG_EXPORT_ERROR_WRITING(LogLevel.ERROR,R.string.msg_export_log_error_writing),
- MSG_EXPORT_LOG_EXPORT_SUCCESS (LogLevel.OK, R.string.msg_export_log_success);
+ MSG_LV_FETCH_ERROR_NOTHING (LogLevel.ERROR, R.string.msg_lv_fetch_error_nothing);
public final int mMsgId;
public final LogLevel mLevel;
@@ -833,6 +861,10 @@ public abstract class OperationResult implements Parcelable {
OK, // should occur once at the end of a successful operation
CANCELLED, // should occur once at the end of a cancelled operation
}
+ // for print of debug log. keep those in sync with above!
+ static final String[] LOG_LEVEL_NAME = new String[] {
+ "[DEBUG]", "[INFO]", "[WARN]", "[ERROR]", "[START]", "[OK]", "[CANCEL]"
+ };
@Override
public int describeContents() {
@@ -931,6 +963,20 @@ public abstract class OperationResult implements Parcelable {
public Iterator<LogEntryParcel> iterator() {
return mParcels.iterator();
}
+
+ /**
+ * returns an indented String of an entire OperationLog
+ * @param indent padding to add at the start of all log entries, made for use with SubLogs
+ * @return printable, indented version of passed operationLog
+ */
+ public String getPrintableOperationLog(Resources resources, int indent) {
+ StringBuilder log = new StringBuilder();
+ for (LogEntryParcel entry : this) {
+ log.append(entry.getPrintableLogEntry(resources, indent)).append("\n");
+ }
+ return log.toString().substring(0, log.length() -1); // get rid of extra new line
+ }
+
}
}