diff options
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/utils')
| -rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt | 39 | ||||
| -rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt | 14 |
2 files changed, 41 insertions, 12 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 f7a637c3..6f4ebab1 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt +++ b/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt @@ -5,10 +5,18 @@ package com.zeapo.pwdstore.utils import android.content.Context +import android.content.SharedPreferences import android.os.Build import android.util.TypedValue +import android.view.View import android.view.autofill.AutofillManager +import android.view.inputmethod.InputMethodManager +import androidx.annotation.IdRes import androidx.annotation.RequiresApi +import androidx.appcompat.app.AlertDialog +import androidx.core.content.getSystemService +import androidx.security.crypto.EncryptedSharedPreferences +import androidx.security.crypto.MasterKeys infix fun Int.hasFlag(flag: Int): Boolean { return this and flag == flag @@ -24,6 +32,37 @@ fun Context.resolveAttribute(attr: Int): Int { return typedValue.data } +fun Context.getEncryptedPrefs(fileName: String): SharedPreferences { + val keyGenParameterSpec = MasterKeys.AES256_GCM_SPEC + val masterKeyAlias = MasterKeys.getOrCreate(keyGenParameterSpec) + return EncryptedSharedPreferences.create( + fileName, + masterKeyAlias, + this, + EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, + EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM + ) +} + +/** + * Extension function for [AlertDialog] that requests focus for the + * view whose id is [id]. Solution based on a StackOverflow + * answer: https://stackoverflow.com/a/13056259/297261 + */ +fun <T : View> AlertDialog.requestInputFocusOnView(@IdRes id: Int) { + setOnShowListener { + findViewById<T>(id)?.apply { + setOnFocusChangeListener { v, _ -> + v.post { + context.getSystemService<InputMethodManager>() + ?.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT) + } + } + requestFocus() + } + } +} + val Context.autofillManager: AutofillManager? @RequiresApi(Build.VERSION_CODES.O) get() = getSystemService(AutofillManager::class.java) 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 1cf8fea0..2cc19ae3 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt +++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt @@ -95,7 +95,7 @@ open class PasswordRepository protected constructor() { // TODO add multiple remotes support for pull/push @JvmStatic - fun addRemote(name: String, url: String, replace: Boolean?) { + fun addRemote(name: String, url: String, replace: Boolean = false) { val storedConfig = repository!!.config val remotes = storedConfig.getSubsections("remote") @@ -116,7 +116,7 @@ open class PasswordRepository protected constructor() { } catch (e: Exception) { e.printStackTrace() } - } else if (replace!!) { + } else if (replace) { try { val uri = URIish(url) @@ -181,16 +181,6 @@ open class PasswordRepository protected constructor() { } /** - * Gets the password items in the root directory - * - * @return a list of passwords in the root directory - */ - @JvmStatic - fun getPasswords(rootDir: File, sortOrder: PasswordSortOrder): ArrayList<PasswordItem> { - return getPasswords(rootDir, rootDir, sortOrder) - } - - /** * Gets the .gpg files in a directory * * @param path the directory path |
