Fix visibility of group sort button in the subscriptions fragment

This commit is contained in:
Mauricio Colli 2020-04-05 16:57:28 -03:00
parent 5c8b9f6b4c
commit 225b9e1b15
No known key found for this signature in database
GPG Key ID: F200BFD6F29DDD85
2 changed files with 12 additions and 13 deletions

View File

@ -31,6 +31,7 @@ import org.schabi.newpipe.local.subscription.SubscriptionViewModel.SubscriptionS
import org.schabi.newpipe.local.subscription.dialog.FeedGroupDialog import org.schabi.newpipe.local.subscription.dialog.FeedGroupDialog
import org.schabi.newpipe.local.subscription.dialog.FeedGroupReorderDialog import org.schabi.newpipe.local.subscription.dialog.FeedGroupReorderDialog
import org.schabi.newpipe.local.subscription.item.* import org.schabi.newpipe.local.subscription.item.*
import org.schabi.newpipe.local.subscription.item.HeaderWithMenuItem.Companion.PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM
import org.schabi.newpipe.local.subscription.services.SubscriptionsExportService import org.schabi.newpipe.local.subscription.services.SubscriptionsExportService
import org.schabi.newpipe.local.subscription.services.SubscriptionsExportService.EXPORT_COMPLETE_ACTION import org.schabi.newpipe.local.subscription.services.SubscriptionsExportService.EXPORT_COMPLETE_ACTION
import org.schabi.newpipe.local.subscription.services.SubscriptionsExportService.KEY_FILE_PATH import org.schabi.newpipe.local.subscription.services.SubscriptionsExportService.KEY_FILE_PATH
@ -361,11 +362,8 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
feedGroupsListState = null feedGroupsListState = null
} }
if (groups.size < 2) { feedGroupsSortMenuItem.showMenuItem = groups.size > 1
items_list.post { feedGroupsSortMenuItem.notifyChanged(HeaderWithMenuItem.PAYLOAD_HIDE_MENU_ITEM) } items_list.post { feedGroupsSortMenuItem.notifyChanged(PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM) }
} else {
items_list.post { feedGroupsSortMenuItem.notifyChanged(HeaderWithMenuItem.PAYLOAD_SHOW_MENU_ITEM) }
}
} }
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////

View File

@ -10,23 +10,19 @@ import org.schabi.newpipe.R
class HeaderWithMenuItem( class HeaderWithMenuItem(
val title: String, val title: String,
@DrawableRes val itemIcon: Int = 0, @DrawableRes val itemIcon: Int = 0,
var showMenuItem: Boolean = true,
private val onClickListener: (() -> Unit)? = null, private val onClickListener: (() -> Unit)? = null,
private val menuItemOnClickListener: (() -> Unit)? = null private val menuItemOnClickListener: (() -> Unit)? = null
) : Item() { ) : Item() {
companion object { companion object {
const val PAYLOAD_SHOW_MENU_ITEM = 1 const val PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM = 1
const val PAYLOAD_HIDE_MENU_ITEM = 2
} }
override fun getLayout(): Int = R.layout.header_with_menu_item override fun getLayout(): Int = R.layout.header_with_menu_item
override fun bind(viewHolder: GroupieViewHolder, position: Int, payloads: MutableList<Any>) { override fun bind(viewHolder: GroupieViewHolder, position: Int, payloads: MutableList<Any>) {
if (payloads.contains(PAYLOAD_SHOW_MENU_ITEM)) { if (payloads.contains(PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM)) {
viewHolder.header_menu_item.visibility = VISIBLE updateMenuItemVisibility(viewHolder)
return
} else if (payloads.contains(PAYLOAD_HIDE_MENU_ITEM)) {
viewHolder.header_menu_item.visibility = GONE
return return
} }
@ -44,5 +40,10 @@ class HeaderWithMenuItem(
val menuItemListener: OnClickListener? = val menuItemListener: OnClickListener? =
menuItemOnClickListener?.let { OnClickListener { menuItemOnClickListener.invoke() } } menuItemOnClickListener?.let { OnClickListener { menuItemOnClickListener.invoke() } }
viewHolder.header_menu_item.setOnClickListener(menuItemListener) viewHolder.header_menu_item.setOnClickListener(menuItemListener)
updateMenuItemVisibility(viewHolder)
}
private fun updateMenuItemVisibility(viewHolder: GroupieViewHolder) {
viewHolder.header_menu_item.visibility = if (showMenuItem) VISIBLE else GONE
} }
} }