Restore selected tabs by index instead of by path

This commit is contained in:
priahoud 2024-07-14 23:35:53 +02:00
parent bdb4bcb702
commit 80deea3407
2 changed files with 12 additions and 11 deletions

View File

@ -131,10 +131,10 @@ class AppSettingsRepository @Inject constructor() {
preferences.put(PREF_LATEST_REPOSITORIES_TABS_OPENED, value)
}
var latestRepositoryTabSelected: String
get() = preferences.get(PREF_LATEST_REPOSITORY_TAB_SELECTED, "")
var latestRepositoryTabSelected: Int
get() = preferences.getInt(PREF_LATEST_REPOSITORY_TAB_SELECTED, -1)
set(value) {
preferences.put(PREF_LATEST_REPOSITORY_TAB_SELECTED, value)
preferences.putInt(PREF_LATEST_REPOSITORY_TAB_SELECTED, value)
}
var latestOpenedRepositoriesPath: String

View File

@ -40,11 +40,12 @@ class TabsManager @Inject constructor(
_tabsFlow.value = repositoriesList.ifEmpty { listOf(newAppTab()) }
val latestSelectedTabPath = appSettingsRepository.latestRepositoryTabSelected
val latestSelectedTabIndex = appSettingsRepository.latestRepositoryTabSelected
val latestSelectedTab = repositoriesList.firstOrNull { it.path == latestSelectedTabPath }
_currentTab.value = latestSelectedTab ?: _tabsFlow.value.first()
_currentTab.value = when(latestSelectedTabIndex < 0) {
true -> _tabsFlow.value.first()
false -> tabsFlow.value[latestSelectedTabIndex]
}
}
fun addNewTabFromPath(path: String, selectTab: Boolean, tabToBeReplacedPath: String? = null) {
@ -79,7 +80,7 @@ class TabsManager @Inject constructor(
}
private fun persistTabSelected(tab: TabInformation) {
appSettingsRepository.latestRepositoryTabSelected = tab.path.orEmpty()
appSettingsRepository.latestRepositoryTabSelected = tabsFlow.value.indexOf(tab)
}
fun closeTab(tab: TabInformation) {
@ -116,10 +117,10 @@ class TabsManager @Inject constructor(
}
private fun updatePersistedTabs() {
val tabsPaths = tabsFlow.value
.mapNotNull { it.path }
val tabs = tabsFlow.value.filter { it.path != null }
appSettingsRepository.latestTabsOpened = Json.encodeToString(tabsPaths)
appSettingsRepository.latestTabsOpened = Json.encodeToString(tabs.map { it.path })
appSettingsRepository.latestRepositoryTabSelected = tabs.indexOf(currentTab.value)
}
fun addNewEmptyTab() {