Skip to content

Commit 4865e5a

Browse files
authored
Select the last tab and update selection after deleting the current tab (#4697)
Task/Issue URL: https://app.asana.com/0/1202552961248957/1202148076467684/f ### Description This PR selects the last tab in the list after the currently-selected tab is deleted. This fixes the behaviour when no tab was selected and when the user went back to the browser, the first tab was shown. ### Steps to test this PR 1. Create at least 3 tabs (with the last tab being selected) 2. Delete the last (selected) tab 3. Notice the tab is removed and the last of the remaining tab is selected 4. Tap on `Undo` 5. Notice the previous tab is shown and selected again 6. Delete the selected tab again 7. Tap on the back button 8. Notice the correct tab is shown ### UI changes [Screen_recording_20240626_151442.webm](https://github.com/duckduckgo/Android/assets/1522856/2ae2fe33-275b-4eb8-a33c-62b647715d09)
1 parent 026d0f0 commit 4865e5a

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

app/src/main/java/com/duckduckgo/app/tabs/db/TabsDao.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ abstract class TabsDao {
9393
if (selectedTab() != null) {
9494
return
9595
}
96-
firstTab()?.let {
96+
lastTab()?.let {
9797
insertTabSelection(TabSelectionEntity(tabId = it.tabId))
9898
}
9999
}

app/src/main/java/com/duckduckgo/app/tabs/ui/TabSwitcherActivity.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,18 @@ class TabSwitcherActivity : DuckDuckGoActivity(), TabSwitcherListener, Coroutine
148148
}
149149

150150
private fun configureObservers() {
151-
viewModel.tabs.observe(this) {
152-
render(it)
151+
viewModel.tabs.observe(this) { tabs ->
152+
render(tabs)
153+
154+
val noTabSelected = tabs.none { it.tabId == tabGridItemDecorator.selectedTabId }
155+
if (noTabSelected && tabs.isNotEmpty()) {
156+
updateTabGridItemDecorator(tabs.last())
157+
}
158+
}
159+
viewModel.activeTab.observe(this) { tab ->
160+
if (tab != null && tab.tabId != tabGridItemDecorator.selectedTabId && !tab.deletable) {
161+
updateTabGridItemDecorator(tab)
162+
}
153163
}
154164
viewModel.deletableTabs.observe(this) {
155165
if (it.isNotEmpty()) {

app/src/main/java/com/duckduckgo/app/tabs/ui/TabSwitcherViewModel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class TabSwitcherViewModel @Inject constructor(
4040
) : ViewModel() {
4141

4242
var tabs: LiveData<List<TabEntity>> = tabRepository.liveTabs
43+
val activeTab = tabRepository.liveSelectedTab
4344
var deletableTabs: LiveData<List<TabEntity>> = tabRepository.flowDeletableTabs.asLiveData(
4445
context = viewModelScope.coroutineContext,
4546
)

0 commit comments

Comments
 (0)