From 66e7d9505e0baffaf17877c1800939a2e0b936d6 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 23 Sep 2017 15:14:12 -0400 Subject: v3.4.1 (#63) * Check browser intent before launching (#54) * Update changelog * fix/misc (#55) * Add kapt plugin * Fix kau vector * Debug lintRelease * Revert debug * Update dependencies * Check context finishing state before showing dialog (#61) * Keep copy of shared pref rather than application context (#60) * Keep copy of shared pref rather than application context * Add back preference name * Add resolver checks (#62) Squashed commit of the following: commit 7fe57d4ab1dbfe8bfb4d4a15bd0fbf636da491fa Author: Allan Wang Date: Sat Sep 23 15:25:18 2017 -0400 Add missing quote commit ffc3ac99248c2250a7f14ef709f37d787cbe0d83 Author: Allan Wang Date: Sat Sep 23 15:20:54 2017 -0400 Update changelog Update gradle Update version name --- .../kotlin/ca/allanwang/kau/email/EmailBuilder.kt | 6 ++- .../main/kotlin/ca/allanwang/kau/kpref/KPref.kt | 17 +++----- .../kotlin/ca/allanwang/kau/utils/ContextUtils.kt | 48 ++++++++++++++++------ 3 files changed, 45 insertions(+), 26 deletions(-) (limited to 'core/src/main/kotlin') 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 88a0945..8c6acff 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt @@ -13,6 +13,7 @@ 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 /** @@ -76,7 +77,10 @@ class EmailBuilder(val email: String, val subject: String) { 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))) + if (intent.resolveActivity(context.packageManager) != null) + context.startActivity(Intent.createChooser(intent, context.resources.getString(R.string.kau_send_via))) + else + context.toast("Cannot resolve email activity", log = true) } } diff --git a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt index be16c7c..fbb8c7d 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt @@ -3,6 +3,7 @@ package ca.allanwang.kau.kpref import android.content.Context import android.content.SharedPreferences import ca.allanwang.kau.kotlin.ILazyResettable +import ca.allanwang.kau.logging.KL /** * Created by Allan Wang on 2017-06-07. @@ -22,15 +23,13 @@ import ca.allanwang.kau.kotlin.ILazyResettable */ open class KPref { - lateinit private var c: Context - lateinit internal var PREFERENCE_NAME: String - private var initialized = false + lateinit var PREFERENCE_NAME: String + lateinit var sp: SharedPreferences fun initialize(c: Context, preferenceName: String) { - if (initialized) throw KPrefException("KPref object $preferenceName has already been initialized; please only do so once") - initialized = true - this.c = c.applicationContext PREFERENCE_NAME = preferenceName + sp = c.applicationContext.getSharedPreferences(preferenceName, Context.MODE_PRIVATE) + KL.d("Shared Preference $preferenceName has been initialized") val toDelete = deleteKeys() if (toDelete.isNotEmpty()) { val edit = sp.edit() @@ -39,12 +38,6 @@ open class KPref { } } - //todo hide this - val sp: SharedPreferences by lazy { - if (!initialized) throw KPrefException("KPref object has not yet been initialized; please initialize it with a context and preference name") - c.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE) - } - internal val prefMap: MutableMap> = mutableMapOf() fun reset() { 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 d561c8a..a72c7dd 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt @@ -77,7 +77,11 @@ fun Context.startActivitySlideOut(clazz: Class, clearStack: Boolea fun Context.startPlayStoreLink(@StringRes packageIdRes: Int) = startPlayStoreLink(string(packageIdRes)) fun Context.startPlayStoreLink(packageId: String) { - startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=$packageId"))) + val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=$packageId")) + if (intent.resolveActivity(packageManager) != null) + startActivity(intent) + else + toast("Cannot resolve play store", log = true) } /** @@ -87,22 +91,24 @@ fun Context.startPlayStoreLink(packageId: String) { fun Context.startLink(vararg url: String?) { val link = url.firstOrNull { !it.isNullOrBlank() } ?: return val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(link)) - startActivity(browserIntent) + if (browserIntent.resolveActivity(packageManager) != null) + startActivity(browserIntent) + else + toast("Cannot resolve browser", log = true) } -fun Context.startLink(@StringRes url: Int) { - val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(string(url))) - startActivity(browserIntent) -} +fun Context.startLink(@StringRes url: Int) = startLink(string(url)) //Toast helpers -inline fun View.toast(@StringRes id: Int, duration: Int = Toast.LENGTH_LONG) = context.toast(id, duration) +inline fun View.toast(@StringRes id: Int, duration: Int = Toast.LENGTH_LONG, log: Boolean = false) = context.toast(id, duration, log) + +inline fun Context.toast(@StringRes id: Int, duration: Int = Toast.LENGTH_LONG, log: Boolean = false) = toast(this.string(id), duration, log) -inline fun Context.toast(@StringRes id: Int, duration: Int = Toast.LENGTH_LONG) = toast(this.string(id), duration) +inline fun View.toast(text: String, duration: Int = Toast.LENGTH_LONG, log: Boolean = false) = context.toast(text, duration, log) -inline fun View.toast(text: String, duration: Int = Toast.LENGTH_LONG) = context.toast(text, duration) -inline fun Context.toast(text: String, duration: Int = Toast.LENGTH_LONG) { +inline fun Context.toast(text: String, duration: Int = Toast.LENGTH_LONG, log: Boolean = false) { Toast.makeText(this, text, duration).show() + if (log) KL.i("Toast: $text") } //Resource retrievers @@ -163,6 +169,10 @@ fun Context.resolveString(@AttrRes attr: Int, fallback: String = ""): String { inline fun Context.materialDialog(action: MaterialDialog.Builder.() -> Unit): MaterialDialog { val builder = MaterialDialog.Builder(this) builder.action() + if (isFinishing) { + KL.d("Material Dialog triggered from finishing context; did not show") + return builder.build() + } return builder.show() } @@ -192,9 +202,21 @@ fun Context.copyToClipboard(text: String?, label: String = "Copied Text", showTo } fun Context.shareText(text: String?) { - if (text == null) return toast(R.string.kau_text_is_null) + if (text == null) return toast("Share text is null") val intent = Intent(Intent.ACTION_SEND) intent.type = "text/plain" intent.putExtra(Intent.EXTRA_TEXT, text) - startActivity(Intent.createChooser(intent, string(R.string.kau_share))) -} \ No newline at end of file + val chooserIntent = Intent.createChooser(intent, string(R.string.kau_share)) + if (chooserIntent.resolveActivity(packageManager) != null) + startActivity(chooserIntent) + else + toast("Cannot resolve activity to share text", log = true) +} + +/** + * Check if given context is finishing. + * This is a wrapper to check if it's both an activity and finishing + * As of now, it is only checked when tied to an activity + */ +inline val Context.isFinishing: Boolean + get() = (this as? Activity)?.isFinishing ?: false \ No newline at end of file -- cgit v1.2.3 From cd41bb2917425599fca5d786ea62a2c3253dda70 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 24 Sep 2017 14:26:09 -0400 Subject: Fix bundle NPE for activity creation Update changelog --- .../kotlin/ca/allanwang/kau/utils/ActivityUtils.kt | 6 +++--- .../kotlin/ca/allanwang/kau/utils/ContextUtils.kt | 20 +++++++++++--------- core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt | 20 ++++++++++++++++---- sample/src/main/res/xml/kau_changelog.xml | 2 +- 4 files changed, 31 insertions(+), 17 deletions(-) (limited to 'core/src/main/kotlin') diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt index 5631e70..33bdc62 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt @@ -32,9 +32,9 @@ fun Activity.startActivityForResult( bundle: Bundle? = null, intentBuilder: Intent.() -> Unit = {}) { val intent = Intent(this, clazz) - val fullBundle = if (transition && buildIsLollipopAndUp) - ActivityOptions.makeSceneTransitionAnimation(this).toBundle() - else Bundle() + val fullBundle = Bundle() + if (transition && buildIsLollipopAndUp) + fullBundle.with(ActivityOptions.makeSceneTransitionAnimation(this).toBundle()) if (bundle != null) fullBundle.putAll(bundle) intent.intentBuilder() startActivityForResult(intent, requestCode, if (fullBundle.isEmpty) null else fullBundle) 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 a72c7dd..0664dc6 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt @@ -43,9 +43,9 @@ fun Context.startActivity( intentBuilder: Intent.() -> Unit = {}) { val intent = Intent(this, clazz) if (clearStack) intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK) - val fullBundle = if (transition && this is Activity && buildIsLollipopAndUp) - ActivityOptions.makeSceneTransitionAnimation(this).toBundle() - else Bundle() + val fullBundle = Bundle() + if (transition && this is Activity && buildIsLollipopAndUp) + fullBundle.with(ActivityOptions.makeSceneTransitionAnimation(this).toBundle()) if (transition && this !is Activity) KL.d("Cannot make scene transition when context is not an instance of an Activity") if (bundle != null) fullBundle.putAll(bundle) intent.intentBuilder() @@ -57,9 +57,10 @@ fun Context.startActivity( * Bring in activity from the right */ fun Context.startActivitySlideIn(clazz: Class, clearStack: Boolean = false, intentBuilder: Intent.() -> Unit = {}, bundleBuilder: Bundle.() -> Unit = {}) { - val bundle = ActivityOptionsCompat.makeCustomAnimation(this, R.anim.kau_slide_in_right, R.anim.kau_fade_out).toBundle() - bundle.bundleBuilder() - startActivity(clazz, clearStack, intentBuilder = intentBuilder, bundle = bundle) + val fullBundle = Bundle() + fullBundle.with(ActivityOptionsCompat.makeCustomAnimation(this, R.anim.kau_slide_in_right, R.anim.kau_fade_out).toBundle()) + fullBundle.bundleBuilder() + startActivity(clazz, clearStack, intentBuilder = intentBuilder, bundle = if (fullBundle.isEmpty) null else fullBundle) } /** @@ -69,9 +70,10 @@ fun Context.startActivitySlideIn(clazz: Class, clearStack: Boolean * Consequently, the stack will be cleared by default */ fun Context.startActivitySlideOut(clazz: Class, clearStack: Boolean = true, intentBuilder: Intent.() -> Unit = {}, bundleBuilder: Bundle.() -> Unit = {}) { - val bundle = ActivityOptionsCompat.makeCustomAnimation(this, R.anim.kau_fade_in, R.anim.kau_slide_out_right_top).toBundle() - bundle.bundleBuilder() - startActivity(clazz, clearStack, intentBuilder = intentBuilder, bundle = bundle) + val fullBundle = Bundle() + fullBundle.with(ActivityOptionsCompat.makeCustomAnimation(this, R.anim.kau_fade_in, R.anim.kau_slide_out_right_top).toBundle()) + fullBundle.bundleBuilder() + startActivity(clazz, clearStack, intentBuilder = intentBuilder, bundle = if (fullBundle.isEmpty) null else fullBundle) } fun Context.startPlayStoreLink(@StringRes packageIdRes: Int) = startPlayStoreLink(string(packageIdRes)) diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt index 50a3c29..954bedc 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt @@ -6,6 +6,7 @@ import android.graphics.Bitmap import android.graphics.Canvas import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable +import android.os.Bundle import android.os.Handler import android.os.Looper import android.support.annotation.IntRange @@ -53,14 +54,16 @@ annotation class KauUtils * Converts minute value to string * Whole hours and days will be converted as such, otherwise it will default to x minutes */ -@KauUtils fun Context.minuteToText(minutes: Long): String = with(minutes) { +@KauUtils +fun Context.minuteToText(minutes: Long): String = with(minutes) { if (this < 0L) string(R.string.kau_none) else if (this % 1440L == 0L) plural(R.plurals.kau_x_days, this / 1440L) else if (this % 60L == 0L) plural(R.plurals.kau_x_hours, this / 60L) else plural(R.plurals.kau_x_minutes, this) } -@KauUtils fun Number.round(@IntRange(from = 1L) decimalCount: Int): String { +@KauUtils +fun Number.round(@IntRange(from = 1L) decimalCount: Int): String { val expression = StringBuilder().append("#.") (1..decimalCount).forEach { expression.append("#") } val formatter = DecimalFormat(expression.toString()) @@ -72,7 +75,8 @@ annotation class KauUtils * Extracts the bitmap of a drawable, and applies a scale if given * For solid colors, a 1 x 1 pixel will be generated */ -@KauUtils fun Drawable.toBitmap(scaling: Float = 1f, config: Bitmap.Config = Bitmap.Config.ARGB_8888): Bitmap { +@KauUtils +fun Drawable.toBitmap(scaling: Float = 1f, config: Bitmap.Config = Bitmap.Config.ARGB_8888): Bitmap { if (this is BitmapDrawable && bitmap != null) { if (scaling == 1f) return bitmap val width = (bitmap.width * scaling).toInt() @@ -122,4 +126,12 @@ class KauException(message: String) : RuntimeException(message) fun String.withMaxLength(n: Int): String = if (length <= n) this - else substring(0, n-1) + KAU_ELLIPSIS \ No newline at end of file + else substring(0, n - 1) + KAU_ELLIPSIS + +/** + * Similar to [Bundle.putAll], but checks for a null insert and returns the parent bundle + */ +fun Bundle.with(bundle: Bundle?): Bundle { + if (bundle != null) putAll(bundle) + return this +} \ No newline at end of file diff --git a/sample/src/main/res/xml/kau_changelog.xml b/sample/src/main/res/xml/kau_changelog.xml index 8476660..53dfe99 100644 --- a/sample/src/main/res/xml/kau_changelog.xml +++ b/sample/src/main/res/xml/kau_changelog.xml @@ -9,7 +9,7 @@ - + -- cgit v1.2.3 From b87c75d607956393ad3b07751eb59ccf41726863 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Wed, 11 Oct 2017 14:17:27 -0400 Subject: 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 --- .../main/kotlin/ca/allanwang/kau/about/FaqIItem.kt | 6 ++--- .../kotlin/ca/allanwang/kau/about/LibraryIItem.kt | 6 ++--- .../kotlin/ca/allanwang/kau/iitems/CardIItem.kt | 2 +- .../ca/allanwang/kau/colorpicker/CircleView.kt | 4 ---- .../kotlin/ca/allanwang/kau/ui/views/CutoutView.kt | 12 ++++++---- .../kotlin/ca/allanwang/kau/logging/KauLogger.kt | 28 +++++++++++++++++++++- .../allanwang/kau/permissions/PermissionManager.kt | 6 ++--- .../ca/allanwang/kau/swipe/SwipeBackLayout.kt | 18 ++++++++------ .../main/kotlin/ca/allanwang/kau/xml/Changelog.kt | 2 +- .../kotlin/ca/allanwang/kau/sample/MainActivity.kt | 2 +- .../ca/allanwang/kau/searchview/SearchItem.kt | 8 +++---- 11 files changed, 61 insertions(+), 33 deletions(-) (limited to 'core/src/main/kotlin') diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt b/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt index 629aa52..5595aed 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt @@ -1,5 +1,6 @@ package ca.allanwang.kau.about +import android.annotation.SuppressLint import android.support.v7.widget.RecyclerView import android.text.method.LinkMovementMethod import android.view.View @@ -22,9 +23,7 @@ class FaqIItem(val content: FaqItem) : KauIItem>) { + fun bindEvents(fastAdapter: FastAdapter>) { fastAdapter.withSelectable(false) .withEventHook(object : ClickEventHook>() { @@ -43,6 +42,7 @@ class FaqIItem(val content: FaqItem) : KauIItem?) { super.bindView(holder, payloads) with(holder) { diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt b/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt index e50460e..88e6f9b 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt @@ -25,7 +25,7 @@ class LibraryIItem(val lib: Library) : KauIItem>) { + fun bindEvents(fastAdapter: FastAdapter>) { fastAdapter.withSelectable(false) .withOnClickListener { v, _, item, _ -> if (item !is LibraryIItem) false @@ -53,11 +53,11 @@ class LibraryIItem(val lib: Library) : KauIItem>) { + fun bindClickEvents(fastAdapter: FastAdapter>) { fastAdapter.withEventHook(object : ClickEventHook>() { override fun onBindMany(viewHolder: RecyclerView.ViewHolder): List? { return if (viewHolder is ViewHolder) listOf(viewHolder.card, viewHolder.button) else null diff --git a/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/CircleView.kt b/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/CircleView.kt index d697c8b..ed98090 100644 --- a/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/CircleView.kt +++ b/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/CircleView.kt @@ -194,7 +194,6 @@ class CircleView @JvmOverloads constructor(context: Context, attrs: AttributeSet companion object { @ColorInt - @JvmStatic private fun translucentColor(color: Int): Int { val factor = 0.7f val alpha = Math.round(Color.alpha(color) * factor) @@ -205,7 +204,6 @@ class CircleView @JvmOverloads constructor(context: Context, attrs: AttributeSet } @ColorInt - @JvmStatic fun shiftColor(@ColorInt color: Int, @FloatRange(from = 0.0, to = 2.0) by: Float): Int { if (by == 1f) return color @@ -215,11 +213,9 @@ class CircleView @JvmOverloads constructor(context: Context, attrs: AttributeSet } @ColorInt - @JvmStatic fun shiftColorDown(@ColorInt color: Int): Int = shiftColor(color, 0.9f) @ColorInt - @JvmStatic fun shiftColorUp(@ColorInt color: Int): Int = shiftColor(color, 1.1f) } } \ No newline at end of file diff --git a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/CutoutView.kt b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/CutoutView.kt index 9e8ac11..fc03563 100644 --- a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/CutoutView.kt +++ b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/CutoutView.kt @@ -147,14 +147,16 @@ class CutoutView @JvmOverloads constructor( paint.textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, mid, metrics) val maxLineWidth = paint.measureText(text) - return if (high - low < precision) low - else if (maxLineWidth > targetWidth) getSingleLineTextSize(text, paint, targetWidth, low, mid, precision, metrics) - else if (maxLineWidth < targetWidth) getSingleLineTextSize(text, paint, targetWidth, mid, high, precision, metrics) - else mid + return when { + high - low < precision -> low + maxLineWidth > targetWidth -> getSingleLineTextSize(text, paint, targetWidth, low, mid, precision, metrics) + maxLineWidth < targetWidth -> getSingleLineTextSize(text, paint, targetWidth, mid, high, precision, metrics) + else -> mid + } } private fun createBitmap() { - if (!(cutout?.isRecycled ?: true)) + if (cutout?.isRecycled == false) cutout?.recycle() if (width == 0 || height == 0) return cutout = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) 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,13 +11,33 @@ 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 @@ -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> by lazy { mutableListOf>() } + private var requestInProgress = false + private val pendingResults: MutableList> by lazy { mutableListOf>() } /** * 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() } /** diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt index ca75ebb..482c911 100644 --- a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt @@ -277,7 +277,7 @@ class MainActivity : KPrefActivity() { } override fun onBackPressed() { - if (!(searchView?.onBackPressed() ?: false)) super.onBackPressed() + if (searchView?.onBackPressed() != true) super.onBackPressed() } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { diff --git a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt index 75d9b27..29341af 100644 --- a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt +++ b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt @@ -34,8 +34,8 @@ class SearchItem(val key: String, ) { companion object { - @JvmStatic var foregroundColor: Int = 0xdd000000.toInt() - @JvmStatic var backgroundColor: Int = 0xfffafafa.toInt() + var foregroundColor: Int = 0xdd000000.toInt() + var backgroundColor: Int = 0xfffafafa.toInt() } var styledContent: SpannableStringBuilder? = null @@ -44,7 +44,7 @@ class SearchItem(val key: String, * Highlight the subText if it is present in the content */ fun withHighlights(subText: String) { - val index = content.indexOf(subText) + val index = content.indexOf(subText, ignoreCase = true) if (index == -1) return styledContent = SpannableStringBuilder(content) styledContent!!.setSpan(StyleSpan(Typeface.BOLD), index, index + subText.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) @@ -60,7 +60,7 @@ class SearchItem(val key: String, holder.container.setRippleBackground(foregroundColor, backgroundColor) holder.title.text = styledContent ?: content - if (description?.isNotBlank() ?: false) holder.desc.visible().text = description + if (description?.isNotBlank() == true) holder.desc.visible().text = description } override fun unbindView(holder: ViewHolder) { -- cgit v1.2.3