aboutsummaryrefslogtreecommitdiff
path: root/core/src/main
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2018-01-20 22:19:03 -0500
committerAllan Wang <me@allanwang.ca>2018-01-20 22:19:03 -0500
commit9c00231884c69456c2deb2918cd0ecd50f3ac0a0 (patch)
tree622d4d5ca60ef582ca96cd84106a1443a543ad8d /core/src/main
parent28c07ba66bf71dd322ffe3253b35862cdfc82e98 (diff)
downloadkau-9c00231884c69456c2deb2918cd0ecd50f3ac0a0.tar.gz
kau-9c00231884c69456c2deb2918cd0ecd50f3ac0a0.tar.bz2
kau-9c00231884c69456c2deb2918cd0ecd50f3ac0a0.zip
Add tablet check in email builder
Diffstat (limited to 'core/src/main')
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt22
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/kotlin/NonReadablePropertyException.kt12
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/kotlin/Streams.kt5
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/kotlin/Zip.kt2
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt1
-rw-r--r--core/src/main/res/values-sw600dp/internal.xml4
-rw-r--r--core/src/main/res/values/internal.xml4
7 files changed, 24 insertions, 26 deletions
diff --git a/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt b/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt
index b75ff4a..9dd5bea 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt
@@ -10,10 +10,7 @@ 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.installerPackageName
-import ca.allanwang.kau.utils.isAppInstalled
-import ca.allanwang.kau.utils.string
-import ca.allanwang.kau.utils.toast
+import ca.allanwang.kau.utils.*
/**
@@ -28,7 +25,8 @@ class EmailBuilder(val email: String, val subject: String) {
private val packages: MutableList<Package> = mutableListOf()
private var attachment: Uri? = null
- fun checkPackage(packageName: String, appName: String) = packages.add(Package(packageName, appName))
+ fun checkPackage(packageName: String, appName: String) =
+ packages.add(Package(packageName, appName))
fun addItem(key: String, value: String) = pairs.put(key, value)
@@ -53,12 +51,13 @@ class EmailBuilder(val email: String, val subject: String) {
"OS SDK" to Build.VERSION.SDK_INT,
"Device (Manufacturer)" to "${Build.DEVICE} (${Build.MANUFACTURER})",
"Model (Product)" to "${Build.MODEL} (${Build.PRODUCT})",
- "Package Installer" to (context.installerPackageName ?: "None")
+ "Package Installer" to (context.installerPackageName ?: "None"),
+ "Tablet" to context.boolean(R.bool.kau_is_tablet)
)
if (context is Activity) {
val metric = DisplayMetrics()
context.windowManager.defaultDisplay.getMetrics(metric)
- deviceItems.put("Screen Dimensions", "${metric.widthPixels} x ${metric.heightPixels}")
+ deviceItems["Screen Dimensions"] = "${metric.widthPixels} x ${metric.heightPixels}"
}
deviceItems.forEach { (k, v) -> emailBuilder.append("$k: $v\n") }
}
@@ -79,8 +78,10 @@ class EmailBuilder(val email: String, val subject: String) {
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 (pairs.isNotEmpty()) {
+ emailBuilder.append("\n")
+ pairs.forEach { (k, v) -> emailBuilder.append("$k: $v\n") }
+ }
if (footer != null)
emailBuilder.append("\n").append(footer)
@@ -110,8 +111,7 @@ class EmailBuilder(val email: String, val subject: String) {
}
}
-fun Context.sendEmail(@StringRes emailId: Int, @StringRes subjectId: Int, builder: EmailBuilder.() -> Unit = {})
- = sendEmail(string(emailId), string(subjectId), builder)
+fun Context.sendEmail(@StringRes emailId: Int, @StringRes subjectId: Int, builder: EmailBuilder.() -> Unit = {}) = sendEmail(string(emailId), string(subjectId), builder)
fun Context.sendEmail(email: String, subject: String, builder: EmailBuilder.() -> Unit = {}) {
diff --git a/core/src/main/kotlin/ca/allanwang/kau/kotlin/NonReadablePropertyException.kt b/core/src/main/kotlin/ca/allanwang/kau/kotlin/NonReadablePropertyException.kt
deleted file mode 100644
index f3add48..0000000
--- a/core/src/main/kotlin/ca/allanwang/kau/kotlin/NonReadablePropertyException.kt
+++ /dev/null
@@ -1,12 +0,0 @@
-package ca.allanwang.kau.kotlin
-
-/**
- * Created by Allan Wang on 2017-06-24.
- *
- * Credits to @zsmb13
- *
- * https://github.com/zsmb13/MaterialDrawerKt/blob/master/library/src/main/java/co/zsmb/materialdrawerkt/NonReadablePropertyException.kt
- */
-class NonReadablePropertyException : Exception()
-
-fun nonReadable(): Nothing = throw NonReadablePropertyException() \ No newline at end of file
diff --git a/core/src/main/kotlin/ca/allanwang/kau/kotlin/Streams.kt b/core/src/main/kotlin/ca/allanwang/kau/kotlin/Streams.kt
index 5dc44a8..0da6d7a 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/kotlin/Streams.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/kotlin/Streams.kt
@@ -5,11 +5,12 @@ package ca.allanwang.kau.kotlin
*/
/**
- * Replica of [Vector.removeIf] in Java
+ * Replica of [java.util.Vector.removeIf] in Java
* Since we don't have access to the internals of our extended class,
* We will simply iterate and remove when the filter returns {@code false}
*/
-@Synchronized inline fun <T, C : MutableIterable<T>> C.kauRemoveIf(filter: (item: T) -> Boolean): C {
+@Synchronized
+inline fun <T, C : MutableIterable<T>> C.kauRemoveIf(filter: (item: T) -> Boolean): C {
val iter = iterator()
while (iter.hasNext())
if (filter(iter.next())) iter.remove()
diff --git a/core/src/main/kotlin/ca/allanwang/kau/kotlin/Zip.kt b/core/src/main/kotlin/ca/allanwang/kau/kotlin/Zip.kt
index 80cab09..17ae5e5 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/kotlin/Zip.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/kotlin/Zip.kt
@@ -53,7 +53,7 @@ inline fun <reified T> Collection<(ZipCallback<T>) -> Unit>.zip(
val result = Array(size) { defaultResult }
val countDown = AtomicInteger(size)
forEachIndexed { index, asyncFun ->
- asyncFun(ZipCallback<T> {
+ asyncFun(ZipCallback {
result[index] = it
if (countDown.decrementAndGet() <= 0)
onFinished(result)
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
index 89ad5f4..67da3f9 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
@@ -98,6 +98,7 @@ inline fun Context.string(@StringRes id: Int): String = getString(id)
inline fun Context.string(@StringRes id: Int, fallback: String?): String? = if (id > 0) string(id) else fallback
inline fun Context.color(@ColorRes id: Int): Int = ContextCompat.getColor(this, id)
+inline fun Context.boolean(@BoolRes id: Int): Boolean = resources.getBoolean(id)
inline fun Context.integer(@IntegerRes id: Int): Int = resources.getInteger(id)
inline fun Context.dimen(@DimenRes id: Int): Float = resources.getDimension(id)
inline fun Context.dimenPixelSize(@DimenRes id: Int): Int = resources.getDimensionPixelSize(id)
diff --git a/core/src/main/res/values-sw600dp/internal.xml b/core/src/main/res/values-sw600dp/internal.xml
new file mode 100644
index 0000000..782b561
--- /dev/null
+++ b/core/src/main/res/values-sw600dp/internal.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <bool name="kau_is_tablet">true</bool>
+</resources> \ No newline at end of file
diff --git a/core/src/main/res/values/internal.xml b/core/src/main/res/values/internal.xml
new file mode 100644
index 0000000..56e5b79
--- /dev/null
+++ b/core/src/main/res/values/internal.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <bool name="kau_is_tablet">false</bool>
+</resources> \ No newline at end of file