@@ -411,7 +411,7 @@ class TabsFragment : ScreenFragment() {
411411
412412 (searchMenuItem?.actionView as FocusSearchView ).allowFocus = true
413413 if (needSelectUpdates) {
414- needSelectUpdates = false
414+ // don't clear the flag here - let selectUpdatesInternal / pageChangeCallback manage it
415415 selectUpdatesInternal(false )
416416 }
417417 }
@@ -448,12 +448,21 @@ class TabsFragment : ScreenFragment() {
448448 }
449449
450450 private fun selectUpdatesInternal (allowSmooth : Boolean ) {
451- if (view != null ) {
452- val viewPager = viewPager
453- viewPager? .setCurrentItem(
451+ val vp = viewPager
452+ if (view != null && vp != null ) {
453+ vp .setCurrentItem(
454454 AppListFragment .Source .UPDATES .ordinal,
455- allowSmooth && viewPager .isLaidOut,
455+ allowSmooth && vp .isLaidOut,
456456 )
457+ // Try to find the Updates fragment now; if it's not created yet, defer the update request
458+ val updatesFrag = productFragments.find { it.source == AppListFragment .Source .UPDATES }
459+ if (updatesFrag != null ) {
460+ updatesFrag.updateRequest()
461+ needSelectUpdates = false
462+ } else {
463+ // wait until fragment is created/attached; pageChangeCallback will trigger the request
464+ needSelectUpdates = true
465+ }
457466 } else {
458467 needSelectUpdates = true
459468 }
@@ -556,6 +565,13 @@ class TabsFragment : ScreenFragment() {
556565 )
557566 }
558567 syncRepositoriesMenuItem!! .setShowAsActionFlags(MenuItem .SHOW_AS_ACTION_ALWAYS )
568+
569+ // If we were waiting for the Updates fragment to be created, trigger its refresh now
570+ if (position == AppListFragment .Source .UPDATES .ordinal && needSelectUpdates) {
571+ productFragments.find { it.source == AppListFragment .Source .UPDATES }?.updateRequest()
572+ needSelectUpdates = false
573+ }
574+
559575 if (showSections && ! source.sections) {
560576 showSections = false
561577 }
0 commit comments