From 372c5da8d09ff9928f937c4288b3f92351a576da Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Wed, 21 Jun 2017 12:23:04 -0700 Subject: Add more configs in email builder --- .../kotlin/ca/allanwang/kau/email/EmailBuilder.kt | 25 +++++++++++++++++----- library/src/main/res/values/strings_commons.xml | 9 ++++++-- 2 files changed, 27 insertions(+), 7 deletions(-) (limited to 'library/src') diff --git a/library/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt b/library/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt index 1553757..ed3b928 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt @@ -1,11 +1,13 @@ package ca.allanwang.kau.email +import android.app.Activity import android.content.Context import android.content.Intent import android.content.pm.PackageManager import android.net.Uri import android.os.Build import android.support.annotation.StringRes +import android.util.DisplayMetrics import ca.allanwang.kau.R import ca.allanwang.kau.logging.KL import ca.allanwang.kau.utils.isAppInstalled @@ -20,10 +22,13 @@ class EmailBuilder(@StringRes val emailId: Int, @StringRes val subjectId: Int) { var deviceDetails: Boolean = true var appInfo: Boolean = true var footer: String? = null + private val pairs: MutableMap = mutableMapOf() private val packages: MutableList = mutableListOf() fun checkPackage(packageName: String, appName: String) = packages.add(Package(packageName, appName)) + fun addItem(key: String, value: String) = pairs.put(key, value) + data class Package(val packageName: String, val appName: String) fun execute(context: Context) { @@ -31,31 +36,41 @@ class EmailBuilder(@StringRes val emailId: Int, @StringRes val subjectId: Int) { intent.putExtra(Intent.EXTRA_SUBJECT, context.string(subjectId)) val emailBuilder = StringBuilder() emailBuilder.append(message).append("\n\n") - if (deviceDetails) + if (deviceDetails) { emailBuilder.append("\nOS Version: ").append(System.getProperty("os.version")).append("(").append(Build.VERSION.INCREMENTAL).append(")") .append("\nOS API Level: ").append(Build.VERSION.SDK_INT) .append("\nDevice: ").append(Build.DEVICE) .append("\nManufacturer: ").append(Build.MANUFACTURER) .append("\nModel (and Product): ").append(Build.MODEL).append(" (").append(Build.PRODUCT).append(")") - .append("\n") - + if (context is Activity) { + val metric = DisplayMetrics() + context.windowManager.defaultDisplay.getMetrics(metric) + emailBuilder.append("\nScreen Dimensions: ${metric.widthPixels} x ${metric.heightPixels}") + } + emailBuilder.append("\n") + } if (appInfo) { try { val appInfo = context.packageManager.getPackageInfo(context.packageName, 0) - emailBuilder.append("\nApp Version Name: ").append(appInfo.versionName) + emailBuilder.append("\nApp: ").append(context.packageName) + .append("\nApp Version Name: ").append(appInfo.versionName) .append("\nApp Version Code: ").append(appInfo.versionCode).append("\n") } catch (e: PackageManager.NameNotFoundException) { KL.e("EmailBuilder packageInfo not found") } } + if (packages.isNotEmpty()) emailBuilder.append("\n") packages.forEach { if (context.isAppInstalled(it.packageName)) emailBuilder.append(String.format("\n%s is installed", it.appName)) } + if (pairs.isNotEmpty()) emailBuilder.append("\n") + pairs.forEach { k, v -> emailBuilder.append("$k: $v\n") } + if (footer != null) - emailBuilder.append("\n\n").append(footer) + emailBuilder.append("\n").append(footer) intent.putExtra(Intent.EXTRA_TEXT, emailBuilder.toString()) context.startActivity(Intent.createChooser(intent, context.resources.getString(R.string.kau_send_via))) diff --git a/library/src/main/res/values/strings_commons.xml b/library/src/main/res/values/strings_commons.xml index 760d22e..2198564 100644 --- a/library/src/main/res/values/strings_commons.xml +++ b/library/src/main/res/values/strings_commons.xml @@ -4,21 +4,26 @@ Most resources are verbatim and x represents a formatted item --> + AMOLED Back Cancel Changelog Close Contact Us - Done + Custom + Dark + Default Do not show again + Done Error Exit Are you sure you want to exit? Are you sure you want to exit %s? Great + Light Login Logout - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Maybe No None -- cgit v1.2.3