From 15507afd4c4cc6d04177549c188360493d1899db Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Thu, 22 Jun 2023 16:58:19 +0200 Subject: [PATCH] Latest opened tab is now remembered Fixes #83 --- .../jetpackduba/gitnuro/preferences/AppSettings.kt | 7 +++++++ .../com/jetpackduba/gitnuro/ui/TabsManager.kt | 13 ++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/preferences/AppSettings.kt b/src/main/kotlin/com/jetpackduba/gitnuro/preferences/AppSettings.kt index cf5fd01..27811df 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/preferences/AppSettings.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/preferences/AppSettings.kt @@ -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) { diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/ui/TabsManager.kt b/src/main/kotlin/com/jetpackduba/gitnuro/ui/TabsManager.kt index 79962b5..52aa7d3 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/ui/TabsManager.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/ui/TabsManager.kt @@ -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) {