From fc061599f8906755762f4041e2073080b941cf54 Mon Sep 17 00:00:00 2001 From: Stypox Date: Fri, 4 Nov 2022 18:20:50 +0100 Subject: [PATCH 1/2] Fix inconsistent channel group list and item view mode --- .../local/subscription/SubscriptionFragment.kt | 16 +++++++++------- .../local/subscription/SubscriptionViewModel.kt | 9 ++++++--- 2 files changed, 15 insertions(+), 10 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 b2337eeca..72cd3cf7c 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 @@ -254,7 +254,11 @@ class SubscriptionFragment : BaseStateFragment() { viewModel = ViewModelProvider(this)[SubscriptionViewModel::class.java] viewModel.stateLiveData.observe(viewLifecycleOwner) { it?.let(this::handleResult) } - viewModel.feedGroupsLiveData.observe(viewLifecycleOwner) { it?.let(this::handleFeedGroups) } + viewModel.feedGroupsLiveData.observe(viewLifecycleOwner) { + it?.let { (groups, listViewMode) -> + handleFeedGroups(groups, listViewMode) + } + } setupInitialLayout() } @@ -405,17 +409,12 @@ class SubscriptionFragment : BaseStateFragment() { } } - private fun handleFeedGroups(groups: List) { - val listViewMode = viewModel.getListViewMode() - + private fun handleFeedGroups(groups: List, listViewMode: Boolean) { if (feedGroupsCarouselState != null) { feedGroupsCarousel.onRestoreInstanceState(feedGroupsCarouselState) feedGroupsCarouselState = null } - feedGroupsCarousel.listViewMode = listViewMode - feedGroupsSortMenuItem.showSortButton = groups.size > 1 - feedGroupsSortMenuItem.listViewMode = listViewMode binding.itemsList.post { if (context == null) { // since this part was posted to the next UI cycle, the fragment might have been @@ -423,6 +422,9 @@ class SubscriptionFragment : BaseStateFragment() { return@post } + feedGroupsCarousel.listViewMode = listViewMode + feedGroupsSortMenuItem.showSortButton = groups.size > 1 + feedGroupsSortMenuItem.listViewMode = listViewMode feedGroupsCarousel.notifyChanged(FeedGroupCarouselItem.PAYLOAD_UPDATE_LIST_VIEW_MODE) feedGroupsSortMenuItem.notifyChanged(GroupsHeader.PAYLOAD_UPDATE_ICONS) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionViewModel.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionViewModel.kt index cb14b33a6..914299c78 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionViewModel.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionViewModel.kt @@ -27,9 +27,9 @@ class SubscriptionViewModel(application: Application) : AndroidViewModel(applica private val listViewModeFlowable = listViewMode.distinctUntilChanged() private val mutableStateLiveData = MutableLiveData() - private val mutableFeedGroupsLiveData = MutableLiveData>() + private val mutableFeedGroupsLiveData = MutableLiveData, Boolean>>() val stateLiveData: LiveData = mutableStateLiveData - val feedGroupsLiveData: LiveData> = mutableFeedGroupsLiveData + val feedGroupsLiveData: LiveData, Boolean>> = mutableFeedGroupsLiveData private var feedGroupItemsDisposable = Flowable .combineLatest( @@ -39,7 +39,10 @@ class SubscriptionViewModel(application: Application) : AndroidViewModel(applica ) .throttleLatest(DEFAULT_THROTTLE_TIMEOUT, TimeUnit.MILLISECONDS) .map { (feedGroups, listViewMode) -> - feedGroups.map(if (listViewMode) ::FeedGroupCardItem else ::FeedGroupCardGridItem) + Pair( + feedGroups.map(if (listViewMode) ::FeedGroupCardItem else ::FeedGroupCardGridItem), + listViewMode + ) } .subscribeOn(Schedulers.io()) .subscribe( From 49c12a31e9a5b87bcb6648577bfdbedb68ca0bd1 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sat, 5 Nov 2022 20:05:59 +0100 Subject: [PATCH 2/2] Fix wrongly calculated channel groups span count --- .../local/subscription/item/FeedGroupCarouselItem.kt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) 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 ad1e7e690..bf9f9072f 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 @@ -10,7 +10,7 @@ import com.xwray.groupie.viewbinding.GroupieViewHolder import org.schabi.newpipe.R import org.schabi.newpipe.databinding.FeedItemCarouselBinding import org.schabi.newpipe.util.DeviceUtils -import java.lang.Integer.max +import org.schabi.newpipe.util.ThemeHelper.getGridSpanCount class FeedGroupCarouselItem( private val carouselAdapter: GroupAdapter>, @@ -71,10 +71,7 @@ class FeedGroupCarouselItem( carouselLayoutManager = if (listViewMode) { LinearLayoutManager(context) } else { - GridLayoutManager( - context, - max(1, viewBinding.recyclerView.width / DeviceUtils.dpToPx(112, context)) - ) + GridLayoutManager(context, getGridSpanCount(context, DeviceUtils.dpToPx(112, context))) } viewBinding.recyclerView.apply {