aboutsummaryrefslogtreecommitdiff
path: root/kpref-activity
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2021-01-11 00:19:31 -0800
committerAllan Wang <me@allanwang.ca>2021-01-11 00:19:31 -0800
commit5f5389b0fde9d12c56e337dff169fa6319b449cf (patch)
tree8f5ec6bc4c5470b6c6fc3c4b2d732bec5d0d3016 /kpref-activity
parent038ad9c3aa4d6678d9ede06cf1ce68b8bdf85021 (diff)
downloadkau-5f5389b0fde9d12c56e337dff169fa6319b449cf.tar.gz
kau-5f5389b0fde9d12c56e337dff169fa6319b449cf.tar.bz2
kau-5f5389b0fde9d12c56e337dff169fa6319b449cf.zip
Remove kotlin synethetics
Diffstat (limited to 'kpref-activity')
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt64
1 files changed, 34 insertions, 30 deletions
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() })
}