Merge pull request #217 from priahoud/restore-selected-tabs-by-index
Restore selected tabs by index instead of by path
This commit is contained in:
commit
b9db9a8d57
@ -131,10 +131,10 @@ class AppSettingsRepository @Inject constructor() {
|
|||||||
preferences.put(PREF_LATEST_REPOSITORIES_TABS_OPENED, value)
|
preferences.put(PREF_LATEST_REPOSITORIES_TABS_OPENED, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
var latestRepositoryTabSelected: String
|
var latestRepositoryTabSelected: Int
|
||||||
get() = preferences.get(PREF_LATEST_REPOSITORY_TAB_SELECTED, "")
|
get() = preferences.getInt(PREF_LATEST_REPOSITORY_TAB_SELECTED, -1)
|
||||||
set(value) {
|
set(value) {
|
||||||
preferences.put(PREF_LATEST_REPOSITORY_TAB_SELECTED, value)
|
preferences.putInt(PREF_LATEST_REPOSITORY_TAB_SELECTED, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
var latestOpenedRepositoriesPath: String
|
var latestOpenedRepositoriesPath: String
|
||||||
|
@ -40,11 +40,12 @@ class TabsManager @Inject constructor(
|
|||||||
|
|
||||||
_tabsFlow.value = repositoriesList.ifEmpty { listOf(newAppTab()) }
|
_tabsFlow.value = repositoriesList.ifEmpty { listOf(newAppTab()) }
|
||||||
|
|
||||||
val latestSelectedTabPath = appSettingsRepository.latestRepositoryTabSelected
|
val latestSelectedTabIndex = appSettingsRepository.latestRepositoryTabSelected
|
||||||
|
|
||||||
val latestSelectedTab = repositoriesList.firstOrNull { it.path == latestSelectedTabPath }
|
_currentTab.value = when(latestSelectedTabIndex < 0) {
|
||||||
|
true -> _tabsFlow.value.first()
|
||||||
_currentTab.value = latestSelectedTab ?: _tabsFlow.value.first()
|
false -> tabsFlow.value[latestSelectedTabIndex]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addNewTabFromPath(path: String, selectTab: Boolean, tabToBeReplacedPath: String? = null) {
|
fun addNewTabFromPath(path: String, selectTab: Boolean, tabToBeReplacedPath: String? = null) {
|
||||||
@ -79,7 +80,7 @@ class TabsManager @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun persistTabSelected(tab: TabInformation) {
|
private fun persistTabSelected(tab: TabInformation) {
|
||||||
appSettingsRepository.latestRepositoryTabSelected = tab.path.orEmpty()
|
appSettingsRepository.latestRepositoryTabSelected = tabsFlow.value.indexOf(tab)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun closeTab(tab: TabInformation) {
|
fun closeTab(tab: TabInformation) {
|
||||||
@ -116,10 +117,10 @@ class TabsManager @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updatePersistedTabs() {
|
private fun updatePersistedTabs() {
|
||||||
val tabsPaths = tabsFlow.value
|
val tabs = tabsFlow.value.filter { it.path != null }
|
||||||
.mapNotNull { it.path }
|
|
||||||
|
|
||||||
appSettingsRepository.latestTabsOpened = Json.encodeToString(tabsPaths)
|
appSettingsRepository.latestTabsOpened = Json.encodeToString(tabs.map { it.path })
|
||||||
|
appSettingsRepository.latestRepositoryTabSelected = tabs.indexOf(currentTab.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addNewEmptyTab() {
|
fun addNewEmptyTab() {
|
||||||
|
Loading…
Reference in New Issue
Block a user