Skip to content

Commit 83d5d43

Browse files
authored
Changed update notification logic to prevent hidden updates (#1139)
1 parent 4cbfcb6 commit 83d5d43

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

app/src/main/kotlin/com/looker/droidify/ui/appList/AppListFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class AppListFragment() : Fragment(), CursorOwner.Callback {
191191
viewModel.setSection(section)
192192
}
193193

194-
private fun updateRequest() {
194+
fun updateRequest() {
195195
if (view != null) {
196196
mainActivity.cursorOwner.attach(this, viewModel.request(source))
197197
}

app/src/main/kotlin/com/looker/droidify/ui/tabsFragment/TabsFragment.kt

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)