diff options
author | Allan Wang <me@allanwang.ca> | 2018-09-09 11:59:24 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-09 11:59:24 -0400 |
commit | d540934915da26ab2cec4c897e973be35e0bfe24 (patch) | |
tree | 6f114d080c168381266a0d5d3a40b685e28b8e9a /kpref-activity/src | |
parent | 718a51ed00a0a5c3dc7a655e617308e82da65d1a (diff) | |
download | kau-d540934915da26ab2cec4c897e973be35e0bfe24.tar.gz kau-d540934915da26ab2cec4c897e973be35e0bfe24.tar.bz2 kau-d540934915da26ab2cec4c897e973be35e0bfe24.zip |
Clean up kotterknife (#161)
* Remove bindview implementations internally
* Remove more bindView calls
* Make config private in ElasticRecyclerActivity
* Fix recyclerview
* Update adapter
* Improve swipe destroy and add direction to swipe finish
Diffstat (limited to 'kpref-activity/src')
-rw-r--r-- | kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt | 24 | ||||
-rw-r--r-- | kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemCore.kt | 12 |
2 files changed, 17 insertions, 19 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 6de57c2..b9681e9 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 @@ -3,7 +3,6 @@ package ca.allanwang.kau.kpref.activity import android.annotation.SuppressLint import android.os.Bundle import android.support.annotation.StringRes -import android.support.v7.widget.RecyclerView import android.support.v7.widget.Toolbar import android.view.View import ca.allanwang.kau.animators.KauAnimator @@ -14,6 +13,7 @@ import ca.allanwang.kau.kpref.activity.items.KPrefItemCore import ca.allanwang.kau.ui.views.RippleCanvas import ca.allanwang.kau.utils.* import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter +import kotlinx.android.synthetic.main.kau_pref_activity.* import org.jetbrains.anko.doAsync import org.jetbrains.anko.uiThread import java.util.* @@ -21,10 +21,9 @@ import java.util.* abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract { private val adapter: FastItemAdapter<KPrefItemCore> = FastItemAdapter() - private val recycler: RecyclerView by bindView(R.id.kau_recycler) - val bgCanvas: RippleCanvas by bindView(R.id.kau_ripple) - val toolbarCanvas: RippleCanvas by bindView(R.id.kau_toolbar_ripple) - val toolbar: Toolbar by bindView(R.id.kau_toolbar) + val bgCanvas: RippleCanvas get() = kau_ripple + val toolbarCanvas: RippleCanvas get() = kau_toolbar_ripple + val toolbar: Toolbar get() = kau_toolbar private lateinit var globalOptions: GlobalOptions private val kprefStack = Stack<Pair<Int, List<KPrefItemCore>>>() /** @@ -61,28 +60,27 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract { } window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN statusBarColor = 0x30000000 - toolbarCanvas.set(resolveColor(R.attr.colorPrimary)) - bgCanvas.set(resolveColor(android.R.attr.colorBackground)) + kau_toolbar_ripple.set(resolveColor(R.attr.colorPrimary)) + kau_ripple.set(resolveColor(android.R.attr.colorBackground)) //setup prefs val core = CoreAttributeBuilder() val builder = kPrefCoreAttributes() core.builder() globalOptions = GlobalOptions(core, this) - recycler.withLinearAdapter(adapter) + kau_recycler.withLinearAdapter(adapter) adapter.withSelectable(false) .withOnClickListener { v, _, item, _ -> item.onClick(v!!); true } showNextPrefs(R.string.kau_settings, onCreateKPrefs(savedInstanceState), true) } - override fun showNextPrefs(@StringRes toolbarTitleRes: Int, builder: KPrefAdapterBuilder.() -> Unit) - = showNextPrefs(toolbarTitleRes, builder, false) + override fun showNextPrefs(@StringRes toolbarTitleRes: Int, builder: KPrefAdapterBuilder.() -> Unit) = showNextPrefs(toolbarTitleRes, builder, false) private fun showNextPrefs(@StringRes toolbarTitleRes: Int, builder: KPrefAdapterBuilder.() -> Unit, first: Boolean) { doAsync { val items = KPrefAdapterBuilder(globalOptions) builder(items) kprefStack.push(toolbarTitleRes to items.list) - recycler.itemAnimator = if (animate && !first) recyclerAnimatorNext else null + kau_recycler.itemAnimator = if (animate && !first) recyclerAnimatorNext else null uiThread { adapter.clear() adapter.add(items.list.filter { it.core.visible() }) @@ -98,7 +96,7 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract { override fun showPrevPrefs() { kprefStack.pop() val (title, list) = kprefStack.peek() - recycler.itemAnimator = if (animate) recyclerAnimatorPrev else null + kau_recycler.itemAnimator = if (animate) recyclerAnimatorPrev else null adapter.clear() adapter.add(list.filter { it.core.visible() }) toolbar.setTitle(title) @@ -117,7 +115,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 - recycler.itemAnimator = null + kau_recycler.itemAnimator = null val list = kprefStack.peek().second adapter.setNewList(list.filter { it.core.visible() }) } diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemCore.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemCore.kt index 2491d01..fcc13ba 100644 --- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemCore.kt +++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemCore.kt @@ -134,12 +134,12 @@ abstract class KPrefItemCore(val core: CoreContract) : AbstractItem<KPrefItemCor } class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { - val title: TextView by bindView(R.id.kau_pref_title) - val container: ViewGroup? by bindOptionalView(R.id.kau_pref_container) - val desc: TextView? by bindOptionalView(R.id.kau_pref_desc) - val icon: ImageView? by bindOptionalView(R.id.kau_pref_icon) - val innerFrame: LinearLayout? by bindOptionalView(R.id.kau_pref_inner_frame) - val lowerFrame: LinearLayout? by bindOptionalView(R.id.kau_pref_lower_frame) + val title: TextView = v.findViewById(R.id.kau_pref_title) + val container: ViewGroup? = v.findViewById(R.id.kau_pref_container) + val desc: TextView? = v.findViewById(R.id.kau_pref_desc) + val icon: ImageView? = v.findViewById(R.id.kau_pref_icon) + val innerFrame: LinearLayout? = v.findViewById(R.id.kau_pref_inner_frame) + val lowerFrame: LinearLayout? = v.findViewById(R.id.kau_pref_lower_frame) val innerView: View? get() = itemView.findViewById(R.id.kau_pref_inner_content) val lowerContent: View? |