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 | |
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
29 files changed, 289 insertions, 308 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 dddb0b9..f4ee4c5 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt @@ -13,14 +13,13 @@ import ca.allanwang.kau.adapters.ThemableIItemColors import ca.allanwang.kau.adapters.ThemableIItemColorsDelegate import ca.allanwang.kau.internal.KauBaseActivity import ca.allanwang.kau.ui.widgets.ElasticDragDismissFrameLayout -import ca.allanwang.kau.ui.widgets.InkPageIndicator import ca.allanwang.kau.utils.AnimHolder import ca.allanwang.kau.utils.INVALID_ID -import ca.allanwang.kau.utils.bindView import ca.allanwang.kau.utils.dimenPixelSize import com.mikepenz.aboutlibraries.Libs import com.mikepenz.aboutlibraries.entity.Library import com.mikepenz.fastadapter.IItem +import kotlinx.android.synthetic.main.kau_activity_about.* /** * Created by Allan Wang on 2017-06-28. @@ -35,12 +34,8 @@ import com.mikepenz.fastadapter.IItem */ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilder: Configs.() -> Unit = {}) : KauBaseActivity(), ViewPager.OnPageChangeListener { - private val draggableFrame: ElasticDragDismissFrameLayout by bindView(R.id.about_draggable_frame) - private val pager: ViewPager by bindView(R.id.about_pager) - private val indicator: InkPageIndicator by bindView(R.id.about_indicator) - val currentPage: Int - get() = pager.currentItem + get() = about_pager.currentItem /** * Holds some common configurations that may be added directly from the constructor @@ -67,18 +62,18 @@ 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) indicator.setColour(configs.textColor!!) - with(pager) { + if (configs.textColor != null) about_indicator.setColour(configs.textColor!!) + with(about_pager) { adapter = AboutPagerAdapter() pageMargin = dimenPixelSize(R.dimen.kau_spacing_normal) offscreenPageLimit = panels.size - 1 addOnPageChangeListener(this@AboutActivityBase) } - indicator.setViewPager(pager) - draggableFrame.addListener(object : ElasticDragDismissFrameLayout.SystemChromeFader(this) { + about_indicator.setViewPager(about_pager) + about_draggable_frame.addListener(object : ElasticDragDismissFrameLayout.SystemChromeFader(this) { override fun onDragDismissed() { window.returnTransition = TransitionInflater.from(this@AboutActivityBase) - .inflateTransition(if (draggableFrame.translationY > 0) R.transition.kau_exit_slide_bottom else R.transition.kau_exit_slide_top) + .inflateTransition(if (about_draggable_frame.translationY > 0) R.transition.kau_exit_slide_bottom else R.transition.kau_exit_slide_top) panels[currentPage].recycler?.stopScroll() finishAfterTransition() } diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/CutoutIItem.kt b/about/src/main/kotlin/ca/allanwang/kau/about/CutoutIItem.kt index 448d27f..37c13d8 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/CutoutIItem.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/CutoutIItem.kt @@ -6,7 +6,6 @@ import ca.allanwang.kau.adapters.ThemableIItem import ca.allanwang.kau.adapters.ThemableIItemDelegate import ca.allanwang.kau.iitems.KauIItem import ca.allanwang.kau.ui.views.CutoutView -import ca.allanwang.kau.utils.bindView /** * Created by Allan Wang on 2017-06-28. @@ -36,7 +35,7 @@ class CutoutIItem(val config: CutoutView.() -> Unit = {}) : KauIItem<CutoutIItem } class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { - val cutout: CutoutView by bindView(R.id.kau_cutout) + val cutout: CutoutView = v.findViewById(R.id.kau_cutout) } }
\ No newline at end of file diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt b/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt index 0729ea4..5cf046e 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt @@ -9,7 +9,10 @@ import android.widget.TextView import ca.allanwang.kau.adapters.ThemableIItem import ca.allanwang.kau.adapters.ThemableIItemDelegate import ca.allanwang.kau.iitems.KauIItem -import ca.allanwang.kau.utils.* +import ca.allanwang.kau.utils.colorToForeground +import ca.allanwang.kau.utils.dpToPx +import ca.allanwang.kau.utils.parentViewGroup +import ca.allanwang.kau.utils.setPaddingLeft import ca.allanwang.kau.xml.FaqItem import com.mikepenz.fastadapter.FastAdapter import com.mikepenz.fastadapter.IItem @@ -27,8 +30,7 @@ class FaqIItem(val content: FaqItem) : KauIItem<LibraryIItem, FaqIItem.ViewHolde fastAdapter.withSelectable(false) .withEventHook(object : ClickEventHook<IItem<*, *>>() { - override fun onBind(viewHolder: RecyclerView.ViewHolder): View? - = (viewHolder as? ViewHolder)?.questionContainer + override fun onBind(viewHolder: RecyclerView.ViewHolder): View? = (viewHolder as? ViewHolder)?.questionContainer override fun onClick(v: View, position: Int, adapter: FastAdapter<IItem<*, *>>, item: IItem<*, *>) { if (item !is FaqIItem) return @@ -71,11 +73,11 @@ class FaqIItem(val content: FaqItem) : KauIItem<LibraryIItem, FaqIItem.ViewHolde } class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { - val container: ViewGroup by bindView(R.id.faq_item) - val questionContainer: ViewGroup by bindView(R.id.faq_item_question_container) - val number: TextView by bindView(R.id.faq_item_number) - val question: TextView by bindView(R.id.faq_item_question) - val answer: CollapsibleTextView by bindView(R.id.faq_item_answer) + val container: ViewGroup = v.findViewById(R.id.faq_item) + val questionContainer: ViewGroup = v.findViewById(R.id.faq_item_question_container) + val number: TextView = v.findViewById(R.id.faq_item_number) + val question: TextView = v.findViewById(R.id.faq_item_question) + val answer: CollapsibleTextView = v.findViewById(R.id.faq_item_answer) init { answer.movementMethod = LinkMovementMethod.getInstance() 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 e7ddcd3..2749c28 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt @@ -9,7 +9,6 @@ import android.widget.TextView import ca.allanwang.kau.adapters.ThemableIItem import ca.allanwang.kau.adapters.ThemableIItemDelegate import ca.allanwang.kau.iitems.KauIItem -import ca.allanwang.kau.utils.bindView import ca.allanwang.kau.utils.gone import ca.allanwang.kau.utils.startLink import ca.allanwang.kau.utils.visible @@ -82,14 +81,14 @@ class LibraryIItem(val lib: Library) : KauIItem<LibraryIItem, LibraryIItem.ViewH } class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { - val card: CardView by bindView(R.id.lib_item_card) - val name: TextView by bindView(R.id.lib_item_name) - val creator: TextView by bindView(R.id.lib_item_author) - val description: TextView by bindView(R.id.lib_item_description) - val version: TextView by bindView(R.id.lib_item_version) - val license: TextView by bindView(R.id.lib_item_license) - val divider: View by bindView(R.id.lib_item_top_divider) - val bottomDivider: View by bindView(R.id.lib_item_bottom_divider) + val card: CardView = v.findViewById(R.id.lib_item_card) + val name: TextView = v.findViewById(R.id.lib_item_name) + val creator: TextView = v.findViewById(R.id.lib_item_author) + val description: TextView = v.findViewById(R.id.lib_item_description) + val version: TextView = v.findViewById(R.id.lib_item_version) + val license: TextView = v.findViewById(R.id.lib_item_license) + val divider: View = v.findViewById(R.id.lib_item_top_divider) + val bottomDivider: View = v.findViewById(R.id.lib_item_bottom_divider) } }
\ No newline at end of file diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt b/adapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt index 9fd5512..ba969a2 100644 --- a/adapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt +++ b/adapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt @@ -71,7 +71,7 @@ class CardIItem( override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) { super.bindView(holder, payloads) - with(holder.itemView.context) context@ { + with(holder.itemView.context) context@{ with(configs) { holder.title.text = string(titleRes, title) val descText = string(descRes, desc) @@ -82,7 +82,8 @@ class CardIItem( holder.button.text = buttonText } val icon = drawable(imageRes) { - imageIIcon?.toDrawable(this@context, sizeDp = 24, color = imageIIconColor) ?: image + imageIIcon?.toDrawable(this@context, sizeDp = 24, color = imageIIconColor) + ?: image } if (icon != null) holder.icon.visible().setImageDrawable(icon) } @@ -109,12 +110,12 @@ class CardIItem( } class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { - val card: CardView by bindView(R.id.kau_card_container) - val icon: ImageView by bindView(R.id.kau_card_image) - val title: TextView by bindView(R.id.kau_card_title) - val description: TextView by bindView(R.id.kau_card_description) - val bottomRow: LinearLayout by bindView(R.id.kau_card_bottom_row) - val button: Button by bindView(R.id.kau_card_button) + val card: CardView = v.findViewById(R.id.kau_card_container) + val icon: ImageView = v.findViewById(R.id.kau_card_image) + val title: TextView = v.findViewById(R.id.kau_card_title) + val description: TextView = v.findViewById(R.id.kau_card_description) + val bottomRow: LinearLayout = v.findViewById(R.id.kau_card_bottom_row) + val button: Button = v.findViewById(R.id.kau_card_button) } }
\ No newline at end of file diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt b/adapter/src/main/kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt index 67e7d30..2116b34 100644 --- a/adapter/src/main/kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt +++ b/adapter/src/main/kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt @@ -8,7 +8,6 @@ import ca.allanwang.kau.adapter.R import ca.allanwang.kau.adapters.ThemableIItem import ca.allanwang.kau.adapters.ThemableIItemDelegate import ca.allanwang.kau.utils.INVALID_ID -import ca.allanwang.kau.utils.bindView import ca.allanwang.kau.utils.string /** @@ -38,8 +37,8 @@ class HeaderIItem( } class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { - val text: TextView by bindView(R.id.kau_header_text) - val container: CardView by bindView(R.id.kau_header_container) + val text: TextView = v.findViewById(R.id.kau_header_text) + val container: CardView = v.findViewById(R.id.kau_header_container) } }
\ No newline at end of file diff --git a/android-lib.gradle b/android-lib.gradle index 2be7c46..7275347 100644 --- a/android-lib.gradle +++ b/android-lib.gradle @@ -1,5 +1,6 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.getkeepsafe.dexcount' group = "ca.allanwang" diff --git a/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPickerView.kt b/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPickerView.kt index dfb0773..b9cea99 100644 --- a/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPickerView.kt +++ b/colorpicker/src/main/kotlin/ca/allanwang/kau/colorpicker/ColorPickerView.kt @@ -56,30 +56,39 @@ internal class ColorPickerView @JvmOverloads constructor( } } - private val gridView: FillGridView by bindView(R.id.md_grid) - private val customFrame: LinearLayout by bindView(R.id.md_colorChooserCustomFrame) - private val customColorIndicator: View by bindView(R.id.md_colorIndicator) - private val hexInput: EditText by bindView(R.id.md_hexInput) - private val alphaLabel: TextView by bindView(R.id.md_colorALabel) - private val alphaSeekbar: SeekBar by bindView(R.id.md_colorA) - private val alphaValue: TextView by bindView(R.id.md_colorAValue) - private val redSeekbar: SeekBar by bindView(R.id.md_colorR) - private val redValue: TextView by bindView(R.id.md_colorRValue) - private val greenSeekbar: SeekBar by bindView(R.id.md_colorG) - private val greenValue: TextView by bindView(R.id.md_colorGValue) - private val blueSeekbar: SeekBar by bindView(R.id.md_colorB) - private val blueValue: TextView by bindView(R.id.md_colorBValue) + private val gridView: FillGridView + private val customFrame: LinearLayout + private val customColorIndicator: View + private val hexInput: EditText + private val alphaLabel: TextView + private val alphaSeekbar: SeekBar + private val alphaValue: TextView + private val redSeekbar: SeekBar + private val redValue: TextView + private val greenSeekbar: SeekBar + private val greenValue: TextView + private val blueSeekbar: SeekBar + private val blueValue: TextView private var customHexTextWatcher: TextWatcher? = null private var customRgbListener: SeekBar.OnSeekBarChangeListener? = null init { - init() - } - - @SuppressLint("PrivateResource") - private fun init() { + //noinspection PrivateResource View.inflate(context, R.layout.md_dialog_colorchooser, this) + gridView = findViewById(R.id.md_grid) + customFrame = findViewById(R.id.md_colorChooserCustomFrame) + customColorIndicator = findViewById(R.id.md_colorIndicator) + hexInput = findViewById(R.id.md_hexInput) + alphaLabel = findViewById(R.id.md_colorALabel) + alphaSeekbar = findViewById(R.id.md_colorA) + alphaValue = findViewById(R.id.md_colorAValue) + redSeekbar = findViewById(R.id.md_colorR) + redValue = findViewById(R.id.md_colorRValue) + greenSeekbar = findViewById(R.id.md_colorG) + greenValue = findViewById(R.id.md_colorGValue) + blueSeekbar = findViewById(R.id.md_colorB) + blueValue = findViewById(R.id.md_colorBValue) } fun bind(builder: ColorContract, dialog: MaterialDialog) { 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 4510744..3951970 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 @@ -3,16 +3,13 @@ package ca.allanwang.kau.ui.activities import android.os.Build import android.os.Bundle import android.support.annotation.RequiresApi -import android.support.design.widget.AppBarLayout -import android.support.design.widget.CoordinatorLayout -import android.support.design.widget.FloatingActionButton import android.support.v7.widget.RecyclerView import android.support.v7.widget.Toolbar import android.transition.TransitionInflater import ca.allanwang.kau.internal.KauBaseActivity import ca.allanwang.kau.ui.R import ca.allanwang.kau.ui.widgets.ElasticDragDismissFrameLayout -import ca.allanwang.kau.utils.bindView +import kotlinx.android.synthetic.main.kau_elastic_recycler_activity.* /** * Created by Allan Wang on 2017-07-17. @@ -28,13 +25,9 @@ import ca.allanwang.kau.utils.bindView @RequiresApi(Build.VERSION_CODES.LOLLIPOP) abstract class ElasticRecyclerActivity : KauBaseActivity() { - val appBar: AppBarLayout by bindView(R.id.kau_appbar) - val toolbar: Toolbar by bindView(R.id.kau_toolbar) - val coordinator: CoordinatorLayout by bindView(R.id.kau_coordinator) - val draggableFrame: ElasticDragDismissFrameLayout by bindView(R.id.kau_draggable) - val recycler: RecyclerView by bindView(R.id.kau_recycler) - val fab: FloatingActionButton by bindView(R.id.kau_fab) - val configs = Configs() + private val configs = Configs() + protected val toolbar: Toolbar get() = kau_toolbar + protected val recycler: RecyclerView get() = kau_recycler class Configs { var exitTransitionBottom = R.transition.kau_exit_slide_bottom @@ -44,13 +37,13 @@ abstract class ElasticRecyclerActivity : KauBaseActivity() { final override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.kau_elastic_recycler_activity) - setSupportActionBar(toolbar) + setSupportActionBar(kau_toolbar) if (!onCreate(savedInstanceState, configs)) return - draggableFrame.addListener(object : ElasticDragDismissFrameLayout.SystemChromeFader(this) { + kau_draggable.addListener(object : ElasticDragDismissFrameLayout.SystemChromeFader(this) { override fun onDragDismissed() { window.returnTransition = TransitionInflater.from(this@ElasticRecyclerActivity) - .inflateTransition(if (draggableFrame.translationY > 0) configs.exitTransitionBottom else configs.exitTransitionTop) - recycler.stopScroll() + .inflateTransition(if (kau_draggable.translationY > 0) configs.exitTransitionBottom else configs.exitTransitionTop) + kau_recycler.stopScroll() finishAfterTransition() } }) @@ -68,7 +61,7 @@ abstract class ElasticRecyclerActivity : KauBaseActivity() { * Receive actions when the a click event is received outside of the coordinator */ fun setOutsideTapListener(listener: () -> Unit) { - draggableFrame.setOnClickListener { listener() } + kau_draggable.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 f46b3eb..193e088 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/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt index 4bc216d..41cd2e0 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt @@ -33,7 +33,7 @@ internal object SwipeBackHelper { } fun onDestroy(activity: Activity) { - val page: SwipeBackPage? = this[activity] + val page: SwipeBackPage? = this[activity] ?: return pageStack.kauRemoveIf { it.activityRef.get() == null || it === page } page?.activityRef?.clear() KL.v { "KauSwipe onDestroy ${activity.localClassName}" } 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 ae09c8a..a323e6c 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt @@ -207,9 +207,16 @@ internal class SwipeBackLayout @JvmOverloads constructor(context: Context, attrs override fun scrollToFinishActivity() { val contentView = contentViewRef.get() ?: return KL.e { "KauSwipe cannot scroll to finish as contentView is null. Is onPostCreate called?" } - val childWidth = contentView.width - val top = 0 - val left = childWidth + OVERSCROLL_DISTANCE + val swipeWidth = contentView.width + OVERSCROLL_DISTANCE + val swipeHeight = contentView.height + OVERSCROLL_DISTANCE + var top = 0 + var left = 0 + when (edgeFlag) { + SWIPE_EDGE_LEFT -> left = swipeWidth + SWIPE_EDGE_TOP -> top = swipeHeight + SWIPE_EDGE_RIGHT -> left = -swipeWidth + SWIPE_EDGE_BOTTOM -> top = -swipeHeight + } dragHelper.smoothSlideViewTo(contentView, left, top) invalidate() } 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 fdee4d8..6568bf2 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt @@ -118,7 +118,7 @@ inline fun Context.animation(@AnimRes id: Int) = AnimationUtils.loadAnimation(th inline fun Context.plural(@PluralsRes id: Int, quantity: Number) = resources.getQuantityString(id, quantity.toInt(), quantity.toInt())!! //Attr retrievers -fun Context.resolveColor(@AttrRes attr: Int, fallback: Int = 0): Int { +fun Context.resolveColor(@AttrRes attr: Int, @ColorInt fallback: Int = 0): Int { val a = theme.obtainStyledAttributes(intArrayOf(attr)) try { return a.getColor(0, fallback) diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt index b0448d1..8c7c039 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt @@ -21,147 +21,133 @@ import kotlin.reflect.KProperty import android.support.v4.app.DialogFragment as SupportDialogFragment import android.support.v4.app.Fragment as SupportFragment +private const val DEPRECATION_MESSAGE = "Kotterknife will be removed in favour of the kotlin_android_extensions plugin" + +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> View.bindView(id: Int) : ReadOnlyProperty<View, V> = required(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Activity.bindView(id: Int) : ReadOnlyProperty<Activity, V> = required(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Dialog.bindView(id: Int) : ReadOnlyProperty<Dialog, V> = required(id, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindViewResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindViewResettable<V>(id)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> DialogFragment.bindView(id: Int) : ReadOnlyProperty<DialogFragment, V> = required(id, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindViewResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindViewResettable<V>(id)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportDialogFragment.bindView(id: Int) : ReadOnlyProperty<android.support.v4.app.DialogFragment, V> = required(id, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindViewResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindViewResettable<V>(id)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Fragment.bindView(id: Int) : ReadOnlyProperty<Fragment, V> = required(id, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindViewResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindViewResettable<V>(id)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportFragment.bindView(id: Int) : ReadOnlyProperty<android.support.v4.app.Fragment, V> = required(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> ViewHolder.bindView(id: Int) : ReadOnlyProperty<ViewHolder, V> = required(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> View.bindOptionalView(id: Int) : ReadOnlyProperty<View, V?> = optional(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Activity.bindOptionalView(id: Int) : ReadOnlyProperty<Activity, V?> = optional(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Dialog.bindOptionalView(id: Int) : ReadOnlyProperty<Dialog, V?> = optional(id, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindOptionalViewResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindOptionalViewResettable<V>(id)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> DialogFragment.bindOptionalView(id: Int) : ReadOnlyProperty<DialogFragment, V?> = optional(id, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindOptionalViewResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindOptionalViewResettable<V>(id)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportDialogFragment.bindOptionalView(id: Int) : ReadOnlyProperty<android.support.v4.app.DialogFragment, V?> = optional(id, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindOptionalViewResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindOptionalViewResettable<V>(id)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Fragment.bindOptionalView(id: Int) : ReadOnlyProperty<Fragment, V?> = optional(id, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindOptionalViewResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindOptionalViewResettable<V>(id)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportFragment.bindOptionalView(id: Int) : ReadOnlyProperty<android.support.v4.app.Fragment, V?> = optional(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> ViewHolder.bindOptionalView(id: Int) : ReadOnlyProperty<ViewHolder, V?> = optional(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> View.bindViews(vararg ids: Int) : ReadOnlyProperty<View, List<V>> = required(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Activity.bindViews(vararg ids: Int) : ReadOnlyProperty<Activity, List<V>> = required(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Dialog.bindViews(vararg ids: Int) : ReadOnlyProperty<Dialog, List<V>> = required(ids, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindViewsResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindViewsResettable<V>(*ids)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> DialogFragment.bindViews(vararg ids: Int) : ReadOnlyProperty<DialogFragment, List<V>> = required(ids, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindViewsResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindViewsResettable<V>(*ids)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportDialogFragment.bindViews(vararg ids: Int) : ReadOnlyProperty<android.support.v4.app.DialogFragment, List<V>> = required(ids, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindViewsResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindViewsResettable<V>(*ids)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Fragment.bindViews(vararg ids: Int) : ReadOnlyProperty<Fragment, List<V>> = required(ids, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindViewsResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindViewsResettable<V>(*ids)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportFragment.bindViews(vararg ids: Int) : ReadOnlyProperty<android.support.v4.app.Fragment, List<V>> = required(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> ViewHolder.bindViews(vararg ids: Int) : ReadOnlyProperty<ViewHolder, List<V>> = required(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> View.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty<View, List<V>> = optional(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Activity.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty<Activity, List<V>> = optional(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Dialog.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty<Dialog, List<V>> = optional(ids, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindOptionalViewsResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindOptionalViewsResettable<V>(*ids)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> DialogFragment.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty<DialogFragment, List<V>> = optional(ids, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindOptionalViewsResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindOptionalViewsResettable<V>(*ids)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportDialogFragment.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty<android.support.v4.app.DialogFragment, List<V>> = optional(ids, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindOptionalViewsResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindOptionalViewsResettable<V>(*ids)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Fragment.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty<Fragment, List<V>> = optional(ids, viewFinder) -@Deprecated("Fragments operate on a different lifecycle. Consider using bindOptionalViewsResettable and resetting using KotterKnife.reset(this)", - ReplaceWith("bindOptionalViewsResettable<V>(*ids)"), - DeprecationLevel.WARNING) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportFragment.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty<android.support.v4.app.Fragment, List<V>> = optional(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> ViewHolder.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty<ViewHolder, List<V>> = optional(ids, viewFinder) @@ -223,99 +209,131 @@ private open class Lazy<in T, out V>(private val initializer: (T, KProperty<*>) * Credits to <a href="https://github.com/MichaelRocks">MichaelRocks</a> */ +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> View.bindViewResettable(id: Int) : ReadOnlyProperty<View, V> = requiredResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Activity.bindViewResettable(id: Int) : ReadOnlyProperty<Activity, V> = requiredResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Dialog.bindViewResettable(id: Int) : ReadOnlyProperty<Dialog, V> = requiredResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> DialogFragment.bindViewResettable(id: Int) : ReadOnlyProperty<DialogFragment, V> = requiredResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportDialogFragment.bindViewResettable(id: Int) : ReadOnlyProperty<android.support.v4.app.DialogFragment, V> = requiredResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Fragment.bindViewResettable(id: Int) : ReadOnlyProperty<Fragment, V> = requiredResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportFragment.bindViewResettable(id: Int) : ReadOnlyProperty<android.support.v4.app.Fragment, V> = requiredResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> ViewHolder.bindViewResettable(id: Int) : ReadOnlyProperty<ViewHolder, V> = requiredResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> View.bindOptionalViewResettable(id: Int) : ReadOnlyProperty<View, V?> = optionalResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Activity.bindOptionalViewResettable(id: Int) : ReadOnlyProperty<Activity, V?> = optionalResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Dialog.bindOptionalViewResettable(id: Int) : ReadOnlyProperty<Dialog, V?> = optionalResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> DialogFragment.bindOptionalViewResettable(id: Int) : ReadOnlyProperty<DialogFragment, V?> = optionalResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportDialogFragment.bindOptionalViewResettable(id: Int) : ReadOnlyProperty<android.support.v4.app.DialogFragment, V?> = optionalResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Fragment.bindOptionalViewResettable(id: Int) : ReadOnlyProperty<Fragment, V?> = optionalResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportFragment.bindOptionalViewResettable(id: Int) : ReadOnlyProperty<android.support.v4.app.Fragment, V?> = optionalResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> ViewHolder.bindOptionalViewResettable(id: Int) : ReadOnlyProperty<ViewHolder, V?> = optionalResettable(id, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> View.bindViewsResettable(vararg ids: Int) : ReadOnlyProperty<View, List<V>> = requiredResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Activity.bindViewsResettable(vararg ids: Int) : ReadOnlyProperty<Activity, List<V>> = requiredResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Dialog.bindViewsResettable(vararg ids: Int) : ReadOnlyProperty<Dialog, List<V>> = requiredResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> DialogFragment.bindViewsResettable(vararg ids: Int) : ReadOnlyProperty<DialogFragment, List<V>> = requiredResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportDialogFragment.bindViewsResettable(vararg ids: Int) : ReadOnlyProperty<android.support.v4.app.DialogFragment, List<V>> = requiredResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Fragment.bindViewsResettable(vararg ids: Int) : ReadOnlyProperty<Fragment, List<V>> = requiredResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportFragment.bindViewsResettable(vararg ids: Int) : ReadOnlyProperty<android.support.v4.app.Fragment, List<V>> = requiredResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> ViewHolder.bindViewsResettable(vararg ids: Int) : ReadOnlyProperty<ViewHolder, List<V>> = requiredResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> View.bindOptionalViewsResettable(vararg ids: Int) : ReadOnlyProperty<View, List<V>> = optionalResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Activity.bindOptionalViewsResettable(vararg ids: Int) : ReadOnlyProperty<Activity, List<V>> = optionalResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Dialog.bindOptionalViewsResettable(vararg ids: Int) : ReadOnlyProperty<Dialog, List<V>> = optionalResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> DialogFragment.bindOptionalViewsResettable(vararg ids: Int) : ReadOnlyProperty<DialogFragment, List<V>> = optionalResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportDialogFragment.bindOptionalViewsResettable(vararg ids: Int) : ReadOnlyProperty<android.support.v4.app.DialogFragment, List<V>> = optionalResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> Fragment.bindOptionalViewsResettable(vararg ids: Int) : ReadOnlyProperty<Fragment, List<V>> = optionalResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> SupportFragment.bindOptionalViewsResettable(vararg ids: Int) : ReadOnlyProperty<android.support.v4.app.Fragment, List<V>> = optionalResettable(ids, viewFinder) +@Deprecated(DEPRECATION_MESSAGE) fun <V : View> ViewHolder.bindOptionalViewsResettable(vararg ids: Int) : ReadOnlyProperty<ViewHolder, List<V>> = optionalResettable(ids, viewFinder) @@ -345,6 +363,7 @@ private class LazyResettable<in T, out V>(initializer: (T, KProperty<*>) -> V) : } } +@Deprecated(DEPRECATION_MESSAGE) object Kotterknife { fun reset(target: Any) { KotterknifeRegistry.reset(target) 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 83b182f..28d51a4 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt @@ -11,8 +11,6 @@ import android.view.View import android.view.ViewGroup import android.widget.TextView import ca.allanwang.kau.R -import ca.allanwang.kau.utils.bindOptionalView -import ca.allanwang.kau.utils.bindView import ca.allanwang.kau.utils.materialDialog import ca.allanwang.kau.utils.use import com.afollestad.materialdialogs.MaterialDialog @@ -64,8 +62,8 @@ internal class ChangelogAdapter(val items: List<Pair<String, ChangelogType>>, @C override fun getItemCount() = items.size internal class ChangelogVH(itemView: View) : RecyclerView.ViewHolder(itemView) { - val text: TextView by bindView(R.id.kau_changelog_text) - val bullet: TextView? by bindOptionalView(R.id.kau_changelog_bullet) + val text: TextView = itemView.findViewById(R.id.kau_changelog_text) + val bullet: TextView? = itemView.findViewById(R.id.kau_changelog_bullet) } } diff --git a/core/src/main/res-public/values/public.xml b/core/src/main/res-public/values/public.xml index ea8ed73..2163b10 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' /> @@ -107,12 +115,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/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? 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 9e83d84..f1e32d1 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt @@ -12,6 +12,7 @@ import ca.allanwang.kau.utils.* import com.mikepenz.google_material_typeface_library.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. @@ -27,14 +28,12 @@ class BlurredImageView @JvmOverloads constructor( ) : FrameLayout(context, attrs, defStyleAttr), MeasureSpecContract by MeasureSpecDelegate() { private var blurred = false - val imageBase: ImageView by bindView(R.id.image_base) - internal val imageBlur: ImageView by bindView(R.id.image_blur) - val imageForeground: ImageView by bindView(R.id.image_foreground) + val imageBase: ImageView get() = image_base init { inflate(R.layout.kau_blurred_imageview, true) initAttrs(context, attrs) - imageForeground.setIcon(GoogleMaterial.Icon.gmd_check, 30) + image_foreground.setIcon(GoogleMaterial.Icon.gmd_check, 30) } override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { @@ -45,8 +44,8 @@ class BlurredImageView @JvmOverloads constructor( override fun clearAnimation() { super.clearAnimation() imageBase.clearAnimation() - imageBlur.clearAnimation() - imageForeground.clearAnimation() + image_blur.clearAnimation() + image_foreground.clearAnimation() } private fun View.scaleAnimate(scale: Float) = animate().scaleXY(scale).setDuration(ANIMATION_DURATION) @@ -68,10 +67,10 @@ class BlurredImageView @JvmOverloads constructor( factor.width = width factor.height = height BlurTask(imageBase, factor) { - imageBlur.setImageDrawable(it) + image_blur.setImageDrawable(it) scaleAnimate(ANIMATION_SCALE).start() - imageBlur.alphaAnimate(1f).start() - imageForeground.alphaAnimate(1f).start() + image_blur.alphaAnimate(1f).start() + image_foreground.alphaAnimate(1f).start() }.execute() } @@ -87,10 +86,10 @@ class BlurredImageView @JvmOverloads constructor( factor.width = width factor.height = height BlurTask(imageBase, factor) { drawable -> - imageBlur.setImageDrawable(drawable) + image_blur.setImageDrawable(drawable) scaleXY = ANIMATION_SCALE - imageBlur.alpha = 1f - imageForeground.alpha = 1f + image_blur.alpha = 1f + image_foreground.alpha = 1f }.execute() } @@ -101,8 +100,8 @@ class BlurredImageView @JvmOverloads constructor( if (!blurred) return blurred = false scaleAnimate(1.0f).start() - imageBlur.alphaAnimate(0f).withEndAction { imageBlur.setImageDrawable(null) }.start() - imageForeground.alphaAnimate(0f).start() + image_blur.alphaAnimate(0f).withEndAction { image_blur.setImageDrawable(null) }.start() + image_foreground.alphaAnimate(0f).start() } @@ -114,9 +113,9 @@ class BlurredImageView @JvmOverloads constructor( clearAnimation() scaleX = 1.0f scaleX = 1.0f - imageBlur.alpha = 0f - imageBlur.setImageDrawable(null) - imageForeground.alpha = 0f + image_blur.alpha = 0f + image_blur.setImageDrawable(null) + image_foreground.alpha = 0f } /** @@ -145,14 +144,14 @@ class BlurredImageView @JvmOverloads constructor( fun fullReset() { reset() fullAction({ it.visible().background = null }) - imageForeground.setBackgroundColorRes(R.color.kau_blurred_image_selection_overlay) - imageForeground.setIcon(GoogleMaterial.Icon.gmd_check, 30, Color.WHITE) + image_foreground.setBackgroundColorRes(R.color.kau_blurred_image_selection_overlay) + image_foreground.setIcon(GoogleMaterial.Icon.gmd_check, 30, Color.WHITE) } private fun fullAction(action: (View) -> Unit) { action(this) action(imageBase) - action(imageBlur) - action(imageForeground) + action(image_blur) + action(image_foreground) } }
\ No newline at end of file diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt index b2cfa46..c0b7e2d 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt @@ -4,7 +4,6 @@ import android.graphics.drawable.Drawable import android.support.v7.widget.RecyclerView import android.view.View import ca.allanwang.kau.iitems.KauIItem -import ca.allanwang.kau.utils.bindView import com.bumptech.glide.load.DataSource import com.bumptech.glide.load.engine.GlideException import com.bumptech.glide.request.RequestListener @@ -64,6 +63,6 @@ class MediaItem(val data: MediaModel) } class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { - val container: BlurredImageView by bindView(R.id.kau_image) + val container: BlurredImageView = v.findViewById(R.id.kau_image) } }
\ No newline at end of file diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt index 1fa18aa..59202c0 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt @@ -7,7 +7,6 @@ import android.support.v7.widget.RecyclerView import android.view.View import ca.allanwang.kau.iitems.KauIItem import ca.allanwang.kau.ui.views.MeasuredImageView -import ca.allanwang.kau.utils.bindView import com.bumptech.glide.load.DataSource import com.bumptech.glide.load.engine.GlideException import com.bumptech.glide.request.RequestListener @@ -58,6 +57,6 @@ class MediaItemBasic(val data: MediaModel) } class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { - val image: MeasuredImageView by bindView(R.id.kau_image) + val image: MeasuredImageView = v.findViewById(R.id.kau_image) } }
\ No newline at end of file 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 07e6d18..37f2373 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt @@ -3,17 +3,16 @@ package ca.allanwang.kau.mediapicker import android.database.Cursor import android.os.Bundle import android.support.design.widget.AppBarLayout -import android.support.design.widget.CoordinatorLayout -import android.support.design.widget.FloatingActionButton import android.support.v4.content.Loader import android.support.v7.widget.LinearLayoutManager -import android.support.v7.widget.RecyclerView -import android.support.v7.widget.Toolbar -import android.widget.TextView import ca.allanwang.kau.adapters.selectedItems import ca.allanwang.kau.adapters.selectionSize -import ca.allanwang.kau.utils.* +import ca.allanwang.kau.utils.hideOnDownwardsScroll +import ca.allanwang.kau.utils.setIcon +import ca.allanwang.kau.utils.toDrawable +import ca.allanwang.kau.utils.toast import com.mikepenz.google_material_typeface_library.GoogleMaterial +import kotlinx.android.synthetic.main.kau_activity_image_picker.* /** * Created by Allan Wang on 2017-07-04. @@ -27,35 +26,29 @@ abstract class MediaPickerActivityBase( mediaActions: List<MediaAction> = emptyList() ) : MediaPickerCore<MediaItem>(mediaType, mediaActions) { - val coordinator: CoordinatorLayout by bindView(R.id.kau_coordinator) - val toolbar: Toolbar by bindView(R.id.kau_toolbar) - val selectionCount: TextView by bindView(R.id.kau_selection_count) - val recycler: RecyclerView by bindView(R.id.kau_recyclerview) - val fab: FloatingActionButton by bindView(R.id.kau_fab) - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.kau_activity_image_picker) - selectionCount.setCompoundDrawables(null, null, GoogleMaterial.Icon.gmd_image.toDrawable(this, 18), null) + kau_selection_count.setCompoundDrawables(null, null, GoogleMaterial.Icon.gmd_image.toDrawable(this, 18), null) - setSupportActionBar(toolbar) + setSupportActionBar(kau_toolbar) supportActionBar?.apply { setDisplayHomeAsUpEnabled(true) setDisplayShowHomeEnabled(true) setHomeAsUpIndicator(GoogleMaterial.Icon.gmd_close.toDrawable(this@MediaPickerActivityBase, 18)) } - toolbar.setNavigationOnClickListener { onBackPressed() } + kau_toolbar.setNavigationOnClickListener { onBackPressed() } - initializeRecycler(recycler) + initializeRecycler(kau_recyclerview) MediaItem.bindEvents(adapter.fastAdapter) adapter.fastAdapter.withSelectionListener { _, _ -> - selectionCount.text = adapter.selectionSize.toString() + kau_selection_count.text = adapter.selectionSize.toString() } - fab.apply { + kau_fab.apply { show() setIcon(GoogleMaterial.Icon.gmd_send) setOnClickListener { @@ -66,7 +59,7 @@ abstract class MediaPickerActivityBase( finish(ArrayList(selection.map { it.data })) } } - hideOnDownwardsScroll(recycler) + hideOnDownwardsScroll(kau_recyclerview) } loadItems() @@ -83,7 +76,7 @@ abstract class MediaPickerActivityBase( * @param scrollable true if scroll flags are enabled, false otherwise */ private fun setToolbarScrollable(scrollable: Boolean) { - val params = toolbar.layoutParams as AppBarLayout.LayoutParams + val params = kau_toolbar.layoutParams as AppBarLayout.LayoutParams if (scrollable) params.scrollFlags = AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS or AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL else @@ -92,7 +85,7 @@ abstract class MediaPickerActivityBase( override fun onLoadFinished(loader: Loader<Cursor>, data: Cursor?) { super.onLoadFinished(loader, data) - setToolbarScrollable((recycler.layoutManager as LinearLayoutManager) + setToolbarScrollable((kau_recyclerview.layoutManager as LinearLayoutManager) .findLastCompletelyVisibleItemPosition() < adapter.adapterItemCount - 1) } 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 9516eab..122838b 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt @@ -3,10 +3,8 @@ package ca.allanwang.kau.mediapicker import android.os.Build import android.os.Bundle import android.support.annotation.RequiresApi -import android.support.v7.widget.RecyclerView -import ca.allanwang.kau.ui.widgets.ElasticDragDismissFrameLayout -import ca.allanwang.kau.utils.bindView import ca.allanwang.kau.utils.toast +import kotlinx.android.synthetic.main.kau_activity_image_picker_overlay.* /** * Created by Allan Wang on 2017-07-23. @@ -22,23 +20,20 @@ abstract class MediaPickerActivityOverlayBase( mediaActions: List<MediaAction> = emptyList() ) : MediaPickerCore<MediaItemBasic>(mediaType, mediaActions) { - val draggable: ElasticDragDismissFrameLayout by bindView(R.id.kau_draggable) - val recycler: RecyclerView by bindView(R.id.kau_recyclerview) - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.kau_activity_image_picker_overlay) - initializeRecycler(recycler) + initializeRecycler(kau_recyclerview) MediaItemBasic.bindEvents(this, adapter.fastAdapter) - draggable.addExitListener(this, R.transition.kau_image_exit_bottom, R.transition.kau_image_exit_top) - draggable.setOnClickListener { finishAfterTransition() } + kau_draggable.addExitListener(this, R.transition.kau_image_exit_bottom, R.transition.kau_image_exit_top) + kau_draggable.setOnClickListener { finishAfterTransition() } loadItems() } override fun finishAfterTransition() { - recycler.stopScroll() + kau_recyclerview.stopScroll() super.finishAfterTransition() } diff --git a/sample/build.gradle b/sample/build.gradle index d2572c3..d7199a3 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' apply plugin: 'com.github.triplet.play' play { 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<IItem<*, *>>() - override fun onCreate(savedInstanceState: Bundle?, configs: Configs): Boolean { - recycler.adapter = adapter + val adapter = ItemAdapter<IItem<*, *>>() + 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<PermissionCheckbox, } class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { - val text: TextView by bindView(R.id.perm_text) - val checkbox: CheckBox by bindView(R.id.perm_checkbox) + val text: TextView = v.findViewById(R.id.perm_text) + val checkbox: CheckBox = v.findViewById(R.id.perm_checkbox) } }
\ No newline at end of file diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/SwipeActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/SwipeActivity.kt index bc2d4a4..4197b6d 100644 --- a/sample/src/main/kotlin/ca/allanwang/kau/sample/SwipeActivity.kt +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/SwipeActivity.kt @@ -2,12 +2,10 @@ package ca.allanwang.kau.sample import android.app.Activity import android.os.Bundle -import android.support.v7.widget.Toolbar -import android.view.ViewGroup -import android.widget.Button import ca.allanwang.kau.internal.KauBaseActivity import ca.allanwang.kau.swipe.* import ca.allanwang.kau.utils.* +import kotlinx.android.synthetic.main.activity_swipe.* /** * Created by Allan Wang on 2017-08-05. @@ -22,37 +20,26 @@ fun Activity.startActivityWithEdge(flag: Int) { class SwipeActivity : KauBaseActivity() { - val toolbar: Toolbar by bindView(R.id.swipe_toolbar) - val container: ViewGroup by bindView(R.id.swipe_container) - val directions: List<Button> 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 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 a3dc7f4..0ae856a 100644 --- a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt +++ b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt @@ -72,9 +72,9 @@ class SearchItem(val key: String, } class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { - val icon: ImageView by bindView(R.id.kau_search_icon) - val title: TextView by bindView(R.id.kau_search_title) - val desc: TextView by bindView(R.id.kau_search_desc) - val container: ConstraintLayout by bindView(R.id.kau_search_item_frame) + val icon: ImageView = v.findViewById(R.id.kau_search_icon) + val title: TextView = v.findViewById(R.id.kau_search_title) + val desc: TextView = v.findViewById(R.id.kau_search_desc) + val container: ConstraintLayout = v.findViewById(R.id.kau_search_item_frame) } }
\ No newline at end of file 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 11e1748..d223ec4 100644 --- a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt +++ b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt @@ -9,7 +9,6 @@ import android.support.annotation.IdRes import android.support.transition.ChangeBounds import android.support.transition.TransitionManager import android.support.transition.TransitionSet -import android.support.v7.widget.AppCompatEditText import android.support.v7.widget.RecyclerView import android.text.Editable import android.text.TextWatcher @@ -18,16 +17,15 @@ import android.view.* import android.view.inputmethod.EditorInfo import android.widget.FrameLayout import android.widget.ImageView -import android.widget.ProgressBar 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.ui.views.BoundedCardView import ca.allanwang.kau.utils.* import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter import com.mikepenz.google_material_typeface_library.GoogleMaterial import com.mikepenz.iconics.typeface.IIcon +import kotlinx.android.synthetic.main.kau_search_view.view.* import org.jetbrains.anko.runOnUiThread @@ -191,14 +189,14 @@ class SearchView @JvmOverloads constructor( SearchItem.backgroundColor = backgroundColor tintBackground(backgroundColor) } - val icons = mutableListOf(navIcon to iconNav, clearIcon to iconClear) + val icons = mutableListOf(navIcon to kau_search_nav, clearIcon to kau_search_clear) val extra = extraIcon - if (extra != null) icons.add(extra.first to iconExtra) + if (extra != null) icons.add(extra.first to kau_search_extra) icons.forEach { (iicon, view) -> view.goneIf(iicon == null).setSearchIcon(iicon) } - if (extra != null) iconExtra.setOnClickListener(extra.second) - divider.invisibleIf(!withDivider) - editText.hint = context.string(hintTextRes, hintText) + 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() textCallback = debounce(textDebounceInterval, this@Configs.textCallback) } @@ -215,7 +213,7 @@ class SearchView @JvmOverloads constructor( val list = if (value.isEmpty() && configs.noResultsFound != INVALID_ID) listOf(SearchItem("", context.string(configs.noResultsFound), iicon = null)) else value - if (configs.highlightQueryText && value.isNotEmpty()) list.forEach { it.withHighlights(editText.text?.toString()) } + if (configs.highlightQueryText && value.isNotEmpty()) list.forEach { it.withHighlights(kau_search_edit_text.text?.toString()) } cardTransition() adapter.setNewList(list) } @@ -231,26 +229,17 @@ class SearchView @JvmOverloads constructor( private val configs = Configs() // views - private val shadow: View by bindView(R.id.kau_search_shadow) - private val card: BoundedCardView by bindView(R.id.kau_search_cardview) - private val iconNav: ImageView by bindView(R.id.kau_search_nav) - private val editText: AppCompatEditText by bindView(R.id.kau_search_edit_text) - private val progress: ProgressBar by bindView(R.id.kau_search_progress) - private val iconExtra: ImageView by bindView(R.id.kau_search_extra) - private val iconClear: ImageView by bindView(R.id.kau_search_clear) - private val divider: View by bindView(R.id.kau_search_divider) - private val recycler: RecyclerView by bindView(R.id.kau_search_recycler) private var textCallback: Debouncer2<String, SearchView> = 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 && card.isVisible + get() = parent != null && kau_search_cardview.isVisible /** * The current text located in our searchview */ val query: String - get() = editText.text?.toString()?.trim() ?: "" + get() = kau_search_edit_text.text?.toString()?.trim() ?: "" /* * Ripple start points and search view offset @@ -264,11 +253,11 @@ class SearchView @JvmOverloads constructor( init { View.inflate(context, R.layout.kau_search_view, this) z = 99f - iconNav.setSearchIcon(configs.navIcon).setOnClickListener { revealClose() } - iconClear.setSearchIcon(configs.clearIcon).setOnClickListener { editText.text?.clear() } + kau_search_nav.setSearchIcon(configs.navIcon).setOnClickListener { revealClose() } + kau_search_clear.setSearchIcon(configs.clearIcon).setOnClickListener { kau_search_edit_text.text?.clear() } tintForeground(configs.foregroundColor) tintBackground(configs.backgroundColor) - with(recycler) { + with(kau_search_recycler) { isNestedScrollingEnabled = false withLinearAdapter(this@SearchView.adapter) addOnScrollListener(object : RecyclerView.OnScrollListener() { @@ -288,7 +277,7 @@ class SearchView @JvmOverloads constructor( if (item.key.isNotBlank()) configs.onItemLongClick(position, item.key, item.content, this@SearchView); true } } - editText.addTextChangedListener(object : TextWatcher { + kau_search_edit_text.addTextChangedListener(object : TextWatcher { override fun afterTextChanged(s: Editable?) {} override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {} @@ -302,10 +291,11 @@ class SearchView @JvmOverloads constructor( clearResults() } }) - editText.setOnEditorActionListener { _, actionId, _ -> + kau_search_edit_text.setOnEditorActionListener { _, actionId, _ -> if (actionId == EditorInfo.IME_ACTION_SEARCH) { - if (configs.searchCallback(editText.text?.toString() ?: "", this)) revealClose() - else editText.hideKeyboard() + if (configs.searchCallback(kau_search_edit_text.text?.toString() + ?: "", this)) revealClose() + else kau_search_edit_text.hideKeyboard() return@setOnEditorActionListener true } false @@ -318,7 +308,7 @@ class SearchView @JvmOverloads constructor( } internal fun cardTransition(builder: TransitionSet.() -> Unit = {}) { - TransitionManager.beginDelayedTransition(card, + 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 { @@ -345,9 +335,9 @@ class SearchView @JvmOverloads constructor( val menuItem = menu.findItem(id) ?: throw IllegalArgumentException("Menu item with given id doesn't exist") if (menuItem.icon == null) menuItem.icon = GoogleMaterial.Icon.gmd_search.toDrawable(context, 18, menuIconColor) - card.gone() + kau_search_cardview.gone() menuItem.setOnMenuItemClickListener { revealOpen(); true } - shadow.setOnClickListener { revealClose() } + kau_search_shadow.setOnClickListener { revealClose() } this.menuItem = menuItem return this } @@ -372,10 +362,10 @@ class SearchView @JvmOverloads constructor( menuX = (locations[0] + view.width / 2) menuHalfHeight = view.height / 2 menuY = (locations[1] + menuHalfHeight) - card.viewTreeObserver.addOnPreDrawListener(object : ViewTreeObserver.OnPreDrawListener { + kau_search_cardview.viewTreeObserver.addOnPreDrawListener(object : ViewTreeObserver.OnPreDrawListener { override fun onPreDraw(): Boolean { view.viewTreeObserver.removeOnPreDrawListener(this) - card.setMarginTop(menuY - card.height / 2) + kau_search_cardview.setMarginTop(menuY - kau_search_cardview.height / 2) return true } }) @@ -398,12 +388,12 @@ class SearchView @JvmOverloads constructor( * This can be done publicly through [configs], which will also save the color */ internal fun tintForeground(@ColorInt color: Int) { - iconNav.drawable.setTint(color) - iconClear.drawable.setTint(color) - divider.setBackgroundColor(color.adjustAlpha(0.1f)) - editText.tint(color) - editText.setTextColor(ColorStateList.valueOf(color)) - editText.setHintTextColor(color.adjustAlpha(0.7f)) + 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)) } /** @@ -411,7 +401,7 @@ class SearchView @JvmOverloads constructor( * This can be done publicly through [configs], which will also save the color */ internal fun tintBackground(@ColorInt color: Int) { - card.setCardBackgroundColor(color) + kau_search_cardview.setCardBackgroundColor(color) } fun revealOpen() { @@ -424,11 +414,11 @@ class SearchView @JvmOverloads constructor( */ configureCoords(menuItem) configs.openListener?.invoke(this@SearchView) - shadow.fadeIn() - editText.showKeyboard() - card.circularReveal(menuX, menuHalfHeight, duration = configs.revealDuration) { + kau_search_shadow.fadeIn() + kau_search_edit_text.showKeyboard() + kau_search_cardview.circularReveal(menuX, menuHalfHeight, duration = configs.revealDuration) { cardTransition() - recycler.visible() + kau_search_recycler.visible() } } } @@ -436,18 +426,18 @@ class SearchView @JvmOverloads constructor( fun revealClose() { if (parent == null || !isOpen) return context.runOnUiThread { - shadow.fadeOut(duration = configs.transitionDuration) + kau_search_shadow.fadeOut(duration = configs.transitionDuration) cardTransition { addEndListener { - card.circularHide(menuX, menuHalfHeight, duration = configs.revealDuration, + kau_search_cardview.circularHide(menuX, menuHalfHeight, duration = configs.revealDuration, onFinish = { configs.closeListener?.invoke(this@SearchView) - if (configs.shouldClearOnClose) editText.text?.clear() + if (configs.shouldClearOnClose) kau_search_edit_text.text?.clear() }) } } - recycler.gone() - editText.hideKeyboard() + kau_search_recycler.gone() + kau_search_edit_text.hideKeyboard() } } |