aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt27
-rw-r--r--android-lib.gradle7
-rw-r--r--core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt26
-rw-r--r--core-ui/src/main/res-public/values/public.xml2
-rw-r--r--core/src/main/res-public/values/public.xml34
-rw-r--r--fastadapter-viewbinding/build.gradle6
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt64
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt69
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt59
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt21
-rw-r--r--sample/build.gradle7
-rw-r--r--searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt243
12 files changed, 300 insertions, 265 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 4fe97da..286d95e 100644
--- a/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt
+++ b/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt
@@ -23,6 +23,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.viewpager.widget.PagerAdapter
import androidx.viewpager.widget.ViewPager
+import ca.allanwang.kau.about.databinding.KauActivityAboutBinding
import ca.allanwang.kau.adapters.FastItemThemedAdapter
import ca.allanwang.kau.adapters.ThemableIItemColors
import ca.allanwang.kau.adapters.ThemableIItemColorsDelegate
@@ -34,7 +35,6 @@ import ca.allanwang.kau.utils.dimenPixelSize
import com.mikepenz.aboutlibraries.Libs
import com.mikepenz.aboutlibraries.entity.Library
import com.mikepenz.fastadapter.GenericItem
-import kotlinx.android.synthetic.main.kau_activity_about.*
/**
* Created by Allan Wang on 2017-06-28.
@@ -51,7 +51,7 @@ abstract class AboutActivityBase(val rClass: Class<*>?) :
KauBaseActivity(), ViewPager.OnPageChangeListener {
val currentPage: Int
- get() = about_pager.currentItem
+ get() = binding.aboutPager.currentItem
/**
* Holds some common configurations that may be added directly from the constructor
@@ -77,31 +77,38 @@ abstract class AboutActivityBase(val rClass: Class<*>?) :
defaultPanels
}
+ private lateinit var binding: KauActivityAboutBinding
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- setContentView(R.layout.kau_activity_about)
+ binding = KauActivityAboutBinding.inflate(layoutInflater)
+ setContentView(binding.root)
+ binding.init()
+ }
+
+ private fun KauActivityAboutBinding.init() {
pageStatus = IntArray(panels.size)
pageStatus[0] = 2 // the first page is instantly visible
if (configs.textColor != null) {
- about_indicator.setColour(configs.textColor!!)
+ aboutIndicator.setColour(configs.textColor!!)
}
- with(about_pager) {
+ with(aboutPager) {
adapter = AboutPagerAdapter()
pageMargin = dimenPixelSize(R.dimen.kau_spacing_normal)
offscreenPageLimit = panels.size - 1
addOnPageChangeListener(this@AboutActivityBase)
}
- about_indicator.setViewPager(about_pager)
- about_draggable_frame.addListener(object :
- ElasticDragDismissFrameLayout.SystemChromeFader(this) {
+ aboutIndicator.setViewPager(aboutPager)
+ aboutDraggableFrame.addListener(object :
+ ElasticDragDismissFrameLayout.SystemChromeFader(this@AboutActivityBase) {
override fun onDragDismissed() {
window.returnTransition = TransitionInflater.from(this@AboutActivityBase)
- .inflateTransition(if (about_draggable_frame.translationY > 0) R.transition.kau_exit_slide_bottom else R.transition.kau_exit_slide_top)
+ .inflateTransition(if (aboutDraggableFrame.translationY > 0) R.transition.kau_exit_slide_bottom else R.transition.kau_exit_slide_top)
panels[currentPage].recycler?.stopScroll()
finishAfterTransition()
}
})
- panels.forEachIndexed { index, contract -> contract.loadItems(this, index) }
+ panels.forEachIndexed { index, contract -> contract.loadItems(this@AboutActivityBase, index) }
}
class Configs : ThemableIItemColors by ThemableIItemColorsDelegate() {
diff --git a/android-lib.gradle b/android-lib.gradle
index 429fd46..d42f8a4 100644
--- a/android-lib.gradle
+++ b/android-lib.gradle
@@ -3,7 +3,7 @@ import kau.Versions
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
-apply plugin: 'kotlin-android-extensions'
+apply plugin: 'kotlin-parcelize'
apply plugin: 'com.github.dcendents.android-maven'
//apply plugin: 'com.getkeepsafe.dexcount'
group = "ca.allanwang"
@@ -36,6 +36,10 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
+ buildFeatures {
+ viewBinding = true
+ }
+
buildTypes {
release {
minifyEnabled false
@@ -62,6 +66,7 @@ android {
pickFirst 'META-INF/core_release.kotlin_module'
pickFirst 'META-INF/library_release.kotlin_module'
pickFirst 'META-INF/library-core_release.kotlin_module'
+ exclude "**/module-info.class"
}
compileOptions {
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 3e7254f..e948f29 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
@@ -23,8 +23,8 @@ import androidx.appcompat.widget.Toolbar
import androidx.recyclerview.widget.RecyclerView
import ca.allanwang.kau.internal.KauBaseActivity
import ca.allanwang.kau.ui.R
+import ca.allanwang.kau.ui.databinding.KauElasticRecyclerActivityBinding
import ca.allanwang.kau.ui.widgets.ElasticDragDismissFrameLayout
-import kotlinx.android.synthetic.main.kau_elastic_recycler_activity.*
/**
* Created by Allan Wang on 2017-07-17.
@@ -41,8 +41,11 @@ import kotlinx.android.synthetic.main.kau_elastic_recycler_activity.*
abstract class ElasticRecyclerActivity : KauBaseActivity() {
private val configs = Configs()
- protected val toolbar: Toolbar get() = kau_toolbar
- protected val recycler: RecyclerView get() = kau_recycler
+
+ private lateinit var binding: KauElasticRecyclerActivityBinding
+
+ protected val toolbar: Toolbar get() = binding.kauToolbar
+ protected val recycler: RecyclerView get() = binding.kauRecycler
class Configs {
var exitTransitionBottom = R.transition.kau_exit_slide_bottom
@@ -51,17 +54,22 @@ abstract class ElasticRecyclerActivity : KauBaseActivity() {
final override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- setContentView(R.layout.kau_elastic_recycler_activity)
- setSupportActionBar(kau_toolbar)
+ binding = KauElasticRecyclerActivityBinding.inflate(layoutInflater)
+ setContentView(binding.root)
+ setSupportActionBar(binding.kauToolbar)
if (!onCreate(savedInstanceState, configs)) {
return
}
- kau_draggable.addListener(object : ElasticDragDismissFrameLayout.SystemChromeFader(this) {
+ binding.init()
+ }
+
+ private fun KauElasticRecyclerActivityBinding.init() {
+ kauDraggable.addListener(object : ElasticDragDismissFrameLayout.SystemChromeFader(this@ElasticRecyclerActivity) {
override fun onDragDismissed() {
window.returnTransition = TransitionInflater.from(this@ElasticRecyclerActivity)
- .inflateTransition(if (kau_draggable.translationY > 0) configs.exitTransitionBottom else configs.exitTransitionTop)
- kau_recycler.stopScroll()
+ .inflateTransition(if (kauDraggable.translationY > 0) configs.exitTransitionBottom else configs.exitTransitionTop)
+ kauRecycler.stopScroll()
finishAfterTransition()
}
})
@@ -79,6 +87,6 @@ abstract class ElasticRecyclerActivity : KauBaseActivity() {
* Receive actions when the a click event is received outside of the coordinator
*/
fun setOutsideTapListener(listener: () -> Unit) {
- kau_draggable.setOnClickListener { listener() }
+ binding.kauDraggable.setOnClickListener { listener() }
}
}
diff --git a/core-ui/src/main/res-public/values/public.xml b/core-ui/src/main/res-public/values/public.xml
index c8c2e56..1e1a9df 100644
--- a/core-ui/src/main/res-public/values/public.xml
+++ b/core-ui/src/main/res-public/values/public.xml
@@ -1,7 +1,7 @@
<resources xmlns:tools='http://schemas.android.com/tools' tools:ignore='ResourceName'>
<!-- AUTO-GENERATED FILE. DO NOT MODIFY. public.xml is generated by the generatepublicxml gradle task -->
- <public name='kau_recycler_detached_background' type='layout' />
<public name='kau_elastic_recycler_activity' type='layout' />
+ <public name='kau_recycler_detached_background' type='layout' />
<public name='kau_recycler_textslider' type='layout' />
<public name='Kau.Translucent' type='style' />
<public name='Kau.Translucent.NoAnimation' type='style' />
diff --git a/core/src/main/res-public/values/public.xml b/core/src/main/res-public/values/public.xml
index 9f8780e..de08b64 100644
--- a/core/src/main/res-public/values/public.xml
+++ b/core/src/main/res-public/values/public.xml
@@ -1,19 +1,27 @@
<resources xmlns:tools='http://schemas.android.com/tools' tools:ignore='ResourceName'>
<!-- AUTO-GENERATED FILE. DO NOT MODIFY. public.xml is generated by the generatepublicxml gradle task -->
- <public name='kau_slide_in_top' type='anim' />
- <public name='kau_slide_in_left' type='anim' />
- <public name='kau_slide_out_right' type='anim' />
- <public name='kau_slide_out_right_top' type='anim' />
<public name='kau_fade_in' type='anim' />
- <public name='kau_slide_out_top' type='anim' />
- <public name='kau_slide_out_bottom' type='anim' />
<public name='kau_fade_out' type='anim' />
- <public name='kau_slide_out_left' type='anim' />
- <public name='kau_slide_out_left_top' type='anim' />
<public name='kau_slide_in_bottom' type='anim' />
+ <public name='kau_slide_in_left' type='anim' />
<public name='kau_slide_in_right' type='anim' />
- <public name='kau_transparent' type='drawable' />
+ <public name='kau_slide_in_top' type='anim' />
+ <public name='kau_slide_out_bottom' type='anim' />
+ <public name='kau_slide_out_left' type='anim' />
+ <public name='kau_slide_out_left_top' type='anim' />
+ <public name='kau_slide_out_right' type='anim' />
+ <public name='kau_slide_out_right_top' type='anim' />
+ <public name='kau_slide_out_top' type='anim' />
<public name='kau_selectable_white' type='drawable' />
+ <public name='kau_transparent' type='drawable' />
+ <public name='kau_enter_slide_bottom' type='transition' />
+ <public name='kau_enter_slide_left' type='transition' />
+ <public name='kau_enter_slide_right' type='transition' />
+ <public name='kau_enter_slide_top' type='transition' />
+ <public name='kau_exit_slide_bottom' type='transition' />
+ <public name='kau_exit_slide_left' type='transition' />
+ <public name='kau_exit_slide_right' type='transition' />
+ <public name='kau_exit_slide_top' type='transition' />
<public name='kau_shadow_overlay' type='color' />
<public name='kau_activity_horizontal_margin' type='dimen' />
<public name='kau_activity_vertical_margin' type='dimen' />
@@ -106,12 +114,4 @@
<public name='KauSlideInFadeOut' type='style' />
<public name='KauSlideInSlideOutRight' type='style' />
<public name='KauSlideInSlideOutBottom' type='style' />
- <public name='kau_enter_slide_bottom' type='transition' />
- <public name='kau_enter_slide_top' type='transition' />
- <public name='kau_exit_slide_bottom' type='transition' />
- <public name='kau_exit_slide_top' type='transition' />
- <public name='kau_enter_slide_right' type='transition' />
- <public name='kau_exit_slide_right' type='transition' />
- <public name='kau_exit_slide_left' type='transition' />
- <public name='kau_enter_slide_left' type='transition' />
</resources> \ No newline at end of file
diff --git a/fastadapter-viewbinding/build.gradle b/fastadapter-viewbinding/build.gradle
index ad1a0a2..6649397 100644
--- a/fastadapter-viewbinding/build.gradle
+++ b/fastadapter-viewbinding/build.gradle
@@ -5,12 +5,6 @@ ext.kauSubModuleMinSdk = Versions.coreMinSdk
apply from: '../android-lib.gradle'
-android {
- buildFeatures {
- viewBinding = true
- }
-}
-
dependencies {
implementation project(':core')
diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt
index 818a770..4f6233a 100644
--- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt
+++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt
@@ -25,30 +25,26 @@ import ca.allanwang.kau.animators.SlideAnimatorAdd
import ca.allanwang.kau.animators.SlideAnimatorRemove
import ca.allanwang.kau.internal.KauBaseActivity
import ca.allanwang.kau.kotlin.lazyUi
+import ca.allanwang.kau.kpref.activity.databinding.KauPrefActivityBinding
import ca.allanwang.kau.kpref.activity.items.KPrefItemCore
import ca.allanwang.kau.ui.views.RippleCanvas
-import ca.allanwang.kau.utils.KAU_LEFT
-import ca.allanwang.kau.utils.KAU_RIGHT
-import ca.allanwang.kau.utils.resolveColor
-import ca.allanwang.kau.utils.setMarginTop
-import ca.allanwang.kau.utils.statusBarColor
-import ca.allanwang.kau.utils.withLinearAdapter
+import ca.allanwang.kau.utils.*
import com.mikepenz.fastadapter.adapters.FastItemAdapter
import com.mikepenz.fastadapter.select.getSelectExtension
-import java.util.Stack
-import kotlinx.android.synthetic.main.kau_pref_activity.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
+import java.util.*
abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
private val adapter: FastItemAdapter<KPrefItemCore> = FastItemAdapter()
- val bgCanvas: RippleCanvas get() = kau_ripple
- val toolbarCanvas: RippleCanvas get() = kau_toolbar_ripple
- val toolbar: Toolbar get() = kau_toolbar
+ val bgCanvas: RippleCanvas get() = binding.kauRipple
+ val toolbarCanvas: RippleCanvas get() = binding.kauToolbarRipple
+ val toolbar: Toolbar get() = binding.kauToolbar
private lateinit var globalOptions: GlobalOptions
private val kprefStack = Stack<Pair<Int, List<KPrefItemCore>>>()
+
/**
* Toggle sliding animations for the kpref items
*/
@@ -56,14 +52,14 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
private val recyclerAnimatorNext: KauAnimator by lazyUi {
KauAnimator(
- SlideAnimatorAdd(KAU_RIGHT, itemDelayFactor = 0f),
- SlideAnimatorRemove(KAU_LEFT, itemDelayFactor = 0f)
+ SlideAnimatorAdd(KAU_RIGHT, itemDelayFactor = 0f),
+ SlideAnimatorRemove(KAU_LEFT, itemDelayFactor = 0f)
)
}
private val recyclerAnimatorPrev: KauAnimator by lazyUi {
KauAnimator(
- SlideAnimatorAdd(KAU_LEFT, itemDelayFactor = 0f),
- SlideAnimatorRemove(KAU_RIGHT, itemDelayFactor = 0f)
+ SlideAnimatorAdd(KAU_LEFT, itemDelayFactor = 0f),
+ SlideAnimatorRemove(KAU_RIGHT, itemDelayFactor = 0f)
)
}
@@ -73,11 +69,19 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
*/
abstract fun kPrefCoreAttributes(): CoreAttributeContract.() -> Unit
+ private lateinit var binding: KauPrefActivityBinding
+
@SuppressLint("NewApi")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// setup layout
- setContentView(R.layout.kau_pref_activity)
+ binding = KauPrefActivityBinding.inflate(layoutInflater)
+ setContentView(binding.root)
+ binding.init(savedInstanceState)
+ }
+
+ @SuppressLint("NewApi")
+ private fun KauPrefActivityBinding.init(savedInstanceState: Bundle?) {
setSupportActionBar(toolbar)
supportActionBar?.apply {
setDisplayHomeAsUpEnabled(true)
@@ -86,20 +90,20 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
setDisplayShowTitleEnabled(false)
}
findViewById<View>(android.R.id.content).setOnApplyWindowInsetsListener { _, insets ->
- kau_toolbar.setMarginTop(insets.systemWindowInsetTop)
+ kauToolbar.setMarginTop(insets.systemWindowInsetTop)
insets
}
window.decorView.systemUiVisibility =
- View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+ View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
statusBarColor = 0x30000000
- kau_toolbar_ripple.set(resolveColor(R.attr.colorPrimary))
- kau_ripple.set(resolveColor(android.R.attr.colorBackground))
+ kauToolbarRipple.set(resolveColor(R.attr.colorPrimary))
+ kauRipple.set(resolveColor(android.R.attr.colorBackground))
// setup prefs
val core = CoreAttributeBuilder()
val builder = kPrefCoreAttributes()
core.builder()
- globalOptions = GlobalOptions(core, this)
- kau_recycler.withLinearAdapter(adapter)
+ globalOptions = GlobalOptions(core, this@KPrefActivity)
+ kauRecycler.withLinearAdapter(adapter)
adapter.apply {
getSelectExtension().isSelectable = true
onClickListener = { v, _, item, _ ->
@@ -111,12 +115,12 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
}
override fun showNextPrefs(@StringRes toolbarTitleRes: Int, builder: KPrefAdapterBuilder.() -> Unit) =
- showNextPrefs(toolbarTitleRes, builder, false)
+ binding.showNextPrefs(toolbarTitleRes, builder, false)
- private fun showNextPrefs(
- @StringRes toolbarTitleRes: Int,
- builder: KPrefAdapterBuilder.() -> Unit,
- first: Boolean
+ private fun KauPrefActivityBinding.showNextPrefs(
+ @StringRes toolbarTitleRes: Int,
+ builder: KPrefAdapterBuilder.() -> Unit,
+ first: Boolean
) {
launch {
val items = withContext(Dispatchers.Default) {
@@ -125,7 +129,7 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
kprefStack.push(toolbarTitleRes to items.list)
items.list
}
- kau_recycler.itemAnimator = if (animate && !first) recyclerAnimatorNext else null
+ kauRecycler.itemAnimator = if (animate && !first) recyclerAnimatorNext else null
show(toolbarTitleRes, items)
}
}
@@ -143,7 +147,7 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
override fun showPrevPrefs() {
kprefStack.pop()
val (title, list) = kprefStack.peek()
- kau_recycler.itemAnimator = if (animate) recyclerAnimatorPrev else null
+ binding.kauRecycler.itemAnimator = if (animate) recyclerAnimatorPrev else null
show(title, list)
}
@@ -160,7 +164,7 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
fun reloadList() {
// If for some reason we are calling a reload before fetching our first kpref list, we will ignore it
if (kprefStack.size < 1) return
- kau_recycler.itemAnimator = null
+ binding.kauRecycler.itemAnimator = null
val list = kprefStack.peek().second
adapter.setNewList(list.filter { it.core.visible() })
}
diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt
index e430dff..d7db7da 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt
@@ -18,12 +18,13 @@ package ca.allanwang.kau.mediapicker
import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
+import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
+import ca.allanwang.kau.mediapicker.databinding.KauBlurredImageviewBinding
import ca.allanwang.kau.ui.views.MeasureSpecContract
import ca.allanwang.kau.ui.views.MeasureSpecDelegate
-import ca.allanwang.kau.utils.inflate
import ca.allanwang.kau.utils.scaleXY
import ca.allanwang.kau.utils.setBackgroundColorRes
import ca.allanwang.kau.utils.setIcon
@@ -31,7 +32,6 @@ import ca.allanwang.kau.utils.visible
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
import jp.wasabeef.blurry.internal.BlurFactor
import jp.wasabeef.blurry.internal.BlurTask
-import kotlinx.android.synthetic.main.kau_blurred_imageview.view.*
/**
* Created by Allan Wang on 2017-07-14.
@@ -51,12 +51,13 @@ class BlurredImageView @JvmOverloads constructor(
var isBlurred = false
private set
- val imageBase: ImageView get() = image_base
+ val imageBase: ImageView get() = binding.imageBase
+
+ private val binding: KauBlurredImageviewBinding = KauBlurredImageviewBinding.inflate(LayoutInflater.from(context), this, true)
init {
- inflate(R.layout.kau_blurred_imageview, true)
initAttrs(context, attrs)
- image_foreground.setIcon(GoogleMaterial.Icon.gmd_check, 30)
+ binding.imageForeground.setIcon(GoogleMaterial.Icon.gmd_check, 30)
}
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
@@ -66,9 +67,11 @@ class BlurredImageView @JvmOverloads constructor(
override fun clearAnimation() {
super.clearAnimation()
- imageBase.clearAnimation()
- image_blur.clearAnimation()
- image_foreground.clearAnimation()
+ with (binding) {
+ imageBase.clearAnimation()
+ imageBlur.clearAnimation()
+ imageForeground.clearAnimation()
+ }
}
private fun View.scaleAnimate(scale: Float) =
@@ -88,10 +91,12 @@ class BlurredImageView @JvmOverloads constructor(
factor.width = width
factor.height = height
BlurTask(imageBase, factor) {
- image_blur.setImageDrawable(it)
- scaleAnimate(ANIMATION_SCALE).start()
- image_blur.alphaAnimate(1f).start()
- image_foreground.alphaAnimate(1f).start()
+ with (binding) {
+ imageBlur.setImageDrawable(it)
+ scaleAnimate(ANIMATION_SCALE).start()
+ imageBlur.alphaAnimate(1f).start()
+ imageForeground.alphaAnimate(1f).start()
+ }
}.execute()
}
@@ -107,10 +112,12 @@ class BlurredImageView @JvmOverloads constructor(
factor.width = width
factor.height = height
BlurTask(imageBase, factor) { drawable ->
- image_blur.setImageDrawable(drawable)
- scaleXY = ANIMATION_SCALE
- image_blur.alpha = 1f
- image_foreground.alpha = 1f
+ with (binding) {
+ imageBlur.setImageDrawable(drawable)
+ scaleXY = ANIMATION_SCALE
+ imageBlur.alpha = 1f
+ imageForeground.alpha = 1f
+ }
}.execute()
}
@@ -121,8 +128,10 @@ class BlurredImageView @JvmOverloads constructor(
if (!isBlurred) return
isBlurred = false
scaleAnimate(1.0f).start()
- image_blur.alphaAnimate(0f).withEndAction { image_blur.setImageDrawable(null) }.start()
- image_foreground.alphaAnimate(0f).start()
+ with (binding) {
+ imageBlur.alphaAnimate(0f).withEndAction { imageBlur.setImageDrawable(null) }.start()
+ imageForeground.alphaAnimate(0f).start()
+ }
}
/**
@@ -133,9 +142,11 @@ class BlurredImageView @JvmOverloads constructor(
clearAnimation()
scaleX = 1.0f
scaleX = 1.0f
- image_blur.alpha = 0f
- image_blur.setImageDrawable(null)
- image_foreground.alpha = 0f
+ with (binding) {
+ imageBlur.alpha = 0f
+ imageBlur.setImageDrawable(null)
+ imageForeground.alpha = 0f
+ }
}
/**
@@ -163,15 +174,17 @@ class BlurredImageView @JvmOverloads constructor(
*/
fun fullReset() {
reset()
- fullAction { it.visible().background = null }
- image_foreground.setBackgroundColorRes(R.color.kau_blurred_image_selection_overlay)
- image_foreground.setIcon(GoogleMaterial.Icon.gmd_check, 30, Color.WHITE)
+ with(binding) {
+ fullAction { it.visible().background = null }
+ imageForeground.setBackgroundColorRes(R.color.kau_blurred_image_selection_overlay)
+ imageForeground.setIcon(GoogleMaterial.Icon.gmd_check, 30, Color.WHITE)
+ }
}
- private fun fullAction(action: (View) -> Unit) {
- action(this)
+ private fun KauBlurredImageviewBinding.fullAction(action: (View) -> Unit) {
+ action(this@BlurredImageView)
action(imageBase)
- action(image_blur)
- action(image_foreground)
+ action(imageBlur)
+ action(imageForeground)
}
}
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 4c97b07..1357d4d 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt
@@ -21,6 +21,7 @@ import androidx.loader.content.Loader
import androidx.recyclerview.widget.LinearLayoutManager
import ca.allanwang.kau.adapters.selectedItems
import ca.allanwang.kau.adapters.selectionSize
+import ca.allanwang.kau.mediapicker.databinding.KauActivityImagePickerBinding
import ca.allanwang.kau.utils.hideOnDownwardsScroll
import ca.allanwang.kau.utils.setIcon
import ca.allanwang.kau.utils.toDrawable
@@ -29,7 +30,6 @@ import com.google.android.material.appbar.AppBarLayout
import com.mikepenz.fastadapter.ISelectionListener
import com.mikepenz.fastadapter.select.selectExtension
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
-import kotlinx.android.synthetic.main.kau_activity_image_picker.*
/**
* Created by Allan Wang on 2017-07-04.
@@ -39,49 +39,54 @@ import kotlinx.android.synthetic.main.kau_activity_image_picker.*
* Having three layered images makes this slightly slower than [MediaPickerActivityOverlayBase]
*/
abstract class MediaPickerActivityBase(
- mediaType: MediaType,
- mediaActions: List<MediaAction> = emptyList()
+ mediaType: MediaType,
+ mediaActions: List<MediaAction> = emptyList()
) : MediaPickerCore<MediaItem>(mediaType, mediaActions) {
+ private lateinit var binding: KauActivityImagePickerBinding
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
+ binding = KauActivityImagePickerBinding.inflate(layoutInflater)
+ setContentView(binding.root)
+ binding.init()
+ }
- setContentView(R.layout.kau_activity_image_picker)
-
- kau_selection_count.setCompoundDrawables(
- null,
- null,
- GoogleMaterial.Icon.gmd_image.toDrawable(this, 18),
- null
+ private fun KauActivityImagePickerBinding.init() {
+ kauSelectionCount.setCompoundDrawables(
+ null,
+ null,
+ GoogleMaterial.Icon.gmd_image.toDrawable(this@MediaPickerActivityBase, 18),
+ null
)
- setSupportActionBar(kau_toolbar)
+ setSupportActionBar(kauToolbar)
supportActionBar?.apply {
setDisplayHomeAsUpEnabled(true)
setDisplayShowHomeEnabled(true)
setHomeAsUpIndicator(
- GoogleMaterial.Icon.gmd_close.toDrawable(
- this@MediaPickerActivityBase,
- 18
- )
+ GoogleMaterial.Icon.gmd_close.toDrawable(
+ this@MediaPickerActivityBase,
+ 18
+ )
)
}
- kau_toolbar.setNavigationOnClickListener { onBackPressed() }
+ kauToolbar.setNavigationOnClickListener { onBackPressed() }
- initializeRecycler(kau_recyclerview)
+ initializeRecycler(kauRecyclerview)
adapter.fastAdapter!!.let {
MediaItem.bindEvents(it)
it.selectExtension {
selectionListener = object : ISelectionListener<MediaItem> {
override fun onSelectionChanged(item: MediaItem, selected: Boolean) {
- kau_selection_count.text = adapter.selectionSize.toString()
+ kauSelectionCount.text = adapter.selectionSize.toString()
}
}
}
}
- kau_fab.apply {
+ kauFab.apply {
show()
setIcon(GoogleMaterial.Icon.gmd_send)
setOnClickListener {
@@ -92,7 +97,7 @@ abstract class MediaPickerActivityBase(
finish(ArrayList(selection.map { it.data }))
}
}
- hideOnDownwardsScroll(kau_recyclerview)
+ hideOnDownwardsScroll(kauRecyclerview)
}
loadItems()
@@ -108,11 +113,11 @@ abstract class MediaPickerActivityBase(
* @param scrollable true if scroll flags are enabled, false otherwise
*/
- private fun setToolbarScrollable(scrollable: Boolean) {
- val params = kau_toolbar.layoutParams as AppBarLayout.LayoutParams
+ private fun KauActivityImagePickerBinding.setToolbarScrollable(scrollable: Boolean) {
+ val params = kauToolbar.layoutParams as AppBarLayout.LayoutParams
if (scrollable) {
params.scrollFlags = AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS or
- AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
+ AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
} else {
params.scrollFlags = 0
}
@@ -120,13 +125,13 @@ abstract class MediaPickerActivityBase(
override fun onLoadFinished(loader: Loader<Cursor>, data: Cursor?) {
super.onLoadFinished(loader, data)
- setToolbarScrollable(
- (kau_recyclerview.layoutManager as LinearLayoutManager)
- .findLastCompletelyVisibleItemPosition() < adapter.adapterItemCount - 1
+ binding.setToolbarScrollable(
+ (binding.kauRecyclerview.layoutManager as LinearLayoutManager)
+ .findLastCompletelyVisibleItemPosition() < adapter.adapterItemCount - 1
)
}
override fun onStatusChange(loaded: Boolean) {
- setToolbarScrollable(loaded)
+ binding.setToolbarScrollable(loaded)
}
}
diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt
index df47688..0ecc298 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt
@@ -18,8 +18,8 @@ package ca.allanwang.kau.mediapicker
import android.os.Build
import android.os.Bundle
import androidx.annotation.RequiresApi
+import ca.allanwang.kau.mediapicker.databinding.KauActivityImagePickerOverlayBinding
import ca.allanwang.kau.utils.toast
-import kotlinx.android.synthetic.main.kau_activity_image_picker_overlay.*
/**
* Created by Allan Wang on 2017-07-23.
@@ -35,20 +35,27 @@ abstract class MediaPickerActivityOverlayBase(
mediaActions: List<MediaAction> = emptyList()
) : MediaPickerCore<MediaItemBasic>(mediaType, mediaActions) {
+ private lateinit var binding: KauActivityImagePickerOverlayBinding
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- setContentView(R.layout.kau_activity_image_picker_overlay)
- initializeRecycler(kau_recyclerview)
- MediaItemBasic.bindEvents(this, adapter.fastAdapter!!)
+ binding = KauActivityImagePickerOverlayBinding.inflate(layoutInflater)
+ setContentView(binding.root)
+ binding.init()
+ }
+
+ private fun KauActivityImagePickerOverlayBinding.init() {
+ initializeRecycler(kauRecyclerview)
+ MediaItemBasic.bindEvents(this@MediaPickerActivityOverlayBase, adapter.fastAdapter!!)
- kau_draggable.addExitListener(this, R.transition.kau_image_exit_bottom, R.transition.kau_image_exit_top)
- kau_draggable.setOnClickListener { finishAfterTransition() }
+ kauDraggable.addExitListener(this@MediaPickerActivityOverlayBase, R.transition.kau_image_exit_bottom, R.transition.kau_image_exit_top)
+ kauDraggable.setOnClickListener { finishAfterTransition() }
loadItems()
}
override fun finishAfterTransition() {
- kau_recyclerview.stopScroll()
+ binding.kauRecyclerview.stopScroll()
super.finishAfterTransition()
}
diff --git a/sample/build.gradle b/sample/build.gradle
index a39ee2d..4779b91 100644
--- a/sample/build.gradle
+++ b/sample/build.gradle
@@ -3,7 +3,7 @@ import kau.Dependencies
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
-apply plugin: 'kotlin-android-extensions'
+apply plugin: 'kotlin-parcelize'
//apply plugin: 'com.bugsnag.android.gradle'
apply plugin: 'com.github.triplet.play'
apply plugin: 'dagger.hilt.android.plugin'
@@ -31,8 +31,8 @@ android {
multiDexEnabled true
testInstrumentationRunner "ca.allanwang.kau.sample.SampleTestRunner"
}
- buildFeatures {
- viewBinding = true
+ viewBinding {
+ enabled true
}
def releaseSigning = file("../files/kau.properties")
@@ -86,6 +86,7 @@ android {
pickFirst 'META-INF/core_release.kotlin_module'
pickFirst 'META-INF/library_release.kotlin_module'
pickFirst 'META-INF/library-core_release.kotlin_module'
+ exclude "**/module-info.class"
}
compileOptions {
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 c2da5fa..ddb8d6d 100644
--- a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt
+++ b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt
@@ -22,11 +22,7 @@ import android.graphics.Color
import android.text.Editable
import android.text.TextWatcher
import android.util.AttributeSet
-import android.view.Menu
-import android.view.MenuItem
-import android.view.View
-import android.view.ViewGroup
-import android.view.ViewTreeObserver
+import android.view.*
import android.view.inputmethod.EditorInfo
import android.widget.FrameLayout
import android.widget.ImageView
@@ -40,33 +36,12 @@ import ca.allanwang.kau.kotlin.Debouncer2
import ca.allanwang.kau.kotlin.debounce
import ca.allanwang.kau.logging.KL
import ca.allanwang.kau.searchview.SearchView.Configs
-import ca.allanwang.kau.utils.INVALID_ID
-import ca.allanwang.kau.utils.addEndListener
-import ca.allanwang.kau.utils.adjustAlpha
-import ca.allanwang.kau.utils.circularHide
-import ca.allanwang.kau.utils.circularReveal
-import ca.allanwang.kau.utils.fadeIn
-import ca.allanwang.kau.utils.fadeOut
-import ca.allanwang.kau.utils.gone
-import ca.allanwang.kau.utils.goneIf
-import ca.allanwang.kau.utils.hideKeyboard
-import ca.allanwang.kau.utils.invisibleIf
-import ca.allanwang.kau.utils.isVisible
-import ca.allanwang.kau.utils.parentViewGroup
-import ca.allanwang.kau.utils.runOnUiThread
-import ca.allanwang.kau.utils.setIcon
-import ca.allanwang.kau.utils.setMarginTop
-import ca.allanwang.kau.utils.showKeyboard
-import ca.allanwang.kau.utils.string
-import ca.allanwang.kau.utils.tint
-import ca.allanwang.kau.utils.toDrawable
-import ca.allanwang.kau.utils.visible
-import ca.allanwang.kau.utils.withLinearAdapter
+import ca.allanwang.kau.searchview.databinding.KauSearchViewBinding
+import ca.allanwang.kau.utils.*
import com.mikepenz.fastadapter.adapters.FastItemAdapter
import com.mikepenz.fastadapter.select.selectExtension
import com.mikepenz.iconics.typeface.IIcon
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
-import kotlinx.android.synthetic.main.kau_search_view.view.*
/**
* Created by Allan Wang on 2017-06-23.
@@ -80,9 +55,9 @@ import kotlinx.android.synthetic.main.kau_search_view.view.*
* https://github.com/lapism/SearchView
*/
class SearchView @JvmOverloads constructor(
- context: Context,
- attrs: AttributeSet? = null,
- defStyleAttr: Int = 0
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {
/**
@@ -204,14 +179,14 @@ class SearchView @JvmOverloads constructor(
* This event is only triggered when [key] is not blank (like in [noResultsFound]
*/
var onItemClick: (position: Int, key: String, content: String, searchView: SearchView) -> Unit =
- { _, _, _, _ -> }
+ { _, _, _, _ -> }
/**
* Long click event for suggestion items
* This event is only triggered when [key] is not blank (like in [noResultsFound]
*/
var onItemLongClick: (position: Int, key: String, content: String, searchView: SearchView) -> Unit =
- { _, _, _, _ -> }
+ { _, _, _, _ -> }
/**
* If a [SearchItem]'s title contains the submitted query, make that portion bold
@@ -232,20 +207,22 @@ class SearchView @JvmOverloads constructor(
SearchItem.backgroundColor = backgroundColor
tintBackground(backgroundColor)
}
- 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)
- }
- icons.forEach { (iicon, view) -> view.goneIf(iicon == null).setSearchIcon(iicon) }
+ with(binding) {
+ val icons = mutableListOf(navIcon to kauSearchNav, clearIcon to kauSearchClear)
+ val extra = extraIcon
+ if (extra != null) {
+ icons.add(extra.first to kauSearchExtra)
+ }
+ icons.forEach { (iicon, view) -> view.goneIf(iicon == null).setSearchIcon(iicon) }
- if (extra != null) {
- kau_search_extra.setOnClickListener(extra.second)
+ if (extra != null) {
+ kauSearchExtra.setOnClickListener(extra.second)
+ }
+ kauSearchDivider.invisibleIf(!withDivider)
+ kauSearchEditText.hint = context.string(hintTextRes, hintText)
+ textCallback.terminate()
+ textCallback = debounce(textDebounceInterval, this@Configs.textCallback)
}
- kau_search_divider.invisibleIf(!withDivider)
- kau_search_edit_text.hint = context.string(hintTextRes, hintText)
- textCallback.terminate()
- textCallback = debounce(textDebounceInterval, this@Configs.textCallback)
}
}
}
@@ -262,7 +239,7 @@ class SearchView @JvmOverloads constructor(
else value
if (configs.highlightQueryText && value.isNotEmpty()) list.forEach {
it.withHighlights(
- kau_search_edit_text.text?.toString()
+ binding.kauSearchEditText.text?.toString()
)
}
cardTransition()
@@ -279,19 +256,20 @@ class SearchView @JvmOverloads constructor(
}
private val configs = Configs()
+
// views
private var textCallback: Debouncer2<String, SearchView> =
- debounce(0) { query, _ -> KL.d { "Search query $query found; set your own textCallback" } }
+ debounce(0) { query, _ -> KL.d { "Search query $query found; set your own textCallback" } }
private val adapter = FastItemAdapter<SearchItem>()
private var menuItem: MenuItem? = null
val isOpen: Boolean
- get() = parent != null && kau_search_cardview.isVisible
+ get() = parent != null && binding.kauSearchCardview.isVisible
/**
* The current text located in our searchview
*/
val query: String
- get() = kau_search_edit_text.text?.toString()?.trim() ?: ""
+ get() = binding.kauSearchEditText.text?.toString()?.trim() ?: ""
/*
* Ripple start points and search view offset
@@ -302,15 +280,20 @@ class SearchView @JvmOverloads constructor(
var menuY: Int = -1 // reference for cardview's marginTop
var menuHalfHeight: Int = -1 // starting y for circular reveal (relative to the cardview)
+ private val binding: KauSearchViewBinding = KauSearchViewBinding.inflate(LayoutInflater.from(context), this, true)
+
init {
- View.inflate(context, R.layout.kau_search_view, this)
z = 99f
- kau_search_nav.setSearchIcon(configs.navIcon).setOnClickListener { revealClose() }
- kau_search_clear.setSearchIcon(configs.clearIcon)
- .setOnClickListener { kau_search_edit_text.text?.clear() }
+ binding.init()
+ }
+
+ private fun KauSearchViewBinding.init() {
+ kauSearchNav.setSearchIcon(configs.navIcon).setOnClickListener { revealClose() }
+ kauSearchClear.setSearchIcon(configs.clearIcon)
+ .setOnClickListener { kauSearchEditText.text?.clear() }
tintForeground(configs.foregroundColor)
tintBackground(configs.backgroundColor)
- with(kau_search_recycler) {
+ with(kauSearchRecycler) {
isNestedScrollingEnabled = false
withLinearAdapter(this@SearchView.adapter)
addOnScrollListener(object : RecyclerView.OnScrollListener() {
@@ -329,25 +312,25 @@ class SearchView @JvmOverloads constructor(
}
onClickListener = { _, _, item, position ->
if (item.key.isNotBlank()) configs.onItemClick(
- position,
- item.key,
- item.content,
- this@SearchView
+ position,
+ item.key,
+ item.content,
+ this@SearchView
); true
}
onLongClickListener = { _, _, item, position ->
if (item.key.isNotBlank()) {
configs.onItemLongClick(
- position,
- item.key,
- item.content,
- this@SearchView
+ position,
+ item.key,
+ item.content,
+ this@SearchView
)
}
true
}
}
- kau_search_edit_text.addTextChangedListener(object : TextWatcher {
+ kauSearchEditText.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable?) {}
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
@@ -362,13 +345,13 @@ class SearchView @JvmOverloads constructor(
}
}
})
- kau_search_edit_text.setOnEditorActionListener { _, actionId, _ ->
+ kauSearchEditText.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
- val query = kau_search_edit_text.text?.toString() ?: ""
- if (configs.searchCallback(query, this)) {
+ val query = kauSearchEditText.text?.toString() ?: ""
+ if (configs.searchCallback(query, this@SearchView)) {
revealClose()
} else {
- kau_search_edit_text.hideKeyboard()
+ kauSearchEditText.hideKeyboard()
}
return@setOnEditorActionListener true
}
@@ -382,13 +365,13 @@ class SearchView @JvmOverloads constructor(
}
internal fun cardTransition(builder: TransitionSet.() -> Unit = {}) {
- TransitionManager.beginDelayedTransition(kau_search_cardview,
- // we are only using change bounds, as the recyclerview items may be animated as well,
- // which causes a measure IllegalStateException
- TransitionSet().addTransition(ChangeBounds()).apply {
- duration = configs.transitionDuration
- builder()
- })
+ TransitionManager.beginDelayedTransition(binding.kauSearchCardview,
+ // we are only using change bounds, as the recyclerview items may be animated as well,
+ // which causes a measure IllegalStateException
+ TransitionSet().addTransition(ChangeBounds()).apply {
+ duration = configs.transitionDuration
+ builder()
+ })
}
/**
@@ -405,20 +388,20 @@ class SearchView @JvmOverloads constructor(
* If not, see the extension function [bindSearchView]
*/
fun bind(
- menu: Menu,
- @IdRes id: Int,
- @ColorInt menuIconColor: Int = Color.WHITE,
- config: Configs.() -> Unit = {}
+ menu: Menu,
+ @IdRes id: Int,
+ @ColorInt menuIconColor: Int = Color.WHITE,
+ config: Configs.() -> Unit = {}
): SearchView {
config(config)
val menuItem = menu.findItem(id)
- ?: throw IllegalArgumentException("Menu item with given id doesn't exist")
+ ?: throw IllegalArgumentException("Menu item with given id doesn't exist")
if (menuItem.icon == null) {
menuItem.icon = GoogleMaterial.Icon.gmd_search.toDrawable(context, 18, menuIconColor)
}
- kau_search_cardview.gone()
+ binding.kauSearchCardview.gone()
menuItem.setOnMenuItemClickListener { revealOpen(); true }
- kau_search_shadow.setOnClickListener { revealClose() }
+ binding.kauSearchShadow.setOnClickListener { revealClose() }
this.menuItem = menuItem
return this
}
@@ -435,7 +418,7 @@ class SearchView @JvmOverloads constructor(
private val locations = IntArray(2)
- private fun configureCoords(item: MenuItem?) {
+ private fun KauSearchViewBinding.configureCoords(item: MenuItem?) {
item ?: return
if (parent !is ViewGroup) {
return
@@ -445,11 +428,11 @@ class SearchView @JvmOverloads constructor(
menuX = (locations[0] + view.width / 2)
menuHalfHeight = view.height / 2
menuY = (locations[1] + menuHalfHeight)
- kau_search_cardview.viewTreeObserver.addOnPreDrawListener(object :
- ViewTreeObserver.OnPreDrawListener {
+ kauSearchCardview.viewTreeObserver.addOnPreDrawListener(object :
+ ViewTreeObserver.OnPreDrawListener {
override fun onPreDraw(): Boolean {
view.viewTreeObserver.removeOnPreDrawListener(this)
- kau_search_cardview.setMarginTop(menuY - kau_search_cardview.height / 2)
+ kauSearchCardview.setMarginTop(menuY - kauSearchCardview.height / 2)
return true
}
})
@@ -472,12 +455,14 @@ class SearchView @JvmOverloads constructor(
* This can be done publicly through [configs], which will also save the color
*/
internal fun tintForeground(@ColorInt color: Int) {
- kau_search_nav.drawable.setTint(color)
- kau_search_clear.drawable.setTint(color)
- kau_search_divider.setBackgroundColor(color.adjustAlpha(0.1f))
- kau_search_edit_text.tint(color)
- kau_search_edit_text.setTextColor(ColorStateList.valueOf(color))
- kau_search_edit_text.setHintTextColor(color.adjustAlpha(0.7f))
+ with(binding) {
+ kauSearchNav.drawable.setTint(color)
+ kauSearchClear.drawable.setTint(color)
+ kauSearchDivider.setBackgroundColor(color.adjustAlpha(0.1f))
+ kauSearchEditText.tint(color)
+ kauSearchEditText.setTextColor(ColorStateList.valueOf(color))
+ kauSearchEditText.setHintTextColor(color.adjustAlpha(0.7f))
+ }
}
/**
@@ -485,14 +470,15 @@ class SearchView @JvmOverloads constructor(
* This can be done publicly through [configs], which will also save the color
*/
internal fun tintBackground(@ColorInt color: Int) {
- kau_search_cardview.setCardBackgroundColor(color)
+ binding.kauSearchCardview.setCardBackgroundColor(color)
}
fun revealOpen() {
if (parent == null || isOpen) {
return
}
- context.runOnUiThread {
+
+ fun KauSearchViewBinding.open() {
/**
* The y component is relative to the cardView, but it hasn't been drawn yet so its own height is 0
* We therefore use half the menuItem height, which is a close approximation to our intended value
@@ -500,41 +486,46 @@ class SearchView @JvmOverloads constructor(
*/
configureCoords(menuItem)
configs.openListener?.invoke(this@SearchView)
- kau_search_shadow.fadeIn()
- kau_search_edit_text.showKeyboard()
- kau_search_cardview.circularReveal(
- menuX,
- menuHalfHeight,
- duration = configs.revealDuration
+ kauSearchShadow.fadeIn()
+ kauSearchEditText.showKeyboard()
+ kauSearchCardview.circularReveal(
+ menuX,
+ menuHalfHeight,
+ duration = configs.revealDuration
) {
cardTransition()
- kau_search_recycler.visible()
+ kauSearchRecycler.visible()
}
}
+
+ context.runOnUiThread { binding.open() }
}
fun revealClose() {
if (parent == null || !isOpen) {
return
}
- context.runOnUiThread {
- kau_search_shadow.fadeOut(duration = configs.transitionDuration)
+
+ fun KauSearchViewBinding.close() {
+ kauSearchShadow.fadeOut(duration = configs.transitionDuration)
cardTransition {
addEndListener {
- kau_search_cardview.circularHide(menuX,
- menuHalfHeight,
- duration = configs.revealDuration,
- onFinish = {
- configs.closeListener?.invoke(this@SearchView)
- if (configs.shouldClearOnClose) {
- kau_search_edit_text.text?.clear()
- }
- })
+ kauSearchCardview.circularHide(menuX,
+ menuHalfHeight,
+ duration = configs.revealDuration,
+ onFinish = {
+ configs.closeListener?.invoke(this@SearchView)
+ if (configs.shouldClearOnClose) {
+ kauSearchEditText.text?.clear()
+ }
+ })
}
}
- kau_search_recycler.gone()
- kau_search_edit_text.hideKeyboard()
+ kauSearchRecycler.gone()
+ kauSearchEditText.hideKeyboard()
}
+
+ context.runOnUiThread { binding.close() }
}
}
@@ -546,12 +537,12 @@ annotation class KauSearch
*/
@KauSearch
fun Activity.bindSearchView(
- menu: Menu,
- @IdRes id: Int,
- @ColorInt menuIconColor: Int = Color.WHITE,
- config: Configs.() -> Unit = {}
+ menu: Menu,
+ @IdRes id: Int,
+ @ColorInt menuIconColor: Int = Color.WHITE,
+ config: Configs.() -> Unit = {}
): SearchView =
- findViewById<ViewGroup>(android.R.id.content).bindSearchView(menu, id, menuIconColor, config)
+ findViewById<ViewGroup>(android.R.id.content).bindSearchView(menu, id, menuIconColor, config)
/**
* Bind searchView to a menu item; call this in [Activity.onCreateOptionsMenu]
@@ -560,17 +551,17 @@ fun Activity.bindSearchView(
*/
@KauSearch
fun ViewGroup.bindSearchView(
- menu: Menu,
- @IdRes id: Int,
- @ColorInt menuIconColor: Int = Color.WHITE,
- config: Configs.() -> Unit = {}
+ menu: Menu,
+ @IdRes id: Int,
+ @ColorInt menuIconColor: Int = Color.WHITE,
+ config: Configs.() -> Unit = {}
): SearchView {
val searchView = SearchView(context)
searchView.layoutParams =
- FrameLayout.LayoutParams(
- FrameLayout.LayoutParams.MATCH_PARENT,
- FrameLayout.LayoutParams.MATCH_PARENT
- )
+ FrameLayout.LayoutParams(
+ FrameLayout.LayoutParams.MATCH_PARENT,
+ FrameLayout.LayoutParams.MATCH_PARENT
+ )
addView(searchView)
searchView.bind(menu, id, menuIconColor, config)
return searchView