From 68be87724ae4470aae7a6058f98082f4e0b7316f Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sat, 31 Oct 2020 10:07:18 +0530 Subject: [PATCH 01/13] Switch to Groupie view binding module. --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index ab3449784..6647b413d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -217,7 +217,7 @@ dependencies { implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0" implementation "com.xwray:groupie:${groupieVersion}" - implementation "com.xwray:groupie-kotlin-android-extensions:${groupieVersion}" + implementation "com.xwray:groupie-viewbinding:${groupieVersion}" implementation "de.hdodenhof:circleimageview:3.1.0" implementation "com.nostra13.universalimageloader:universal-image-loader:1.9.5" From 46afe5153f6d7e774fd63e0a07007eb485d42e84 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Fri, 27 Nov 2020 20:18:38 +0530 Subject: [PATCH 02/13] Use BindableItem in EmptyPlaceholderItem. --- .../local/subscription/item/EmptyPlaceholderItem.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/EmptyPlaceholderItem.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/EmptyPlaceholderItem.kt index ef7eb93cd..59bef55cf 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/item/EmptyPlaceholderItem.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/EmptyPlaceholderItem.kt @@ -1,11 +1,13 @@ package org.schabi.newpipe.local.subscription.item -import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder -import com.xwray.groupie.kotlinandroidextensions.Item +import android.view.View +import com.xwray.groupie.viewbinding.BindableItem import org.schabi.newpipe.R +import org.schabi.newpipe.databinding.ListEmptyViewBinding -class EmptyPlaceholderItem : Item() { +class EmptyPlaceholderItem : BindableItem() { override fun getLayout(): Int = R.layout.list_empty_view - override fun bind(viewHolder: GroupieViewHolder, position: Int) {} + override fun bind(viewBinding: ListEmptyViewBinding, position: Int) {} override fun getSpanSize(spanCount: Int, position: Int): Int = spanCount + override fun initializeViewBinding(view: View) = ListEmptyViewBinding.bind(view) } From b387946d34e388a7c9a54a745b5c693a9d445c0a Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Fri, 27 Nov 2020 20:19:48 +0530 Subject: [PATCH 03/13] Use BindableItem in FeedGroupAddItem. --- .../local/subscription/item/FeedGroupAddItem.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddItem.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddItem.kt index 1bc4d1673..434b4f29a 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddItem.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddItem.kt @@ -1,10 +1,12 @@ package org.schabi.newpipe.local.subscription.item -import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder -import com.xwray.groupie.kotlinandroidextensions.Item +import android.view.View +import com.xwray.groupie.viewbinding.BindableItem import org.schabi.newpipe.R +import org.schabi.newpipe.databinding.FeedGroupAddNewItemBinding -class FeedGroupAddItem : Item() { +class FeedGroupAddItem : BindableItem() { override fun getLayout(): Int = R.layout.feed_group_add_new_item - override fun bind(viewHolder: GroupieViewHolder, position: Int) {} + override fun bind(viewBinding: FeedGroupAddNewItemBinding, position: Int) {} + override fun initializeViewBinding(view: View) = FeedGroupAddNewItemBinding.bind(view) } From ee94b296ae77054e8097c3ba3817761a0648737f Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Fri, 27 Nov 2020 20:22:06 +0530 Subject: [PATCH 04/13] Use BindableItem in FeedGroupCardItem. --- .../subscription/item/FeedGroupCardItem.kt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCardItem.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCardItem.kt index 12ff47b3f..a9731df8a 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCardItem.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCardItem.kt @@ -1,18 +1,17 @@ package org.schabi.newpipe.local.subscription.item -import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder -import com.xwray.groupie.kotlinandroidextensions.Item -import kotlinx.android.synthetic.main.feed_group_card_item.icon -import kotlinx.android.synthetic.main.feed_group_card_item.title +import android.view.View +import com.xwray.groupie.viewbinding.BindableItem import org.schabi.newpipe.R import org.schabi.newpipe.database.feed.model.FeedGroupEntity +import org.schabi.newpipe.databinding.FeedGroupCardItemBinding import org.schabi.newpipe.local.subscription.FeedGroupIcon data class FeedGroupCardItem( val groupId: Long = FeedGroupEntity.GROUP_ALL_ID, val name: String, val icon: FeedGroupIcon -) : Item() { +) : BindableItem() { constructor (feedGroupEntity: FeedGroupEntity) : this(feedGroupEntity.uid, feedGroupEntity.name, feedGroupEntity.icon) override fun getId(): Long { @@ -24,8 +23,10 @@ data class FeedGroupCardItem( override fun getLayout(): Int = R.layout.feed_group_card_item - override fun bind(viewHolder: GroupieViewHolder, position: Int) { - viewHolder.title.text = name - viewHolder.icon.setImageResource(icon.getDrawableRes(viewHolder.containerView.context)) + override fun bind(viewBinding: FeedGroupCardItemBinding, position: Int) { + viewBinding.title.text = name + viewBinding.icon.setImageResource(icon.getDrawableRes(viewBinding.root.context)) } + + override fun initializeViewBinding(view: View) = FeedGroupCardItemBinding.bind(view) } From 761f6568fa1e4a3da0964552e60376224158e5e0 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sat, 28 Nov 2020 13:32:39 +0530 Subject: [PATCH 05/13] Use BindableItem in FeedGroupCarouselItem. --- .../subscription/SubscriptionFragment.kt | 24 +++++++----------- .../item/FeedGroupCarouselItem.kt | 25 +++++++++++-------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt index a84745dbf..61a6601fa 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt @@ -17,7 +17,6 @@ import android.view.MenuInflater import android.view.View import android.view.ViewGroup import android.widget.Toast -import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.preference.PreferenceManager @@ -27,12 +26,13 @@ import com.xwray.groupie.Group import com.xwray.groupie.GroupAdapter import com.xwray.groupie.Item import com.xwray.groupie.Section -import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder +import com.xwray.groupie.viewbinding.GroupieViewHolder import icepick.State import io.reactivex.rxjava3.disposables.CompositeDisposable import org.schabi.newpipe.R import org.schabi.newpipe.database.feed.model.FeedGroupEntity import org.schabi.newpipe.databinding.DialogTitleBinding +import org.schabi.newpipe.databinding.FeedItemCarouselBinding import org.schabi.newpipe.databinding.FragmentSubscriptionBinding import org.schabi.newpipe.extractor.channel.ChannelInfoItem import org.schabi.newpipe.fragments.BaseStateFragment @@ -79,7 +79,7 @@ class SubscriptionFragment : BaseStateFragment() { private var subscriptionBroadcastReceiver: BroadcastReceiver? = null - private val groupAdapter = GroupAdapter() + private val groupAdapter = GroupAdapter>() private val feedGroupsSection = Section() private var feedGroupsCarousel: FeedGroupCarouselItem? = null private lateinit var importExportItem: FeedImportExportItem @@ -234,7 +234,7 @@ class SubscriptionFragment : BaseStateFragment() { private fun setupInitialLayout() { Section().apply { - val carouselAdapter = GroupAdapter() + val carouselAdapter = GroupAdapter>() carouselAdapter.add(FeedGroupCardItem(-1, getString(R.string.all), FeedGroupIcon.RSS)) carouselAdapter.add(feedGroupsSection) @@ -288,15 +288,12 @@ class SubscriptionFragment : BaseStateFragment() { binding.itemsList.adapter = groupAdapter viewModel = ViewModelProvider(this).get(SubscriptionViewModel::class.java) - viewModel.stateLiveData.observe(viewLifecycleOwner, Observer { it?.let(this::handleResult) }) - viewModel.feedGroupsLiveData.observe(viewLifecycleOwner, Observer { it?.let(this::handleFeedGroups) }) + viewModel.stateLiveData.observe(viewLifecycleOwner, { it?.let(this::handleResult) }) + viewModel.feedGroupsLiveData.observe(viewLifecycleOwner, { it?.let(this::handleFeedGroups) }) } private fun showLongTapDialog(selectedItem: ChannelInfoItem) { - val commands = arrayOf( - getString(R.string.share), - getString(R.string.unsubscribe) - ) + val commands = arrayOf(getString(R.string.share), getString(R.string.unsubscribe)) val actions = DialogInterface.OnClickListener { _, i -> when (i) { @@ -439,11 +436,8 @@ class SubscriptionFragment : BaseStateFragment() { return when (listMode) { getString(R.string.list_view_mode_auto_key) -> { val configuration = resources.configuration - - ( - configuration.orientation == Configuration.ORIENTATION_LANDSCAPE && - configuration.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE) - ) + configuration.orientation == Configuration.ORIENTATION_LANDSCAPE + && configuration.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE) } getString(R.string.list_view_mode_grid_key) -> true else -> false diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCarouselItem.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCarouselItem.kt index dfffce59c..44af16280 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCarouselItem.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCarouselItem.kt @@ -6,13 +6,16 @@ import android.view.View import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.xwray.groupie.GroupAdapter -import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder -import com.xwray.groupie.kotlinandroidextensions.Item -import kotlinx.android.synthetic.main.feed_item_carousel.recycler_view +import com.xwray.groupie.viewbinding.BindableItem +import com.xwray.groupie.viewbinding.GroupieViewHolder import org.schabi.newpipe.R +import org.schabi.newpipe.databinding.FeedItemCarouselBinding import org.schabi.newpipe.local.subscription.decoration.FeedGroupCarouselDecoration -class FeedGroupCarouselItem(context: Context, private val carouselAdapter: GroupAdapter) : Item() { +class FeedGroupCarouselItem( + context: Context, + private val carouselAdapter: GroupAdapter> +) : BindableItem() { private val feedGroupCarouselDecoration = FeedGroupCarouselDecoration(context) private var linearLayoutManager: LinearLayoutManager? = null @@ -30,12 +33,12 @@ class FeedGroupCarouselItem(context: Context, private val carouselAdapter: Group listState = state } - override fun createViewHolder(itemView: View): GroupieViewHolder { - val viewHolder = super.createViewHolder(itemView) + override fun initializeViewBinding(view: View): FeedItemCarouselBinding { + val viewHolder = FeedItemCarouselBinding.bind(view) - linearLayoutManager = LinearLayoutManager(itemView.context, RecyclerView.HORIZONTAL, false) + linearLayoutManager = LinearLayoutManager(view.context, RecyclerView.HORIZONTAL, false) - viewHolder.recycler_view.apply { + viewHolder.recyclerView.apply { layoutManager = linearLayoutManager adapter = carouselAdapter addItemDecoration(feedGroupCarouselDecoration) @@ -44,12 +47,12 @@ class FeedGroupCarouselItem(context: Context, private val carouselAdapter: Group return viewHolder } - override fun bind(viewHolder: GroupieViewHolder, position: Int) { - viewHolder.recycler_view.apply { adapter = carouselAdapter } + override fun bind(viewBinding: FeedItemCarouselBinding, position: Int) { + viewBinding.recyclerView.apply { adapter = carouselAdapter } linearLayoutManager?.onRestoreInstanceState(listState) } - override fun unbind(viewHolder: GroupieViewHolder) { + override fun unbind(viewHolder: GroupieViewHolder) { super.unbind(viewHolder) listState = linearLayoutManager?.onSaveInstanceState() From 9d27d49c1f849b3a6170bfb6efa2680761406ee2 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sat, 28 Nov 2020 13:43:15 +0530 Subject: [PATCH 06/13] Use BindableItem in FeedGroupReorderItem. --- .../subscription/item/FeedGroupReorderItem.kt | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupReorderItem.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupReorderItem.kt index e56bb408c..48b06b08a 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupReorderItem.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupReorderItem.kt @@ -1,16 +1,15 @@ package org.schabi.newpipe.local.subscription.item import android.view.MotionEvent +import android.view.View import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper.DOWN import androidx.recyclerview.widget.ItemTouchHelper.UP -import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder -import com.xwray.groupie.kotlinandroidextensions.Item -import kotlinx.android.synthetic.main.feed_group_reorder_item.group_icon -import kotlinx.android.synthetic.main.feed_group_reorder_item.group_name -import kotlinx.android.synthetic.main.feed_group_reorder_item.handle +import com.xwray.groupie.viewbinding.BindableItem +import com.xwray.groupie.viewbinding.GroupieViewHolder import org.schabi.newpipe.R import org.schabi.newpipe.database.feed.model.FeedGroupEntity +import org.schabi.newpipe.databinding.FeedGroupReorderItemBinding import org.schabi.newpipe.local.subscription.FeedGroupIcon data class FeedGroupReorderItem( @@ -18,7 +17,7 @@ data class FeedGroupReorderItem( val name: String, val icon: FeedGroupIcon, val dragCallback: ItemTouchHelper -) : Item() { +) : BindableItem() { constructor (feedGroupEntity: FeedGroupEntity, dragCallback: ItemTouchHelper) : this(feedGroupEntity.uid, feedGroupEntity.name, feedGroupEntity.icon, dragCallback) @@ -31,12 +30,12 @@ data class FeedGroupReorderItem( override fun getLayout(): Int = R.layout.feed_group_reorder_item - override fun bind(viewHolder: GroupieViewHolder, position: Int) { - viewHolder.group_name.text = name - viewHolder.group_icon.setImageResource(icon.getDrawableRes(viewHolder.containerView.context)) - viewHolder.handle.setOnTouchListener { _, event -> + override fun bind(viewBinding: FeedGroupReorderItemBinding, position: Int) { + viewBinding.groupName.text = name + viewBinding.groupIcon.setImageResource(icon.getDrawableRes(viewBinding.root.context)) + viewBinding.handle.setOnTouchListener { _, event -> if (event.actionMasked == MotionEvent.ACTION_DOWN) { - dragCallback.startDrag(viewHolder) + dragCallback.startDrag(GroupieViewHolder(viewBinding)) return@setOnTouchListener true } @@ -47,4 +46,6 @@ data class FeedGroupReorderItem( override fun getDragDirs(): Int { return UP or DOWN } + + override fun initializeViewBinding(view: View) = FeedGroupReorderItemBinding.bind(view) } From 51a948bfcf2b733e5497c67432e0d9145f1b7376 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sat, 28 Nov 2020 13:51:39 +0530 Subject: [PATCH 07/13] Use BindableItem in FeedImportExportItem. --- .../subscription/item/FeedImportExportItem.kt | 51 +++++++++---------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedImportExportItem.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedImportExportItem.kt index 00de83538..afca7064f 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedImportExportItem.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedImportExportItem.kt @@ -7,14 +7,10 @@ import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView import androidx.annotation.DrawableRes -import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder -import com.xwray.groupie.kotlinandroidextensions.Item -import kotlinx.android.synthetic.main.feed_import_export_group.export_to_options -import kotlinx.android.synthetic.main.feed_import_export_group.import_export -import kotlinx.android.synthetic.main.feed_import_export_group.import_export_expand_icon -import kotlinx.android.synthetic.main.feed_import_export_group.import_export_options -import kotlinx.android.synthetic.main.feed_import_export_group.import_from_options +import com.xwray.groupie.viewbinding.BindableItem +import com.xwray.groupie.viewbinding.GroupieViewHolder import org.schabi.newpipe.R +import org.schabi.newpipe.databinding.FeedImportExportGroupBinding import org.schabi.newpipe.extractor.NewPipe import org.schabi.newpipe.extractor.exceptions.ExtractionException import org.schabi.newpipe.ktx.animateRotation @@ -27,50 +23,52 @@ class FeedImportExportItem( val onImportFromServiceSelected: (Int) -> Unit, val onExportSelected: () -> Unit, var isExpanded: Boolean = false -) : Item() { +) : BindableItem() { companion object { const val REFRESH_EXPANDED_STATUS = 123 } - override fun bind(viewHolder: GroupieViewHolder, position: Int, payloads: MutableList) { + override fun bind(viewBinding: FeedImportExportGroupBinding, position: Int, payloads: MutableList) { if (payloads.contains(REFRESH_EXPANDED_STATUS)) { - viewHolder.import_export_options.apply { if (isExpanded) expand() else collapse() } + viewBinding.importExportOptions.apply { if (isExpanded) expand() else collapse() } return } - super.bind(viewHolder, position, payloads) + super.bind(viewBinding, position, payloads) } override fun getLayout(): Int = R.layout.feed_import_export_group - override fun bind(viewHolder: GroupieViewHolder, position: Int) { - if (viewHolder.import_from_options.childCount == 0) setupImportFromItems(viewHolder.import_from_options) - if (viewHolder.export_to_options.childCount == 0) setupExportToItems(viewHolder.export_to_options) + override fun bind(viewBinding: FeedImportExportGroupBinding, position: Int) { + if (viewBinding.importFromOptions.childCount == 0) setupImportFromItems(viewBinding.importFromOptions) + if (viewBinding.exportToOptions.childCount == 0) setupExportToItems(viewBinding.exportToOptions) - expandIconListener?.let { viewHolder.import_export_options.removeListener(it) } + expandIconListener?.let { viewBinding.importExportOptions.removeListener(it) } expandIconListener = CollapsibleView.StateListener { newState -> - viewHolder.import_export_expand_icon.animateRotation( + viewBinding.importExportExpandIcon.animateRotation( 250, if (newState == CollapsibleView.COLLAPSED) 0 else 180 ) } - viewHolder.import_export_options.currentState = if (isExpanded) CollapsibleView.EXPANDED else CollapsibleView.COLLAPSED - viewHolder.import_export_expand_icon.rotation = if (isExpanded) 180F else 0F - viewHolder.import_export_options.ready() + viewBinding.importExportOptions.currentState = if (isExpanded) CollapsibleView.EXPANDED else CollapsibleView.COLLAPSED + viewBinding.importExportExpandIcon.rotation = if (isExpanded) 180F else 0F + viewBinding.importExportOptions.ready() - viewHolder.import_export_options.addListener(expandIconListener) - viewHolder.import_export.setOnClickListener { - viewHolder.import_export_options.switchState() - isExpanded = viewHolder.import_export_options.currentState == CollapsibleView.EXPANDED + viewBinding.importExportOptions.addListener(expandIconListener) + viewBinding.importExport.setOnClickListener { + viewBinding.importExportOptions.switchState() + isExpanded = viewBinding.importExportOptions.currentState == CollapsibleView.EXPANDED } } - override fun unbind(viewHolder: GroupieViewHolder) { + override fun unbind(viewHolder: GroupieViewHolder) { super.unbind(viewHolder) - expandIconListener?.let { viewHolder.import_export_options.removeListener(it) } + expandIconListener?.let { viewHolder.binding.importExportOptions.removeListener(it) } expandIconListener = null } + override fun initializeViewBinding(view: View) = FeedImportExportGroupBinding.bind(view) + private var expandIconListener: CollapsibleView.StateListener? = null private fun addItemView(title: String, @DrawableRes icon: Int, container: ViewGroup): View { @@ -117,7 +115,8 @@ class FeedImportExportItem( private fun setupExportToItems(listHolder: ViewGroup) { val previousBackupItem = addItemView( listHolder.context.getString(R.string.file), - ThemeHelper.resolveResourceIdFromAttr(listHolder.context, R.attr.ic_save), listHolder + ThemeHelper.resolveResourceIdFromAttr(listHolder.context, R.attr.ic_save), + listHolder ) previousBackupItem.setOnClickListener { onExportSelected() } } From 9e5f079cf254d741b9e3357075f0c43cb81730ab Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sat, 28 Nov 2020 13:58:34 +0530 Subject: [PATCH 08/13] Use BindableItem in HeaderItem. --- .../local/subscription/item/HeaderItem.kt | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/HeaderItem.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/HeaderItem.kt index 9798dac1b..e04164573 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/item/HeaderItem.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/HeaderItem.kt @@ -1,19 +1,23 @@ package org.schabi.newpipe.local.subscription.item +import android.view.View import android.view.View.OnClickListener -import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder -import com.xwray.groupie.kotlinandroidextensions.Item -import kotlinx.android.synthetic.main.header_item.header_title +import com.xwray.groupie.viewbinding.BindableItem import org.schabi.newpipe.R +import org.schabi.newpipe.databinding.HeaderItemBinding -class HeaderItem(val title: String, private val onClickListener: (() -> Unit)? = null) : Item() { - +class HeaderItem( + val title: String, + private val onClickListener: (() -> Unit)? = null +) : BindableItem() { override fun getLayout(): Int = R.layout.header_item - override fun bind(viewHolder: GroupieViewHolder, position: Int) { - viewHolder.header_title.text = title + override fun bind(viewBinding: HeaderItemBinding, position: Int) { + viewBinding.headerTitle.text = title val listener: OnClickListener? = if (onClickListener != null) OnClickListener { onClickListener.invoke() } else null - viewHolder.root.setOnClickListener(listener) + viewBinding.root.setOnClickListener(listener) } + + override fun initializeViewBinding(view: View) = HeaderItemBinding.bind(view) } From a188125982626a9cdb2d5584fa2bfa82ef530119 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sat, 28 Nov 2020 14:01:30 +0530 Subject: [PATCH 09/13] Use BindableItem in HeaderWithMenuItem. --- .../subscription/item/HeaderWithMenuItem.kt | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/HeaderWithMenuItem.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/HeaderWithMenuItem.kt index b5aa6b1d0..55f56b3f5 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/item/HeaderWithMenuItem.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/HeaderWithMenuItem.kt @@ -1,13 +1,12 @@ package org.schabi.newpipe.local.subscription.item +import android.view.View import android.view.View.OnClickListener import androidx.annotation.DrawableRes import androidx.core.view.isVisible -import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder -import com.xwray.groupie.kotlinandroidextensions.Item -import kotlinx.android.synthetic.main.header_with_menu_item.header_menu_item -import kotlinx.android.synthetic.main.header_with_menu_item.header_title +import com.xwray.groupie.viewbinding.BindableItem import org.schabi.newpipe.R +import org.schabi.newpipe.databinding.HeaderWithMenuItemBinding class HeaderWithMenuItem( val title: String, @@ -15,37 +14,39 @@ class HeaderWithMenuItem( var showMenuItem: Boolean = true, private val onClickListener: (() -> Unit)? = null, private val menuItemOnClickListener: (() -> Unit)? = null -) : Item() { +) : BindableItem() { companion object { const val PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM = 1 } override fun getLayout(): Int = R.layout.header_with_menu_item - override fun bind(viewHolder: GroupieViewHolder, position: Int, payloads: MutableList) { + override fun bind(viewBinding: HeaderWithMenuItemBinding, position: Int, payloads: MutableList) { if (payloads.contains(PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM)) { - updateMenuItemVisibility(viewHolder) + updateMenuItemVisibility(viewBinding) return } - super.bind(viewHolder, position, payloads) + super.bind(viewBinding, position, payloads) } - override fun bind(viewHolder: GroupieViewHolder, position: Int) { - viewHolder.header_title.text = title - viewHolder.header_menu_item.setImageResource(itemIcon) + override fun bind(viewBinding: HeaderWithMenuItemBinding, position: Int) { + viewBinding.headerTitle.text = title + viewBinding.headerMenuItem.setImageResource(itemIcon) val listener: OnClickListener? = - onClickListener?.let { OnClickListener { onClickListener.invoke() } } - viewHolder.root.setOnClickListener(listener) + onClickListener?.let { OnClickListener { onClickListener.invoke() } } + viewBinding.root.setOnClickListener(listener) val menuItemListener: OnClickListener? = - menuItemOnClickListener?.let { OnClickListener { menuItemOnClickListener.invoke() } } - viewHolder.header_menu_item.setOnClickListener(menuItemListener) - updateMenuItemVisibility(viewHolder) + menuItemOnClickListener?.let { OnClickListener { menuItemOnClickListener.invoke() } } + viewBinding.headerMenuItem.setOnClickListener(menuItemListener) + updateMenuItemVisibility(viewBinding) } - private fun updateMenuItemVisibility(viewHolder: GroupieViewHolder) { - viewHolder.header_menu_item.isVisible = showMenuItem + override fun initializeViewBinding(view: View) = HeaderWithMenuItemBinding.bind(view) + + private fun updateMenuItemVisibility(viewBinding: HeaderWithMenuItemBinding) { + viewBinding.headerMenuItem.isVisible = showMenuItem } } From e2dd058430ef92c315b0e2fd59c88efa141e8944 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sat, 28 Nov 2020 14:03:26 +0530 Subject: [PATCH 10/13] Use BindableItem in PickerIconItem. --- .../local/subscription/item/PickerIconItem.kt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/PickerIconItem.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/PickerIconItem.kt index 4f3678e95..11fc4833a 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/item/PickerIconItem.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/PickerIconItem.kt @@ -1,20 +1,25 @@ package org.schabi.newpipe.local.subscription.item import android.content.Context +import android.view.View import androidx.annotation.DrawableRes -import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder -import com.xwray.groupie.kotlinandroidextensions.Item -import kotlinx.android.synthetic.main.picker_icon_item.icon_view +import com.xwray.groupie.viewbinding.BindableItem import org.schabi.newpipe.R +import org.schabi.newpipe.databinding.PickerIconItemBinding import org.schabi.newpipe.local.subscription.FeedGroupIcon -class PickerIconItem(context: Context, val icon: FeedGroupIcon) : Item() { +class PickerIconItem( + context: Context, + val icon: FeedGroupIcon +) : BindableItem() { @DrawableRes val iconRes: Int = icon.getDrawableRes(context) override fun getLayout(): Int = R.layout.picker_icon_item - override fun bind(viewHolder: GroupieViewHolder, position: Int) { - viewHolder.icon_view.setImageResource(iconRes) + override fun bind(viewBinding: PickerIconItemBinding, position: Int) { + viewBinding.iconView.setImageResource(iconRes) } + + override fun initializeViewBinding(view: View) = PickerIconItemBinding.bind(view) } From 77675b361fa5f516b96d03d045d11ccf1250db20 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sat, 28 Nov 2020 14:08:24 +0530 Subject: [PATCH 11/13] Use BindableItem in PickerSubscriptionItem. --- .../item/PickerSubscriptionItem.kt | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/PickerSubscriptionItem.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/PickerSubscriptionItem.kt index 0138b1ffe..3540e6938 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/item/PickerSubscriptionItem.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/PickerSubscriptionItem.kt @@ -1,14 +1,14 @@ package org.schabi.newpipe.local.subscription.item import android.view.View +import androidx.core.view.isGone import androidx.core.view.isVisible import com.nostra13.universalimageloader.core.ImageLoader -import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder -import com.xwray.groupie.kotlinandroidextensions.Item -import kotlinx.android.synthetic.main.picker_subscription_item.* -import kotlinx.android.synthetic.main.picker_subscription_item.view.* +import com.xwray.groupie.viewbinding.BindableItem +import com.xwray.groupie.viewbinding.GroupieViewHolder import org.schabi.newpipe.R import org.schabi.newpipe.database.subscription.SubscriptionEntity +import org.schabi.newpipe.databinding.PickerSubscriptionItemBinding import org.schabi.newpipe.ktx.AnimationType import org.schabi.newpipe.ktx.animate import org.schabi.newpipe.util.ImageDisplayConstants @@ -16,31 +16,36 @@ import org.schabi.newpipe.util.ImageDisplayConstants data class PickerSubscriptionItem( val subscriptionEntity: SubscriptionEntity, var isSelected: Boolean = false -) : Item() { +) : BindableItem() { override fun getId(): Long = subscriptionEntity.uid override fun getLayout(): Int = R.layout.picker_subscription_item override fun getSpanSize(spanCount: Int, position: Int): Int = 1 - override fun bind(viewHolder: GroupieViewHolder, position: Int) { + override fun bind(viewBinding: PickerSubscriptionItemBinding, position: Int) { ImageLoader.getInstance().displayImage( subscriptionEntity.avatarUrl, - viewHolder.thumbnail_view, ImageDisplayConstants.DISPLAY_AVATAR_OPTIONS + viewBinding.thumbnailView, ImageDisplayConstants.DISPLAY_AVATAR_OPTIONS ) - viewHolder.title_view.text = subscriptionEntity.name - viewHolder.selected_highlight.isVisible = isSelected + viewBinding.titleView.text = subscriptionEntity.name + viewBinding.selectedHighlight.isVisible = isSelected } - override fun unbind(viewHolder: GroupieViewHolder) { + override fun unbind(viewHolder: GroupieViewHolder) { super.unbind(viewHolder) - viewHolder.selected_highlight.animate().setListener(null).cancel() - viewHolder.selected_highlight.visibility = View.GONE - viewHolder.selected_highlight.alpha = 1F + viewHolder.binding.selectedHighlight.apply { + animate().setListener(null).cancel() + isGone = true + alpha = 1F + } } + override fun initializeViewBinding(view: View) = PickerSubscriptionItemBinding.bind(view) + fun updateSelected(containerView: View, isSelected: Boolean) { this.isSelected = isSelected - containerView.selected_highlight.animate(isSelected, 150, AnimationType.LIGHT_SCALE_AND_ALPHA) + PickerSubscriptionItemBinding.bind(containerView).selectedHighlight + .animate(isSelected, 150, AnimationType.LIGHT_SCALE_AND_ALPHA) } } From e0de66b1bea0ca70859261f1872955734b5db2da Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sat, 28 Nov 2020 14:31:39 +0530 Subject: [PATCH 12/13] Fix some issues. --- .../newpipe/local/subscription/SubscriptionFragment.kt | 4 ++-- .../newpipe/local/subscription/item/HeaderWithMenuItem.kt | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt index 61a6601fa..b74288a34 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt @@ -436,8 +436,8 @@ class SubscriptionFragment : BaseStateFragment() { return when (listMode) { getString(R.string.list_view_mode_auto_key) -> { val configuration = resources.configuration - configuration.orientation == Configuration.ORIENTATION_LANDSCAPE - && configuration.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE) + configuration.orientation == Configuration.ORIENTATION_LANDSCAPE && + configuration.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE) } getString(R.string.list_view_mode_grid_key) -> true else -> false diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/HeaderWithMenuItem.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/HeaderWithMenuItem.kt index 55f56b3f5..79a272178 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/item/HeaderWithMenuItem.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/HeaderWithMenuItem.kt @@ -34,12 +34,10 @@ class HeaderWithMenuItem( viewBinding.headerTitle.text = title viewBinding.headerMenuItem.setImageResource(itemIcon) - val listener: OnClickListener? = - onClickListener?.let { OnClickListener { onClickListener.invoke() } } + val listener = onClickListener?.let { OnClickListener { onClickListener.invoke() } } viewBinding.root.setOnClickListener(listener) - val menuItemListener: OnClickListener? = - menuItemOnClickListener?.let { OnClickListener { menuItemOnClickListener.invoke() } } + val menuItemListener = menuItemOnClickListener?.let { OnClickListener { menuItemOnClickListener.invoke() } } viewBinding.headerMenuItem.setOnClickListener(menuItemListener) updateMenuItemVisibility(viewBinding) } From 01396923f112e965ead4a92f1c92f41ceec2ae24 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sun, 29 Nov 2020 16:08:54 +0530 Subject: [PATCH 13/13] Use the base Groupie library in ChannelItem. --- .../subscription/dialog/FeedGroupDialog.kt | 2 +- .../dialog/FeedGroupReorderDialog.kt | 2 +- .../local/subscription/item/ChannelItem.kt | 32 +++++++++++-------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialog.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialog.kt index 7c7ebdea9..6f821f432 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialog.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialog.kt @@ -19,9 +19,9 @@ import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.RecyclerView import com.xwray.groupie.GroupAdapter +import com.xwray.groupie.GroupieViewHolder import com.xwray.groupie.OnItemClickListener import com.xwray.groupie.Section -import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder import icepick.Icepick import icepick.State import org.schabi.newpipe.R diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupReorderDialog.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupReorderDialog.kt index 3b74ddc74..2b09a3b3b 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupReorderDialog.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupReorderDialog.kt @@ -12,8 +12,8 @@ import androidx.recyclerview.widget.ItemTouchHelper.SimpleCallback import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.xwray.groupie.GroupAdapter +import com.xwray.groupie.GroupieViewHolder import com.xwray.groupie.TouchCallback -import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder import icepick.Icepick import icepick.State import org.schabi.newpipe.R diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/ChannelItem.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/ChannelItem.kt index 8089f6480..a87ffb695 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/item/ChannelItem.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/ChannelItem.kt @@ -1,13 +1,11 @@ package org.schabi.newpipe.local.subscription.item import android.content.Context +import android.widget.ImageView +import android.widget.TextView import com.nostra13.universalimageloader.core.ImageLoader -import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder -import com.xwray.groupie.kotlinandroidextensions.Item -import kotlinx.android.synthetic.main.list_channel_item.itemAdditionalDetails -import kotlinx.android.synthetic.main.list_channel_item.itemChannelDescriptionView -import kotlinx.android.synthetic.main.list_channel_item.itemThumbnailView -import kotlinx.android.synthetic.main.list_channel_item.itemTitleView +import com.xwray.groupie.GroupieViewHolder +import com.xwray.groupie.Item import org.schabi.newpipe.R import org.schabi.newpipe.extractor.channel.ChannelInfoItem import org.schabi.newpipe.util.ImageDisplayConstants @@ -19,8 +17,7 @@ class ChannelItem( private val subscriptionId: Long = -1L, var itemVersion: ItemVersion = ItemVersion.NORMAL, var gesturesListener: OnClickGesture? = null -) : Item() { - +) : Item() { override fun getId(): Long = if (subscriptionId == -1L) super.getId() else subscriptionId enum class ItemVersion { NORMAL, MINI, GRID } @@ -32,18 +29,25 @@ class ChannelItem( } override fun bind(viewHolder: GroupieViewHolder, position: Int) { - viewHolder.itemTitleView.text = infoItem.name - viewHolder.itemAdditionalDetails.text = getDetailLine(viewHolder.root.context) - if (itemVersion == ItemVersion.NORMAL) viewHolder.itemChannelDescriptionView.text = infoItem.description + val itemTitleView = viewHolder.root.findViewById(R.id.itemTitleView) + val itemAdditionalDetails = viewHolder.root.findViewById(R.id.itemAdditionalDetails) + val itemChannelDescriptionView = viewHolder.root.findViewById(R.id.itemChannelDescriptionView) + val itemThumbnailView = viewHolder.root.findViewById(R.id.itemThumbnailView) + + itemTitleView.text = infoItem.name + itemAdditionalDetails.text = getDetailLine(viewHolder.root.context) + if (itemVersion == ItemVersion.NORMAL) { + itemChannelDescriptionView.text = infoItem.description + } ImageLoader.getInstance().displayImage( - infoItem.thumbnailUrl, viewHolder.itemThumbnailView, + infoItem.thumbnailUrl, itemThumbnailView, ImageDisplayConstants.DISPLAY_THUMBNAIL_OPTIONS ) gesturesListener?.run { - viewHolder.containerView.setOnClickListener { selected(infoItem) } - viewHolder.containerView.setOnLongClickListener { held(infoItem); true } + viewHolder.root.setOnClickListener { selected(infoItem) } + viewHolder.root.setOnLongClickListener { held(infoItem); true } } }