aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/ca
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2018-02-13 16:51:56 -0500
committerGitHub <noreply@github.com>2018-02-13 16:51:56 -0500
commitcdb1bd6eec2c90abc9d3d982814552443c7fc3b2 (patch)
tree2d21dfcce61fec76384d862b410ee61579169bc2 /core/src/main/kotlin/ca
parentf5d6ddb72a3dc369b95631a607471f9a6ea5e70f (diff)
downloadkau-cdb1bd6eec2c90abc9d3d982814552443c7fc3b2.tar.gz
kau-cdb1bd6eec2c90abc9d3d982814552443c7fc3b2.tar.bz2
kau-cdb1bd6eec2c90abc9d3d982814552443c7fc3b2.zip
Update docs (#135)
* Update docs * Update format * Update dependencies
Diffstat (limited to 'core/src/main/kotlin/ca')
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt15
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefDelegate.kt4
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt4
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/logging/KL.kt2
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt2
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt11
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionResult.kt2
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt3
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt1
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/FontUtils.kt2
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt3
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/NetworkUtils.kt4
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/RecyclerUtils.kt2
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt3
14 files changed, 43 insertions, 15 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 9dd5bea..804eacb 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt
@@ -15,6 +15,8 @@ import ca.allanwang.kau.utils.*
/**
* Created by Allan Wang on 2017-06-20.
+ *
+ * Helper tool to call an email intent with device information
*/
class EmailBuilder(val email: String, val subject: String) {
var message: String = "Write here."
@@ -34,6 +36,9 @@ class EmailBuilder(val email: String, val subject: String) {
attachment = uri
}
+ /**
+ * Optional handler to update the created intent
+ */
var extras: Intent.() -> Unit = {}
data class Package(val packageName: String, val appName: String)
@@ -72,10 +77,12 @@ class EmailBuilder(val email: String, val subject: String) {
}
}
- if (packages.isNotEmpty()) emailBuilder.append("\n")
- packages.forEach {
- if (context.isAppInstalled(it.packageName))
- emailBuilder.append(String.format("\n%s is installed", it.appName))
+ 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()) {
diff --git a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefDelegate.kt b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefDelegate.kt
index ca3701b..33ba807 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefDelegate.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefDelegate.kt
@@ -21,8 +21,8 @@ class StringSet(set: Collection<String>) : LinkedHashSet<String>(set)
* Also contains an optional mutable postSetter that will be called every time a new value is given
*/
class KPrefDelegate<T : Any> internal constructor(
- private val key: String, private val fallback: T, private val pref: KPref, var postSetter: (value: T) -> Unit = {}, lock: Any? = null
-) : ILazyResettable<T>, java.io.Serializable {
+ private val key: String, private val fallback: T, private val pref: KPref, private var postSetter: (value: T) -> Unit = {}, lock: Any? = null
+) : ILazyResettable<T> {
private object UNINITIALIZED
diff --git a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt
index ff08e3c..6525305 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt
@@ -8,8 +8,8 @@ fun KPref.kprefSingle(key: String) = KPrefSingleDelegate(key, this)
* Created by Allan Wang on 2017-06-07.
*
* Singular KPref Delegate for booleans
- * When the shared pref is not initialized, it will return true then set the pref to false
- * All subsequent retrievals will be false
+ * When the shared pref is not initialized, it will return [true] then set the pref to [false]
+ * All subsequent retrievals will be [false]
* This is useful for one time toggles such as showcasing items
*/
class KPrefSingleDelegate internal constructor(private val key: String, private val pref: KPref, lock: Any? = null) : ILazyResettable<Boolean> {
diff --git a/core/src/main/kotlin/ca/allanwang/kau/logging/KL.kt b/core/src/main/kotlin/ca/allanwang/kau/logging/KL.kt
index f690571..9f48ab5 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/logging/KL.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/logging/KL.kt
@@ -4,5 +4,7 @@ import ca.allanwang.kau.BuildConfig
/**
* Created by Allan Wang on 2017-06-19.
+ *
+ * Internal KAU logger
*/
object KL : KauLogger("KAU", { BuildConfig.DEBUG }) \ No newline at end of file
diff --git a/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt b/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt
index e639867..799d32f 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt
@@ -21,6 +21,8 @@ import android.util.Log
* inline fun _d(message: () -> Any?) {
* if (BuildConfig.DEBUG) d(message)
* }
+ * This use case allows for a constant boolean check, which should be caught and removed by proguard
+ * for production builds
*/
open class KauLogger(
/**
diff --git a/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt b/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt
index 8b639ad..3b15e0b 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt
@@ -15,6 +15,9 @@ import java.lang.ref.WeakReference
/**
* Created by Allan Wang on 2017-07-03.
+ *
+ * Permission manager that is decoupled from activities
+ * Keeps track of pending requests, and warns about invalid requests
*/
internal object PermissionManager {
@@ -24,7 +27,7 @@ internal object PermissionManager {
/**
* Retrieve permissions requested in our manifest
*/
- val manifestPermission = lazyContext<Array<String>> {
+ private val manifestPermission = lazyContext<Array<String>> {
try {
it.packageManager.getPackageInfo(it.packageName, PackageManager.GET_PERMISSIONS)?.requestedPermissions ?: emptyArray()
} catch (e: Exception) {
@@ -44,7 +47,7 @@ internal object PermissionManager {
} else KL.d { "Request is postponed since another one is still in progress; did you remember to override onRequestPermissionsResult?" }
}
- @Synchronized internal fun requestPermissions(context: Context, permissions: Array<out String>) {
+ @Synchronized private fun requestPermissions(context: Context, permissions: Array<out String>) {
permissions.forEach {
if (!manifestPermission(context).contains(it)) {
KL.e { "Requested permission $it is not stated in the manifest" }
@@ -57,6 +60,10 @@ internal object PermissionManager {
ActivityCompat.requestPermissions(activity, permissions, 1)
}
+ /**
+ * Handles permission result by allowing accepted permissions for all pending requests
+ * Also cleans up destroyed or completed pending requests
+ */
fun onRequestPermissionsResult(context: Context, permissions: Array<out String>, grantResults: IntArray) {
KL.i { "On permission result: pending ${pendingResults.size}" }
val count = Math.min(permissions.size, grantResults.size)
diff --git a/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionResult.kt b/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionResult.kt
index 14bfdff..ba3e6dd 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionResult.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionResult.kt
@@ -4,6 +4,8 @@ import android.content.pm.PackageManager
/**
* Created by Allan Wang on 2017-07-03.
+ *
+ * Pending permission collector
*/
class PermissionResult(permissions: Array<out String>, val callback: (granted: Boolean, deniedPerm: String?) -> Unit) {
val permissions = mutableSetOf(*permissions)
diff --git a/core/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt b/core/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt
index 36ad52f..4de6695 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt
@@ -3,6 +3,8 @@ package ca.allanwang.kau.permissions
import android.Manifest
import android.app.Activity
import android.content.Context
+import android.os.Build
+import android.support.annotation.RequiresApi
/**
@@ -60,6 +62,7 @@ const val PERMISSION_ADD_VOICEMAIL = Manifest.permission.ADD_VOICEMAIL
const val PERMISSION_USE_SIP = Manifest.permission.USE_SIP
const val PERMISSION_PROCESS_OUTGOING_CALLS = Manifest.permission.PROCESS_OUTGOING_CALLS
+@RequiresApi(Build.VERSION_CODES.KITKAT_WATCH)
const val PERMISSION_BODY_SENSORS = Manifest.permission.BODY_SENSORS
const val PERMISSION_SEND_SMS = Manifest.permission.SEND_SMS
diff --git a/core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt b/core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt
index 86aba6e..62a16d9 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt
@@ -12,7 +12,6 @@ import android.view.View
/**
* Created by Allan Wang on 2016-11-17.
*
- *
* Canvas drawn ripples that keep the previous color
* Extends to view dimensions
* Supports multiple ripples from varying locations
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/FontUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/FontUtils.kt
index 3fc509d..05073c7 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/FontUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/FontUtils.kt
@@ -8,7 +8,7 @@ import android.graphics.Typeface
*/
object FontUtils {
- val sTypefaceCache: MutableMap<String, Typeface> = mutableMapOf()
+ private val sTypefaceCache: MutableMap<String, Typeface> = mutableMapOf()
fun get(context: Context, font: String): Typeface {
synchronized(sTypefaceCache) {
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt
index a8c710e..51691af 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt
@@ -14,7 +14,8 @@ import com.mikepenz.iconics.typeface.IIcon
@KauUtils
fun IIcon.toDrawable(c: Context, sizeDp: Int = 24, @ColorInt color: Int = Color.WHITE, builder: IconicsDrawable.() -> Unit = {}): Drawable {
val state = ColorStateList.valueOf(color)
- val icon = IconicsDrawable(c).icon(this).sizeDp(sizeDp).color(state)
+ val icon = IconicsDrawable(c).icon(this).color(state)
+ if (sizeDp > 0) icon.sizeDp(sizeDp)
icon.builder()
return icon
} \ No newline at end of file
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/NetworkUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/NetworkUtils.kt
index 53016be..2271c16 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/NetworkUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/NetworkUtils.kt
@@ -1,5 +1,6 @@
package ca.allanwang.kau.utils
+import android.annotation.SuppressLint
import android.content.Context
import android.net.ConnectivityManager
@@ -7,6 +8,7 @@ import android.net.ConnectivityManager
* Created by Allan Wang on 2017-07-07.
*/
inline val Context.isNetworkAvailable: Boolean
+ @SuppressLint("MissingPermission")
get() {
val connectivityManager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetworkInfo = connectivityManager.activeNetworkInfo
@@ -14,6 +16,7 @@ inline val Context.isNetworkAvailable: Boolean
}
inline val Context.isWifiConnected: Boolean
+ @SuppressLint("MissingPermission")
get() {
val connectivityManager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetworkInfo = connectivityManager.activeNetworkInfo
@@ -21,6 +24,7 @@ inline val Context.isWifiConnected: Boolean
}
inline val Context.isMobileDataConnected: Boolean
+ @SuppressLint("MissingPermission")
get() {
val connectivityManager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetworkInfo = connectivityManager.activeNetworkInfo
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/RecyclerUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/RecyclerUtils.kt
index f80c85e..3a34db5 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/RecyclerUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/RecyclerUtils.kt
@@ -13,7 +13,7 @@ fun RecyclerView.withMarginDecoration(sizeDp: Int, edgeFlags: Int) {
class MarginItemDecoration(sizeDp: Int, val edgeFlags: Int) : RecyclerView.ItemDecoration() {
- val sizePx = sizeDp.dpToPx
+ private val sizePx = sizeDp.dpToPx
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
super.getItemOffsets(outRect, view, parent, state)
diff --git a/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt b/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt
index cbebd55..83b182f 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt
@@ -23,8 +23,9 @@ import org.xmlpull.v1.XmlPullParser
/**
* Created by Allan Wang on 2017-05-28.
+ *
+ * Easy changelog loader
*/
-
fun Context.showChangelog(@XmlRes xmlRes: Int, @ColorInt textColor: Int? = null, customize: MaterialDialog.Builder.() -> Unit = {}) {
doAsync {
val items = parse(this@showChangelog, xmlRes)