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("org.junit.jupiter:junit-jupiter:5.9.2")
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("net.i2p.crypto:eddsa:0.3.0")
implementation("net.java.dev.jna:jna:5.13.0")
implementation("io.github.oshai:kotlin-logging-jvm:5.0.1")
implementation("org.slf4j:slf4j-api: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 {

View File

@ -28,8 +28,8 @@ import com.jetpackduba.gitnuro.git.AppGpgSigner
import com.jetpackduba.gitnuro.logging.printError
import com.jetpackduba.gitnuro.managers.AppStateManager
import com.jetpackduba.gitnuro.managers.TempFilesManager
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository
import com.jetpackduba.gitnuro.repositories.ProxySettings
import com.jetpackduba.gitnuro.preferences.AppSettings
import com.jetpackduba.gitnuro.preferences.ProxySettings
import com.jetpackduba.gitnuro.system.systemSeparator
import com.jetpackduba.gitnuro.theme.AppTheme
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.dialogs.settings.ProxyType
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 java.io.File
import java.net.Authenticator
@ -65,7 +61,7 @@ class App {
lateinit var appStateManager: AppStateManager
@Inject
lateinit var appSettingsRepository: AppSettingsRepository
lateinit var appSettings: AppSettings
@Inject
lateinit var appGpgSigner: AppGpgSigner
@ -93,15 +89,15 @@ class App {
logging.initLogging()
initProxySettings()
val windowPlacement = appSettingsRepository.windowPlacement.toWindowPlacement
val windowPlacement = appSettings.windowPlacement.toWindowPlacement
val dirToOpen = getDirToOpen(args)
appEnvInfo.isFlatpak = args.contains("--flatpak")
appStateManager.loadRepositoriesTabs()
try {
if (appSettingsRepository.theme == Theme.CUSTOM) {
appSettingsRepository.loadCustomTheme()
if (appSettings.theme == Theme.CUSTOM) {
appSettings.loadCustomTheme()
}
} catch (ex: Exception) {
printError(TAG, "Failed to load custom theme")
@ -117,9 +113,9 @@ class App {
application {
var isOpen by remember { mutableStateOf(true) }
val theme by appSettingsRepository.themeState.collectAsState()
val customTheme by appSettingsRepository.customThemeFlow.collectAsState()
val scale by appSettingsRepository.scaleUiFlow.collectAsState()
val theme by appSettings.themeState.collectAsState()
val customTheme by appSettings.customThemeFlow.collectAsState()
val scale by appSettings.scaleUiFlow.collectAsState()
val windowState = rememberWindowState(
placement = windowPlacement,
@ -127,7 +123,7 @@ class App {
)
// Save window state for next time the Window is started
appSettingsRepository.windowPlacement = windowState.placement.preferenceValue
appSettings.windowPlacement = windowState.placement.preferenceValue
if (isOpen) {
Window(
@ -169,7 +165,7 @@ class App {
private fun initProxySettings() {
appStateManager.appScope.launch {
appSettingsRepository.proxyFlow.collect { proxySettings ->
appSettings.proxyFlow.collect { proxySettings ->
if (proxySettings.useProxy) {
when (proxySettings.proxyType) {
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.logging.printLog
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.AssistedInject
import org.eclipse.jgit.api.Git
@ -25,7 +25,7 @@ private const val GH_CLI_ARGS = "auth git-credential"
class HttpCredentialsProvider @AssistedInject constructor(
private val credentialsStateManager: CredentialsStateManager,
private val shellManager: IShellManager,
private val appSettingsRepository: AppSettingsRepository,
private val appSettings: AppSettings,
private val credentialsCacheRepository: CredentialsCacheRepository,
@Assisted val git: Git?,
) : CredentialsProvider(), CredentialsCache {
@ -71,7 +71,7 @@ class HttpCredentialsProvider @AssistedInject constructor(
}
if (sslTrustNowItem != null) {
sslTrustNowItem.value = appSettingsRepository.verifySsl
sslTrustNowItem.value = appSettings.verifySsl
}
val externalCredentialsHelper = getExternalCredentialsHelper(uri, git)
@ -86,7 +86,7 @@ class HttpCredentialsProvider @AssistedInject constructor(
userItem.value = credentials.user
passwordItem.value = credentials.password.toCharArray()
if (appSettingsRepository.cacheCredentialsInMemory) {
if (appSettings.cacheCredentialsInMemory) {
credentialsCached = CredentialsType.HttpCredentials(
url = uri.toString(),
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.IShellManager
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.ui.TabsManager
import com.jetpackduba.gitnuro.updates.UpdatesRepository
@ -32,7 +32,7 @@ interface AppComponent {
fun settingsViewModel(): SettingsViewModel
fun credentialsStateManager(): CredentialsStateManager
fun appPreferences(): AppSettingsRepository
fun appPreferences(): AppSettings
fun appEnvInfo(): AppEnvInfo

View File

@ -1,6 +1,6 @@
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.withContext
import org.eclipse.jgit.api.Git
@ -10,13 +10,13 @@ import javax.inject.Inject
class PullBranchUseCase @Inject constructor(
private val handleTransportUseCase: HandleTransportUseCase,
private val appSettingsRepository: AppSettingsRepository,
private val appSettings: AppSettings,
) {
suspend operator fun invoke(git: Git, pullType: PullType) = withContext(Dispatchers.IO) {
val pullWithRebase = when (pullType) {
PullType.REBASE -> true
PullType.MERGE -> false
PullType.DEFAULT -> appSettingsRepository.pullRebase
PullType.DEFAULT -> appSettings.pullRebase
}
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.isRejected
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.isActive
import kotlinx.coroutines.withContext
@ -18,7 +18,7 @@ import javax.inject.Inject
class PushBranchUseCase @Inject constructor(
private val handleTransportUseCase: HandleTransportUseCase,
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
suspend operator fun invoke(git: Git, force: Boolean, pushTags: Boolean) = withContext(Dispatchers.IO) {
@ -53,7 +53,7 @@ class PushBranchUseCase @Inject constructor(
}
.setForce(force)
.run {
if (force && appSettingsRepository.pushWithLease) {
if (force && appSettings.pushWithLease) {
if (tracking != null) {
val remoteBranchName = "${Constants.R_REMOTES}$remote/${tracking.branch}"

View File

@ -1,6 +1,7 @@
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>) {
initPreferencesPath()

View File

@ -1,7 +1,7 @@
package com.jetpackduba.gitnuro.managers
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.Dispatchers
import kotlinx.coroutines.cancel
@ -15,7 +15,7 @@ import javax.inject.Singleton
@Singleton
class AppStateManager @Inject constructor(
private val appSettingsRepository: AppSettingsRepository,
private val appSettings: AppSettings,
@AppCoroutineScope val appScope: CoroutineScope,
) {
private val mutex = Mutex()
@ -39,14 +39,14 @@ class AppStateManager @Inject constructor(
if (_latestOpenedRepositoriesPaths.count() > 10)
_latestOpenedRepositoriesPaths.removeLast()
appSettingsRepository.latestOpenedRepositoriesPath = Json.encodeToString(_latestOpenedRepositoriesPaths)
appSettings.latestOpenedRepositoriesPath = Json.encodeToString(_latestOpenedRepositoriesPaths)
} finally {
mutex.unlock()
}
}
fun loadRepositoriesTabs() {
val repositoriesPathsSaved = appSettingsRepository.latestOpenedRepositoriesPath
val repositoriesPathsSaved = appSettings.latestOpenedRepositoriesPath
if (repositoriesPathsSaved.isNotEmpty()) {
val repositories = Json.decodeFromString<List<String>>(repositoriesPathsSaved)
_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.preferences.WindowsPlacementPreference
import com.jetpackduba.gitnuro.system.OS
import com.jetpackduba.gitnuro.system.currentOs
import com.jetpackduba.gitnuro.theme.ColorsScheme
@ -58,7 +57,7 @@ private const val DEFAULT_VERIFY_SSL = true
const val DEFAULT_UI_SCALE = -1f
@Singleton
class AppSettingsRepository @Inject constructor() {
class AppSettings @Inject constructor() {
private val preferences: Preferences = Preferences.userRoot().node(PREFERENCES_NAME)
private val _themeState = MutableStateFlow(theme)
@ -374,6 +373,8 @@ data class ProxySettings(
val hostPassword: String,
)
// TODO migrate old prefs path to new one?
fun initPreferencesPath() {
if (currentOs == OS.LINUX) {
val xdgConfigHome: String? = System.getenv("XDG_CONFIG_HOME")

View File

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

View File

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

View File

@ -18,7 +18,7 @@ import androidx.compose.ui.unit.dp
import com.jetpackduba.gitnuro.AppIcons
import com.jetpackduba.gitnuro.extensions.handMouseClickable
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.ui.components.*
import com.jetpackduba.gitnuro.ui.dialogs.errors.ErrorDialog

View File

@ -1,5 +1,6 @@
package com.jetpackduba.gitnuro.ui.tree_files
import arrow.core.compareTo
import com.jetpackduba.gitnuro.system.systemSeparator
import kotlin.math.max
@ -59,7 +60,9 @@ private class PathsComparator : Comparator<String> {
override fun compare(path1: String, path2: String): Int {
val path1Parts = path1.split(systemSeparator)
val path2Parts = path2.split(systemSeparator)
path1Parts.compareTo(path2Parts)
val maxIndex = max(path1Parts.count(), path2Parts.count())
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.TabState
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.entriesToTreeEntry
import kotlinx.coroutines.CoroutineScope
@ -24,7 +24,7 @@ private const val MIN_TIME_IN_MS_TO_SHOW_LOAD = 300L
class CommitChangesViewModel @Inject constructor(
private val tabState: TabState,
private val getCommitDiffEntriesUseCase: GetCommitDiffEntriesUseCase,
private val appSettingsRepository: AppSettingsRepository,
private val appSettings: AppSettings,
tabScope: CoroutineScope,
) {
private val _showSearch = MutableStateFlow(false)
@ -39,7 +39,7 @@ class CommitChangesViewModel @Inject constructor(
val textScroll = MutableStateFlow(ScrollState(0))
val showAsTree = appSettingsRepository.showChangesAsTreeFlow
val showAsTree = appSettings.showChangesAsTreeFlow
private val treeContractedDirectories = MutableStateFlow(emptyList<String>())
private val _commitChangesState = MutableStateFlow<CommitChangesState>(CommitChangesState.Loading)
@ -133,7 +133,7 @@ class CommitChangesViewModel @Inject constructor(
}
fun alternateShowAsTree() {
appSettingsRepository.showChangesAsTree = !appSettingsRepository.showChangesAsTree
appSettings.showChangesAsTree = !appSettings.showChangesAsTree
}
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.diff.*
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.ui.TabsManager
import kotlinx.coroutines.CoroutineScope
@ -33,7 +33,7 @@ class DiffViewModel @Inject constructor(
private val stageEntryUseCase: StageEntryUseCase,
private val unstageEntryUseCase: UnstageEntryUseCase,
private val openFileInExternalAppUseCase: OpenFileInExternalAppUseCase,
private val settings: AppSettingsRepository,
private val settings: AppSettings,
private val generateSplitHunkFromDiffResultUseCase: GenerateSplitHunkFromDiffResultUseCase,
private val discardUnstagedHunkLineUseCase: DiscardUnstagedHunkLineUseCase,
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.GenerateSplitHunkFromDiffResultUseCase
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.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
@ -23,7 +23,7 @@ class HistoryViewModel @Inject constructor(
private val tabState: TabState,
private val formatDiffUseCase: FormatDiffUseCase,
private val getCommitDiffEntriesUseCase: GetCommitDiffEntriesUseCase,
private val settings: AppSettingsRepository,
private val settings: AppSettings,
private val generateSplitHunkFromDiffResultUseCase: GenerateSplitHunkFromDiffResultUseCase,
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.rebase.StartRebaseInteractiveUseCase
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.GetStatusSummaryUseCase
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.log.LogDialog
import kotlinx.coroutines.CoroutineScope
@ -56,7 +57,7 @@ class LogViewModel @Inject constructor(
private val createTagOnCommitUseCase: CreateTagOnCommitUseCase,
private val startRebaseInteractiveUseCase: StartRebaseInteractiveUseCase,
private val tabState: TabState,
private val appSettingsRepository: AppSettingsRepository,
private val appSettings: AppSettings,
tabScope: CoroutineScope,
sharedStashViewModel: SharedStashViewModel,
sharedBranchesViewModel: SharedBranchesViewModel,
@ -100,12 +101,12 @@ class LogViewModel @Inject constructor(
init {
tabScope.launch {
appSettingsRepository.commitsLimitEnabledFlow.drop(1).collectLatest {
appSettings.commitsLimitEnabledFlow.drop(1).collectLatest {
tabState.refreshData(RefreshType.ONLY_LOG)
}
}
tabScope.launch {
appSettingsRepository.commitsLimitFlow.collectLatest {
appSettings.commitsLimitFlow.collectLatest {
tabState.refreshData(RefreshType.ONLY_LOG)
}
}
@ -139,13 +140,13 @@ class LogViewModel @Inject constructor(
)
val hasUncommittedChanges = statusSummary.total > 0
val commitsLimit = if (appSettingsRepository.commitsLimitEnabled) {
appSettingsRepository.commitsLimit
val commitsLimit = if (appSettings.commitsLimitEnabled) {
appSettings.commitsLimit
} else
Int.MAX_VALUE
val commitsLimitDisplayed = if (appSettingsRepository.commitsLimitEnabled) {
appSettingsRepository.commitsLimit
val commitsLimitDisplayed = if (appSettings.commitsLimitEnabled) {
appSettings.commitsLimit
} else
-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.StashChangesUseCase
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 javax.inject.Inject
@ -23,7 +23,7 @@ class MenuViewModel @Inject constructor(
private val stashChangesUseCase: StashChangesUseCase,
private val stageUntrackedFileUseCase: StageUntrackedFileUseCase,
private val openRepositoryInTerminalUseCase: OpenRepositoryInTerminalUseCase,
private val settings: AppSettingsRepository,
private val settings: AppSettings,
) {
val isPullWithRebaseDefault = settings.pullRebaseFlow

View File

@ -3,10 +3,11 @@ package com.jetpackduba.gitnuro.viewmodels
import com.jetpackduba.gitnuro.Logging
import com.jetpackduba.gitnuro.TaskType
import com.jetpackduba.gitnuro.di.qualifiers.AppCoroutineScope
import com.jetpackduba.gitnuro.git.RefreshType
import com.jetpackduba.gitnuro.logging.printError
import com.jetpackduba.gitnuro.managers.Error
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.PickerType
import com.jetpackduba.gitnuro.theme.Theme
@ -21,7 +22,7 @@ private const val TAG = "SettingsViewModel"
@Singleton
class SettingsViewModel @Inject constructor(
private val appSettingsRepository: AppSettingsRepository,
private val appSettings: AppSettings,
private val openFilePickerUseCase: OpenFilePickerUseCase,
private val logging: Logging,
@AppCoroutineScope private val appScope: CoroutineScope,
@ -29,121 +30,121 @@ class SettingsViewModel @Inject constructor(
// Temporary values to detect changed variables
var commitsLimit: Int = -1
val themeState = appSettingsRepository.themeState
val ffMergeFlow = appSettingsRepository.ffMergeFlow
val pullRebaseFlow = appSettingsRepository.pullRebaseFlow
val pushWithLeaseFlow = appSettingsRepository.pushWithLeaseFlow
val commitsLimitEnabledFlow = appSettingsRepository.commitsLimitEnabledFlow
val swapUncommittedChangesFlow = appSettingsRepository.swapUncommittedChangesFlow
val cacheCredentialsInMemoryFlow = appSettingsRepository.cacheCredentialsInMemoryFlow
val verifySslFlow = appSettingsRepository.verifySslFlow
val terminalPathFlow = appSettingsRepository.terminalPathFlow
val themeState = appSettings.themeState
val ffMergeFlow = appSettings.ffMergeFlow
val pullRebaseFlow = appSettings.pullRebaseFlow
val pushWithLeaseFlow = appSettings.pushWithLeaseFlow
val commitsLimitEnabledFlow = appSettings.commitsLimitEnabledFlow
val swapUncommittedChangesFlow = appSettings.swapUncommittedChangesFlow
val cacheCredentialsInMemoryFlow = appSettings.cacheCredentialsInMemoryFlow
val verifySslFlow = appSettings.verifySslFlow
val terminalPathFlow = appSettings.terminalPathFlow
var scaleUi: Float
get() = appSettingsRepository.scaleUi
get() = appSettings.scaleUi
set(value) {
appSettingsRepository.scaleUi = value
appSettings.scaleUi = value
}
var commitsLimitEnabled: Boolean
get() = appSettingsRepository.commitsLimitEnabled
get() = appSettings.commitsLimitEnabled
set(value) {
appSettingsRepository.commitsLimitEnabled = value
appSettings.commitsLimitEnabled = value
}
var swapUncommittedChanges: Boolean
get() = appSettingsRepository.swapUncommittedChanges
get() = appSettings.swapUncommittedChanges
set(value) {
appSettingsRepository.swapUncommittedChanges = value
appSettings.swapUncommittedChanges = value
}
var ffMerge: Boolean
get() = appSettingsRepository.ffMerge
get() = appSettings.ffMerge
set(value) {
appSettingsRepository.ffMerge = value
appSettings.ffMerge = value
}
var cacheCredentialsInMemory: Boolean
get() = appSettingsRepository.cacheCredentialsInMemory
get() = appSettings.cacheCredentialsInMemory
set(value) {
appSettingsRepository.cacheCredentialsInMemory = value
appSettings.cacheCredentialsInMemory = value
}
var verifySsl: Boolean
get() = appSettingsRepository.verifySsl
get() = appSettings.verifySsl
set(value) {
appSettingsRepository.verifySsl = value
appSettings.verifySsl = value
}
var pullRebase: Boolean
get() = appSettingsRepository.pullRebase
get() = appSettings.pullRebase
set(value) {
appSettingsRepository.pullRebase = value
appSettings.pullRebase = value
}
var pushWithLease: Boolean
get() = appSettingsRepository.pushWithLease
get() = appSettings.pushWithLease
set(value) {
appSettingsRepository.pushWithLease = value
appSettings.pushWithLease = value
}
var theme: Theme
get() = appSettingsRepository.theme
get() = appSettings.theme
set(value) {
appSettingsRepository.theme = value
appSettings.theme = value
}
var terminalPath: String
get() = appSettingsRepository.terminalPath
get() = appSettings.terminalPath
set(value) {
appSettingsRepository.terminalPath = value
appSettings.terminalPath = value
}
var useProxy: Boolean
get() = appSettingsRepository.useProxy
get() = appSettings.useProxy
set(value) {
appSettingsRepository.useProxy = value
appSettings.useProxy = value
}
var proxyType: ProxyType
get() = appSettingsRepository.proxyType
get() = appSettings.proxyType
set(value) {
appSettingsRepository.proxyType = value
appSettings.proxyType = value
}
var proxyHostName: String
get() = appSettingsRepository.proxyHostName
get() = appSettings.proxyHostName
set(value) {
appSettingsRepository.proxyHostName = value
appSettings.proxyHostName = value
}
var proxyPortNumber: Int
get() = appSettingsRepository.proxyPortNumber
get() = appSettings.proxyPortNumber
set(value) {
appSettingsRepository.proxyPortNumber = value
appSettings.proxyPortNumber = value
}
var proxyUseAuth: Boolean
get() = appSettingsRepository.proxyUseAuth
get() = appSettings.proxyUseAuth
set(value) {
appSettingsRepository.proxyUseAuth = value
appSettings.proxyUseAuth = value
}
var proxyHostUser: String
get() = appSettingsRepository.proxyHostUser
get() = appSettings.proxyHostUser
set(value) {
appSettingsRepository.proxyHostUser = value
appSettings.proxyHostUser = value
}
var proxyHostPassword: String
get() = appSettingsRepository.proxyHostPassword
get() = appSettings.proxyHostPassword
set(value) {
appSettingsRepository.proxyHostPassword = value
appSettings.proxyHostPassword = value
}
fun saveCustomTheme(filePath: String): Error? {
return try {
appSettingsRepository.saveCustomTheme(filePath)
appSettings.saveCustomTheme(filePath)
null
} catch (ex: Exception) {
ex.printStackTrace()
@ -157,14 +158,14 @@ class SettingsViewModel @Inject constructor(
}
fun resetInfo() {
commitsLimit = appSettingsRepository.commitsLimit
commitsLimit = appSettings.commitsLimit
}
fun savePendingChanges() = appScope.launch {
val commitsLimit = this@SettingsViewModel.commitsLimit
if (appSettingsRepository.commitsLimit != commitsLimit) {
appSettingsRepository.setCommitsLimit(commitsLimit)
if (appSettings.commitsLimit != 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.MergeBranchUseCase
import com.jetpackduba.gitnuro.git.rebase.RebaseBranchUseCase
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository
import com.jetpackduba.gitnuro.repositories.BranchesVisibilityRepository
import com.jetpackduba.gitnuro.preferences.AppSettings
import kotlinx.coroutines.Job
import org.eclipse.jgit.internal.diffmergetool.MergeTools
import org.eclipse.jgit.lib.Ref
import javax.inject.Inject
@ -20,19 +18,15 @@ interface ISharedBranchesViewModel {
fun deleteBranch(branch: Ref): Job
fun checkoutRef(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(
private val rebaseBranchUseCase: RebaseBranchUseCase,
private val tabState: TabState,
private val appSettingsRepository: AppSettingsRepository,
private val appSettings: AppSettings,
private val mergeBranchUseCase: MergeBranchUseCase,
private val deleteBranchUseCase: DeleteBranchUseCase,
private val checkoutRefUseCase: CheckoutRefUseCase,
private val branchesVisibilityRepository: BranchesVisibilityRepository,
) : ISharedBranchesViewModel {
override fun mergeBranch(ref: Ref) = tabState.safeProcessing(
@ -41,7 +35,7 @@ class SharedBranchesViewModel @Inject constructor(
subtitle = "Merging branch ${ref.simpleName}",
taskType = TaskType.MERGE_BRANCH,
) { git ->
mergeBranchUseCase(git, ref, appSettingsRepository.ffMerge)
mergeBranchUseCase(git, ref, appSettings.ffMerge)
}
override fun deleteBranch(branch: Ref) = tabState.safeProcessing(
@ -70,30 +64,4 @@ class SharedBranchesViewModel @Inject constructor(
) { git ->
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.workspace.*
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.entriesToTreeEntry
import kotlinx.coroutines.CoroutineScope
@ -30,8 +30,6 @@ import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
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.RepositoryState
import java.io.File
@ -62,7 +60,7 @@ class StatusViewModel @Inject constructor(
private val saveAuthorUseCase: SaveAuthorUseCase,
private val sharedRepositoryStateManager: SharedRepositoryStateManager,
private val getSpecificCommitMessageUseCase: GetSpecificCommitMessageUseCase,
private val appSettingsRepository: AppSettingsRepository,
private val appSettings: AppSettings,
tabScope: CoroutineScope,
) {
private val _showSearchUnstaged = MutableStateFlow(false)
@ -77,11 +75,11 @@ class StatusViewModel @Inject constructor(
private val _searchFilterStaged = MutableStateFlow(TextFieldValue(""))
val searchFilterStaged: StateFlow<TextFieldValue> = _searchFilterStaged
val swapUncommittedChanges = appSettingsRepository.swapUncommittedChangesFlow
val swapUncommittedChanges = appSettings.swapUncommittedChangesFlow
val rebaseInteractiveState = sharedRepositoryStateManager.rebaseInteractiveState
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 stageStateFiltered: StateFlow<StageState> = combine(
@ -508,7 +506,7 @@ class StatusViewModel @Inject constructor(
}
fun alternateShowAsTree() {
appSettingsRepository.showChangesAsTree = !appSettingsRepository.showChangesAsTree
appSettings.showChangesAsTree = !appSettings.showChangesAsTree
}
fun stageByDirectory(dir: String) = tabState.runOperation(