From d540934915da26ab2cec4c897e973be35e0bfe24 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 9 Sep 2018 11:59:24 -0400 Subject: 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 --- .../ca/allanwang/kau/sample/AdapterActivity.kt | 11 ++++---- .../ca/allanwang/kau/sample/PermissionCheckbox.kt | 5 ++-- .../ca/allanwang/kau/sample/SwipeActivity.kt | 29 ++++++---------------- 3 files changed, 15 insertions(+), 30 deletions(-) (limited to 'sample/src') diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/AdapterActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/AdapterActivity.kt index 874e73b..ada60ca 100644 --- a/sample/src/main/kotlin/ca/allanwang/kau/sample/AdapterActivity.kt +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/AdapterActivity.kt @@ -1,11 +1,12 @@ package ca.allanwang.kau.sample import android.os.Bundle +import ca.allanwang.kau.adapters.fastAdapter import ca.allanwang.kau.iitems.CardIItem import ca.allanwang.kau.ui.activities.ElasticRecyclerActivity import ca.allanwang.kau.utils.toast import com.mikepenz.fastadapter.IItem -import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter +import com.mikepenz.fastadapter.adapters.ItemAdapter import com.mikepenz.google_material_typeface_library.GoogleMaterial /** @@ -13,10 +14,9 @@ import com.mikepenz.google_material_typeface_library.GoogleMaterial */ class AdapterActivity : ElasticRecyclerActivity() { - val adapter = FastItemAdapter>() - override fun onCreate(savedInstanceState: Bundle?, configs: Configs): Boolean { - recycler.adapter = adapter + val adapter = ItemAdapter>() + recycler.adapter = fastAdapter(adapter) adapter.add(listOf( CardIItem { titleRes = R.string.kau_text_copied @@ -43,8 +43,7 @@ class AdapterActivity : ElasticRecyclerActivity() { titleRes = R.string.kau_text_copied button = "Test" buttonClick = { toast("HI") } - } - )) + })) setOutsideTapListener { finishAfterTransition() } return true } diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt index 3dba332..beb1a29 100644 --- a/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt @@ -5,7 +5,6 @@ import android.view.View import android.widget.CheckBox import android.widget.TextView import ca.allanwang.kau.iitems.KauIItem -import ca.allanwang.kau.utils.bindView import ca.allanwang.kau.utils.hasPermission /** @@ -23,7 +22,7 @@ class PermissionCheckbox(val permission: String) : KauIItem by bindViews(R.id.swipe_from_left, R.id.swipe_from_right, R.id.swipe_from_top, R.id.swipe_from_bottom) - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_swipe) - directions.forEach { - val swipeEdge = when (it.id) { - R.id.swipe_from_left -> SWIPE_EDGE_LEFT - R.id.swipe_from_right -> SWIPE_EDGE_RIGHT - R.id.swipe_from_top -> SWIPE_EDGE_TOP - R.id.swipe_from_bottom -> SWIPE_EDGE_BOTTOM - else -> -1 - } - it.setOnClickListener { startActivityWithEdge(swipeEdge) } - } + listOf(swipe_from_left, swipe_from_right, swipe_from_top, swipe_from_bottom) + .zip(listOf(SWIPE_EDGE_LEFT, SWIPE_EDGE_RIGHT, SWIPE_EDGE_TOP, SWIPE_EDGE_BOTTOM)) + .forEach { (button, edge) -> button.setOnClickListener { startActivityWithEdge(edge) } } val flag = intent.getIntExtra(SWIPE_EDGE, -1) - toolbar.title = when (flag) { + swipe_toolbar.title = when (flag) { SWIPE_EDGE_LEFT -> "Left Edge Swipe" SWIPE_EDGE_RIGHT -> "Right Edge Swipe" SWIPE_EDGE_TOP -> "Top Edge Swipe" SWIPE_EDGE_BOTTOM -> "Bottom Edge Swipe" else -> "Invalid Edge Swipe" } - setSupportActionBar(toolbar) + setSupportActionBar(swipe_toolbar) val headerColor = rndColor.darken(0.6f) - toolbar.setBackgroundColor(headerColor) + swipe_toolbar.setBackgroundColor(headerColor) statusBarColor = headerColor val bg = headerColor.darken(0.2f) - container.setBackgroundColor(bg) + swipe_container.setBackgroundColor(bg) navigationBarColor = bg kauSwipeOnCreate { edgeFlag = flag -- cgit v1.2.3