aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.kt
diff options
context:
space:
mode:
authorAditya Wasan <adityawasan55@gmail.com>2020-07-01 00:00:02 +0530
committerGitHub <noreply@github.com>2020-07-01 00:00:02 +0530
commit82a9a6125473dbffa6a76f33c6ff83b4a1bd69b3 (patch)
tree965c887adfb0c5603f6e8f9dbcbd04d4d1011904 /app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.kt
parente11ef1ca1d504bcccf73e75c3782cce2c8fc4bec (diff)
downloadHardenedPass-82a9a6125473dbffa6a76f33c6ff83b4a1bd69b3.tar.gz
HardenedPass-82a9a6125473dbffa6a76f33c6ff83b4a1bd69b3.zip
Use PreferenceKeys file to manage SharedPreferences keys. (#891)
* Use PreferenceKeys file to manage SharedPreferences keys. Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * Use PreferenceKeys in all files Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * Divide PreferenceKeys into multiple regions Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * Fix build error Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * Use PreferenceKeys in more files Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * Reformat code Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * Fix build error Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * Fix merge issues Signed-off-by: Aditya Wasan <adityawasan55@gmail.com>
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.kt')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.kt11
1 files changed, 6 insertions, 5 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.kt
index a58bde69..177233a8 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.kt
@@ -31,6 +31,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.zeapo.pwdstore.R
import com.zeapo.pwdstore.model.PasswordEntry
import com.zeapo.pwdstore.utils.PasswordRepository
+import com.zeapo.pwdstore.utils.PreferenceKeys
import com.zeapo.pwdstore.utils.splitLines
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@@ -228,7 +229,7 @@ class AutofillService : AccessibilityService(), CoroutineScope by CoroutineScope
// if autofill_always checked, show dialog even if no matches (automatic
// or otherwise)
- if (items.isEmpty() && !settings!!.getBoolean("autofill_always", false)) {
+ if (items.isEmpty() && !settings!!.getBoolean(PreferenceKeys.AUTOFILL_ALWAYS, false)) {
return
}
showSelectPasswordDialog(packageName, appName, isWeb)
@@ -268,7 +269,7 @@ class AutofillService : AccessibilityService(), CoroutineScope by CoroutineScope
var settingsURL = webViewURL
// if autofill_default is checked and prefs.getString DNE, 'Automatically match with password'/"first" otherwise "never"
- val defValue = if (settings!!.getBoolean("autofill_default", true)) "/first" else "/never"
+ val defValue = if (settings!!.getBoolean(PreferenceKeys.AUTOFILL_DEFAULT, true)) "/first" else "/never"
val prefs: SharedPreferences = getSharedPreferences("autofill_web", Context.MODE_PRIVATE)
var preference: String
@@ -305,7 +306,7 @@ class AutofillService : AccessibilityService(), CoroutineScope by CoroutineScope
private fun setAppMatchingPasswords(appName: String, packageName: String) {
// if autofill_default is checked and prefs.getString DNE, 'Automatically match with password'/"first" otherwise "never"
- val defValue = if (settings!!.getBoolean("autofill_default", true)) "/first" else "/never"
+ val defValue = if (settings!!.getBoolean(PreferenceKeys.AUTOFILL_DEFAULT, true)) "/first" else "/never"
val prefs: SharedPreferences = getSharedPreferences("autofill", Context.MODE_PRIVATE)
val preference: String?
@@ -414,7 +415,7 @@ class AutofillService : AccessibilityService(), CoroutineScope by CoroutineScope
// make it optional (or make height a setting for the same effect)
val itemNames = arrayOfNulls<CharSequence>(items.size + 2)
val passwordDirectory = PasswordRepository.getRepositoryDirectory(applicationContext).toString()
- val autofillFullPath = settings!!.getBoolean("autofill_full_path", false)
+ val autofillFullPath = settings!!.getBoolean(PreferenceKeys.AUTOFILL_FULL_PATH, false)
for (i in items.indices) {
if (autofillFullPath) {
itemNames[i] = items[i].path.replace(".gpg", "")
@@ -518,7 +519,7 @@ class AutofillService : AccessibilityService(), CoroutineScope by CoroutineScope
// save password entry for pasting the username as well
if (entry?.hasUsername() == true) {
lastPassword = entry
- val ttl = Integer.parseInt(settings!!.getString("general_show_time", "45")!!)
+ val ttl = Integer.parseInt(settings!!.getString(PreferenceKeys.GENERAL_SHOW_TIME, "45")!!)
withContext(Dispatchers.Main) { Toast.makeText(applicationContext, getString(R.string.autofill_toast_username, ttl), Toast.LENGTH_LONG).show() }
lastPasswordMaxDate = System.currentTimeMillis() + ttl * 1000L
}