Renamed AppSettings to repository
This commit is contained in:
parent
8ef62d126f
commit
b2777d2d90
@ -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.9.0")
|
||||
implementation("com.squareup.retrofit2:retrofit:2.11.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("io.arrow-kt:arrow-core:1.2.0")
|
||||
implementation("androidx.datastore:datastore-preferences-core:1.0.0")
|
||||
}
|
||||
|
||||
fun currentOs(): OS {
|
||||
|
@ -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.preferences.AppSettings
|
||||
import com.jetpackduba.gitnuro.preferences.ProxySettings
|
||||
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository
|
||||
import com.jetpackduba.gitnuro.repositories.ProxySettings
|
||||
import com.jetpackduba.gitnuro.system.systemSeparator
|
||||
import com.jetpackduba.gitnuro.theme.AppTheme
|
||||
import com.jetpackduba.gitnuro.theme.Theme
|
||||
@ -42,6 +42,10 @@ 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
|
||||
@ -61,7 +65,7 @@ class App {
|
||||
lateinit var appStateManager: AppStateManager
|
||||
|
||||
@Inject
|
||||
lateinit var appSettings: AppSettings
|
||||
lateinit var appSettingsRepository: AppSettingsRepository
|
||||
|
||||
@Inject
|
||||
lateinit var appGpgSigner: AppGpgSigner
|
||||
@ -89,15 +93,15 @@ class App {
|
||||
logging.initLogging()
|
||||
initProxySettings()
|
||||
|
||||
val windowPlacement = appSettings.windowPlacement.toWindowPlacement
|
||||
val windowPlacement = appSettingsRepository.windowPlacement.toWindowPlacement
|
||||
val dirToOpen = getDirToOpen(args)
|
||||
|
||||
appEnvInfo.isFlatpak = args.contains("--flatpak")
|
||||
appStateManager.loadRepositoriesTabs()
|
||||
|
||||
try {
|
||||
if (appSettings.theme == Theme.CUSTOM) {
|
||||
appSettings.loadCustomTheme()
|
||||
if (appSettingsRepository.theme == Theme.CUSTOM) {
|
||||
appSettingsRepository.loadCustomTheme()
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
printError(TAG, "Failed to load custom theme")
|
||||
@ -113,9 +117,9 @@ class App {
|
||||
|
||||
application {
|
||||
var isOpen by remember { mutableStateOf(true) }
|
||||
val theme by appSettings.themeState.collectAsState()
|
||||
val customTheme by appSettings.customThemeFlow.collectAsState()
|
||||
val scale by appSettings.scaleUiFlow.collectAsState()
|
||||
val theme by appSettingsRepository.themeState.collectAsState()
|
||||
val customTheme by appSettingsRepository.customThemeFlow.collectAsState()
|
||||
val scale by appSettingsRepository.scaleUiFlow.collectAsState()
|
||||
|
||||
val windowState = rememberWindowState(
|
||||
placement = windowPlacement,
|
||||
@ -123,7 +127,7 @@ class App {
|
||||
)
|
||||
|
||||
// Save window state for next time the Window is started
|
||||
appSettings.windowPlacement = windowState.placement.preferenceValue
|
||||
appSettingsRepository.windowPlacement = windowState.placement.preferenceValue
|
||||
|
||||
if (isOpen) {
|
||||
Window(
|
||||
@ -165,7 +169,7 @@ class App {
|
||||
|
||||
private fun initProxySettings() {
|
||||
appStateManager.appScope.launch {
|
||||
appSettings.proxyFlow.collect { proxySettings ->
|
||||
appSettingsRepository.proxyFlow.collect { proxySettings ->
|
||||
if (proxySettings.useProxy) {
|
||||
when (proxySettings.proxyType) {
|
||||
ProxyType.HTTP -> setHttpProxy(proxySettings)
|
||||
|
@ -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.preferences.AppSettings
|
||||
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository
|
||||
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 appSettings: AppSettings,
|
||||
private val appSettingsRepository: AppSettingsRepository,
|
||||
private val credentialsCacheRepository: CredentialsCacheRepository,
|
||||
@Assisted val git: Git?,
|
||||
) : CredentialsProvider(), CredentialsCache {
|
||||
@ -71,7 +71,7 @@ class HttpCredentialsProvider @AssistedInject constructor(
|
||||
}
|
||||
|
||||
if (sslTrustNowItem != null) {
|
||||
sslTrustNowItem.value = appSettings.verifySsl
|
||||
sslTrustNowItem.value = appSettingsRepository.verifySsl
|
||||
}
|
||||
|
||||
val externalCredentialsHelper = getExternalCredentialsHelper(uri, git)
|
||||
@ -86,7 +86,7 @@ class HttpCredentialsProvider @AssistedInject constructor(
|
||||
userItem.value = credentials.user
|
||||
passwordItem.value = credentials.password.toCharArray()
|
||||
|
||||
if (appSettings.cacheCredentialsInMemory) {
|
||||
if (appSettingsRepository.cacheCredentialsInMemory) {
|
||||
credentialsCached = CredentialsType.HttpCredentials(
|
||||
url = uri.toString(),
|
||||
userName = credentials.user,
|
||||
|
@ -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.preferences.AppSettings
|
||||
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository
|
||||
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(): AppSettings
|
||||
fun appPreferences(): AppSettingsRepository
|
||||
|
||||
fun appEnvInfo(): AppEnvInfo
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.jetpackduba.gitnuro.git.remote_operations
|
||||
|
||||
import com.jetpackduba.gitnuro.preferences.AppSettings
|
||||
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository
|
||||
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 appSettings: AppSettings,
|
||||
private val appSettingsRepository: AppSettingsRepository,
|
||||
) {
|
||||
suspend operator fun invoke(git: Git, pullType: PullType) = withContext(Dispatchers.IO) {
|
||||
val pullWithRebase = when (pullType) {
|
||||
PullType.REBASE -> true
|
||||
PullType.MERGE -> false
|
||||
PullType.DEFAULT -> appSettings.pullRebase
|
||||
PullType.DEFAULT -> appSettingsRepository.pullRebase
|
||||
}
|
||||
|
||||
handleTransportUseCase(git) {
|
||||
|
@ -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.preferences.AppSettings
|
||||
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository
|
||||
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 appSettings: AppSettings,
|
||||
private val appSettingsRepository: AppSettingsRepository,
|
||||
) {
|
||||
// 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 && appSettings.pushWithLease) {
|
||||
if (force && appSettingsRepository.pushWithLease) {
|
||||
|
||||
if (tracking != null) {
|
||||
val remoteBranchName = "${Constants.R_REMOTES}$remote/${tracking.branch}"
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.jetpackduba.gitnuro
|
||||
|
||||
import com.jetpackduba.gitnuro.managers.ShellManager
|
||||
import com.jetpackduba.gitnuro.preferences.initPreferencesPath
|
||||
import com.jetpackduba.gitnuro.repositories.initPreferencesPath
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
initPreferencesPath()
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.jetpackduba.gitnuro.managers
|
||||
|
||||
import com.jetpackduba.gitnuro.di.qualifiers.AppCoroutineScope
|
||||
import com.jetpackduba.gitnuro.preferences.AppSettings
|
||||
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository
|
||||
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 appSettings: AppSettings,
|
||||
private val appSettingsRepository: AppSettingsRepository,
|
||||
@AppCoroutineScope val appScope: CoroutineScope,
|
||||
) {
|
||||
private val mutex = Mutex()
|
||||
@ -39,14 +39,14 @@ class AppStateManager @Inject constructor(
|
||||
if (_latestOpenedRepositoriesPaths.count() > 10)
|
||||
_latestOpenedRepositoriesPaths.removeLast()
|
||||
|
||||
appSettings.latestOpenedRepositoriesPath = Json.encodeToString(_latestOpenedRepositoriesPaths)
|
||||
appSettingsRepository.latestOpenedRepositoriesPath = Json.encodeToString(_latestOpenedRepositoriesPaths)
|
||||
} finally {
|
||||
mutex.unlock()
|
||||
}
|
||||
}
|
||||
|
||||
fun loadRepositoriesTabs() {
|
||||
val repositoriesPathsSaved = appSettings.latestOpenedRepositoriesPath
|
||||
val repositoriesPathsSaved = appSettingsRepository.latestOpenedRepositoriesPath
|
||||
if (repositoriesPathsSaved.isNotEmpty()) {
|
||||
val repositories = Json.decodeFromString<List<String>>(repositoriesPathsSaved)
|
||||
_latestOpenedRepositoriesPaths.addAll(repositories)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.jetpackduba.gitnuro.preferences
|
||||
package com.jetpackduba.gitnuro.repositories
|
||||
|
||||
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
|
||||
@ -57,7 +58,7 @@ private const val DEFAULT_VERIFY_SSL = true
|
||||
const val DEFAULT_UI_SCALE = -1f
|
||||
|
||||
@Singleton
|
||||
class AppSettings @Inject constructor() {
|
||||
class AppSettingsRepository @Inject constructor() {
|
||||
private val preferences: Preferences = Preferences.userRoot().node(PREFERENCES_NAME)
|
||||
|
||||
private val _themeState = MutableStateFlow(theme)
|
||||
@ -373,8 +374,6 @@ 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")
|
@ -1,13 +1,13 @@
|
||||
package com.jetpackduba.gitnuro.terminal
|
||||
|
||||
import com.jetpackduba.gitnuro.preferences.AppSettings
|
||||
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository
|
||||
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: AppSettings,
|
||||
private val settings: AppSettingsRepository,
|
||||
) {
|
||||
operator fun invoke(path: String) {
|
||||
val terminalEmulators = terminalProvider.getTerminalEmulators()
|
||||
|
@ -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.preferences.AppSettings
|
||||
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository
|
||||
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 appSettings: AppSettings
|
||||
private val appSettingsRepository: AppSettingsRepository
|
||||
) {
|
||||
lateinit var appComponent: AppComponent
|
||||
|
||||
@ -27,7 +27,7 @@ class TabsManager @Inject constructor(
|
||||
val currentTab: StateFlow<TabInformation?> = _currentTab
|
||||
|
||||
fun loadPersistedTabs() {
|
||||
val repositoriesSaved = appSettings.latestTabsOpened
|
||||
val repositoriesSaved = appSettingsRepository.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 = appSettings.latestRepositoryTabSelected
|
||||
val latestSelectedTabPath = appSettingsRepository.latestRepositoryTabSelected
|
||||
|
||||
val latestSelectedTab = repositoriesList.firstOrNull { it.path == latestSelectedTabPath }
|
||||
|
||||
@ -78,7 +78,7 @@ class TabsManager @Inject constructor(
|
||||
}
|
||||
|
||||
private fun persistTabSelected(tab: TabInformation) {
|
||||
appSettings.latestRepositoryTabSelected = tab.path.orEmpty()
|
||||
appSettingsRepository.latestRepositoryTabSelected = tab.path.orEmpty()
|
||||
}
|
||||
|
||||
fun closeTab(tab: TabInformation) {
|
||||
@ -118,7 +118,7 @@ class TabsManager @Inject constructor(
|
||||
val tabsPaths = tabsFlow.value
|
||||
.mapNotNull { it.path }
|
||||
|
||||
appSettings.latestTabsOpened = Json.encodeToString(tabsPaths)
|
||||
appSettingsRepository.latestTabsOpened = Json.encodeToString(tabsPaths)
|
||||
}
|
||||
|
||||
fun addNewEmptyTab() {
|
||||
|
@ -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.preferences.DEFAULT_UI_SCALE
|
||||
import com.jetpackduba.gitnuro.repositories.DEFAULT_UI_SCALE
|
||||
import com.jetpackduba.gitnuro.theme.*
|
||||
import com.jetpackduba.gitnuro.ui.components.*
|
||||
import com.jetpackduba.gitnuro.ui.dialogs.errors.ErrorDialog
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.jetpackduba.gitnuro.ui.tree_files
|
||||
|
||||
import arrow.core.compareTo
|
||||
import com.jetpackduba.gitnuro.system.systemSeparator
|
||||
import kotlin.math.max
|
||||
|
||||
@ -61,8 +60,6 @@ private class PathsComparator : Comparator<String> {
|
||||
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) {
|
||||
|
@ -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.preferences.AppSettings
|
||||
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository
|
||||
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 appSettings: AppSettings,
|
||||
private val appSettingsRepository: AppSettingsRepository,
|
||||
tabScope: CoroutineScope,
|
||||
) {
|
||||
private val _showSearch = MutableStateFlow(false)
|
||||
@ -39,7 +39,7 @@ class CommitChangesViewModel @Inject constructor(
|
||||
|
||||
val textScroll = MutableStateFlow(ScrollState(0))
|
||||
|
||||
val showAsTree = appSettings.showChangesAsTreeFlow
|
||||
val showAsTree = appSettingsRepository.showChangesAsTreeFlow
|
||||
private val treeContractedDirectories = MutableStateFlow(emptyList<String>())
|
||||
|
||||
private val _commitChangesState = MutableStateFlow<CommitChangesState>(CommitChangesState.Loading)
|
||||
@ -133,7 +133,7 @@ class CommitChangesViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
fun alternateShowAsTree() {
|
||||
appSettings.showChangesAsTree = !appSettings.showChangesAsTree
|
||||
appSettingsRepository.showChangesAsTree = !appSettingsRepository.showChangesAsTree
|
||||
}
|
||||
|
||||
fun onDirectoryClicked(directoryPath: String) {
|
||||
|
@ -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.preferences.AppSettings
|
||||
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository
|
||||
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: AppSettings,
|
||||
private val settings: AppSettingsRepository,
|
||||
private val generateSplitHunkFromDiffResultUseCase: GenerateSplitHunkFromDiffResultUseCase,
|
||||
private val discardUnstagedHunkLineUseCase: DiscardUnstagedHunkLineUseCase,
|
||||
private val tabsManager: TabsManager,
|
||||
|
@ -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.preferences.AppSettings
|
||||
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository
|
||||
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: AppSettings,
|
||||
private val settings: AppSettingsRepository,
|
||||
private val generateSplitHunkFromDiffResultUseCase: GenerateSplitHunkFromDiffResultUseCase,
|
||||
private val tabScope: CoroutineScope,
|
||||
) {
|
||||
|
@ -15,11 +15,10 @@ 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.preferences.AppSettings
|
||||
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository
|
||||
import com.jetpackduba.gitnuro.ui.SelectedItem
|
||||
import com.jetpackduba.gitnuro.ui.log.LogDialog
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@ -57,7 +56,7 @@ class LogViewModel @Inject constructor(
|
||||
private val createTagOnCommitUseCase: CreateTagOnCommitUseCase,
|
||||
private val startRebaseInteractiveUseCase: StartRebaseInteractiveUseCase,
|
||||
private val tabState: TabState,
|
||||
private val appSettings: AppSettings,
|
||||
private val appSettingsRepository: AppSettingsRepository,
|
||||
tabScope: CoroutineScope,
|
||||
sharedStashViewModel: SharedStashViewModel,
|
||||
sharedBranchesViewModel: SharedBranchesViewModel,
|
||||
@ -101,12 +100,12 @@ class LogViewModel @Inject constructor(
|
||||
|
||||
init {
|
||||
tabScope.launch {
|
||||
appSettings.commitsLimitEnabledFlow.drop(1).collectLatest {
|
||||
appSettingsRepository.commitsLimitEnabledFlow.drop(1).collectLatest {
|
||||
tabState.refreshData(RefreshType.ONLY_LOG)
|
||||
}
|
||||
}
|
||||
tabScope.launch {
|
||||
appSettings.commitsLimitFlow.collectLatest {
|
||||
appSettingsRepository.commitsLimitFlow.collectLatest {
|
||||
tabState.refreshData(RefreshType.ONLY_LOG)
|
||||
}
|
||||
}
|
||||
@ -140,13 +139,13 @@ class LogViewModel @Inject constructor(
|
||||
)
|
||||
|
||||
val hasUncommittedChanges = statusSummary.total > 0
|
||||
val commitsLimit = if (appSettings.commitsLimitEnabled) {
|
||||
appSettings.commitsLimit
|
||||
val commitsLimit = if (appSettingsRepository.commitsLimitEnabled) {
|
||||
appSettingsRepository.commitsLimit
|
||||
} else
|
||||
Int.MAX_VALUE
|
||||
|
||||
val commitsLimitDisplayed = if (appSettings.commitsLimitEnabled) {
|
||||
appSettings.commitsLimit
|
||||
val commitsLimitDisplayed = if (appSettingsRepository.commitsLimitEnabled) {
|
||||
appSettingsRepository.commitsLimit
|
||||
} else
|
||||
-1
|
||||
|
||||
|
@ -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.preferences.AppSettings
|
||||
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository
|
||||
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: AppSettings,
|
||||
private val settings: AppSettingsRepository,
|
||||
) {
|
||||
val isPullWithRebaseDefault = settings.pullRebaseFlow
|
||||
|
||||
|
@ -3,11 +3,10 @@ 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.preferences.AppSettings
|
||||
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository
|
||||
import com.jetpackduba.gitnuro.system.OpenFilePickerUseCase
|
||||
import com.jetpackduba.gitnuro.system.PickerType
|
||||
import com.jetpackduba.gitnuro.theme.Theme
|
||||
@ -22,7 +21,7 @@ private const val TAG = "SettingsViewModel"
|
||||
|
||||
@Singleton
|
||||
class SettingsViewModel @Inject constructor(
|
||||
private val appSettings: AppSettings,
|
||||
private val appSettingsRepository: AppSettingsRepository,
|
||||
private val openFilePickerUseCase: OpenFilePickerUseCase,
|
||||
private val logging: Logging,
|
||||
@AppCoroutineScope private val appScope: CoroutineScope,
|
||||
@ -30,121 +29,121 @@ class SettingsViewModel @Inject constructor(
|
||||
// Temporary values to detect changed variables
|
||||
var commitsLimit: Int = -1
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
var scaleUi: Float
|
||||
get() = appSettings.scaleUi
|
||||
get() = appSettingsRepository.scaleUi
|
||||
set(value) {
|
||||
appSettings.scaleUi = value
|
||||
appSettingsRepository.scaleUi = value
|
||||
}
|
||||
|
||||
var commitsLimitEnabled: Boolean
|
||||
get() = appSettings.commitsLimitEnabled
|
||||
get() = appSettingsRepository.commitsLimitEnabled
|
||||
set(value) {
|
||||
appSettings.commitsLimitEnabled = value
|
||||
appSettingsRepository.commitsLimitEnabled = value
|
||||
}
|
||||
|
||||
var swapUncommittedChanges: Boolean
|
||||
get() = appSettings.swapUncommittedChanges
|
||||
get() = appSettingsRepository.swapUncommittedChanges
|
||||
set(value) {
|
||||
appSettings.swapUncommittedChanges = value
|
||||
appSettingsRepository.swapUncommittedChanges = value
|
||||
}
|
||||
|
||||
var ffMerge: Boolean
|
||||
get() = appSettings.ffMerge
|
||||
get() = appSettingsRepository.ffMerge
|
||||
set(value) {
|
||||
appSettings.ffMerge = value
|
||||
appSettingsRepository.ffMerge = value
|
||||
}
|
||||
|
||||
var cacheCredentialsInMemory: Boolean
|
||||
get() = appSettings.cacheCredentialsInMemory
|
||||
get() = appSettingsRepository.cacheCredentialsInMemory
|
||||
set(value) {
|
||||
appSettings.cacheCredentialsInMemory = value
|
||||
appSettingsRepository.cacheCredentialsInMemory = value
|
||||
}
|
||||
|
||||
var verifySsl: Boolean
|
||||
get() = appSettings.verifySsl
|
||||
get() = appSettingsRepository.verifySsl
|
||||
set(value) {
|
||||
appSettings.verifySsl = value
|
||||
appSettingsRepository.verifySsl = value
|
||||
}
|
||||
|
||||
var pullRebase: Boolean
|
||||
get() = appSettings.pullRebase
|
||||
get() = appSettingsRepository.pullRebase
|
||||
set(value) {
|
||||
appSettings.pullRebase = value
|
||||
appSettingsRepository.pullRebase = value
|
||||
}
|
||||
|
||||
var pushWithLease: Boolean
|
||||
get() = appSettings.pushWithLease
|
||||
get() = appSettingsRepository.pushWithLease
|
||||
set(value) {
|
||||
appSettings.pushWithLease = value
|
||||
appSettingsRepository.pushWithLease = value
|
||||
}
|
||||
|
||||
var theme: Theme
|
||||
get() = appSettings.theme
|
||||
get() = appSettingsRepository.theme
|
||||
set(value) {
|
||||
appSettings.theme = value
|
||||
appSettingsRepository.theme = value
|
||||
}
|
||||
|
||||
var terminalPath: String
|
||||
get() = appSettings.terminalPath
|
||||
get() = appSettingsRepository.terminalPath
|
||||
set(value) {
|
||||
appSettings.terminalPath = value
|
||||
appSettingsRepository.terminalPath = value
|
||||
}
|
||||
|
||||
var useProxy: Boolean
|
||||
get() = appSettings.useProxy
|
||||
get() = appSettingsRepository.useProxy
|
||||
set(value) {
|
||||
appSettings.useProxy = value
|
||||
appSettingsRepository.useProxy = value
|
||||
}
|
||||
|
||||
var proxyType: ProxyType
|
||||
get() = appSettings.proxyType
|
||||
get() = appSettingsRepository.proxyType
|
||||
set(value) {
|
||||
appSettings.proxyType = value
|
||||
appSettingsRepository.proxyType = value
|
||||
}
|
||||
|
||||
var proxyHostName: String
|
||||
get() = appSettings.proxyHostName
|
||||
get() = appSettingsRepository.proxyHostName
|
||||
set(value) {
|
||||
appSettings.proxyHostName = value
|
||||
appSettingsRepository.proxyHostName = value
|
||||
}
|
||||
|
||||
var proxyPortNumber: Int
|
||||
get() = appSettings.proxyPortNumber
|
||||
get() = appSettingsRepository.proxyPortNumber
|
||||
set(value) {
|
||||
appSettings.proxyPortNumber = value
|
||||
appSettingsRepository.proxyPortNumber = value
|
||||
}
|
||||
|
||||
var proxyUseAuth: Boolean
|
||||
get() = appSettings.proxyUseAuth
|
||||
get() = appSettingsRepository.proxyUseAuth
|
||||
set(value) {
|
||||
appSettings.proxyUseAuth = value
|
||||
appSettingsRepository.proxyUseAuth = value
|
||||
}
|
||||
|
||||
var proxyHostUser: String
|
||||
get() = appSettings.proxyHostUser
|
||||
get() = appSettingsRepository.proxyHostUser
|
||||
set(value) {
|
||||
appSettings.proxyHostUser = value
|
||||
appSettingsRepository.proxyHostUser = value
|
||||
}
|
||||
|
||||
var proxyHostPassword: String
|
||||
get() = appSettings.proxyHostPassword
|
||||
get() = appSettingsRepository.proxyHostPassword
|
||||
set(value) {
|
||||
appSettings.proxyHostPassword = value
|
||||
appSettingsRepository.proxyHostPassword = value
|
||||
}
|
||||
|
||||
fun saveCustomTheme(filePath: String): Error? {
|
||||
return try {
|
||||
appSettings.saveCustomTheme(filePath)
|
||||
appSettingsRepository.saveCustomTheme(filePath)
|
||||
null
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
@ -158,14 +157,14 @@ class SettingsViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
fun resetInfo() {
|
||||
commitsLimit = appSettings.commitsLimit
|
||||
commitsLimit = appSettingsRepository.commitsLimit
|
||||
}
|
||||
|
||||
fun savePendingChanges() = appScope.launch {
|
||||
val commitsLimit = this@SettingsViewModel.commitsLimit
|
||||
|
||||
if (appSettings.commitsLimit != commitsLimit) {
|
||||
appSettings.setCommitsLimit(commitsLimit)
|
||||
if (appSettingsRepository.commitsLimit != commitsLimit) {
|
||||
appSettingsRepository.setCommitsLimit(commitsLimit)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,8 +8,10 @@ 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.preferences.AppSettings
|
||||
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository
|
||||
import com.jetpackduba.gitnuro.repositories.BranchesVisibilityRepository
|
||||
import kotlinx.coroutines.Job
|
||||
import org.eclipse.jgit.internal.diffmergetool.MergeTools
|
||||
import org.eclipse.jgit.lib.Ref
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -18,15 +20,19 @@ 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 appSettings: AppSettings,
|
||||
private val appSettingsRepository: AppSettingsRepository,
|
||||
private val mergeBranchUseCase: MergeBranchUseCase,
|
||||
private val deleteBranchUseCase: DeleteBranchUseCase,
|
||||
private val checkoutRefUseCase: CheckoutRefUseCase,
|
||||
private val branchesVisibilityRepository: BranchesVisibilityRepository,
|
||||
) : ISharedBranchesViewModel {
|
||||
|
||||
override fun mergeBranch(ref: Ref) = tabState.safeProcessing(
|
||||
@ -35,7 +41,7 @@ class SharedBranchesViewModel @Inject constructor(
|
||||
subtitle = "Merging branch ${ref.simpleName}",
|
||||
taskType = TaskType.MERGE_BRANCH,
|
||||
) { git ->
|
||||
mergeBranchUseCase(git, ref, appSettings.ffMerge)
|
||||
mergeBranchUseCase(git, ref, appSettingsRepository.ffMerge)
|
||||
}
|
||||
|
||||
override fun deleteBranch(branch: Ref) = tabState.safeProcessing(
|
||||
@ -64,4 +70,30 @@ 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))
|
||||
}
|
||||
}
|
||||
|
@ -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.preferences.AppSettings
|
||||
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository
|
||||
import com.jetpackduba.gitnuro.ui.tree_files.TreeItem
|
||||
import com.jetpackduba.gitnuro.ui.tree_files.entriesToTreeEntry
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@ -30,6 +30,8 @@ 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
|
||||
@ -60,7 +62,7 @@ class StatusViewModel @Inject constructor(
|
||||
private val saveAuthorUseCase: SaveAuthorUseCase,
|
||||
private val sharedRepositoryStateManager: SharedRepositoryStateManager,
|
||||
private val getSpecificCommitMessageUseCase: GetSpecificCommitMessageUseCase,
|
||||
private val appSettings: AppSettings,
|
||||
private val appSettingsRepository: AppSettingsRepository,
|
||||
tabScope: CoroutineScope,
|
||||
) {
|
||||
private val _showSearchUnstaged = MutableStateFlow(false)
|
||||
@ -75,11 +77,11 @@ class StatusViewModel @Inject constructor(
|
||||
private val _searchFilterStaged = MutableStateFlow(TextFieldValue(""))
|
||||
val searchFilterStaged: StateFlow<TextFieldValue> = _searchFilterStaged
|
||||
|
||||
val swapUncommittedChanges = appSettings.swapUncommittedChangesFlow
|
||||
val swapUncommittedChanges = appSettingsRepository.swapUncommittedChangesFlow
|
||||
val rebaseInteractiveState = sharedRepositoryStateManager.rebaseInteractiveState
|
||||
|
||||
private val treeContractedDirectories = MutableStateFlow(emptyList<String>())
|
||||
private val showAsTree = appSettings.showChangesAsTreeFlow
|
||||
private val showAsTree = appSettingsRepository.showChangesAsTreeFlow
|
||||
private val _stageState = MutableStateFlow<StageState>(StageState.Loading)
|
||||
|
||||
private val stageStateFiltered: StateFlow<StageState> = combine(
|
||||
@ -506,7 +508,7 @@ class StatusViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
fun alternateShowAsTree() {
|
||||
appSettings.showChangesAsTree = !appSettings.showChangesAsTree
|
||||
appSettingsRepository.showChangesAsTree = !appSettingsRepository.showChangesAsTree
|
||||
}
|
||||
|
||||
fun stageByDirectory(dir: String) = tabState.runOperation(
|
||||
|
Loading…
Reference in New Issue
Block a user