From f3200df6c1190a2d4ec739d23b1f43182dd292f5 Mon Sep 17 00:00:00 2001 From: Danilo Ercoli Date: Tue, 25 Oct 2016 13:15:42 +0200 Subject: [PATCH] Move common code into methods. --- .../org/wordpress/android/util/AppLog.java | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/WordPressUtils/src/main/java/org/wordpress/android/util/AppLog.java b/WordPressUtils/src/main/java/org/wordpress/android/util/AppLog.java index 9d49a42a6d7b..fea7bf08f57b 100644 --- a/WordPressUtils/src/main/java/org/wordpress/android/util/AppLog.java +++ b/WordPressUtils/src/main/java/org/wordpress/android/util/AppLog.java @@ -231,14 +231,9 @@ private static String getStringStackTrace(Throwable throwable) { return errors.toString(); } - /** - * Returns entire log as html for display (see AppLogViewerActivity) - * @param context - * @return Arraylist of Strings containing log messages - */ - public static ArrayList toHtmlList(Context context) { - ArrayList items = new ArrayList(); + private static String getAppInfoHeaderText(Context context) { + StringBuilder sb = new StringBuilder(); PackageManager packageManager = context.getPackageManager(); PackageInfo pkInfo = PackageUtils.getPackageInfo(context); @@ -249,10 +244,26 @@ public static ArrayList toHtmlList(Context context) { } else { appName = "Unknown"; } + sb.append(appName).append(" - ").append(PackageUtils.getVersionName(context)) + .append(" - Version code: ").append(PackageUtils.getVersionCode(context)); + return sb.toString(); + } + + private static String getDeviceInfoHeaderText(Context context) { + return "Android device name: " + DeviceUtils.getInstance().getDeviceName(context); + } + + /** + * Returns entire log as html for display (see AppLogViewerActivity) + * @param context + * @return Arraylist of Strings containing log messages + */ + public static ArrayList toHtmlList(Context context) { + ArrayList items = new ArrayList(); // add version & device info - be sure to change HEADER_LINE_COUNT if additional lines are added - items.add("" + appName + " - " + PackageUtils.getVersionName(context) + " - Version code: " + PackageUtils.getVersionCode(context) + ""); - items.add("Android device name: " + DeviceUtils.getInstance().getDeviceName(context) + ""); + items.add("" + getAppInfoHeaderText(context) + ""); + items.add("" + getDeviceInfoHeaderText(context) + ""); Iterator it = mLogEntries.iterator(); while (it.hasNext()) { @@ -269,21 +280,9 @@ public static ArrayList toHtmlList(Context context) { public static String toPlainText(Context context) { StringBuilder sb = new StringBuilder(); - PackageManager packageManager = context.getPackageManager(); - PackageInfo pkInfo = PackageUtils.getPackageInfo(context); - - ApplicationInfo applicationInfo = pkInfo != null ? pkInfo.applicationInfo : null; - String appName; - if (applicationInfo != null && packageManager.getApplicationLabel(applicationInfo) != null) { - appName = packageManager.getApplicationLabel(applicationInfo).toString(); - } else { - appName = "Unknown"; - } - // add version & device info - sb.append(appName).append(" - ").append(PackageUtils.getVersionName(context)) - .append(" - Version code: ").append(PackageUtils.getVersionCode(context)).append("\n") - .append("Android device name: ").append(DeviceUtils.getInstance().getDeviceName(context)).append("\n\n"); + sb.append(getAppInfoHeaderText(context)).append("\n") + .append(getDeviceInfoHeaderText(context)).append("\n\n"); Iterator it = mLogEntries.iterator(); int lineNum = 1;