aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/ca
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/kotlin/ca')
-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
5 files changed, 16 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)