summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorHarsh Shandilya <msfjarvis@gmail.com>2019-11-04 18:59:49 +0530
committerHarsh Shandilya <msfjarvis@gmail.com>2019-11-04 19:50:48 +0530
commit077e67d8e3537463a9719c4bc9f663bbe143978b (patch)
tree441f87529ddc8038cd591ebc01567621ebd5f939 /app/src/main
parenta409cae2a84c483f6fc9fbdfd2996d8e807f648b (diff)
PasswordRepository: Refactor getRepositoryDirectory to be non-nullable
Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt18
1 files changed, 4 insertions, 14 deletions
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 2c13fe61..97e506f5 100644
--- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt
@@ -138,20 +138,14 @@ open class PasswordRepository protected constructor() {
}
@JvmStatic
- fun getRepositoryDirectory(context: Context): File? {
- var dir: File? = null
+ fun getRepositoryDirectory(context: Context): File {
val settings = PreferenceManager.getDefaultSharedPreferences(context.applicationContext)
-
- if (settings.getBoolean("git_external", false)) {
+ return if (settings.getBoolean("git_external", false)) {
val externalRepo = settings.getString("git_external_repo", null)
- if (externalRepo != null) {
- dir = File(externalRepo)
- }
+ File(requireNotNull(externalRepo))
} else {
- dir = File(context.filesDir.toString() + "/store")
+ File(context.filesDir.toString() + "/store")
}
-
- return dir
}
@JvmStatic
@@ -159,10 +153,6 @@ open class PasswordRepository protected constructor() {
val dir = getRepositoryDirectory(context)
val settings = PreferenceManager.getDefaultSharedPreferences(context.applicationContext)
- if (dir == null) {
- return null
- }
-
// uninitialize the repo if the dir does not exist or is absolutely empty
if (!dir.exists() || !dir.isDirectory || dir.listFiles()!!.isEmpty()) {
settings.edit().putBoolean("repository_initialized", false).apply()