Latest opened tab is now remembered

Fixes #83
This commit is contained in:
Abdelilah El Aissaoui 2023-06-22 16:58:19 +02:00
parent e1cc4c496b
commit 15507afd4c
No known key found for this signature in database
GPG Key ID: 7587FC860F594869
2 changed files with 19 additions and 1 deletions

View File

@ -21,6 +21,7 @@ import javax.inject.Singleton
private const val PREFERENCES_NAME = "GitnuroConfig"
private const val PREF_LATEST_REPOSITORIES_TABS_OPENED = "latestRepositoriesTabsOpened"
private const val PREF_LATEST_REPOSITORY_TAB_SELECTED = "latestRepositoryTabSelected"
private const val PREF_LAST_OPENED_REPOSITORIES_PATH = "lastOpenedRepositoriesList"
private const val PREF_THEME = "theme"
private const val PREF_COMMITS_LIMIT = "commitsLimit"
@ -77,6 +78,12 @@ class AppSettings @Inject constructor() {
preferences.put(PREF_LATEST_REPOSITORIES_TABS_OPENED, value)
}
var latestRepositoryTabSelected: String
get() = preferences.get(PREF_LATEST_REPOSITORY_TAB_SELECTED, "")
set(value) {
preferences.put(PREF_LATEST_REPOSITORY_TAB_SELECTED, value)
}
var latestOpenedRepositoriesPath: String
get() = preferences.get(PREF_LAST_OPENED_REPOSITORIES_PATH, "")
set(value) {

View File

@ -39,7 +39,12 @@ class TabsManager @Inject constructor(
listOf()
_tabsFlow.value = repositoriesList.ifEmpty { listOf(newAppTab()) }
_currentTab.value = _tabsFlow.value.first()
val latestSelectedTabPath = appSettings.latestRepositoryTabSelected
val latestSelectedTab = repositoriesList.firstOrNull { it.path == latestSelectedTabPath }
_currentTab.value = latestSelectedTab ?: _tabsFlow.value.first()
}
fun addNewTabFromPath(path: String, selectTab: Boolean, tabToBeReplaced: TabInformation? = null) {
@ -68,6 +73,12 @@ class TabsManager @Inject constructor(
fun selectTab(tab: TabInformation) {
_currentTab.value = tab
persistTabSelected(tab)
}
private fun persistTabSelected(tab: TabInformation) {
appSettings.latestRepositoryTabSelected = tab.path.orEmpty()
}
fun closeTab(tab: TabInformation) {