PasswordRepository: Refactor getRepositoryDirectory to be non-nullable
Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
This commit is contained in:
parent
a409cae2a8
commit
077e67d8e3
1 changed files with 4 additions and 14 deletions
|
@ -138,20 +138,14 @@ open class PasswordRepository protected constructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getRepositoryDirectory(context: Context): File? {
|
fun getRepositoryDirectory(context: Context): File {
|
||||||
var dir: File? = null
|
|
||||||
val settings = PreferenceManager.getDefaultSharedPreferences(context.applicationContext)
|
val settings = PreferenceManager.getDefaultSharedPreferences(context.applicationContext)
|
||||||
|
return if (settings.getBoolean("git_external", false)) {
|
||||||
if (settings.getBoolean("git_external", false)) {
|
|
||||||
val externalRepo = settings.getString("git_external_repo", null)
|
val externalRepo = settings.getString("git_external_repo", null)
|
||||||
if (externalRepo != null) {
|
File(requireNotNull(externalRepo))
|
||||||
dir = File(externalRepo)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
dir = File(context.filesDir.toString() + "/store")
|
File(context.filesDir.toString() + "/store")
|
||||||
}
|
}
|
||||||
|
|
||||||
return dir
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
@ -159,10 +153,6 @@ open class PasswordRepository protected constructor() {
|
||||||
val dir = getRepositoryDirectory(context)
|
val dir = getRepositoryDirectory(context)
|
||||||
val settings = PreferenceManager.getDefaultSharedPreferences(context.applicationContext)
|
val settings = PreferenceManager.getDefaultSharedPreferences(context.applicationContext)
|
||||||
|
|
||||||
if (dir == null) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
// uninitialize the repo if the dir does not exist or is absolutely empty
|
// uninitialize the repo if the dir does not exist or is absolutely empty
|
||||||
if (!dir.exists() || !dir.isDirectory || dir.listFiles()!!.isEmpty()) {
|
if (!dir.exists() || !dir.isDirectory || dir.listFiles()!!.isEmpty()) {
|
||||||
settings.edit().putBoolean("repository_initialized", false).apply()
|
settings.edit().putBoolean("repository_initialized", false).apply()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue