aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/utils
diff options
context:
space:
mode:
authorFabian Henneke <FabianHenneke@users.noreply.github.com>2020-08-11 18:11:39 +0200
committerGitHub <noreply@github.com>2020-08-11 18:11:39 +0200
commit15aa92980239d6d61c3b0febc0407b7f63e152b3 (patch)
tree92b25ea3bca41e37fe4727bab82665b04ee8206e /app/src/main/java/com/zeapo/pwdstore/utils
parent8f957ca99454efe1711e2424620d2632bed6cb63 (diff)
downloadHardenedPass-15aa92980239d6d61c3b0febc0407b7f63e152b3.tar.gz
HardenedPass-15aa92980239d6d61c3b0febc0407b7f63e152b3.zip
Switch to URL-based Git config and refactor Git settings (#1008)
* Make Git config URL-based and refactor * Use Kotlin style null handling for string prefs * Also show an error if generated URL can't be parsed * Add some testcases for migration strategy Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> Co-authored-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/utils')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt2
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt9
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/utils/PreferenceKeys.kt9
3 files changed, 13 insertions, 7 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt b/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt
index a3ddc170..e088097b 100644
--- a/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt
@@ -101,6 +101,8 @@ fun Context.getEncryptedPrefs(fileName: String): SharedPreferences {
val Context.sharedPrefs: SharedPreferences
get() = PreferenceManager.getDefaultSharedPreferences(applicationContext)
+fun SharedPreferences.getString(key: String): String? = getString(key, null)
+
suspend fun FragmentActivity.commitChange(
message: String,
finishWithResultOnEnd: Intent? = null,
diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt
index e07f30f2..0a918d0c 100644
--- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt
@@ -39,8 +39,7 @@ open class PasswordRepository protected constructor() {
@JvmStatic
fun getSortOrder(settings: SharedPreferences): PasswordSortOrder {
- return valueOf(settings.getString(PreferenceKeys.SORT_ORDER, null)
- ?: FOLDER_FIRST.name)
+ return valueOf(settings.getString(PreferenceKeys.SORT_ORDER) ?: FOLDER_FIRST.name)
}
}
}
@@ -155,7 +154,7 @@ open class PasswordRepository protected constructor() {
@JvmStatic
fun getRepositoryDirectory(): File {
return if (settings.getBoolean(PreferenceKeys.GIT_EXTERNAL, false)) {
- val externalRepo = settings.getString(PreferenceKeys.GIT_EXTERNAL_REPO, null)
+ val externalRepo = settings.getString(PreferenceKeys.GIT_EXTERNAL_REPO)
if (externalRepo != null)
File(externalRepo)
else
@@ -239,7 +238,7 @@ open class PasswordRepository protected constructor() {
* @param username username
*/
@JvmStatic
- fun setUserName(username: String) {
+ fun setGitAuthorName(username: String) {
setStringConfig("user", null, "name", username)
}
@@ -249,7 +248,7 @@ open class PasswordRepository protected constructor() {
* @param email email
*/
@JvmStatic
- fun setUserEmail(email: String) {
+ fun setGitAuthorEmail(email: String) {
setStringConfig("user", null, "email", email)
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PreferenceKeys.kt b/app/src/main/java/com/zeapo/pwdstore/utils/PreferenceKeys.kt
index 24bf2096..05fb9326 100644
--- a/app/src/main/java/com/zeapo/pwdstore/utils/PreferenceKeys.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/utils/PreferenceKeys.kt
@@ -23,16 +23,21 @@ object PreferenceKeys {
const val FILTER_RECURSIVELY = "filter_recursively"
const val GENERAL_SHOW_TIME = "general_show_time"
const val GIT_CONFIG = "git_config"
- const val GIT_CONFIG_USER_EMAIL = "git_config_user_email"
- const val GIT_CONFIG_USER_NAME = "git_config_user_name"
+ const val GIT_CONFIG_AUTHOR_EMAIL = "git_config_user_email"
+ const val GIT_CONFIG_AUTHOR_NAME = "git_config_user_name"
const val GIT_EXTERNAL = "git_external"
const val GIT_EXTERNAL_REPO = "git_external_repo"
const val GIT_REMOTE_AUTH = "git_remote_auth"
+ @Deprecated("Use GIT_REMOTE_URL instead")
const val GIT_REMOTE_LOCATION = "git_remote_location"
+ @Deprecated("Use GIT_REMOTE_URL instead")
const val GIT_REMOTE_PORT = "git_remote_port"
const val GIT_REMOTE_PROTOCOL = "git_remote_protocol"
const val GIT_DELETE_REPO = "git_delete_repo"
+ @Deprecated("Use GIT_REMOTE_URL instead")
const val GIT_REMOTE_SERVER = "git_remote_server"
+ const val GIT_REMOTE_URL = "git_remote_url"
+ @Deprecated("Use GIT_REMOTE_URL instead")
const val GIT_REMOTE_USERNAME = "git_remote_username"
const val GIT_SERVER_INFO = "git_server_info"
const val GIT_BRANCH_NAME = "git_branch"