From 99f1e76a4d8d35d4d3ca1aadf68bbc227a70ba01 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 27 Jul 2019 17:56:41 -0700 Subject: Migrate some items --- about/build.gradle | 4 ++- .../main/kotlin/ca/allanwang/kau/about/FaqIItem.kt | 9 +++--- .../kotlin/ca/allanwang/kau/about/LibraryIItem.kt | 23 ++++++++------- .../kotlin/ca/allanwang/kau/iitems/CardIItem.kt | 6 ++-- .../kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt | 2 +- .../allanwang/kau/mediapicker/MediaActionItem.kt | 13 +++++---- .../ca/allanwang/kau/mediapicker/MediaItem.kt | 34 +++++++++++++--------- 7 files changed, 53 insertions(+), 38 deletions(-) diff --git a/about/build.gradle b/about/build.gradle index b970530..274ef5c 100644 --- a/about/build.gradle +++ b/about/build.gradle @@ -1,3 +1,5 @@ +import kau.Dependencies + apply from: '../android-lib.gradle' android { @@ -10,7 +12,7 @@ dependencies { implementation project(':core-ui') implementation project(':fastadapter') - api kau.Dependencies.aboutLibraries + api Dependencies.aboutLibraries } apply from: '../artifacts.gradle' 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 8ae445d..4873f6e 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt @@ -32,23 +32,24 @@ import ca.allanwang.kau.xml.FaqItem import com.mikepenz.fastadapter.FastAdapter import com.mikepenz.fastadapter.IItem import com.mikepenz.fastadapter.listeners.ClickEventHook +import com.mikepenz.fastadapter.select.getSelectExtension /** * Created by Allan Wang on 2017-08-02. */ -class FaqIItem(val content: FaqItem) : KauIItem( +class FaqIItem(val content: FaqItem) : KauIItem< FaqIItem.ViewHolder>( R.layout.kau_iitem_faq, ::ViewHolder, R.id.kau_item_faq ), ThemableIItem by ThemableIItemDelegate() { companion object { fun bindEvents(fastAdapter: FastAdapter>) { - fastAdapter.withSelectable(false) - .withEventHook(object : ClickEventHook>() { + fastAdapter.getSelectExtension().isSelectable = true + fastAdapter.addEventHook(object : ClickEventHook>() { override fun onBind(viewHolder: RecyclerView.ViewHolder): View? = (viewHolder as? ViewHolder)?.questionContainer - override fun onClick(v: View, position: Int, adapter: FastAdapter>, item: IItem<*>) { + override fun onClick(v: View, position: Int, fastAdapter: FastAdapter>, item: IItem<*>) { if (item !is FaqIItem) return item.isExpanded = !item.isExpanded v.parentViewGroup.findViewById(R.id.faq_item_answer) 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 dbff49a..445d435 100644 --- a/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt +++ b/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt @@ -30,26 +30,27 @@ import ca.allanwang.kau.utils.visible import com.mikepenz.aboutlibraries.entity.Library import com.mikepenz.fastadapter.FastAdapter import com.mikepenz.fastadapter.IItem +import com.mikepenz.fastadapter.select.getSelectExtension /** * Created by Allan Wang on 2017-06-27. */ -class LibraryIItem(val lib: Library) : KauIItem( +class LibraryIItem(val lib: Library) : KauIItem( R.layout.kau_iitem_library, ::ViewHolder, R.id.kau_item_library ), ThemableIItem by ThemableIItemDelegate() { companion object { fun bindEvents(fastAdapter: FastAdapter>) { - fastAdapter.withSelectable(false) - .withOnClickListener { v, _, item, _ -> - if (item !is LibraryIItem) - false - else - with(item.lib) { - v!!.context.startLink(libraryWebsite, repositoryLink, authorWebsite) - true - } - } + fastAdapter.getSelectExtension().isSelectable = true + fastAdapter.onClickListener = { v, _, item, _ -> + if (item !is LibraryIItem) + false + else + with(item.lib) { + v!!.context.startLink(libraryWebsite, repositoryLink, authorWebsite) + true + } + } } } diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt index 47c465c..f9f06b9 100644 --- a/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt +++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt @@ -46,18 +46,18 @@ import com.mikepenz.iconics.typeface.IIcon */ class CardIItem( val builder: Config.() -> Unit = {} -) : KauIItem( +) : KauIItem< CardIItem.ViewHolder>( R.layout.kau_iitem_card, ::ViewHolder, R.id.kau_item_card ), ThemableIItem by ThemableIItemDelegate() { companion object { fun bindClickEvents(fastAdapter: FastAdapter>) { - fastAdapter.withEventHook(object : ClickEventHook>() { + fastAdapter.addEventHook(object : ClickEventHook>() { override fun onBindMany(viewHolder: RecyclerView.ViewHolder): List? { return if (viewHolder is ViewHolder) listOf(viewHolder.card, viewHolder.button) else null } - override fun onClick(v: View, position: Int, adapter: FastAdapter>, item: IItem<*>) { + override fun onClick(v: View, position: Int, fastAdapter: FastAdapter>, item: IItem<*>) { if (item !is CardIItem) return with(item.configs) { when (v.id) { diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt index 2c488b1..551cb59 100644 --- a/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt +++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt @@ -34,7 +34,7 @@ import ca.allanwang.kau.utils.string class HeaderIItem( text: String? = null, var textRes: Int = INVALID_ID -) : KauIItem( +) : KauIItem( R.layout.kau_iitem_header, { ViewHolder(it) }, R.id.kau_item_header_big_margin_top ), ThemableIItem by ThemableIItemDelegate() { diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt index a365e13..55b448e 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt @@ -26,7 +26,6 @@ import ca.allanwang.kau.permissions.PERMISSION_WRITE_EXTERNAL_STORAGE import ca.allanwang.kau.permissions.kauRequestPermissions import ca.allanwang.kau.utils.materialDialog import ca.allanwang.kau.utils.string -import com.mikepenz.google_material_typeface_library.GoogleMaterial import com.mikepenz.iconics.typeface.IIcon import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial import java.io.File @@ -37,18 +36,22 @@ import java.io.File class MediaActionItem( val action: MediaAction, val mediaType: MediaType -) : KauIItem( +) : KauIItem( R.layout.kau_iitem_image_basic, { MediaItemBasic.ViewHolder(it) }, R.id.kau_item_media_action ) { - override fun isSelectable(): Boolean = false - override fun bindView(holder: MediaItemBasic.ViewHolder, payloads: MutableList) { super.bindView(holder, payloads) holder.image.apply { - setImageDrawable(MediaPickerCore.getIconDrawable(context, action.iicon(this@MediaActionItem), action.color)) + setImageDrawable( + MediaPickerCore.getIconDrawable( + context, + action.iicon(this@MediaActionItem), + action.color + ) + ) setOnClickListener { action(context, this@MediaActionItem) } } } 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 5d3e7b9..5d47590 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt @@ -24,33 +24,37 @@ import com.bumptech.glide.load.engine.GlideException import com.bumptech.glide.request.RequestListener import com.bumptech.glide.request.target.Target import com.mikepenz.fastadapter.FastAdapter +import com.mikepenz.fastadapter.select.getSelectExtension /** * Created by Allan Wang on 2017-07-04. */ class MediaItem(val data: MediaModel) : - KauIItem(R.layout.kau_iitem_image, { ViewHolder(it) }), + KauIItem(R.layout.kau_iitem_image, { ViewHolder(it) }), GlideContract by GlideDelegate() { private var failedToLoad = false companion object { fun bindEvents(fastAdapter: FastAdapter) { - fastAdapter.withMultiSelect(true) - .withSelectable(true) - //adapter selector occurs before the on click event - .withOnClickListener { v, _, item, _ -> - val image = v as BlurredImageView - if (item.isSelected) image.blur() - else image.removeBlur() - true - } + fastAdapter.getSelectExtension().apply { + isSelectable = true + multiSelect = true + } + fastAdapter.onClickListener = { v, _, item, _ -> + val image = v as BlurredImageView + if (item.isSelected) image.blur() + else image.removeBlur() + true + } } } - override fun isSelectable(): Boolean = !failedToLoad + override var isSelectable: Boolean + get() = !failedToLoad + set(value) {} - override fun bindView(holder: ViewHolder, payloads: List) { + override fun bindView(holder: ViewHolder, payloads: MutableList) { super.bindView(holder, payloads) glide(holder.itemView) .load(data.data) @@ -63,7 +67,11 @@ class MediaItem(val data: MediaModel) : isFirstResource: Boolean ): Boolean { failedToLoad = true - holder.container.imageBase.setImageDrawable(MediaPickerCore.getErrorDrawable(holder.itemView.context)) + holder.container.imageBase.setImageDrawable( + MediaPickerCore.getErrorDrawable( + holder.itemView.context + ) + ) return true } -- cgit v1.2.3