Revert "Renamed AppSettings to repository"

This reverts commit b2777d2d90.
This commit is contained in:
Abdelilah El Aissaoui 2024-05-06 14:04:20 +02:00
parent b2777d2d90
commit 8d7b39f136
No known key found for this signature in database
GPG Key ID: 7587FC860F594869
21 changed files with 125 additions and 156 deletions

View File

@ -61,14 +61,14 @@ dependencies {
testImplementation(platform("org.junit:junit-bom:5.9.0")) testImplementation(platform("org.junit:junit-bom:5.9.0"))
testImplementation("org.junit.jupiter:junit-jupiter:5.9.2") testImplementation("org.junit.jupiter:junit-jupiter:5.9.2")
testImplementation("io.mockk:mockk:1.13.4") testImplementation("io.mockk:mockk:1.13.4")
implementation("com.squareup.retrofit2:retrofit:2.11.0") implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("com.squareup.retrofit2:converter-scalars:2.9.0") implementation("com.squareup.retrofit2:converter-scalars:2.9.0")
implementation("net.i2p.crypto:eddsa:0.3.0") implementation("net.i2p.crypto:eddsa:0.3.0")
implementation("net.java.dev.jna:jna:5.13.0") implementation("net.java.dev.jna:jna:5.13.0")
implementation("io.github.oshai:kotlin-logging-jvm:5.0.1") implementation("io.github.oshai:kotlin-logging-jvm:5.0.1")
implementation("org.slf4j:slf4j-api:2.0.7") implementation("org.slf4j:slf4j-api:2.0.7")
implementation("org.slf4j:slf4j-reload4j:2.0.7") implementation("org.slf4j:slf4j-reload4j:2.0.7")
implementation("androidx.datastore:datastore-preferences-core:1.0.0") implementation("io.arrow-kt:arrow-core:1.2.0")
} }
fun currentOs(): OS { fun currentOs(): OS {

View File

@ -28,8 +28,8 @@ import com.jetpackduba.gitnuro.git.AppGpgSigner
import com.jetpackduba.gitnuro.logging.printError import com.jetpackduba.gitnuro.logging.printError
import com.jetpackduba.gitnuro.managers.AppStateManager import com.jetpackduba.gitnuro.managers.AppStateManager
import com.jetpackduba.gitnuro.managers.TempFilesManager import com.jetpackduba.gitnuro.managers.TempFilesManager
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository import com.jetpackduba.gitnuro.preferences.AppSettings
import com.jetpackduba.gitnuro.repositories.ProxySettings import com.jetpackduba.gitnuro.preferences.ProxySettings
import com.jetpackduba.gitnuro.system.systemSeparator import com.jetpackduba.gitnuro.system.systemSeparator
import com.jetpackduba.gitnuro.theme.AppTheme import com.jetpackduba.gitnuro.theme.AppTheme
import com.jetpackduba.gitnuro.theme.Theme import com.jetpackduba.gitnuro.theme.Theme
@ -42,10 +42,6 @@ import com.jetpackduba.gitnuro.ui.components.emptyTabInformation
import com.jetpackduba.gitnuro.ui.context_menu.AppPopupMenu import com.jetpackduba.gitnuro.ui.context_menu.AppPopupMenu
import com.jetpackduba.gitnuro.ui.dialogs.settings.ProxyType import com.jetpackduba.gitnuro.ui.dialogs.settings.ProxyType
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.eclipse.jgit.internal.diffmergetool.DiffToolConfig
import org.eclipse.jgit.internal.diffmergetool.DiffTools
import org.eclipse.jgit.internal.diffmergetool.MergeToolConfig
import org.eclipse.jgit.internal.diffmergetool.MergeTools
import org.eclipse.jgit.lib.GpgSigner import org.eclipse.jgit.lib.GpgSigner
import java.io.File import java.io.File
import java.net.Authenticator import java.net.Authenticator
@ -65,7 +61,7 @@ class App {
lateinit var appStateManager: AppStateManager lateinit var appStateManager: AppStateManager
@Inject @Inject
lateinit var appSettingsRepository: AppSettingsRepository lateinit var appSettings: AppSettings
@Inject @Inject
lateinit var appGpgSigner: AppGpgSigner lateinit var appGpgSigner: AppGpgSigner
@ -93,15 +89,15 @@ class App {
logging.initLogging() logging.initLogging()
initProxySettings() initProxySettings()
val windowPlacement = appSettingsRepository.windowPlacement.toWindowPlacement val windowPlacement = appSettings.windowPlacement.toWindowPlacement
val dirToOpen = getDirToOpen(args) val dirToOpen = getDirToOpen(args)
appEnvInfo.isFlatpak = args.contains("--flatpak") appEnvInfo.isFlatpak = args.contains("--flatpak")
appStateManager.loadRepositoriesTabs() appStateManager.loadRepositoriesTabs()
try { try {
if (appSettingsRepository.theme == Theme.CUSTOM) { if (appSettings.theme == Theme.CUSTOM) {
appSettingsRepository.loadCustomTheme() appSettings.loadCustomTheme()
} }
} catch (ex: Exception) { } catch (ex: Exception) {
printError(TAG, "Failed to load custom theme") printError(TAG, "Failed to load custom theme")
@ -117,9 +113,9 @@ class App {
application { application {
var isOpen by remember { mutableStateOf(true) } var isOpen by remember { mutableStateOf(true) }
val theme by appSettingsRepository.themeState.collectAsState() val theme by appSettings.themeState.collectAsState()
val customTheme by appSettingsRepository.customThemeFlow.collectAsState() val customTheme by appSettings.customThemeFlow.collectAsState()
val scale by appSettingsRepository.scaleUiFlow.collectAsState() val scale by appSettings.scaleUiFlow.collectAsState()
val windowState = rememberWindowState( val windowState = rememberWindowState(
placement = windowPlacement, placement = windowPlacement,
@ -127,7 +123,7 @@ class App {
) )
// Save window state for next time the Window is started // Save window state for next time the Window is started
appSettingsRepository.windowPlacement = windowState.placement.preferenceValue appSettings.windowPlacement = windowState.placement.preferenceValue
if (isOpen) { if (isOpen) {
Window( Window(
@ -169,7 +165,7 @@ class App {
private fun initProxySettings() { private fun initProxySettings() {
appStateManager.appScope.launch { appStateManager.appScope.launch {
appSettingsRepository.proxyFlow.collect { proxySettings -> appSettings.proxyFlow.collect { proxySettings ->
if (proxySettings.useProxy) { if (proxySettings.useProxy) {
when (proxySettings.proxyType) { when (proxySettings.proxyType) {
ProxyType.HTTP -> setHttpProxy(proxySettings) ProxyType.HTTP -> setHttpProxy(proxySettings)

View File

@ -4,7 +4,7 @@ import com.jetpackduba.gitnuro.exceptions.NotSupportedHelper
import com.jetpackduba.gitnuro.git.remote_operations.CredentialsCache import com.jetpackduba.gitnuro.git.remote_operations.CredentialsCache
import com.jetpackduba.gitnuro.logging.printLog import com.jetpackduba.gitnuro.logging.printLog
import com.jetpackduba.gitnuro.managers.IShellManager import com.jetpackduba.gitnuro.managers.IShellManager
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository import com.jetpackduba.gitnuro.preferences.AppSettings
import dagger.assisted.Assisted import dagger.assisted.Assisted
import dagger.assisted.AssistedInject import dagger.assisted.AssistedInject
import org.eclipse.jgit.api.Git import org.eclipse.jgit.api.Git
@ -25,7 +25,7 @@ private const val GH_CLI_ARGS = "auth git-credential"
class HttpCredentialsProvider @AssistedInject constructor( class HttpCredentialsProvider @AssistedInject constructor(
private val credentialsStateManager: CredentialsStateManager, private val credentialsStateManager: CredentialsStateManager,
private val shellManager: IShellManager, private val shellManager: IShellManager,
private val appSettingsRepository: AppSettingsRepository, private val appSettings: AppSettings,
private val credentialsCacheRepository: CredentialsCacheRepository, private val credentialsCacheRepository: CredentialsCacheRepository,
@Assisted val git: Git?, @Assisted val git: Git?,
) : CredentialsProvider(), CredentialsCache { ) : CredentialsProvider(), CredentialsCache {
@ -71,7 +71,7 @@ class HttpCredentialsProvider @AssistedInject constructor(
} }
if (sslTrustNowItem != null) { if (sslTrustNowItem != null) {
sslTrustNowItem.value = appSettingsRepository.verifySsl sslTrustNowItem.value = appSettings.verifySsl
} }
val externalCredentialsHelper = getExternalCredentialsHelper(uri, git) val externalCredentialsHelper = getExternalCredentialsHelper(uri, git)
@ -86,7 +86,7 @@ class HttpCredentialsProvider @AssistedInject constructor(
userItem.value = credentials.user userItem.value = credentials.user
passwordItem.value = credentials.password.toCharArray() passwordItem.value = credentials.password.toCharArray()
if (appSettingsRepository.cacheCredentialsInMemory) { if (appSettings.cacheCredentialsInMemory) {
credentialsCached = CredentialsType.HttpCredentials( credentialsCached = CredentialsType.HttpCredentials(
url = uri.toString(), url = uri.toString(),
userName = credentials.user, userName = credentials.user,

View File

@ -10,7 +10,7 @@ import com.jetpackduba.gitnuro.di.modules.ShellModule
import com.jetpackduba.gitnuro.managers.AppStateManager import com.jetpackduba.gitnuro.managers.AppStateManager
import com.jetpackduba.gitnuro.managers.IShellManager import com.jetpackduba.gitnuro.managers.IShellManager
import com.jetpackduba.gitnuro.managers.TempFilesManager import com.jetpackduba.gitnuro.managers.TempFilesManager
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository import com.jetpackduba.gitnuro.preferences.AppSettings
import com.jetpackduba.gitnuro.terminal.ITerminalProvider import com.jetpackduba.gitnuro.terminal.ITerminalProvider
import com.jetpackduba.gitnuro.ui.TabsManager import com.jetpackduba.gitnuro.ui.TabsManager
import com.jetpackduba.gitnuro.updates.UpdatesRepository import com.jetpackduba.gitnuro.updates.UpdatesRepository
@ -32,7 +32,7 @@ interface AppComponent {
fun settingsViewModel(): SettingsViewModel fun settingsViewModel(): SettingsViewModel
fun credentialsStateManager(): CredentialsStateManager fun credentialsStateManager(): CredentialsStateManager
fun appPreferences(): AppSettingsRepository fun appPreferences(): AppSettings
fun appEnvInfo(): AppEnvInfo fun appEnvInfo(): AppEnvInfo

View File

@ -1,6 +1,6 @@
package com.jetpackduba.gitnuro.git.remote_operations package com.jetpackduba.gitnuro.git.remote_operations
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository import com.jetpackduba.gitnuro.preferences.AppSettings
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.eclipse.jgit.api.Git import org.eclipse.jgit.api.Git
@ -10,13 +10,13 @@ import javax.inject.Inject
class PullBranchUseCase @Inject constructor( class PullBranchUseCase @Inject constructor(
private val handleTransportUseCase: HandleTransportUseCase, private val handleTransportUseCase: HandleTransportUseCase,
private val appSettingsRepository: AppSettingsRepository, private val appSettings: AppSettings,
) { ) {
suspend operator fun invoke(git: Git, pullType: PullType) = withContext(Dispatchers.IO) { suspend operator fun invoke(git: Git, pullType: PullType) = withContext(Dispatchers.IO) {
val pullWithRebase = when (pullType) { val pullWithRebase = when (pullType) {
PullType.REBASE -> true PullType.REBASE -> true
PullType.MERGE -> false PullType.MERGE -> false
PullType.DEFAULT -> appSettingsRepository.pullRebase PullType.DEFAULT -> appSettings.pullRebase
} }
handleTransportUseCase(git) { handleTransportUseCase(git) {

View File

@ -4,7 +4,7 @@ import com.jetpackduba.gitnuro.git.branches.GetTrackingBranchUseCase
import com.jetpackduba.gitnuro.git.branches.TrackingBranch import com.jetpackduba.gitnuro.git.branches.TrackingBranch
import com.jetpackduba.gitnuro.git.isRejected import com.jetpackduba.gitnuro.git.isRejected
import com.jetpackduba.gitnuro.git.statusMessage import com.jetpackduba.gitnuro.git.statusMessage
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository import com.jetpackduba.gitnuro.preferences.AppSettings
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.isActive import kotlinx.coroutines.isActive
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
@ -18,7 +18,7 @@ import javax.inject.Inject
class PushBranchUseCase @Inject constructor( class PushBranchUseCase @Inject constructor(
private val handleTransportUseCase: HandleTransportUseCase, private val handleTransportUseCase: HandleTransportUseCase,
private val getTrackingBranchUseCase: GetTrackingBranchUseCase, private val getTrackingBranchUseCase: GetTrackingBranchUseCase,
private val appSettingsRepository: AppSettingsRepository, private val appSettings: AppSettings,
) { ) {
// TODO This use case should also set the tracking branch to the new remote branch // TODO This use case should also set the tracking branch to the new remote branch
suspend operator fun invoke(git: Git, force: Boolean, pushTags: Boolean) = withContext(Dispatchers.IO) { suspend operator fun invoke(git: Git, force: Boolean, pushTags: Boolean) = withContext(Dispatchers.IO) {
@ -53,7 +53,7 @@ class PushBranchUseCase @Inject constructor(
} }
.setForce(force) .setForce(force)
.run { .run {
if (force && appSettingsRepository.pushWithLease) { if (force && appSettings.pushWithLease) {
if (tracking != null) { if (tracking != null) {
val remoteBranchName = "${Constants.R_REMOTES}$remote/${tracking.branch}" val remoteBranchName = "${Constants.R_REMOTES}$remote/${tracking.branch}"

View File

@ -1,6 +1,7 @@
package com.jetpackduba.gitnuro package com.jetpackduba.gitnuro
import com.jetpackduba.gitnuro.repositories.initPreferencesPath import com.jetpackduba.gitnuro.managers.ShellManager
import com.jetpackduba.gitnuro.preferences.initPreferencesPath
fun main(args: Array<String>) { fun main(args: Array<String>) {
initPreferencesPath() initPreferencesPath()

View File

@ -1,7 +1,7 @@
package com.jetpackduba.gitnuro.managers package com.jetpackduba.gitnuro.managers
import com.jetpackduba.gitnuro.di.qualifiers.AppCoroutineScope import com.jetpackduba.gitnuro.di.qualifiers.AppCoroutineScope
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository import com.jetpackduba.gitnuro.preferences.AppSettings
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel import kotlinx.coroutines.cancel
@ -15,7 +15,7 @@ import javax.inject.Singleton
@Singleton @Singleton
class AppStateManager @Inject constructor( class AppStateManager @Inject constructor(
private val appSettingsRepository: AppSettingsRepository, private val appSettings: AppSettings,
@AppCoroutineScope val appScope: CoroutineScope, @AppCoroutineScope val appScope: CoroutineScope,
) { ) {
private val mutex = Mutex() private val mutex = Mutex()
@ -39,14 +39,14 @@ class AppStateManager @Inject constructor(
if (_latestOpenedRepositoriesPaths.count() > 10) if (_latestOpenedRepositoriesPaths.count() > 10)
_latestOpenedRepositoriesPaths.removeLast() _latestOpenedRepositoriesPaths.removeLast()
appSettingsRepository.latestOpenedRepositoriesPath = Json.encodeToString(_latestOpenedRepositoriesPaths) appSettings.latestOpenedRepositoriesPath = Json.encodeToString(_latestOpenedRepositoriesPaths)
} finally { } finally {
mutex.unlock() mutex.unlock()
} }
} }
fun loadRepositoriesTabs() { fun loadRepositoriesTabs() {
val repositoriesPathsSaved = appSettingsRepository.latestOpenedRepositoriesPath val repositoriesPathsSaved = appSettings.latestOpenedRepositoriesPath
if (repositoriesPathsSaved.isNotEmpty()) { if (repositoriesPathsSaved.isNotEmpty()) {
val repositories = Json.decodeFromString<List<String>>(repositoriesPathsSaved) val repositories = Json.decodeFromString<List<String>>(repositoriesPathsSaved)
_latestOpenedRepositoriesPaths.addAll(repositories) _latestOpenedRepositoriesPaths.addAll(repositories)

View File

@ -1,7 +1,6 @@
package com.jetpackduba.gitnuro.repositories package com.jetpackduba.gitnuro.preferences
import com.jetpackduba.gitnuro.extensions.defaultWindowPlacement import com.jetpackduba.gitnuro.extensions.defaultWindowPlacement
import com.jetpackduba.gitnuro.preferences.WindowsPlacementPreference
import com.jetpackduba.gitnuro.system.OS import com.jetpackduba.gitnuro.system.OS
import com.jetpackduba.gitnuro.system.currentOs import com.jetpackduba.gitnuro.system.currentOs
import com.jetpackduba.gitnuro.theme.ColorsScheme import com.jetpackduba.gitnuro.theme.ColorsScheme
@ -58,7 +57,7 @@ private const val DEFAULT_VERIFY_SSL = true
const val DEFAULT_UI_SCALE = -1f const val DEFAULT_UI_SCALE = -1f
@Singleton @Singleton
class AppSettingsRepository @Inject constructor() { class AppSettings @Inject constructor() {
private val preferences: Preferences = Preferences.userRoot().node(PREFERENCES_NAME) private val preferences: Preferences = Preferences.userRoot().node(PREFERENCES_NAME)
private val _themeState = MutableStateFlow(theme) private val _themeState = MutableStateFlow(theme)
@ -374,6 +373,8 @@ data class ProxySettings(
val hostPassword: String, val hostPassword: String,
) )
// TODO migrate old prefs path to new one?
fun initPreferencesPath() { fun initPreferencesPath() {
if (currentOs == OS.LINUX) { if (currentOs == OS.LINUX) {
val xdgConfigHome: String? = System.getenv("XDG_CONFIG_HOME") val xdgConfigHome: String? = System.getenv("XDG_CONFIG_HOME")

View File

@ -1,13 +1,13 @@
package com.jetpackduba.gitnuro.terminal package com.jetpackduba.gitnuro.terminal
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository import com.jetpackduba.gitnuro.preferences.AppSettings
import javax.inject.Inject import javax.inject.Inject
// For flatpak: https://github.com/flathub/com.visualstudio.code#use-host-shell-in-the-integrated-terminal // For flatpak: https://github.com/flathub/com.visualstudio.code#use-host-shell-in-the-integrated-terminal
class OpenRepositoryInTerminalUseCase @Inject constructor( class OpenRepositoryInTerminalUseCase @Inject constructor(
private val terminalProvider: ITerminalProvider, private val terminalProvider: ITerminalProvider,
private val settings: AppSettingsRepository, private val settings: AppSettings,
) { ) {
operator fun invoke(path: String) { operator fun invoke(path: String) {
val terminalEmulators = terminalProvider.getTerminalEmulators() val terminalEmulators = terminalProvider.getTerminalEmulators()

View File

@ -3,7 +3,7 @@ package com.jetpackduba.gitnuro.ui
import androidx.compose.runtime.MutableState import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import com.jetpackduba.gitnuro.di.AppComponent import com.jetpackduba.gitnuro.di.AppComponent
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository import com.jetpackduba.gitnuro.preferences.AppSettings
import com.jetpackduba.gitnuro.ui.components.TabInformation import com.jetpackduba.gitnuro.ui.components.TabInformation
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
@ -16,7 +16,7 @@ import javax.inject.Singleton
@Singleton @Singleton
class TabsManager @Inject constructor( class TabsManager @Inject constructor(
private val appSettingsRepository: AppSettingsRepository private val appSettings: AppSettings
) { ) {
lateinit var appComponent: AppComponent lateinit var appComponent: AppComponent
@ -27,7 +27,7 @@ class TabsManager @Inject constructor(
val currentTab: StateFlow<TabInformation?> = _currentTab val currentTab: StateFlow<TabInformation?> = _currentTab
fun loadPersistedTabs() { fun loadPersistedTabs() {
val repositoriesSaved = appSettingsRepository.latestTabsOpened val repositoriesSaved = appSettings.latestTabsOpened
val repositoriesList = if (repositoriesSaved.isNotEmpty()) val repositoriesList = if (repositoriesSaved.isNotEmpty())
Json.decodeFromString<List<String>>(repositoriesSaved).map { path -> Json.decodeFromString<List<String>>(repositoriesSaved).map { path ->
@ -40,7 +40,7 @@ class TabsManager @Inject constructor(
_tabsFlow.value = repositoriesList.ifEmpty { listOf(newAppTab()) } _tabsFlow.value = repositoriesList.ifEmpty { listOf(newAppTab()) }
val latestSelectedTabPath = appSettingsRepository.latestRepositoryTabSelected val latestSelectedTabPath = appSettings.latestRepositoryTabSelected
val latestSelectedTab = repositoriesList.firstOrNull { it.path == latestSelectedTabPath } val latestSelectedTab = repositoriesList.firstOrNull { it.path == latestSelectedTabPath }
@ -78,7 +78,7 @@ class TabsManager @Inject constructor(
} }
private fun persistTabSelected(tab: TabInformation) { private fun persistTabSelected(tab: TabInformation) {
appSettingsRepository.latestRepositoryTabSelected = tab.path.orEmpty() appSettings.latestRepositoryTabSelected = tab.path.orEmpty()
} }
fun closeTab(tab: TabInformation) { fun closeTab(tab: TabInformation) {
@ -118,7 +118,7 @@ class TabsManager @Inject constructor(
val tabsPaths = tabsFlow.value val tabsPaths = tabsFlow.value
.mapNotNull { it.path } .mapNotNull { it.path }
appSettingsRepository.latestTabsOpened = Json.encodeToString(tabsPaths) appSettings.latestTabsOpened = Json.encodeToString(tabsPaths)
} }
fun addNewEmptyTab() { fun addNewEmptyTab() {

View File

@ -18,7 +18,7 @@ import androidx.compose.ui.unit.dp
import com.jetpackduba.gitnuro.AppIcons import com.jetpackduba.gitnuro.AppIcons
import com.jetpackduba.gitnuro.extensions.handMouseClickable import com.jetpackduba.gitnuro.extensions.handMouseClickable
import com.jetpackduba.gitnuro.managers.Error import com.jetpackduba.gitnuro.managers.Error
import com.jetpackduba.gitnuro.repositories.DEFAULT_UI_SCALE import com.jetpackduba.gitnuro.preferences.DEFAULT_UI_SCALE
import com.jetpackduba.gitnuro.theme.* import com.jetpackduba.gitnuro.theme.*
import com.jetpackduba.gitnuro.ui.components.* import com.jetpackduba.gitnuro.ui.components.*
import com.jetpackduba.gitnuro.ui.dialogs.errors.ErrorDialog import com.jetpackduba.gitnuro.ui.dialogs.errors.ErrorDialog

View File

@ -1,5 +1,6 @@
package com.jetpackduba.gitnuro.ui.tree_files package com.jetpackduba.gitnuro.ui.tree_files
import arrow.core.compareTo
import com.jetpackduba.gitnuro.system.systemSeparator import com.jetpackduba.gitnuro.system.systemSeparator
import kotlin.math.max import kotlin.math.max
@ -60,6 +61,8 @@ private class PathsComparator : Comparator<String> {
val path1Parts = path1.split(systemSeparator) val path1Parts = path1.split(systemSeparator)
val path2Parts = path2.split(systemSeparator) val path2Parts = path2.split(systemSeparator)
path1Parts.compareTo(path2Parts)
val maxIndex = max(path1Parts.count(), path2Parts.count()) val maxIndex = max(path1Parts.count(), path2Parts.count())
for (i in 0 until maxIndex) { for (i in 0 until maxIndex) {

View File

@ -10,7 +10,7 @@ import com.jetpackduba.gitnuro.extensions.lowercaseContains
import com.jetpackduba.gitnuro.git.RefreshType import com.jetpackduba.gitnuro.git.RefreshType
import com.jetpackduba.gitnuro.git.TabState import com.jetpackduba.gitnuro.git.TabState
import com.jetpackduba.gitnuro.git.diff.GetCommitDiffEntriesUseCase import com.jetpackduba.gitnuro.git.diff.GetCommitDiffEntriesUseCase
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository import com.jetpackduba.gitnuro.preferences.AppSettings
import com.jetpackduba.gitnuro.ui.tree_files.TreeItem import com.jetpackduba.gitnuro.ui.tree_files.TreeItem
import com.jetpackduba.gitnuro.ui.tree_files.entriesToTreeEntry import com.jetpackduba.gitnuro.ui.tree_files.entriesToTreeEntry
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@ -24,7 +24,7 @@ private const val MIN_TIME_IN_MS_TO_SHOW_LOAD = 300L
class CommitChangesViewModel @Inject constructor( class CommitChangesViewModel @Inject constructor(
private val tabState: TabState, private val tabState: TabState,
private val getCommitDiffEntriesUseCase: GetCommitDiffEntriesUseCase, private val getCommitDiffEntriesUseCase: GetCommitDiffEntriesUseCase,
private val appSettingsRepository: AppSettingsRepository, private val appSettings: AppSettings,
tabScope: CoroutineScope, tabScope: CoroutineScope,
) { ) {
private val _showSearch = MutableStateFlow(false) private val _showSearch = MutableStateFlow(false)
@ -39,7 +39,7 @@ class CommitChangesViewModel @Inject constructor(
val textScroll = MutableStateFlow(ScrollState(0)) val textScroll = MutableStateFlow(ScrollState(0))
val showAsTree = appSettingsRepository.showChangesAsTreeFlow val showAsTree = appSettings.showChangesAsTreeFlow
private val treeContractedDirectories = MutableStateFlow(emptyList<String>()) private val treeContractedDirectories = MutableStateFlow(emptyList<String>())
private val _commitChangesState = MutableStateFlow<CommitChangesState>(CommitChangesState.Loading) private val _commitChangesState = MutableStateFlow<CommitChangesState>(CommitChangesState.Loading)
@ -133,7 +133,7 @@ class CommitChangesViewModel @Inject constructor(
} }
fun alternateShowAsTree() { fun alternateShowAsTree() {
appSettingsRepository.showChangesAsTree = !appSettingsRepository.showChangesAsTree appSettings.showChangesAsTree = !appSettings.showChangesAsTree
} }
fun onDirectoryClicked(directoryPath: String) { fun onDirectoryClicked(directoryPath: String) {

View File

@ -8,7 +8,7 @@ import com.jetpackduba.gitnuro.git.RefreshType
import com.jetpackduba.gitnuro.git.TabState import com.jetpackduba.gitnuro.git.TabState
import com.jetpackduba.gitnuro.git.diff.* import com.jetpackduba.gitnuro.git.diff.*
import com.jetpackduba.gitnuro.git.workspace.* import com.jetpackduba.gitnuro.git.workspace.*
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository import com.jetpackduba.gitnuro.preferences.AppSettings
import com.jetpackduba.gitnuro.system.OpenFileInExternalAppUseCase import com.jetpackduba.gitnuro.system.OpenFileInExternalAppUseCase
import com.jetpackduba.gitnuro.ui.TabsManager import com.jetpackduba.gitnuro.ui.TabsManager
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@ -33,7 +33,7 @@ class DiffViewModel @Inject constructor(
private val stageEntryUseCase: StageEntryUseCase, private val stageEntryUseCase: StageEntryUseCase,
private val unstageEntryUseCase: UnstageEntryUseCase, private val unstageEntryUseCase: UnstageEntryUseCase,
private val openFileInExternalAppUseCase: OpenFileInExternalAppUseCase, private val openFileInExternalAppUseCase: OpenFileInExternalAppUseCase,
private val settings: AppSettingsRepository, private val settings: AppSettings,
private val generateSplitHunkFromDiffResultUseCase: GenerateSplitHunkFromDiffResultUseCase, private val generateSplitHunkFromDiffResultUseCase: GenerateSplitHunkFromDiffResultUseCase,
private val discardUnstagedHunkLineUseCase: DiscardUnstagedHunkLineUseCase, private val discardUnstagedHunkLineUseCase: DiscardUnstagedHunkLineUseCase,
private val tabsManager: TabsManager, private val tabsManager: TabsManager,

View File

@ -11,7 +11,7 @@ import com.jetpackduba.gitnuro.git.diff.DiffResult
import com.jetpackduba.gitnuro.git.diff.FormatDiffUseCase import com.jetpackduba.gitnuro.git.diff.FormatDiffUseCase
import com.jetpackduba.gitnuro.git.diff.GenerateSplitHunkFromDiffResultUseCase import com.jetpackduba.gitnuro.git.diff.GenerateSplitHunkFromDiffResultUseCase
import com.jetpackduba.gitnuro.git.diff.GetCommitDiffEntriesUseCase import com.jetpackduba.gitnuro.git.diff.GetCommitDiffEntriesUseCase
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository import com.jetpackduba.gitnuro.preferences.AppSettings
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
@ -23,7 +23,7 @@ class HistoryViewModel @Inject constructor(
private val tabState: TabState, private val tabState: TabState,
private val formatDiffUseCase: FormatDiffUseCase, private val formatDiffUseCase: FormatDiffUseCase,
private val getCommitDiffEntriesUseCase: GetCommitDiffEntriesUseCase, private val getCommitDiffEntriesUseCase: GetCommitDiffEntriesUseCase,
private val settings: AppSettingsRepository, private val settings: AppSettings,
private val generateSplitHunkFromDiffResultUseCase: GenerateSplitHunkFromDiffResultUseCase, private val generateSplitHunkFromDiffResultUseCase: GenerateSplitHunkFromDiffResultUseCase,
private val tabScope: CoroutineScope, private val tabScope: CoroutineScope,
) { ) {

View File

@ -15,10 +15,11 @@ import com.jetpackduba.gitnuro.git.graph.GraphNode
import com.jetpackduba.gitnuro.git.log.* import com.jetpackduba.gitnuro.git.log.*
import com.jetpackduba.gitnuro.git.rebase.StartRebaseInteractiveUseCase import com.jetpackduba.gitnuro.git.rebase.StartRebaseInteractiveUseCase
import com.jetpackduba.gitnuro.git.tags.CreateTagOnCommitUseCase import com.jetpackduba.gitnuro.git.tags.CreateTagOnCommitUseCase
import com.jetpackduba.gitnuro.git.tags.DeleteTagUseCase
import com.jetpackduba.gitnuro.git.workspace.CheckHasUncommittedChangesUseCase import com.jetpackduba.gitnuro.git.workspace.CheckHasUncommittedChangesUseCase
import com.jetpackduba.gitnuro.git.workspace.GetStatusSummaryUseCase import com.jetpackduba.gitnuro.git.workspace.GetStatusSummaryUseCase
import com.jetpackduba.gitnuro.git.workspace.StatusSummary import com.jetpackduba.gitnuro.git.workspace.StatusSummary
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository import com.jetpackduba.gitnuro.preferences.AppSettings
import com.jetpackduba.gitnuro.ui.SelectedItem import com.jetpackduba.gitnuro.ui.SelectedItem
import com.jetpackduba.gitnuro.ui.log.LogDialog import com.jetpackduba.gitnuro.ui.log.LogDialog
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@ -56,7 +57,7 @@ class LogViewModel @Inject constructor(
private val createTagOnCommitUseCase: CreateTagOnCommitUseCase, private val createTagOnCommitUseCase: CreateTagOnCommitUseCase,
private val startRebaseInteractiveUseCase: StartRebaseInteractiveUseCase, private val startRebaseInteractiveUseCase: StartRebaseInteractiveUseCase,
private val tabState: TabState, private val tabState: TabState,
private val appSettingsRepository: AppSettingsRepository, private val appSettings: AppSettings,
tabScope: CoroutineScope, tabScope: CoroutineScope,
sharedStashViewModel: SharedStashViewModel, sharedStashViewModel: SharedStashViewModel,
sharedBranchesViewModel: SharedBranchesViewModel, sharedBranchesViewModel: SharedBranchesViewModel,
@ -100,12 +101,12 @@ class LogViewModel @Inject constructor(
init { init {
tabScope.launch { tabScope.launch {
appSettingsRepository.commitsLimitEnabledFlow.drop(1).collectLatest { appSettings.commitsLimitEnabledFlow.drop(1).collectLatest {
tabState.refreshData(RefreshType.ONLY_LOG) tabState.refreshData(RefreshType.ONLY_LOG)
} }
} }
tabScope.launch { tabScope.launch {
appSettingsRepository.commitsLimitFlow.collectLatest { appSettings.commitsLimitFlow.collectLatest {
tabState.refreshData(RefreshType.ONLY_LOG) tabState.refreshData(RefreshType.ONLY_LOG)
} }
} }
@ -139,13 +140,13 @@ class LogViewModel @Inject constructor(
) )
val hasUncommittedChanges = statusSummary.total > 0 val hasUncommittedChanges = statusSummary.total > 0
val commitsLimit = if (appSettingsRepository.commitsLimitEnabled) { val commitsLimit = if (appSettings.commitsLimitEnabled) {
appSettingsRepository.commitsLimit appSettings.commitsLimit
} else } else
Int.MAX_VALUE Int.MAX_VALUE
val commitsLimitDisplayed = if (appSettingsRepository.commitsLimitEnabled) { val commitsLimitDisplayed = if (appSettings.commitsLimitEnabled) {
appSettingsRepository.commitsLimit appSettings.commitsLimit
} else } else
-1 -1

View File

@ -10,7 +10,7 @@ import com.jetpackduba.gitnuro.git.remote_operations.PushBranchUseCase
import com.jetpackduba.gitnuro.git.stash.PopLastStashUseCase import com.jetpackduba.gitnuro.git.stash.PopLastStashUseCase
import com.jetpackduba.gitnuro.git.stash.StashChangesUseCase import com.jetpackduba.gitnuro.git.stash.StashChangesUseCase
import com.jetpackduba.gitnuro.git.workspace.StageUntrackedFileUseCase import com.jetpackduba.gitnuro.git.workspace.StageUntrackedFileUseCase
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository import com.jetpackduba.gitnuro.preferences.AppSettings
import com.jetpackduba.gitnuro.terminal.OpenRepositoryInTerminalUseCase import com.jetpackduba.gitnuro.terminal.OpenRepositoryInTerminalUseCase
import javax.inject.Inject import javax.inject.Inject
@ -23,7 +23,7 @@ class MenuViewModel @Inject constructor(
private val stashChangesUseCase: StashChangesUseCase, private val stashChangesUseCase: StashChangesUseCase,
private val stageUntrackedFileUseCase: StageUntrackedFileUseCase, private val stageUntrackedFileUseCase: StageUntrackedFileUseCase,
private val openRepositoryInTerminalUseCase: OpenRepositoryInTerminalUseCase, private val openRepositoryInTerminalUseCase: OpenRepositoryInTerminalUseCase,
private val settings: AppSettingsRepository, private val settings: AppSettings,
) { ) {
val isPullWithRebaseDefault = settings.pullRebaseFlow val isPullWithRebaseDefault = settings.pullRebaseFlow

View File

@ -3,10 +3,11 @@ package com.jetpackduba.gitnuro.viewmodels
import com.jetpackduba.gitnuro.Logging import com.jetpackduba.gitnuro.Logging
import com.jetpackduba.gitnuro.TaskType import com.jetpackduba.gitnuro.TaskType
import com.jetpackduba.gitnuro.di.qualifiers.AppCoroutineScope import com.jetpackduba.gitnuro.di.qualifiers.AppCoroutineScope
import com.jetpackduba.gitnuro.git.RefreshType
import com.jetpackduba.gitnuro.logging.printError import com.jetpackduba.gitnuro.logging.printError
import com.jetpackduba.gitnuro.managers.Error import com.jetpackduba.gitnuro.managers.Error
import com.jetpackduba.gitnuro.managers.newErrorNow import com.jetpackduba.gitnuro.managers.newErrorNow
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository import com.jetpackduba.gitnuro.preferences.AppSettings
import com.jetpackduba.gitnuro.system.OpenFilePickerUseCase import com.jetpackduba.gitnuro.system.OpenFilePickerUseCase
import com.jetpackduba.gitnuro.system.PickerType import com.jetpackduba.gitnuro.system.PickerType
import com.jetpackduba.gitnuro.theme.Theme import com.jetpackduba.gitnuro.theme.Theme
@ -21,7 +22,7 @@ private const val TAG = "SettingsViewModel"
@Singleton @Singleton
class SettingsViewModel @Inject constructor( class SettingsViewModel @Inject constructor(
private val appSettingsRepository: AppSettingsRepository, private val appSettings: AppSettings,
private val openFilePickerUseCase: OpenFilePickerUseCase, private val openFilePickerUseCase: OpenFilePickerUseCase,
private val logging: Logging, private val logging: Logging,
@AppCoroutineScope private val appScope: CoroutineScope, @AppCoroutineScope private val appScope: CoroutineScope,
@ -29,121 +30,121 @@ class SettingsViewModel @Inject constructor(
// Temporary values to detect changed variables // Temporary values to detect changed variables
var commitsLimit: Int = -1 var commitsLimit: Int = -1
val themeState = appSettingsRepository.themeState val themeState = appSettings.themeState
val ffMergeFlow = appSettingsRepository.ffMergeFlow val ffMergeFlow = appSettings.ffMergeFlow
val pullRebaseFlow = appSettingsRepository.pullRebaseFlow val pullRebaseFlow = appSettings.pullRebaseFlow
val pushWithLeaseFlow = appSettingsRepository.pushWithLeaseFlow val pushWithLeaseFlow = appSettings.pushWithLeaseFlow
val commitsLimitEnabledFlow = appSettingsRepository.commitsLimitEnabledFlow val commitsLimitEnabledFlow = appSettings.commitsLimitEnabledFlow
val swapUncommittedChangesFlow = appSettingsRepository.swapUncommittedChangesFlow val swapUncommittedChangesFlow = appSettings.swapUncommittedChangesFlow
val cacheCredentialsInMemoryFlow = appSettingsRepository.cacheCredentialsInMemoryFlow val cacheCredentialsInMemoryFlow = appSettings.cacheCredentialsInMemoryFlow
val verifySslFlow = appSettingsRepository.verifySslFlow val verifySslFlow = appSettings.verifySslFlow
val terminalPathFlow = appSettingsRepository.terminalPathFlow val terminalPathFlow = appSettings.terminalPathFlow
var scaleUi: Float var scaleUi: Float
get() = appSettingsRepository.scaleUi get() = appSettings.scaleUi
set(value) { set(value) {
appSettingsRepository.scaleUi = value appSettings.scaleUi = value
} }
var commitsLimitEnabled: Boolean var commitsLimitEnabled: Boolean
get() = appSettingsRepository.commitsLimitEnabled get() = appSettings.commitsLimitEnabled
set(value) { set(value) {
appSettingsRepository.commitsLimitEnabled = value appSettings.commitsLimitEnabled = value
} }
var swapUncommittedChanges: Boolean var swapUncommittedChanges: Boolean
get() = appSettingsRepository.swapUncommittedChanges get() = appSettings.swapUncommittedChanges
set(value) { set(value) {
appSettingsRepository.swapUncommittedChanges = value appSettings.swapUncommittedChanges = value
} }
var ffMerge: Boolean var ffMerge: Boolean
get() = appSettingsRepository.ffMerge get() = appSettings.ffMerge
set(value) { set(value) {
appSettingsRepository.ffMerge = value appSettings.ffMerge = value
} }
var cacheCredentialsInMemory: Boolean var cacheCredentialsInMemory: Boolean
get() = appSettingsRepository.cacheCredentialsInMemory get() = appSettings.cacheCredentialsInMemory
set(value) { set(value) {
appSettingsRepository.cacheCredentialsInMemory = value appSettings.cacheCredentialsInMemory = value
} }
var verifySsl: Boolean var verifySsl: Boolean
get() = appSettingsRepository.verifySsl get() = appSettings.verifySsl
set(value) { set(value) {
appSettingsRepository.verifySsl = value appSettings.verifySsl = value
} }
var pullRebase: Boolean var pullRebase: Boolean
get() = appSettingsRepository.pullRebase get() = appSettings.pullRebase
set(value) { set(value) {
appSettingsRepository.pullRebase = value appSettings.pullRebase = value
} }
var pushWithLease: Boolean var pushWithLease: Boolean
get() = appSettingsRepository.pushWithLease get() = appSettings.pushWithLease
set(value) { set(value) {
appSettingsRepository.pushWithLease = value appSettings.pushWithLease = value
} }
var theme: Theme var theme: Theme
get() = appSettingsRepository.theme get() = appSettings.theme
set(value) { set(value) {
appSettingsRepository.theme = value appSettings.theme = value
} }
var terminalPath: String var terminalPath: String
get() = appSettingsRepository.terminalPath get() = appSettings.terminalPath
set(value) { set(value) {
appSettingsRepository.terminalPath = value appSettings.terminalPath = value
} }
var useProxy: Boolean var useProxy: Boolean
get() = appSettingsRepository.useProxy get() = appSettings.useProxy
set(value) { set(value) {
appSettingsRepository.useProxy = value appSettings.useProxy = value
} }
var proxyType: ProxyType var proxyType: ProxyType
get() = appSettingsRepository.proxyType get() = appSettings.proxyType
set(value) { set(value) {
appSettingsRepository.proxyType = value appSettings.proxyType = value
} }
var proxyHostName: String var proxyHostName: String
get() = appSettingsRepository.proxyHostName get() = appSettings.proxyHostName
set(value) { set(value) {
appSettingsRepository.proxyHostName = value appSettings.proxyHostName = value
} }
var proxyPortNumber: Int var proxyPortNumber: Int
get() = appSettingsRepository.proxyPortNumber get() = appSettings.proxyPortNumber
set(value) { set(value) {
appSettingsRepository.proxyPortNumber = value appSettings.proxyPortNumber = value
} }
var proxyUseAuth: Boolean var proxyUseAuth: Boolean
get() = appSettingsRepository.proxyUseAuth get() = appSettings.proxyUseAuth
set(value) { set(value) {
appSettingsRepository.proxyUseAuth = value appSettings.proxyUseAuth = value
} }
var proxyHostUser: String var proxyHostUser: String
get() = appSettingsRepository.proxyHostUser get() = appSettings.proxyHostUser
set(value) { set(value) {
appSettingsRepository.proxyHostUser = value appSettings.proxyHostUser = value
} }
var proxyHostPassword: String var proxyHostPassword: String
get() = appSettingsRepository.proxyHostPassword get() = appSettings.proxyHostPassword
set(value) { set(value) {
appSettingsRepository.proxyHostPassword = value appSettings.proxyHostPassword = value
} }
fun saveCustomTheme(filePath: String): Error? { fun saveCustomTheme(filePath: String): Error? {
return try { return try {
appSettingsRepository.saveCustomTheme(filePath) appSettings.saveCustomTheme(filePath)
null null
} catch (ex: Exception) { } catch (ex: Exception) {
ex.printStackTrace() ex.printStackTrace()
@ -157,14 +158,14 @@ class SettingsViewModel @Inject constructor(
} }
fun resetInfo() { fun resetInfo() {
commitsLimit = appSettingsRepository.commitsLimit commitsLimit = appSettings.commitsLimit
} }
fun savePendingChanges() = appScope.launch { fun savePendingChanges() = appScope.launch {
val commitsLimit = this@SettingsViewModel.commitsLimit val commitsLimit = this@SettingsViewModel.commitsLimit
if (appSettingsRepository.commitsLimit != commitsLimit) { if (appSettings.commitsLimit != commitsLimit) {
appSettingsRepository.setCommitsLimit(commitsLimit) appSettings.setCommitsLimit(commitsLimit)
} }
} }

View File

@ -8,10 +8,8 @@ import com.jetpackduba.gitnuro.git.branches.CheckoutRefUseCase
import com.jetpackduba.gitnuro.git.branches.DeleteBranchUseCase import com.jetpackduba.gitnuro.git.branches.DeleteBranchUseCase
import com.jetpackduba.gitnuro.git.branches.MergeBranchUseCase import com.jetpackduba.gitnuro.git.branches.MergeBranchUseCase
import com.jetpackduba.gitnuro.git.rebase.RebaseBranchUseCase import com.jetpackduba.gitnuro.git.rebase.RebaseBranchUseCase
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository import com.jetpackduba.gitnuro.preferences.AppSettings
import com.jetpackduba.gitnuro.repositories.BranchesVisibilityRepository
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import org.eclipse.jgit.internal.diffmergetool.MergeTools
import org.eclipse.jgit.lib.Ref import org.eclipse.jgit.lib.Ref
import javax.inject.Inject import javax.inject.Inject
@ -20,19 +18,15 @@ interface ISharedBranchesViewModel {
fun deleteBranch(branch: Ref): Job fun deleteBranch(branch: Ref): Job
fun checkoutRef(ref: Ref): Job fun checkoutRef(ref: Ref): Job
fun rebaseBranch(ref: Ref): Job fun rebaseBranch(ref: Ref): Job
fun alternateBranchVisibility(branch: Ref, isHidden: Boolean): Job
fun hideAllBranches(branches: List<Ref>): Job
fun showAllBranches(): Job
} }
class SharedBranchesViewModel @Inject constructor( class SharedBranchesViewModel @Inject constructor(
private val rebaseBranchUseCase: RebaseBranchUseCase, private val rebaseBranchUseCase: RebaseBranchUseCase,
private val tabState: TabState, private val tabState: TabState,
private val appSettingsRepository: AppSettingsRepository, private val appSettings: AppSettings,
private val mergeBranchUseCase: MergeBranchUseCase, private val mergeBranchUseCase: MergeBranchUseCase,
private val deleteBranchUseCase: DeleteBranchUseCase, private val deleteBranchUseCase: DeleteBranchUseCase,
private val checkoutRefUseCase: CheckoutRefUseCase, private val checkoutRefUseCase: CheckoutRefUseCase,
private val branchesVisibilityRepository: BranchesVisibilityRepository,
) : ISharedBranchesViewModel { ) : ISharedBranchesViewModel {
override fun mergeBranch(ref: Ref) = tabState.safeProcessing( override fun mergeBranch(ref: Ref) = tabState.safeProcessing(
@ -41,7 +35,7 @@ class SharedBranchesViewModel @Inject constructor(
subtitle = "Merging branch ${ref.simpleName}", subtitle = "Merging branch ${ref.simpleName}",
taskType = TaskType.MERGE_BRANCH, taskType = TaskType.MERGE_BRANCH,
) { git -> ) { git ->
mergeBranchUseCase(git, ref, appSettingsRepository.ffMerge) mergeBranchUseCase(git, ref, appSettings.ffMerge)
} }
override fun deleteBranch(branch: Ref) = tabState.safeProcessing( override fun deleteBranch(branch: Ref) = tabState.safeProcessing(
@ -70,30 +64,4 @@ class SharedBranchesViewModel @Inject constructor(
) { git -> ) { git ->
rebaseBranchUseCase(git, ref) rebaseBranchUseCase(git, ref)
} }
override fun alternateBranchVisibility(branch: Ref, isHidden: Boolean) =
tabState.runOperation(refreshType = RefreshType.NONE) { _ ->
if (isHidden) {
showBranch(branch)
} else {
hideBranch(branch)
}
}
override fun hideAllBranches(branches: List<Ref>) = tabState.runOperation(refreshType = RefreshType.NONE) {
branchesVisibilityRepository.hideBranches(branches.map { it.name })
}
override fun showAllBranches() = tabState.runOperation(refreshType = RefreshType.NONE) {
branchesVisibilityRepository.showAllBranches()
}
private suspend fun hideBranch(ref: Ref) {
branchesVisibilityRepository.hideBranches(listOf(ref.name))
}
private suspend fun showBranch(ref: Ref) = tabState.runOperation(refreshType = RefreshType.NONE) { _ ->
branchesVisibilityRepository.showBranches(listOf(ref.name))
}
} }

View File

@ -21,7 +21,7 @@ import com.jetpackduba.gitnuro.git.rebase.SkipRebaseUseCase
import com.jetpackduba.gitnuro.git.repository.ResetRepositoryStateUseCase import com.jetpackduba.gitnuro.git.repository.ResetRepositoryStateUseCase
import com.jetpackduba.gitnuro.git.workspace.* import com.jetpackduba.gitnuro.git.workspace.*
import com.jetpackduba.gitnuro.models.AuthorInfo import com.jetpackduba.gitnuro.models.AuthorInfo
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository import com.jetpackduba.gitnuro.preferences.AppSettings
import com.jetpackduba.gitnuro.ui.tree_files.TreeItem import com.jetpackduba.gitnuro.ui.tree_files.TreeItem
import com.jetpackduba.gitnuro.ui.tree_files.entriesToTreeEntry import com.jetpackduba.gitnuro.ui.tree_files.entriesToTreeEntry
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@ -30,8 +30,6 @@ import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.eclipse.jgit.api.Git import org.eclipse.jgit.api.Git
import org.eclipse.jgit.internal.diffmergetool.DiffTools
import org.eclipse.jgit.internal.diffmergetool.ExternalDiffTool
import org.eclipse.jgit.lib.PersonIdent import org.eclipse.jgit.lib.PersonIdent
import org.eclipse.jgit.lib.RepositoryState import org.eclipse.jgit.lib.RepositoryState
import java.io.File import java.io.File
@ -62,7 +60,7 @@ class StatusViewModel @Inject constructor(
private val saveAuthorUseCase: SaveAuthorUseCase, private val saveAuthorUseCase: SaveAuthorUseCase,
private val sharedRepositoryStateManager: SharedRepositoryStateManager, private val sharedRepositoryStateManager: SharedRepositoryStateManager,
private val getSpecificCommitMessageUseCase: GetSpecificCommitMessageUseCase, private val getSpecificCommitMessageUseCase: GetSpecificCommitMessageUseCase,
private val appSettingsRepository: AppSettingsRepository, private val appSettings: AppSettings,
tabScope: CoroutineScope, tabScope: CoroutineScope,
) { ) {
private val _showSearchUnstaged = MutableStateFlow(false) private val _showSearchUnstaged = MutableStateFlow(false)
@ -77,11 +75,11 @@ class StatusViewModel @Inject constructor(
private val _searchFilterStaged = MutableStateFlow(TextFieldValue("")) private val _searchFilterStaged = MutableStateFlow(TextFieldValue(""))
val searchFilterStaged: StateFlow<TextFieldValue> = _searchFilterStaged val searchFilterStaged: StateFlow<TextFieldValue> = _searchFilterStaged
val swapUncommittedChanges = appSettingsRepository.swapUncommittedChangesFlow val swapUncommittedChanges = appSettings.swapUncommittedChangesFlow
val rebaseInteractiveState = sharedRepositoryStateManager.rebaseInteractiveState val rebaseInteractiveState = sharedRepositoryStateManager.rebaseInteractiveState
private val treeContractedDirectories = MutableStateFlow(emptyList<String>()) private val treeContractedDirectories = MutableStateFlow(emptyList<String>())
private val showAsTree = appSettingsRepository.showChangesAsTreeFlow private val showAsTree = appSettings.showChangesAsTreeFlow
private val _stageState = MutableStateFlow<StageState>(StageState.Loading) private val _stageState = MutableStateFlow<StageState>(StageState.Loading)
private val stageStateFiltered: StateFlow<StageState> = combine( private val stageStateFiltered: StateFlow<StageState> = combine(
@ -508,7 +506,7 @@ class StatusViewModel @Inject constructor(
} }
fun alternateShowAsTree() { fun alternateShowAsTree() {
appSettingsRepository.showChangesAsTree = !appSettingsRepository.showChangesAsTree appSettings.showChangesAsTree = !appSettings.showChangesAsTree
} }
fun stageByDirectory(dir: String) = tabState.runOperation( fun stageByDirectory(dir: String) = tabState.runOperation(