aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-10-11 14:17:27 -0400
committerGitHub <noreply@github.com>2017-10-11 14:17:27 -0400
commitb87c75d607956393ad3b07751eb59ccf41726863 (patch)
tree28d580e11e1befcc3895f46f52b03966f0f922ec /core
parentff597a7ef456fcb37160fa7a46b45296098ca413 (diff)
downloadkau-b87c75d607956393ad3b07751eb59ccf41726863.tar.gz
kau-b87c75d607956393ad3b07751eb59ccf41726863.tar.bz2
kau-b87c75d607956393ad3b07751eb59ccf41726863.zip
fix/misc (#81)
* Remove jvmstatic, fixes #68 * Create HO logging * Remove double null boolean notation * Replace multi if else with when * Ignore case in setSpan, closes #82
Diffstat (limited to 'core')
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt28
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt6
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt18
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt2
4 files changed, 42 insertions, 12 deletions
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 14655f0..61f0708 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt
@@ -11,14 +11,34 @@ import android.util.Log
*
* Base logger class with a predefined tag
* This may be extended by an object to effectively replace [Log]
+ * Almost everything is opened to make everything customizable
*/
open class KauLogger(val tag: String) {
+ /**
+ * Global toggle to enable the whole logger
+ */
open var enabled = true
+
+ /**
+ * Global toggle to show private text
+ */
open var showPrivateText = false
+
+ /**
+ * If both msg and priv msg are accepted, output the combined output
+ */
open var messageJoiner: (msg: String, privMsg: String) -> String = { msg, privMsg -> "$msg: $privMsg" }
/**
+ * Open hook to change the output of the logger (for instance, output to stdout rather than Android log files
+ * Does not use reference notation to avoid constructor leaks
+ */
+ open var logFun: (priority: Int, message: String?, privateMessage: String?, t: Throwable?) -> Unit = { p, m, pm, t ->
+ logImpl(p, m, pm, t)
+ }
+
+ /**
* Filter pass-through to decide what we wish to log
* By default, we will ignore verbose and debug logs
* @returns {@code true} to log the message, {@code false} to ignore
@@ -35,14 +55,20 @@ open class KauLogger(val tag: String) {
showPrivateText = enable
}
- open fun log(priority: Int, message: String?, privateMessage: String?, t: Throwable? = null) {
+ private fun log(priority: Int, message: String?, privateMessage: String?, t: Throwable? = null) {
if (!shouldLog(priority, message, privateMessage, t)) return
logImpl(priority, message, privateMessage, t)
}
+ /**
+ * Condition to pass to allow the input to be logged
+ */
protected open fun shouldLog(priority: Int, message: String?, privateMessage: String?, t: Throwable?): Boolean
= enabled && filter(priority)
+ /**
+ * Base implementation of the Android logger
+ */
protected open fun logImpl(priority: Int, message: String?, privateMessage: String?, t: Throwable?) {
val text = if (showPrivateText) {
if (message == null) privateMessage
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 5fe0ddf..18f3e41 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt
@@ -18,8 +18,8 @@ import java.lang.ref.WeakReference
*/
internal object PermissionManager {
- var requestInProgress = false
- val pendingResults: MutableList<WeakReference<PermissionResult>> by lazy { mutableListOf<WeakReference<PermissionResult>>() }
+ private var requestInProgress = false
+ private val pendingResults: MutableList<WeakReference<PermissionResult>> by lazy { mutableListOf<WeakReference<PermissionResult>>() }
/**
* Retrieve permissions requested in our manifest
@@ -63,7 +63,7 @@ internal object PermissionManager {
val iter = pendingResults.iterator()
while (iter.hasNext()) {
val action = iter.next().get()
- if ((0 until count).any { action?.onResult(permissions[it], grantResults[it]) ?: true })
+ if ((0 until count).any { action?.onResult(permissions[it], grantResults[it]) != false })
iter.remove()
}
if (pendingResults.isEmpty())
diff --git a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt
index c0875d1..065f4bb 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt
@@ -349,7 +349,7 @@ internal class SwipeBackLayout @JvmOverloads constructor(context: Context, attrs
listeners.forEach { it.get()?.onScroll(scrollPercent, contentOffset, edgeFlag) }
if (scrollPercent >= 1) {
- if (!(activity?.isFinishing ?: true)) {
+ if (activity?.isFinishing == false) {
if (scrollPercent >= scrollThreshold && isScrollOverValid) {
isScrollOverValid = false
listeners.forEach { it.get()?.onScrollToClose(edgeFlag) }
@@ -390,15 +390,19 @@ internal class SwipeBackLayout @JvmOverloads constructor(context: Context, attrs
}
override fun clampViewPositionHorizontal(child: View, left: Int, dx: Int): Int {
- return if (edgeFlag == SWIPE_EDGE_RIGHT) Math.min(0, Math.max(left, -child.width))
- else if (edgeFlag == SWIPE_EDGE_LEFT) Math.min(child.width, Math.max(left, 0))
- else 0
+ return when (edgeFlag) {
+ SWIPE_EDGE_RIGHT -> Math.min(0, Math.max(left, -child.width))
+ SWIPE_EDGE_LEFT -> Math.min(child.width, Math.max(left, 0))
+ else -> 0
+ }
}
override fun clampViewPositionVertical(child: View, top: Int, dy: Int): Int {
- return if (edgeFlag == SWIPE_EDGE_BOTTOM) Math.min(0, Math.max(top, -child.height))
- else if (edgeFlag == SWIPE_EDGE_TOP) Math.min(child.height, Math.max(top, 0))
- else 0
+ return when (edgeFlag) {
+ SWIPE_EDGE_BOTTOM -> Math.min(0, Math.max(top, -child.height))
+ SWIPE_EDGE_TOP -> Math.min(child.height, Math.max(top, 0))
+ else -> 0
+ }
}
}
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 4bf1836..58f1ccc 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt
@@ -87,7 +87,7 @@ internal enum class ChangelogType(val tag: String, val attr: String, @LayoutRes
ITEM("item", "text", R.layout.kau_changelog_content);
companion object {
- @JvmStatic val values = values()
+ val values = values()
}
/**