@@ -45,7 +45,7 @@ import org.schabi.newpipe.local.subscription.dialog.FeedGroupReorderDialog
4545import org.schabi.newpipe.local.subscription.item.ChannelItem
4646import org.schabi.newpipe.local.subscription.item.EmptyPlaceholderItem
4747import org.schabi.newpipe.local.subscription.item.FeedGroupAddItem
48- import org.schabi.newpipe.local.subscription.item.FeedGroupAddItemVertical
48+ import org.schabi.newpipe.local.subscription.item.FeedGroupAddVerticalItem
4949import org.schabi.newpipe.local.subscription.item.FeedGroupCardItem
5050import org.schabi.newpipe.local.subscription.item.FeedGroupCardVerticalItem
5151import org.schabi.newpipe.local.subscription.item.FeedGroupCarouselItem
@@ -78,10 +78,12 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
7878
7979 private val groupAdapter = GroupAdapter <GroupieViewHolder <FeedItemCarouselBinding >>()
8080 private val feedGroupsSection = Section ()
81+ private val feedGroupsVerticalSection = Section ()
8182 private var feedGroupsCarousel: FeedGroupCarouselItem ? = null
83+ private var feedGroupsVerticalCarousel: FeedGroupCarouselItem ? = null
8284 private lateinit var feedGroupsSortMenuItem: HeaderWithMenuItem
8385 private val subscriptionsSection = Section ()
84- private var listView : Boolean = false
86+ private var defaultListView : Boolean = true
8587
8688 private val requestExportLauncher =
8789 registerForActivityResult(StartActivityForResult (), this ::requestExportResult)
@@ -255,7 +257,7 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
255257 // ////////////////////////////////////////////////////////////////////////
256258
257259 private fun setupInitialLayout () {
258- listView = false
260+ defaultListView = true
259261 Section ().apply {
260262 val carouselAdapter = GroupAdapter <GroupieViewHolder <FeedItemCarouselBinding >>()
261263
@@ -302,16 +304,17 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
302304 listOf (subscriptionsSection)
303305 )
304306 )
307+ view?.let { initViews(it, savedInstanceState = Bundle ()) }
305308 }
306309
307310 private fun changeLayout () {
308- listView = true
311+ defaultListView = false
309312 Section ().apply {
310313 val carouselAdapter = GroupAdapter <GroupieViewHolder <FeedItemCarouselBinding >>()
311314
312315 carouselAdapter.add(FeedGroupCardVerticalItem (- 1 , getString(R .string.all), FeedGroupIcon .RSS ))
313- carouselAdapter.add(feedGroupsSection )
314- carouselAdapter.add(FeedGroupAddItemVertical ())
316+ carouselAdapter.add(feedGroupsVerticalSection )
317+ carouselAdapter.add(FeedGroupAddVerticalItem ())
315318
316319 carouselAdapter.setOnItemClickListener { item, _ ->
317320 listenerFeedVerticalGroups.selected(item)
@@ -325,7 +328,7 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
325328 listenerFeedVerticalGroups.held(item)
326329 return @setOnItemLongClickListener true
327330 }
328- feedGroupsCarousel = FeedGroupCarouselItem (requireContext(), carouselAdapter, RecyclerView .VERTICAL )
331+ feedGroupsVerticalCarousel = FeedGroupCarouselItem (requireContext(), carouselAdapter, RecyclerView .VERTICAL )
329332
330333 feedGroupsSortMenuItem = HeaderWithMenuItem (
331334 getString(R .string.feed_groups_header_title),
@@ -334,7 +337,7 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
334337 listViewOnClickListener = ::setupInitialLayout,
335338 menuItemOnClickListener = ::openReorderDialog
336339 )
337- add(Section (feedGroupsSortMenuItem, listOf (feedGroupsCarousel )))
340+ add(Section (feedGroupsSortMenuItem, listOf (feedGroupsVerticalCarousel )))
338341 groupAdapter.clear()
339342 groupAdapter.add(this )
340343 }
@@ -349,6 +352,7 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
349352 listOf (subscriptionsSection)
350353 )
351354 )
355+ view?.let { initViews(it, savedInstanceState = Bundle ()) }
352356 }
353357
354358 override fun initViews (rootView : View , savedInstanceState : Bundle ? ) {
@@ -427,7 +431,7 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
427431 override fun selected (selectedItem : Item <* >? ) {
428432 when (selectedItem) {
429433 is FeedGroupCardVerticalItem -> NavigationHelper .openFeedFragment(fm, selectedItem.groupId, selectedItem.name)
430- is FeedGroupAddItemVertical -> FeedGroupDialog .newInstance().show(fm, null )
434+ is FeedGroupAddVerticalItem -> FeedGroupDialog .newInstance().show(fm, null )
431435 }
432436 }
433437
@@ -480,7 +484,7 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
480484 }
481485
482486 private fun handleFeedGroups (groups : List <Group >) {
483- if (! listView ) {
487+ if (defaultListView ) {
484488 feedGroupsSection.update(groups)
485489
486490 if (feedGroupsListState != null ) {
@@ -494,11 +498,11 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
494498 }
495499
496500 private fun handleFeedGroupsVertical (groups : List <Group >) {
497- if (listView ) {
498- feedGroupsSection .update(groups)
501+ if (! defaultListView ) {
502+ feedGroupsVerticalSection .update(groups)
499503
500504 if (feedGroupsListVerticalState != null ) {
501- feedGroupsCarousel ?.onRestoreInstanceState(feedGroupsListVerticalState)
505+ feedGroupsVerticalCarousel ?.onRestoreInstanceState(feedGroupsListVerticalState)
502506 feedGroupsListVerticalState = null
503507 }
504508
0 commit comments