diff options
21 files changed, 202 insertions, 98 deletions
diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt b/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt index 452d28c..f7eddb9 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt @@ -69,7 +69,9 @@ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilde val panels: List<AboutPanelContract> by lazy { val defaultPanels = mutableListOf(AboutPanelMain(), AboutPanelLibs()) - if (configs.faqXmlRes != INVALID_ID) defaultPanels.add(AboutPanelFaqs()) + if (configs.faqXmlRes != INVALID_ID) { + defaultPanels.add(AboutPanelFaqs()) + } defaultPanels } @@ -78,7 +80,9 @@ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilde setContentView(R.layout.kau_activity_about) pageStatus = IntArray(panels.size) pageStatus[0] = 2 //the first page is instantly visible - if (configs.textColor != null) about_indicator.setColour(configs.textColor!!) + if (configs.textColor != null) { + about_indicator.setColour(configs.textColor!!) + } with(about_pager) { adapter = AboutPagerAdapter() pageMargin = dimenPixelSize(R.dimen.kau_spacing_normal) 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 275945b..cd53f55 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt @@ -43,13 +43,14 @@ class LibraryIItem(val lib: Library) : KauIItem<LibraryIItem.ViewHolder>( fun bindEvents(fastAdapter: FastAdapter<GenericItem>) { fastAdapter.getSelectExtension().isSelectable = true fastAdapter.onClickListener = { v, _, item, _ -> - if (item !is LibraryIItem) + if (item !is LibraryIItem) { false - else + } else { with(item.lib) { v!!.context.startLink(libraryWebsite, repositoryLink, authorWebsite) true } + } } } } diff --git a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt index aff4d1c..3e7254f 100644 --- a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt +++ b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt @@ -53,7 +53,9 @@ abstract class ElasticRecyclerActivity : KauBaseActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.kau_elastic_recycler_activity) setSupportActionBar(kau_toolbar) - if (!onCreate(savedInstanceState, configs)) return + if (!onCreate(savedInstanceState, configs)) { + return + } kau_draggable.addListener(object : ElasticDragDismissFrameLayout.SystemChromeFader(this) { override fun onDragDismissed() { diff --git a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt index 52672fa..6095a32 100644 --- a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt +++ b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt @@ -204,7 +204,9 @@ class ElasticDragDismissFrameLayout @JvmOverloads constructor( } translationY = dragTo - if (shouldScale) scaleXY = 1 - (1 - dragDismissScale) * dragFraction + if (shouldScale) { + scaleXY = 1 - (1 - dragDismissScale) * dragFraction + } // if we've reversed direction and gone past the settle point then clear the flags to // allow the list to get the scroll events & reset any transforms 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 78661b1..5ae8376 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt @@ -104,8 +104,9 @@ class EmailBuilder(val email: String, val subject: String) { if (packages.isNotEmpty()) { emailBuilder.append("\n") packages.forEach { - if (context.isAppInstalled(it.packageName)) + if (context.isAppInstalled(it.packageName)) { emailBuilder.append(String.format("\n%s is installed", it.appName)) + } } } 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 65d15a7..582b0cd 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/kotlin/Streams.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/kotlin/Streams.kt @@ -26,8 +26,11 @@ package ca.allanwang.kau.kotlin */ 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() + while (iter.hasNext()) { + if (filter(iter.next())) { + iter.remove() + } + } return this } @@ -38,7 +41,9 @@ inline fun <T, C : MutableIterable<T>> C.kauRemoveIf(filter: (item: T) -> Boolea inline fun <T : Any> Iterator<T>.firstOrNull(predicate: (T) -> Boolean): T? { while (hasNext()) { val data = next() - if (predicate(data)) return data + if (predicate(data)) { + return data + } } return null } 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 4562b00..9410c4c 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt @@ -64,16 +64,18 @@ open class KauLogger( } inline fun log(priority: Int, message: () -> Any?, t: Throwable? = null) { - if (shouldLog(priority)) + if (shouldLog(priority)) { logImpl(priority, message()?.toString(), t) + } } open fun logImpl(priority: Int, message: String?, t: Throwable?) { val msg = message ?: "null" - if (t != null) + if (t != null) { Log.e(tag, msg, t) - else + } else { Log.println(priority, tag, msg) + } } /** @@ -113,8 +115,11 @@ class KauLoggerExtension(val tag: String, val logger: KauLogger) { inline fun log(priority: Int, message: () -> Any?, t: Throwable? = null) = logger.log(priority, { val msg = message()?.toString() - if (msg == null) null - else "$tag: $msg" + if (msg == null) { + null + } else { + "$tag: $msg" + } }, t) inline fun checkThread(id: Int) { 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 1f564ce..0fb0046 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt @@ -52,7 +52,9 @@ internal class SwipeBackLayout @JvmOverloads constructor( */ override var scrollThreshold = DEFAULT_SCROLL_THRESHOLD set(value) { - if (value >= 1.0f || value <= 0f) throw IllegalArgumentException("Threshold value should be between 0.0 and 1.0") + if (value >= 1.0f || value <= 0f) { + throw IllegalArgumentException("Threshold value should be between 0.0 and 1.0") + } field = value } @@ -130,8 +132,9 @@ internal class SwipeBackLayout @JvmOverloads constructor( * We will verify that only one axis is used at a time */ set(value) { - if (value !in arrayOf(SWIPE_EDGE_TOP, SWIPE_EDGE_BOTTOM, SWIPE_EDGE_LEFT, SWIPE_EDGE_RIGHT)) + if (value !in arrayOf(SWIPE_EDGE_TOP, SWIPE_EDGE_BOTTOM, SWIPE_EDGE_LEFT, SWIPE_EDGE_RIGHT)) { throw IllegalArgumentException("Edge flag is not valid; use one of the SWIPE_EDGE_* values") + } field = value horizontal = edgeFlag == SWIPE_EDGE_LEFT || edgeFlag == SWIPE_EDGE_RIGHT dragHelper.setEdgeTrackingEnabled(value) @@ -197,8 +200,9 @@ internal class SwipeBackLayout @JvmOverloads constructor( val iter = listeners.iterator() while (iter.hasNext()) { val l = iter.next().get() - if (l == null || l == listener) + if (l == null || l == listener) { iter.remove() + } } } @@ -210,10 +214,11 @@ internal class SwipeBackLayout @JvmOverloads constructor( val iter = listeners.iterator() while (iter.hasNext()) { val l = iter.next().get() - if (l == null) + if (l == null) { iter.remove() - else if (l == listener) + } else if (l == listener) { return true + } } return false } @@ -239,12 +244,14 @@ internal class SwipeBackLayout @JvmOverloads constructor( } override fun onInterceptTouchEvent(event: MotionEvent): Boolean { - if (!swipeEnabled || disallowIntercept) return false - try { - return dragHelper.shouldInterceptTouchEvent(event) - } catch (e: Exception) { + if (!swipeEnabled || disallowIntercept) { return false } + return try { + dragHelper.shouldInterceptTouchEvent(event) + } catch (e: Exception) { + false + } } @SuppressLint("ClickableViewAccessibility") diff --git a/core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt b/core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt index a46e6c5..bb4cd88 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt @@ -94,7 +94,9 @@ class ProgressAnimator private constructor() : ValueAnimator() { * @return [condition] */ private fun ProgressAction.runIf(condition: Boolean, progress: Float): Boolean { - if (condition) this(progress) + if (condition) { + this(progress) + } return condition } @@ -170,7 +172,9 @@ class ProgressAnimator private constructor() : ValueAnimator() { fun withDisposableEndAction(action: ProgressDisposableRunnable) = endActions.add(action) fun reset() { - if (isRunning) cancel() + if (isRunning) { + cancel() + } animators.clear() startActions.clear() cancelActions.clear() diff --git a/core/src/main/kotlin/ca/allanwang/kau/ui/views/CollapsibleViewDelegate.kt b/core/src/main/kotlin/ca/allanwang/kau/ui/views/CollapsibleViewDelegate.kt index b2a0d27..4631aec 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/ui/views/CollapsibleViewDelegate.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/ui/views/CollapsibleViewDelegate.kt @@ -62,15 +62,22 @@ class CollapsibleViewDelegate : CollapsibleView { override var expansion = 0f set(value) { - if (value == field) return + if (value == field) { + return + } var v = value - if (v > 1) v = 1f - else if (v < 0) v = 0f + if (v > 1) { + v = 1f + } else if (v < 0) { + v = 0f + } stateHolder = - if (v == 0f) KAU_COLLAPSED - else if (v == 1f) KAU_EXPANDED - else if (v - field < 0) KAU_COLLAPSING - else KAU_EXPANDING + when { + v == 0f -> KAU_COLLAPSED + v == 1f -> KAU_EXPANDED + v - field < 0 -> KAU_COLLAPSING + else -> KAU_EXPANDING + } field = v view?.goneIf(state == KAU_COLLAPSED) view?.requestLayout() @@ -89,8 +96,11 @@ class CollapsibleViewDelegate : CollapsibleView { override fun resetCollapsibleAnimation() { animator?.cancel() animator = null - if (stateHolder == KAU_COLLAPSING) stateHolder = KAU_COLLAPSED - else if (stateHolder == KAU_EXPANDING) stateHolder = KAU_EXPANDED + if (stateHolder == KAU_COLLAPSING) { + stateHolder = KAU_COLLAPSED + } else if (stateHolder == KAU_EXPANDING) { + stateHolder = KAU_EXPANDED + } } override fun getCollapsibleDimension(): Pair<Int, Int> { @@ -116,8 +126,14 @@ class CollapsibleViewDelegate : CollapsibleView { override fun collapse(animate: Boolean) = setExpanded(false, animate) override fun setExpanded(expand: Boolean) = setExpanded(expand, true) override fun setExpanded(expand: Boolean, animate: Boolean) { - if (expand == expanded) return //state already matches + if (expand == expanded) { + return //state already matches + } val target = if (expand) 1f else 0f - if (animate) animateSize(target) else expansion = target + if (animate) { + animateSize(target) + } else { + expansion = target + } } } diff --git a/core/src/main/kotlin/ca/allanwang/kau/ui/views/MeasureSpecDelegate.kt b/core/src/main/kotlin/ca/allanwang/kau/ui/views/MeasureSpecDelegate.kt index 6481306..8800c2d 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/ui/views/MeasureSpecDelegate.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/ui/views/MeasureSpecDelegate.kt @@ -95,7 +95,9 @@ class MeasureSpecDelegate : MeasureSpecContract { private val parentFrame = Rect() override fun initAttrs(context: Context, attrs: AttributeSet?) { - if (attrs == null) return + if (attrs == null) { + return + } val styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.MeasureSpecDelegate) relativeWidth = styledAttrs.getFloat(R.styleable.MeasureSpecDelegate_relativeWidth, relativeWidth) relativeHeight = styledAttrs.getFloat(R.styleable.MeasureSpecDelegate_relativeHeight, relativeHeight) @@ -114,20 +116,24 @@ class MeasureSpecDelegate : MeasureSpecContract { var width = View.MeasureSpec.getSize(widthMeasureSpec).toFloat() var height = View.MeasureSpec.getSize(heightMeasureSpec).toFloat() //first cycle - relative to parent - if (relativeHeightToParent > 0) + if (relativeHeightToParent > 0) { height = relativeHeightToParent * parentFrame.height() - if (relativeWidthToParent > 0) + } + if (relativeWidthToParent > 0) { width = relativeWidthToParent * parentFrame.width() + } //second cycle - relative to each other - if (relativeHeight > 0) + if (relativeHeight > 0) { height = relativeHeight * width - else if (relativeWidth > 0) + } else if (relativeWidth > 0) { width = relativeWidth * height + } //third cycle - relative to each other - if (postRelativeHeight > 0) + if (postRelativeHeight > 0) { height = postRelativeHeight * width - else if (postRelativeWidth > 0) + } else if (postRelativeWidth > 0) { width = postRelativeWidth * height + } return Pair(width.measureSpec, height.measureSpec) } 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 176b9ea..a972447 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 @@ -102,11 +102,12 @@ class RippleCanvas @JvmOverloads constructor( ripple.radius = animation.animatedValue as Float invalidate() } - if (callback != null) + if (callback != null) { animator.addListener(object : AnimatorListenerAdapter() { override fun onAnimationCancel(animation: Animator?) = callback() override fun onAnimationEnd(animation: Animator?) = callback() }) + } animator.start() } 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 21141f1..3b593a6 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt @@ -125,7 +125,9 @@ inline var Activity.statusBarColor: Int get() = if (buildIsLollipopAndUp) window.statusBarColor else Color.BLACK @SuppressLint("NewApi") set(value) { - if (buildIsLollipopAndUp) window.statusBarColor = value + if (buildIsLollipopAndUp) { + window.statusBarColor = value + } } inline var Activity.statusBarLight: Boolean 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 d002fb8..2f552ed 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt @@ -80,22 +80,27 @@ inline fun <T : Activity> 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) + if (clearStack) { + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK) + } intent.intentBuilder() val bundle = Bundle() bundle.bundleBuilder() - startActivity(intent, if (bundle.isEmpty) null else bundle) - if (clearStack && this is Activity) finish() + startActivity(intent, bundle.takeIf { !it.isEmpty }) + if (clearStack && this is Activity) { + finish() + } } fun Context.startPlayStoreLink(@StringRes packageIdRes: Int) = startPlayStoreLink(string(packageIdRes)) fun Context.startPlayStoreLink(packageId: String) { val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=$packageId")) - if (intent.resolveActivity(packageManager) != null) + if (intent.resolveActivity(packageManager) != null) { startActivity(intent) - else + } else { toast("Cannot resolve play store", log = true) + } } /** @@ -105,10 +110,11 @@ 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)) - if (browserIntent.resolveActivity(packageManager) != null) + if (browserIntent.resolveActivity(packageManager) != null) { startActivity(browserIntent) - else + } else { toast("Cannot resolve browser", log = true) + } } fun Context.startLink(@StringRes url: Int) = startLink(string(url)) @@ -240,19 +246,22 @@ fun Context.hasPermission(permissions: String) = !buildIsMarshmallowAndUp || Con fun Context.copyToClipboard(text: String?, label: String = "Copied Text", showToast: Boolean = true) { val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager clipboard.setPrimaryClip(ClipData.newPlainText(label, text ?: "")) - if (showToast) toast(R.string.kau_text_copied) + if (showToast) { + toast(R.string.kau_text_copied) + } } fun Context.shareText(text: String?) { - if (text == null) return toast("Share text is null") + text ?: return toast("Share text is null") val intent = Intent(Intent.ACTION_SEND) intent.type = "text/plain" intent.putExtra(Intent.EXTRA_TEXT, text) val chooserIntent = Intent.createChooser(intent, string(R.string.kau_share)) - if (chooserIntent.resolveActivity(packageManager) != null) + if (chooserIntent.resolveActivity(packageManager) != null) { startActivity(chooserIntent) - else + } else { toast("Cannot resolve activity to share text", log = true) + } } /** diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt index 186d125..e4ec19c 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt @@ -105,7 +105,7 @@ fun ImageView.setIcon( @ColorInt color: Int = Color.WHITE, builder: IconicsDrawable.() -> Unit = {} ) { - if (icon == null) return + icon ?: return setImageDrawable(icon.toDrawable(context, sizeDp = sizeDp, color = color, builder = builder)) } @@ -274,7 +274,9 @@ fun Context.fullLinearRecycler(rvAdapter: RecyclerView.Adapter<*>? = null, confi layoutManager = LinearLayoutManager(this@fullLinearRecycler) layoutParams = RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.MATCH_PARENT) - if (rvAdapter != null) adapter = rvAdapter + if (rvAdapter != null) { + adapter = rvAdapter + } configs() } @@ -296,8 +298,9 @@ inline fun <T : ImageView> T.fadeScaleTransition( minScale: Float = 0.7f, crossinline action: T.() -> Unit ) { - if (!isVisible) action() - else { + if (!isVisible) { + action() + } else { var transitioned = false ValueAnimator.ofFloat(1.0f, 0.0f, 1.0f).apply { this.duration = duration @@ -323,12 +326,17 @@ fun FloatingActionButton.hideOnDownwardsScroll(recycler: RecyclerView) { recycler.addOnScrollListener(object : RecyclerView.OnScrollListener() { override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { - if (newState == RecyclerView.SCROLL_STATE_IDLE && !isShown) show() + if (newState == RecyclerView.SCROLL_STATE_IDLE && !isShown) { + show() + } } override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { - if (dy > 0 && isShown) hide() - else if (dy < 0 && isHidden) show() + if (dy > 0 && isShown) { + hide() + } else if (dy < 0 && isHidden) { + show() + } } }) } 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 9adcbf4..0872b68 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt @@ -84,8 +84,9 @@ internal fun parse(context: Context, @XmlRes xmlRes: Int): List<Pair<String, Cha context.resources.getXml(xmlRes).use { parser: XmlResourceParser -> var eventType = parser.eventType while (eventType != XmlPullParser.END_DOCUMENT) { - if (eventType == XmlPullParser.START_TAG) + if (eventType == XmlPullParser.START_TAG) { ChangelogType.values.any { it.add(parser, items) } + } eventType = parser.next() } } @@ -104,9 +105,12 @@ internal enum class ChangelogType(val tag: String, val attr: String, @LayoutRes * Returns true if tag matches; false otherwise */ fun add(parser: XmlResourceParser, list: MutableList<Pair<String, ChangelogType>>): Boolean { - if (parser.name != tag) return false - if (parser.getAttributeValue(null, attr).isNotBlank()) + if (parser.name != tag) { + return false + } + if (parser.getAttributeValue(null, attr).isNotBlank()) { list.add(Pair(parser.getAttributeValue(null, attr), this)) + } return true } } diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt index 5531f59..c5ce61f 100644 --- a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt +++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt @@ -79,7 +79,9 @@ class FastItemThemedAdapter<Item : GenericItem>( } fun themeChanged() { - if (adapterItemCount == 0) return + if (adapterItemCount == 0) { + return + } injectTheme(adapterItems) notifyAdapterDataSetChanged() } diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt index c7cff55..ad83d8a 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt @@ -110,11 +110,12 @@ abstract class MediaPickerActivityBase( */ private fun setToolbarScrollable(scrollable: Boolean) { val params = kau_toolbar.layoutParams as AppBarLayout.LayoutParams - if (scrollable) + if (scrollable) { params.scrollFlags = AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS or AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL - else + } else { params.scrollFlags = 0 + } } override fun onLoadFinished(loader: Loader<Cursor>, data: Cursor?) { diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt index d21b33f..cc6df81 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt @@ -147,9 +147,8 @@ abstract class MediaPickerCore<T : GenericItem>( recycler.apply { val manager = object : GridLayoutManager(context, computeColumnCount(context)) { override fun getExtraLayoutSpace(state: RecyclerView.State?): Int { - return if (mediaType != MediaType.VIDEO) extraSpace else super.getExtraLayoutSpace( - state - ) + return if (mediaType != MediaType.VIDEO) extraSpace + else super.getExtraLayoutSpace(state) } } setItemViewCacheSize(CACHE_SIZE) 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 7bf01b3..78d8782 100644 --- a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt +++ b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt @@ -66,7 +66,9 @@ class SearchItem( internal fun withHighlights(subText: String?) { subText ?: return val index = content.indexOf(subText, ignoreCase = true) - if (index == -1) return + if (index == -1) { + return + } styledContent = SpannableStringBuilder(content) styledContent!!.setSpan( StyleSpan(Typeface.BOLD), @@ -81,12 +83,17 @@ class SearchItem( holder.title.setTextColor(foregroundColor) holder.desc.setTextColor(foregroundColor.adjustAlpha(0.6f)) - if (image != null) holder.icon.setImageDrawable(image) - else holder.icon.setIcon(iicon, sizeDp = 18, color = foregroundColor) + if (image != null) { + holder.icon.setImageDrawable(image) + } else { + holder.icon.setIcon(iicon, sizeDp = 18, color = foregroundColor) + } holder.container.setRippleBackground(foregroundColor, backgroundColor) holder.title.text = styledContent ?: content - if (description?.isNotBlank() == true) holder.desc.visible().text = description + if (description?.isNotBlank() == true) { + holder.desc.visible().text = description + } } override fun unbindView(holder: ViewHolder) { diff --git a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt index da06ec4..a552a01 100644 --- a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt +++ b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt @@ -234,10 +234,14 @@ class SearchView @JvmOverloads constructor( } val icons = mutableListOf(navIcon to kau_search_nav, clearIcon to kau_search_clear) val extra = extraIcon - if (extra != null) icons.add(extra.first to kau_search_extra) + if (extra != null) { + icons.add(extra.first to kau_search_extra) + } icons.forEach { (iicon, view) -> view.goneIf(iicon == null).setSearchIcon(iicon) } - if (extra != null) kau_search_extra.setOnClickListener(extra.second) + if (extra != null) { + kau_search_extra.setOnClickListener(extra.second) + } kau_search_divider.invisibleIf(!withDivider) kau_search_edit_text.hint = context.string(hintTextRes, hintText) textCallback.terminate() @@ -312,7 +316,9 @@ class SearchView @JvmOverloads constructor( addOnScrollListener(object : RecyclerView.OnScrollListener() { override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { super.onScrollStateChanged(recyclerView, newState) - if (newState == RecyclerView.SCROLL_STATE_DRAGGING) hideKeyboard() + if (newState == RecyclerView.SCROLL_STATE_DRAGGING) { + hideKeyboard() + } } }) itemAnimator = null @@ -330,12 +336,15 @@ class SearchView @JvmOverloads constructor( ); true } onLongClickListener = { _, _, item, position -> - if (item.key.isNotBlank()) configs.onItemLongClick( - position, - item.key, - item.content, - this@SearchView - ); true + if (item.key.isNotBlank()) { + configs.onItemLongClick( + position, + item.key, + item.content, + this@SearchView + ) + } + true } } kau_search_edit_text.addTextChangedListener(object : TextWatcher { @@ -346,20 +355,21 @@ class SearchView @JvmOverloads constructor( override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { val text = s.toString().trim() textCallback.cancel() - if (text.isNotEmpty()) + if (text.isNotEmpty()) { textCallback(text, this@SearchView) - else if (!configs.textClearedCallback(this@SearchView)) + } else if (!configs.textClearedCallback(this@SearchView)) { clearResults() + } } }) kau_search_edit_text.setOnEditorActionListener { _, actionId, _ -> if (actionId == EditorInfo.IME_ACTION_SEARCH) { - if (configs.searchCallback( - kau_search_edit_text.text?.toString() - ?: "", this - ) - ) revealClose() - else kau_search_edit_text.hideKeyboard() + val query = kau_search_edit_text.text?.toString() ?: "" + if (configs.searchCallback(query, this)) { + revealClose() + } else { + kau_search_edit_text.hideKeyboard() + } return@setOnEditorActionListener true } false @@ -427,7 +437,9 @@ class SearchView @JvmOverloads constructor( private fun configureCoords(item: MenuItem?) { item ?: return - if (parent !is ViewGroup) return + if (parent !is ViewGroup) { + return + } val view = parentViewGroup.findViewById<View>(item.itemId) ?: return view.getLocationInWindow(locations) menuX = (locations[0] + view.width / 2) @@ -477,7 +489,9 @@ class SearchView @JvmOverloads constructor( } fun revealOpen() { - if (parent == null || isOpen) return + if (parent == null || isOpen) { + return + } context.runOnUiThread { /** * The y component is relative to the cardView, but it hasn't been drawn yet so its own height is 0 @@ -500,7 +514,9 @@ class SearchView @JvmOverloads constructor( } fun revealClose() { - if (parent == null || !isOpen) return + if (parent == null || !isOpen) { + return + } context.runOnUiThread { kau_search_shadow.fadeOut(duration = configs.transitionDuration) cardTransition { @@ -510,7 +526,9 @@ class SearchView @JvmOverloads constructor( duration = configs.revealDuration, onFinish = { configs.closeListener?.invoke(this@SearchView) - if (configs.shouldClearOnClose) kau_search_edit_text.text?.clear() + if (configs.shouldClearOnClose) { + kau_search_edit_text.text?.clear() + } }) } } |