From d0b15cec49a41ec1ea51890ac7b7c8cb8515f6a4 Mon Sep 17 00:00:00 2001 From: Fabian Henneke Date: Mon, 24 Aug 2020 12:03:33 +0200 Subject: Improve Git server config activity (#1051) --- .../com/zeapo/pwdstore/git/config/GitSettings.kt | 31 +++++++++++++++------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'app/src/main/java/com/zeapo/pwdstore/git/config') diff --git a/app/src/main/java/com/zeapo/pwdstore/git/config/GitSettings.kt b/app/src/main/java/com/zeapo/pwdstore/git/config/GitSettings.kt index b81a8f8f..2efae40c 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/config/GitSettings.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/config/GitSettings.kt @@ -55,14 +55,14 @@ object GitSettings { var protocol get() = Protocol.fromString(settings.getString(PreferenceKeys.GIT_REMOTE_PROTOCOL)) - set(value) { + private set(value) { settings.edit { putString(PreferenceKeys.GIT_REMOTE_PROTOCOL, value.pref) } } var connectionMode get() = ConnectionMode.fromString(settings.getString(PreferenceKeys.GIT_REMOTE_AUTH)) - set(value) { + private set(value) { settings.edit { putString(PreferenceKeys.GIT_REMOTE_AUTH, value.pref) } @@ -71,6 +71,8 @@ object GitSettings { get() = settings.getString(PreferenceKeys.GIT_REMOTE_URL) private set(value) { require(value != null) + if (value == url) + return settings.edit { putString(PreferenceKeys.GIT_REMOTE_URL, value) } @@ -96,20 +98,31 @@ object GitSettings { } var branch get() = settings.getString(PreferenceKeys.GIT_BRANCH_NAME) ?: DEFAULT_BRANCH - set(value) { + private set(value) { settings.edit { putString(PreferenceKeys.GIT_BRANCH_NAME, value) } } - fun updateUrlIfValid(newUrl: String): Boolean { - try { + enum class UpdateConnectionSettingsResult { + Valid, + FailedToParseUrl, + MissingUsername, + } + + fun updateConnectionSettingsIfValid(newProtocol: Protocol, newConnectionMode: ConnectionMode, newUrl: String, newBranch: String): UpdateConnectionSettingsResult { + val parsedUrl = try { URIish(newUrl) } catch (_: Exception) { - return false + return UpdateConnectionSettingsResult.FailedToParseUrl } - if (newUrl != url) - url = newUrl - return true + if (newConnectionMode != ConnectionMode.None && parsedUrl.user.isNullOrBlank()) + return UpdateConnectionSettingsResult.MissingUsername + + url = newUrl + protocol = newProtocol + connectionMode = newConnectionMode + branch = newBranch + return UpdateConnectionSettingsResult.Valid } } -- cgit v1.2.3