Skip to content

Commit f3200df

Browse files
committed
Move common code into methods.
1 parent da0bda0 commit f3200df

File tree

1 file changed

+22
-23
lines changed
  • WordPressUtils/src/main/java/org/wordpress/android/util

1 file changed

+22
-23
lines changed

WordPressUtils/src/main/java/org/wordpress/android/util/AppLog.java

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,9 @@ private static String getStringStackTrace(Throwable throwable) {
231231
return errors.toString();
232232
}
233233

234-
/**
235-
* Returns entire log as html for display (see AppLogViewerActivity)
236-
* @param context
237-
* @return Arraylist of Strings containing log messages
238-
*/
239-
public static ArrayList<String> toHtmlList(Context context) {
240-
ArrayList<String> items = new ArrayList<String>();
241234

235+
private static String getAppInfoHeaderText(Context context) {
236+
StringBuilder sb = new StringBuilder();
242237
PackageManager packageManager = context.getPackageManager();
243238
PackageInfo pkInfo = PackageUtils.getPackageInfo(context);
244239

@@ -249,10 +244,26 @@ public static ArrayList<String> toHtmlList(Context context) {
249244
} else {
250245
appName = "Unknown";
251246
}
247+
sb.append(appName).append(" - ").append(PackageUtils.getVersionName(context))
248+
.append(" - Version code: ").append(PackageUtils.getVersionCode(context));
249+
return sb.toString();
250+
}
251+
252+
private static String getDeviceInfoHeaderText(Context context) {
253+
return "Android device name: " + DeviceUtils.getInstance().getDeviceName(context);
254+
}
255+
256+
/**
257+
* Returns entire log as html for display (see AppLogViewerActivity)
258+
* @param context
259+
* @return Arraylist of Strings containing log messages
260+
*/
261+
public static ArrayList<String> toHtmlList(Context context) {
262+
ArrayList<String> items = new ArrayList<String>();
252263

253264
// add version & device info - be sure to change HEADER_LINE_COUNT if additional lines are added
254-
items.add("<strong>" + appName + " - " + PackageUtils.getVersionName(context) + " - Version code: " + PackageUtils.getVersionCode(context) + "</strong>");
255-
items.add("<strong>Android device name: " + DeviceUtils.getInstance().getDeviceName(context) + "</strong>");
265+
items.add("<strong>" + getAppInfoHeaderText(context) + "</strong>");
266+
items.add("<strong>" + getDeviceInfoHeaderText(context) + "</strong>");
256267

257268
Iterator<LogEntry> it = mLogEntries.iterator();
258269
while (it.hasNext()) {
@@ -269,21 +280,9 @@ public static ArrayList<String> toHtmlList(Context context) {
269280
public static String toPlainText(Context context) {
270281
StringBuilder sb = new StringBuilder();
271282

272-
PackageManager packageManager = context.getPackageManager();
273-
PackageInfo pkInfo = PackageUtils.getPackageInfo(context);
274-
275-
ApplicationInfo applicationInfo = pkInfo != null ? pkInfo.applicationInfo : null;
276-
String appName;
277-
if (applicationInfo != null && packageManager.getApplicationLabel(applicationInfo) != null) {
278-
appName = packageManager.getApplicationLabel(applicationInfo).toString();
279-
} else {
280-
appName = "Unknown";
281-
}
282-
283283
// add version & device info
284-
sb.append(appName).append(" - ").append(PackageUtils.getVersionName(context))
285-
.append(" - Version code: ").append(PackageUtils.getVersionCode(context)).append("\n")
286-
.append("Android device name: ").append(DeviceUtils.getInstance().getDeviceName(context)).append("\n\n");
284+
sb.append(getAppInfoHeaderText(context)).append("\n")
285+
.append(getDeviceInfoHeaderText(context)).append("\n\n");
287286

288287
Iterator<LogEntry> it = mLogEntries.iterator();
289288
int lineNum = 1;

0 commit comments

Comments
 (0)