aboutsummaryrefslogtreecommitdiff
path: root/library/src/main/kotlin/ca
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-21 12:23:04 -0700
committerAllan Wang <me@allanwang.ca>2017-06-21 12:23:04 -0700
commit372c5da8d09ff9928f937c4288b3f92351a576da (patch)
tree82bab43c3a54650cdf5978896d21e372f839e6e5 /library/src/main/kotlin/ca
parent7601adcb8254b4dc1818526061e1013f2e216fc5 (diff)
downloadkau-372c5da8d09ff9928f937c4288b3f92351a576da.tar.gz
kau-372c5da8d09ff9928f937c4288b3f92351a576da.tar.bz2
kau-372c5da8d09ff9928f937c4288b3f92351a576da.zip
Add more configs in email builder
Diffstat (limited to 'library/src/main/kotlin/ca')
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt25
1 files changed, 20 insertions, 5 deletions
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<String, String> = mutableMapOf()
private val packages: MutableList<Package> = 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)))