mirror of
https://github.com/android-password-store/Android-Password-Store
synced 2025-08-31 06:15:48 +00:00
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>
This commit is contained in:
@@ -14,6 +14,7 @@ import androidx.preference.PreferenceManager
|
|||||||
import com.github.ajalt.timberkt.Timber.DebugTree
|
import com.github.ajalt.timberkt.Timber.DebugTree
|
||||||
import com.github.ajalt.timberkt.Timber.plant
|
import com.github.ajalt.timberkt.Timber.plant
|
||||||
import com.zeapo.pwdstore.git.config.setUpBouncyCastleForSshj
|
import com.zeapo.pwdstore.git.config.setUpBouncyCastleForSshj
|
||||||
|
import com.zeapo.pwdstore.utils.PreferenceKeys
|
||||||
|
|
||||||
@Suppress("Unused")
|
@Suppress("Unused")
|
||||||
class Application : android.app.Application(), SharedPreferences.OnSharedPreferenceChangeListener {
|
class Application : android.app.Application(), SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
@@ -23,7 +24,8 @@ class Application : android.app.Application(), SharedPreferences.OnSharedPrefere
|
|||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
prefs = PreferenceManager.getDefaultSharedPreferences(this)
|
prefs = PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
if (BuildConfig.ENABLE_DEBUG_FEATURES || prefs?.getBoolean("enable_debug_logging", false) == true) {
|
if (BuildConfig.ENABLE_DEBUG_FEATURES || prefs?.getBoolean(PreferenceKeys.ENABLE_DEBUG_LOGGING, false) ==
|
||||||
|
true) {
|
||||||
plant(DebugTree())
|
plant(DebugTree())
|
||||||
}
|
}
|
||||||
prefs?.registerOnSharedPreferenceChangeListener(this)
|
prefs?.registerOnSharedPreferenceChangeListener(this)
|
||||||
@@ -37,13 +39,13 @@ class Application : android.app.Application(), SharedPreferences.OnSharedPrefere
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onSharedPreferenceChanged(prefs: SharedPreferences, key: String) {
|
override fun onSharedPreferenceChanged(prefs: SharedPreferences, key: String) {
|
||||||
if (key == "app_theme") {
|
if (key == PreferenceKeys.APP_THEME) {
|
||||||
setNightMode()
|
setNightMode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setNightMode() {
|
private fun setNightMode() {
|
||||||
AppCompatDelegate.setDefaultNightMode(when (prefs?.getString("app_theme", getString(R.string.app_theme_def))) {
|
AppCompatDelegate.setDefaultNightMode(when (prefs?.getString(PreferenceKeys.APP_THEME, getString(R.string.app_theme_def))) {
|
||||||
"light" -> MODE_NIGHT_NO
|
"light" -> MODE_NIGHT_NO
|
||||||
"dark" -> MODE_NIGHT_YES
|
"dark" -> MODE_NIGHT_YES
|
||||||
"follow_system" -> MODE_NIGHT_FOLLOW_SYSTEM
|
"follow_system" -> MODE_NIGHT_FOLLOW_SYSTEM
|
||||||
|
@@ -17,6 +17,7 @@ import androidx.core.app.NotificationCompat
|
|||||||
import androidx.core.content.getSystemService
|
import androidx.core.content.getSystemService
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import com.github.ajalt.timberkt.d
|
import com.github.ajalt.timberkt.d
|
||||||
|
import com.zeapo.pwdstore.utils.PreferenceKeys
|
||||||
import com.zeapo.pwdstore.utils.clipboard
|
import com.zeapo.pwdstore.utils.clipboard
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -44,7 +45,7 @@ class ClipboardService : Service() {
|
|||||||
|
|
||||||
ACTION_START -> {
|
ACTION_START -> {
|
||||||
val time = try {
|
val time = try {
|
||||||
Integer.parseInt(settings.getString("general_show_time", "45") as String)
|
Integer.parseInt(settings.getString(PreferenceKeys.GENERAL_SHOW_TIME, "45") as String)
|
||||||
} catch (e: NumberFormatException) {
|
} catch (e: NumberFormatException) {
|
||||||
45
|
45
|
||||||
}
|
}
|
||||||
@@ -82,7 +83,7 @@ class ClipboardService : Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun clearClipboard() {
|
private fun clearClipboard() {
|
||||||
val deepClear = settings.getBoolean("clear_clipboard_20x", false)
|
val deepClear = settings.getBoolean(PreferenceKeys.CLEAR_CLIPBOARD_20X, false)
|
||||||
val clipboard = clipboard
|
val clipboard = clipboard
|
||||||
|
|
||||||
if (clipboard != null) {
|
if (clipboard != null) {
|
||||||
|
@@ -12,20 +12,21 @@ import androidx.core.content.edit
|
|||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import com.zeapo.pwdstore.crypto.DecryptActivity
|
import com.zeapo.pwdstore.crypto.DecryptActivity
|
||||||
import com.zeapo.pwdstore.utils.BiometricAuthenticator
|
import com.zeapo.pwdstore.utils.BiometricAuthenticator
|
||||||
|
import com.zeapo.pwdstore.utils.PreferenceKeys
|
||||||
|
|
||||||
class LaunchActivity : AppCompatActivity() {
|
class LaunchActivity : AppCompatActivity() {
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
val prefs = PreferenceManager.getDefaultSharedPreferences(this)
|
val prefs = PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
if (prefs.getBoolean("biometric_auth", false)) {
|
if (prefs.getBoolean(PreferenceKeys.BIOMETRIC_AUTH, false)) {
|
||||||
BiometricAuthenticator.authenticate(this) {
|
BiometricAuthenticator.authenticate(this) {
|
||||||
when (it) {
|
when (it) {
|
||||||
is BiometricAuthenticator.Result.Success -> {
|
is BiometricAuthenticator.Result.Success -> {
|
||||||
startTargetActivity(false)
|
startTargetActivity(false)
|
||||||
}
|
}
|
||||||
is BiometricAuthenticator.Result.HardwareUnavailableOrDisabled -> {
|
is BiometricAuthenticator.Result.HardwareUnavailableOrDisabled -> {
|
||||||
prefs.edit { remove("biometric_auth") }
|
prefs.edit { remove(PreferenceKeys.BIOMETRIC_AUTH) }
|
||||||
startTargetActivity(false)
|
startTargetActivity(false)
|
||||||
}
|
}
|
||||||
is BiometricAuthenticator.Result.Failure, BiometricAuthenticator.Result.Cancelled -> {
|
is BiometricAuthenticator.Result.Failure, BiometricAuthenticator.Result.Cancelled -> {
|
||||||
|
@@ -31,6 +31,7 @@ import com.zeapo.pwdstore.ui.adapters.PasswordItemRecyclerAdapter
|
|||||||
import com.zeapo.pwdstore.ui.dialogs.ItemCreationBottomSheet
|
import com.zeapo.pwdstore.ui.dialogs.ItemCreationBottomSheet
|
||||||
import com.zeapo.pwdstore.utils.PasswordItem
|
import com.zeapo.pwdstore.utils.PasswordItem
|
||||||
import com.zeapo.pwdstore.utils.PasswordRepository
|
import com.zeapo.pwdstore.utils.PasswordRepository
|
||||||
|
import com.zeapo.pwdstore.utils.PreferenceKeys
|
||||||
import com.zeapo.pwdstore.utils.viewBinding
|
import com.zeapo.pwdstore.utils.viewBinding
|
||||||
import me.zhanghai.android.fastscroll.FastScrollerBuilder
|
import me.zhanghai.android.fastscroll.FastScrollerBuilder
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -78,7 +79,8 @@ class PasswordFragment : Fragment(R.layout.password_recycler_view) {
|
|||||||
} else {
|
} else {
|
||||||
// When authentication is set to ConnectionMode.None then the only git operation we
|
// When authentication is set to ConnectionMode.None then the only git operation we
|
||||||
// can run is a pull, so automatically fallback to that.
|
// can run is a pull, so automatically fallback to that.
|
||||||
val operationId = when (ConnectionMode.fromString(settings.getString("git_remote_auth", null))) {
|
val operationId = when (ConnectionMode.fromString(settings.getString
|
||||||
|
(PreferenceKeys.GIT_REMOTE_AUTH, null))) {
|
||||||
ConnectionMode.None -> BaseGitActivity.REQUEST_PULL
|
ConnectionMode.None -> BaseGitActivity.REQUEST_PULL
|
||||||
else -> BaseGitActivity.REQUEST_SYNC
|
else -> BaseGitActivity.REQUEST_SYNC
|
||||||
}
|
}
|
||||||
|
@@ -65,6 +65,7 @@ import com.zeapo.pwdstore.utils.PasswordRepository.Companion.getRepositoryDirect
|
|||||||
import com.zeapo.pwdstore.utils.PasswordRepository.Companion.initialize
|
import com.zeapo.pwdstore.utils.PasswordRepository.Companion.initialize
|
||||||
import com.zeapo.pwdstore.utils.PasswordRepository.Companion.isInitialized
|
import com.zeapo.pwdstore.utils.PasswordRepository.Companion.isInitialized
|
||||||
import com.zeapo.pwdstore.utils.PasswordRepository.PasswordSortOrder.Companion.getSortOrder
|
import com.zeapo.pwdstore.utils.PasswordRepository.PasswordSortOrder.Companion.getSortOrder
|
||||||
|
import com.zeapo.pwdstore.utils.PreferenceKeys
|
||||||
import com.zeapo.pwdstore.utils.commitChange
|
import com.zeapo.pwdstore.utils.commitChange
|
||||||
import com.zeapo.pwdstore.utils.isInsideRepository
|
import com.zeapo.pwdstore.utils.isInsideRepository
|
||||||
import com.zeapo.pwdstore.utils.listFilesRecursively
|
import com.zeapo.pwdstore.utils.listFilesRecursively
|
||||||
@@ -121,7 +122,7 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) {
|
|||||||
// If user opens app with permission granted then revokes and returns,
|
// If user opens app with permission granted then revokes and returns,
|
||||||
// prevent attempt to create password list fragment
|
// prevent attempt to create password list fragment
|
||||||
var savedInstance = savedInstanceState
|
var savedInstance = savedInstanceState
|
||||||
if (savedInstanceState != null && (!settings.getBoolean("git_external", false) ||
|
if (savedInstanceState != null && (!settings.getBoolean(PreferenceKeys.GIT_EXTERNAL, false) ||
|
||||||
ContextCompat.checkSelfPermission(
|
ContextCompat.checkSelfPermission(
|
||||||
activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||||
!= PackageManager.PERMISSION_GRANTED)) {
|
!= PackageManager.PERMISSION_GRANTED)) {
|
||||||
@@ -187,12 +188,12 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) {
|
|||||||
public override fun onResume() {
|
public override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
// do not attempt to checkLocalRepository() if no storage permission: immediate crash
|
// do not attempt to checkLocalRepository() if no storage permission: immediate crash
|
||||||
if (settings.getBoolean("git_external", false)) {
|
if (settings.getBoolean(PreferenceKeys.GIT_EXTERNAL, false)) {
|
||||||
hasRequiredStoragePermissions(true)
|
hasRequiredStoragePermissions(true)
|
||||||
} else {
|
} else {
|
||||||
checkLocalRepository()
|
checkLocalRepository()
|
||||||
}
|
}
|
||||||
if (settings.getBoolean("search_on_start", false) && ::searchItem.isInitialized) {
|
if (settings.getBoolean(PreferenceKeys.SEARCH_ON_START, false) && ::searchItem.isInitialized) {
|
||||||
if (!searchItem.isActionViewExpanded) {
|
if (!searchItem.isActionViewExpanded) {
|
||||||
searchItem.expandActionView()
|
searchItem.expandActionView()
|
||||||
}
|
}
|
||||||
@@ -211,7 +212,7 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) {
|
|||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||||
val menuRes = when {
|
val menuRes = when {
|
||||||
ConnectionMode.fromString(settings.getString("git_remote_auth", null))
|
ConnectionMode.fromString(settings.getString(PreferenceKeys.GIT_REMOTE_AUTH, null))
|
||||||
== ConnectionMode.None -> R.menu.main_menu_no_auth
|
== ConnectionMode.None -> R.menu.main_menu_no_auth
|
||||||
PasswordRepository.isGitRepo() -> R.menu.main_menu_git
|
PasswordRepository.isGitRepo() -> R.menu.main_menu_git
|
||||||
else -> R.menu.main_menu_non_git
|
else -> R.menu.main_menu_non_git
|
||||||
@@ -261,7 +262,7 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (settings.getBoolean("search_on_start", false)) {
|
if (settings.getBoolean(PreferenceKeys.SEARCH_ON_START, false)) {
|
||||||
searchItem.expandActionView()
|
searchItem.expandActionView()
|
||||||
}
|
}
|
||||||
return super.onPrepareOptionsMenu(menu)
|
return super.onPrepareOptionsMenu(menu)
|
||||||
@@ -346,7 +347,7 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) {
|
|||||||
check(localDir.mkdir()) { "Failed to create directory!" }
|
check(localDir.mkdir()) { "Failed to create directory!" }
|
||||||
createRepository(localDir)
|
createRepository(localDir)
|
||||||
if (File(localDir.absolutePath + "/.gpg-id").createNewFile()) {
|
if (File(localDir.absolutePath + "/.gpg-id").createNewFile()) {
|
||||||
settings.edit { putBoolean("repository_initialized", true) }
|
settings.edit { putBoolean(PreferenceKeys.REPOSITORY_INITIALIZED, true) }
|
||||||
} else {
|
} else {
|
||||||
throw IllegalStateException("Failed to initialize repository state.")
|
throw IllegalStateException("Failed to initialize repository state.")
|
||||||
}
|
}
|
||||||
@@ -361,8 +362,8 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initializeRepositoryInfo() {
|
private fun initializeRepositoryInfo() {
|
||||||
val externalRepo = settings.getBoolean("git_external", false)
|
val externalRepo = settings.getBoolean(PreferenceKeys.GIT_EXTERNAL, false)
|
||||||
val externalRepoPath = settings.getString("git_external_repo", null)
|
val externalRepoPath = settings.getString(PreferenceKeys.GIT_EXTERNAL_REPO, null)
|
||||||
if (externalRepo && !hasRequiredStoragePermissions()) {
|
if (externalRepo && !hasRequiredStoragePermissions()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -375,7 +376,7 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) {
|
|||||||
return // if not empty, just show me the passwords!
|
return // if not empty, just show me the passwords!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val keyIds = settings.getStringSet("openpgp_key_ids_set", HashSet())
|
val keyIds = settings.getStringSet(PreferenceKeys.OPENPGP_KEY_IDS_SET, HashSet())
|
||||||
if (keyIds != null && keyIds.isEmpty()) {
|
if (keyIds != null && keyIds.isEmpty()) {
|
||||||
MaterialAlertDialogBuilder(this)
|
MaterialAlertDialogBuilder(this)
|
||||||
.setMessage(resources.getString(R.string.key_dialog_text))
|
.setMessage(resources.getString(R.string.key_dialog_text))
|
||||||
@@ -431,12 +432,12 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun checkLocalRepository(localDir: File?) {
|
private fun checkLocalRepository(localDir: File?) {
|
||||||
if (localDir != null && settings.getBoolean("repository_initialized", false)) {
|
if (localDir != null && settings.getBoolean(PreferenceKeys.REPOSITORY_INITIALIZED, false)) {
|
||||||
d { "Check, dir: ${localDir.absolutePath}" }
|
d { "Check, dir: ${localDir.absolutePath}" }
|
||||||
// do not push the fragment if we already have it
|
// do not push the fragment if we already have it
|
||||||
if (supportFragmentManager.findFragmentByTag("PasswordsList") == null ||
|
if (supportFragmentManager.findFragmentByTag("PasswordsList") == null ||
|
||||||
settings.getBoolean("repo_changed", false)) {
|
settings.getBoolean(PreferenceKeys.REPO_CHANGED, false)) {
|
||||||
settings.edit { putBoolean("repo_changed", false) }
|
settings.edit { putBoolean(PreferenceKeys.REPO_CHANGED, false) }
|
||||||
plist = PasswordFragment()
|
plist = PasswordFragment()
|
||||||
val args = Bundle()
|
val args = Bundle()
|
||||||
args.putString(REQUEST_ARG_PATH, getRepositoryDirectory(applicationContext).absolutePath)
|
args.putString(REQUEST_ARG_PATH, getRepositoryDirectory(applicationContext).absolutePath)
|
||||||
@@ -535,7 +536,7 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) {
|
|||||||
.show()
|
.show()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (settings.getStringSet("openpgp_key_ids_set", HashSet()).isNullOrEmpty()) {
|
if (settings.getStringSet(PreferenceKeys.OPENPGP_KEY_IDS_SET, HashSet()).isNullOrEmpty()) {
|
||||||
MaterialAlertDialogBuilder(this)
|
MaterialAlertDialogBuilder(this)
|
||||||
.setTitle(resources.getString(R.string.no_key_selected_dialog_title))
|
.setTitle(resources.getString(R.string.no_key_selected_dialog_title))
|
||||||
.setMessage(resources.getString(R.string.no_key_selected_dialog_text))
|
.setMessage(resources.getString(R.string.no_key_selected_dialog_text))
|
||||||
@@ -751,7 +752,7 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) {
|
|||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
when (requestCode) {
|
when (requestCode) {
|
||||||
// if we get here with a RESULT_OK then it's probably OK :)
|
// if we get here with a RESULT_OK then it's probably OK :)
|
||||||
BaseGitActivity.REQUEST_CLONE -> settings.edit { putBoolean("repository_initialized", true) }
|
BaseGitActivity.REQUEST_CLONE -> settings.edit { putBoolean(PreferenceKeys.REPOSITORY_INITIALIZED, true) }
|
||||||
// if went from decrypt->edit and user saved changes, we need to commitChange
|
// if went from decrypt->edit and user saved changes, we need to commitChange
|
||||||
REQUEST_CODE_DECRYPT_AND_VERIFY -> {
|
REQUEST_CODE_DECRYPT_AND_VERIFY -> {
|
||||||
if (data != null && data.getBooleanExtra("needCommit", false)) {
|
if (data != null && data.getBooleanExtra("needCommit", false)) {
|
||||||
@@ -770,9 +771,9 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) {
|
|||||||
HOME -> checkLocalRepository()
|
HOME -> checkLocalRepository()
|
||||||
// duplicate code
|
// duplicate code
|
||||||
CLONE_REPO_BUTTON -> {
|
CLONE_REPO_BUTTON -> {
|
||||||
if (settings.getBoolean("git_external", false) &&
|
if (settings.getBoolean(PreferenceKeys.GIT_EXTERNAL, false) &&
|
||||||
settings.getString("git_external_repo", null) != null) {
|
settings.getString(PreferenceKeys.GIT_EXTERNAL_REPO, null) != null) {
|
||||||
val externalRepoPath = settings.getString("git_external_repo", null)
|
val externalRepoPath = settings.getString(PreferenceKeys.GIT_EXTERNAL_REPO, null)
|
||||||
val dir = externalRepoPath?.let { File(it) }
|
val dir = externalRepoPath?.let { File(it) }
|
||||||
if (dir != null &&
|
if (dir != null &&
|
||||||
dir.exists() &&
|
dir.exists() &&
|
||||||
@@ -832,7 +833,7 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) {
|
|||||||
.setTitle(resources.getString(R.string.location_dialog_title))
|
.setTitle(resources.getString(R.string.location_dialog_title))
|
||||||
.setMessage(resources.getString(R.string.location_dialog_text))
|
.setMessage(resources.getString(R.string.location_dialog_text))
|
||||||
.setPositiveButton(resources.getString(R.string.location_hidden)) { _, _ ->
|
.setPositiveButton(resources.getString(R.string.location_hidden)) { _, _ ->
|
||||||
settings.edit { putBoolean("git_external", false) }
|
settings.edit { putBoolean(PreferenceKeys.GIT_EXTERNAL, false) }
|
||||||
when (operation) {
|
when (operation) {
|
||||||
NEW_REPO_BUTTON -> initializeRepositoryInfo()
|
NEW_REPO_BUTTON -> initializeRepositoryInfo()
|
||||||
CLONE_REPO_BUTTON -> {
|
CLONE_REPO_BUTTON -> {
|
||||||
@@ -843,8 +844,8 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.setNegativeButton(resources.getString(R.string.location_sdcard)) { _, _ ->
|
.setNegativeButton(resources.getString(R.string.location_sdcard)) { _, _ ->
|
||||||
settings.edit { putBoolean("git_external", true) }
|
settings.edit { putBoolean(PreferenceKeys.GIT_EXTERNAL, true) }
|
||||||
val externalRepo = settings.getString("git_external_repo", null)
|
val externalRepo = settings.getString(PreferenceKeys.GIT_EXTERNAL_REPO, null)
|
||||||
if (externalRepo == null) {
|
if (externalRepo == null) {
|
||||||
val intent = Intent(activity, UserPreference::class.java)
|
val intent = Intent(activity, UserPreference::class.java)
|
||||||
intent.putExtra("operation", "git_external")
|
intent.putExtra("operation", "git_external")
|
||||||
|
@@ -30,6 +30,7 @@ import com.zeapo.pwdstore.autofill.oreo.AutofillPreferences
|
|||||||
import com.zeapo.pwdstore.autofill.oreo.DirectoryStructure
|
import com.zeapo.pwdstore.autofill.oreo.DirectoryStructure
|
||||||
import com.zeapo.pwdstore.utils.PasswordItem
|
import com.zeapo.pwdstore.utils.PasswordItem
|
||||||
import com.zeapo.pwdstore.utils.PasswordRepository
|
import com.zeapo.pwdstore.utils.PasswordRepository
|
||||||
|
import com.zeapo.pwdstore.utils.PreferenceKeys
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.FlowPreview
|
import kotlinx.coroutines.FlowPreview
|
||||||
@@ -140,9 +141,9 @@ class SearchableRepositoryViewModel(application: Application) : AndroidViewModel
|
|||||||
get() = PasswordRepository.getRepositoryDirectory(getApplication())
|
get() = PasswordRepository.getRepositoryDirectory(getApplication())
|
||||||
private val settings = PreferenceManager.getDefaultSharedPreferences(getApplication())
|
private val settings = PreferenceManager.getDefaultSharedPreferences(getApplication())
|
||||||
private val showHiddenDirs
|
private val showHiddenDirs
|
||||||
get() = settings.getBoolean("show_hidden_folders", false)
|
get() = settings.getBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, false)
|
||||||
private val defaultSearchMode
|
private val defaultSearchMode
|
||||||
get() = if (settings.getBoolean("filter_recursively", true)) {
|
get() = if (settings.getBoolean(PreferenceKeys.FILTER_RECURSIVELY, true)) {
|
||||||
SearchMode.RecursivelyInSubdirectories
|
SearchMode.RecursivelyInSubdirectories
|
||||||
} else {
|
} else {
|
||||||
SearchMode.InCurrentDirectoryOnly
|
SearchMode.InCurrentDirectoryOnly
|
||||||
|
@@ -52,6 +52,7 @@ import com.zeapo.pwdstore.sshkeygen.ShowSshKeyFragment
|
|||||||
import com.zeapo.pwdstore.sshkeygen.SshKeyGenActivity
|
import com.zeapo.pwdstore.sshkeygen.SshKeyGenActivity
|
||||||
import com.zeapo.pwdstore.utils.BiometricAuthenticator
|
import com.zeapo.pwdstore.utils.BiometricAuthenticator
|
||||||
import com.zeapo.pwdstore.utils.PasswordRepository
|
import com.zeapo.pwdstore.utils.PasswordRepository
|
||||||
|
import com.zeapo.pwdstore.utils.PreferenceKeys
|
||||||
import com.zeapo.pwdstore.utils.autofillManager
|
import com.zeapo.pwdstore.utils.autofillManager
|
||||||
import com.zeapo.pwdstore.utils.getEncryptedPrefs
|
import com.zeapo.pwdstore.utils.getEncryptedPrefs
|
||||||
import me.msfjarvis.openpgpktx.util.OpenPgpUtils
|
import me.msfjarvis.openpgpktx.util.OpenPgpUtils
|
||||||
@@ -88,16 +89,16 @@ class UserPreference : AppCompatActivity() {
|
|||||||
addPreferencesFromResource(R.xml.preference)
|
addPreferencesFromResource(R.xml.preference)
|
||||||
|
|
||||||
// Git preferences
|
// Git preferences
|
||||||
val gitServerPreference = findPreference<Preference>("git_server_info")
|
val gitServerPreference = findPreference<Preference>(PreferenceKeys.GIT_SERVER_INFO)
|
||||||
val openkeystoreIdPreference = findPreference<Preference>("ssh_openkeystore_clear_keyid")
|
val openkeystoreIdPreference = findPreference<Preference>(PreferenceKeys.SSH_OPENKEYSTORE_CLEAR_KEY_ID)
|
||||||
val gitConfigPreference = findPreference<Preference>("git_config")
|
val gitConfigPreference = findPreference<Preference>(PreferenceKeys.GIT_CONFIG)
|
||||||
val sshKeyPreference = findPreference<Preference>("ssh_key")
|
val sshKeyPreference = findPreference<Preference>(PreferenceKeys.SSH_KEY)
|
||||||
val sshKeygenPreference = findPreference<Preference>("ssh_keygen")
|
val sshKeygenPreference = findPreference<Preference>(PreferenceKeys.SSH_KEYGEN)
|
||||||
clearSavedPassPreference = findPreference("clear_saved_pass")
|
clearSavedPassPreference = findPreference(PreferenceKeys.CLEAR_SAVED_PASS)
|
||||||
val viewSshKeyPreference = findPreference<Preference>("ssh_see_key")
|
val viewSshKeyPreference = findPreference<Preference>(PreferenceKeys.SSH_SEE_KEY)
|
||||||
val deleteRepoPreference = findPreference<Preference>("git_delete_repo")
|
val deleteRepoPreference = findPreference<Preference>(PreferenceKeys.GIT_DELETE_REPO)
|
||||||
val externalGitRepositoryPreference = findPreference<Preference>("git_external")
|
val externalGitRepositoryPreference = findPreference<Preference>(PreferenceKeys.GIT_EXTERNAL)
|
||||||
val selectExternalGitRepositoryPreference = findPreference<Preference>("pref_select_external")
|
val selectExternalGitRepositoryPreference = findPreference<Preference>(PreferenceKeys.PREF_SELECT_EXTERNAL)
|
||||||
|
|
||||||
if (!PasswordRepository.isGitRepo()) {
|
if (!PasswordRepository.isGitRepo()) {
|
||||||
listOfNotNull(
|
listOfNotNull(
|
||||||
@@ -109,21 +110,21 @@ class UserPreference : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crypto preferences
|
// Crypto preferences
|
||||||
val keyPreference = findPreference<Preference>("openpgp_key_id_pref")
|
val keyPreference = findPreference<Preference>(PreferenceKeys.OPENPGP_KEY_ID_PREF)
|
||||||
|
|
||||||
// General preferences
|
// General preferences
|
||||||
val showTimePreference = findPreference<Preference>("general_show_time")
|
val showTimePreference = findPreference<Preference>(PreferenceKeys.GENERAL_SHOW_TIME)
|
||||||
val clearClipboard20xPreference = findPreference<CheckBoxPreference>("clear_clipboard_20x")
|
val clearClipboard20xPreference = findPreference<CheckBoxPreference>(PreferenceKeys.CLEAR_CLIPBOARD_20X)
|
||||||
|
|
||||||
// Autofill preferences
|
// Autofill preferences
|
||||||
autoFillEnablePreference = findPreference("autofill_enable")
|
autoFillEnablePreference = findPreference(PreferenceKeys.AUTOFILL_ENABLE)
|
||||||
val oreoAutofillDirectoryStructurePreference = findPreference<ListPreference>("oreo_autofill_directory_structure")
|
val oreoAutofillDirectoryStructurePreference = findPreference<ListPreference>(PreferenceKeys.OREO_AUTOFILL_DIRECTORY_STRUCTURE)
|
||||||
val oreoAutofillDefaultUsername = findPreference<EditTextPreference>("oreo_autofill_default_username")
|
val oreoAutofillDefaultUsername = findPreference<EditTextPreference>(PreferenceKeys.OREO_AUTOFILL_DEFAULT_USERNAME)
|
||||||
val oreoAutofillCustomPublixSuffixes = findPreference<EditTextPreference>("oreo_autofill_custom_public_suffixes")
|
val oreoAutofillCustomPublixSuffixes = findPreference<EditTextPreference>(PreferenceKeys.OREO_AUTOFILL_CUSTOM_PUBLIC_SUFFIXES)
|
||||||
val autoFillAppsPreference = findPreference<Preference>("autofill_apps")
|
val autoFillAppsPreference = findPreference<Preference>(PreferenceKeys.AUTOFILL_APPS)
|
||||||
val autoFillDefaultPreference = findPreference<CheckBoxPreference>("autofill_default")
|
val autoFillDefaultPreference = findPreference<CheckBoxPreference>(PreferenceKeys.AUTOFILL_DEFAULT)
|
||||||
val autoFillAlwaysShowDialogPreference = findPreference<CheckBoxPreference>("autofill_always")
|
val autoFillAlwaysShowDialogPreference = findPreference<CheckBoxPreference>(PreferenceKeys.AUTOFILL_ALWAYS)
|
||||||
val autoFillShowFullNamePreference = findPreference<CheckBoxPreference>("autofill_full_path")
|
val autoFillShowFullNamePreference = findPreference<CheckBoxPreference>(PreferenceKeys.AUTOFILL_FULL_PATH)
|
||||||
autofillDependencies = listOfNotNull(
|
autofillDependencies = listOfNotNull(
|
||||||
autoFillAppsPreference,
|
autoFillAppsPreference,
|
||||||
autoFillDefaultPreference,
|
autoFillDefaultPreference,
|
||||||
@@ -143,13 +144,13 @@ class UserPreference : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Misc preferences
|
// Misc preferences
|
||||||
val appVersionPreference = findPreference<Preference>("app_version")
|
val appVersionPreference = findPreference<Preference>(PreferenceKeys.APP_VERSION)
|
||||||
|
|
||||||
selectExternalGitRepositoryPreference?.summary = sharedPreferences.getString("git_external_repo", getString(R.string.no_repo_selected))
|
selectExternalGitRepositoryPreference?.summary = sharedPreferences.getString(PreferenceKeys.GIT_EXTERNAL_REPO, getString(R.string.no_repo_selected))
|
||||||
viewSshKeyPreference?.isVisible = sharedPreferences.getBoolean("use_generated_key", false)
|
viewSshKeyPreference?.isVisible = sharedPreferences.getBoolean(PreferenceKeys.USE_GENERATED_KEY, false)
|
||||||
deleteRepoPreference?.isVisible = !sharedPreferences.getBoolean("git_external", false)
|
deleteRepoPreference?.isVisible = !sharedPreferences.getBoolean(PreferenceKeys.GIT_EXTERNAL, false)
|
||||||
clearClipboard20xPreference?.isVisible = sharedPreferences.getString("general_show_time", "45")?.toInt() != 0
|
clearClipboard20xPreference?.isVisible = sharedPreferences.getString(PreferenceKeys.GENERAL_SHOW_TIME, "45")?.toInt() != 0
|
||||||
openkeystoreIdPreference?.isVisible = sharedPreferences.getString("ssh_openkeystore_keyid", null)?.isNotEmpty()
|
openkeystoreIdPreference?.isVisible = sharedPreferences.getString(PreferenceKeys.SSH_OPENKEYSTORE_KEYID, null)?.isNotEmpty()
|
||||||
?: false
|
?: false
|
||||||
|
|
||||||
updateAutofillSettings()
|
updateAutofillSettings()
|
||||||
@@ -160,7 +161,7 @@ class UserPreference : AppCompatActivity() {
|
|||||||
keyPreference?.let { pref ->
|
keyPreference?.let { pref ->
|
||||||
updateKeyIDsSummary(pref)
|
updateKeyIDsSummary(pref)
|
||||||
pref.onPreferenceClickListener = ClickListener {
|
pref.onPreferenceClickListener = ClickListener {
|
||||||
val providerPackageName = requireNotNull(sharedPreferences.getString("openpgp_provider_list", ""))
|
val providerPackageName = requireNotNull(sharedPreferences.getString(PreferenceKeys.OPENPGP_PROVIDER_LIST, ""))
|
||||||
if (providerPackageName.isEmpty()) {
|
if (providerPackageName.isEmpty()) {
|
||||||
Snackbar.make(requireView(), resources.getString(R.string.provider_toast_text), Snackbar.LENGTH_LONG).show()
|
Snackbar.make(requireView(), resources.getString(R.string.provider_toast_text), Snackbar.LENGTH_LONG).show()
|
||||||
false
|
false
|
||||||
@@ -193,17 +194,17 @@ class UserPreference : AppCompatActivity() {
|
|||||||
|
|
||||||
clearSavedPassPreference?.onPreferenceClickListener = ClickListener {
|
clearSavedPassPreference?.onPreferenceClickListener = ClickListener {
|
||||||
encryptedPreferences.edit {
|
encryptedPreferences.edit {
|
||||||
if (encryptedPreferences.getString("https_password", null) != null)
|
if (encryptedPreferences.getString(PreferenceKeys.HTTPS_PASSWORD, null) != null)
|
||||||
remove("https_password")
|
remove(PreferenceKeys.HTTPS_PASSWORD)
|
||||||
else if (encryptedPreferences.getString("ssh_key_local_passphrase", null) != null)
|
else if (encryptedPreferences.getString(PreferenceKeys.SSH_KEY_LOCAL_PASSPHRASE, null) != null)
|
||||||
remove("ssh_key_local_passphrase")
|
remove(PreferenceKeys.SSH_KEY_LOCAL_PASSPHRASE)
|
||||||
}
|
}
|
||||||
updateClearSavedPassphrasePrefs()
|
updateClearSavedPassphrasePrefs()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
openkeystoreIdPreference?.onPreferenceClickListener = ClickListener {
|
openkeystoreIdPreference?.onPreferenceClickListener = ClickListener {
|
||||||
sharedPreferences.edit { putString("ssh_openkeystore_keyid", null) }
|
sharedPreferences.edit { putString(PreferenceKeys.SSH_OPENKEYSTORE_KEYID, null) }
|
||||||
it.isVisible = false
|
it.isVisible = false
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
@@ -237,7 +238,7 @@ class UserPreference : AppCompatActivity() {
|
|||||||
removeDynamicShortcuts(dynamicShortcuts.map { it.id }.toMutableList())
|
removeDynamicShortcuts(dynamicShortcuts.map { it.id }.toMutableList())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sharedPreferences.edit { putBoolean("repository_initialized", false) }
|
sharedPreferences.edit { putBoolean(PreferenceKeys.REPOSITORY_INITIALIZED, false) }
|
||||||
dialogInterface.cancel()
|
dialogInterface.cancel()
|
||||||
callingActivity.finish()
|
callingActivity.finish()
|
||||||
}
|
}
|
||||||
@@ -248,7 +249,7 @@ class UserPreference : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
selectExternalGitRepositoryPreference?.summary =
|
selectExternalGitRepositoryPreference?.summary =
|
||||||
sharedPreferences.getString("git_external_repo", context.getString(R.string.no_repo_selected))
|
sharedPreferences.getString(PreferenceKeys.GIT_EXTERNAL_REPO, context.getString(R.string.no_repo_selected))
|
||||||
selectExternalGitRepositoryPreference?.onPreferenceClickListener = ClickListener {
|
selectExternalGitRepositoryPreference?.onPreferenceClickListener = ClickListener {
|
||||||
callingActivity.selectExternalGitRepository()
|
callingActivity.selectExternalGitRepository()
|
||||||
true
|
true
|
||||||
@@ -257,7 +258,7 @@ class UserPreference : AppCompatActivity() {
|
|||||||
val resetRepo = Preference.OnPreferenceChangeListener { _, o ->
|
val resetRepo = Preference.OnPreferenceChangeListener { _, o ->
|
||||||
deleteRepoPreference?.isVisible = !(o as Boolean)
|
deleteRepoPreference?.isVisible = !(o as Boolean)
|
||||||
PasswordRepository.closeRepository()
|
PasswordRepository.closeRepository()
|
||||||
sharedPreferences.edit { putBoolean("repo_changed", true) }
|
sharedPreferences.edit { putBoolean(PreferenceKeys.REPO_CHANGED, true) }
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,8 +276,8 @@ class UserPreference : AppCompatActivity() {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
findPreference<Preference>("export_passwords")?.apply {
|
findPreference<Preference>(PreferenceKeys.EXPORT_PASSWORDS)?.apply {
|
||||||
isVisible = sharedPreferences.getBoolean("repository_initialized", false)
|
isVisible = sharedPreferences.getBoolean(PreferenceKeys.REPOSITORY_INITIALIZED, false)
|
||||||
onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||||
callingActivity.exportPasswords()
|
callingActivity.exportPasswords()
|
||||||
true
|
true
|
||||||
@@ -294,12 +295,13 @@ class UserPreference : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
showTimePreference?.summaryProvider = Preference.SummaryProvider<Preference> {
|
showTimePreference?.summaryProvider = Preference.SummaryProvider<Preference> {
|
||||||
getString(R.string.pref_clipboard_timeout_summary, sharedPreferences.getString("general_show_time", "45"))
|
getString(R.string.pref_clipboard_timeout_summary, sharedPreferences.getString
|
||||||
|
(PreferenceKeys.GENERAL_SHOW_TIME, "45"))
|
||||||
}
|
}
|
||||||
|
|
||||||
findPreference<CheckBoxPreference>("enable_debug_logging")?.isVisible = !BuildConfig.ENABLE_DEBUG_FEATURES
|
findPreference<CheckBoxPreference>(PreferenceKeys.ENABLE_DEBUG_LOGGING)?.isVisible = !BuildConfig.ENABLE_DEBUG_FEATURES
|
||||||
|
|
||||||
findPreference<CheckBoxPreference>("biometric_auth")?.apply {
|
findPreference<CheckBoxPreference>(PreferenceKeys.BIOMETRIC_AUTH)?.apply {
|
||||||
val isFingerprintSupported = BiometricManager.from(requireContext()).canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS
|
val isFingerprintSupported = BiometricManager.from(requireContext()).canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS
|
||||||
if (!isFingerprintSupported) {
|
if (!isFingerprintSupported) {
|
||||||
isEnabled = false
|
isEnabled = false
|
||||||
@@ -314,13 +316,13 @@ class UserPreference : AppCompatActivity() {
|
|||||||
when (result) {
|
when (result) {
|
||||||
is BiometricAuthenticator.Result.Success -> {
|
is BiometricAuthenticator.Result.Success -> {
|
||||||
// Apply the changes
|
// Apply the changes
|
||||||
putBoolean("biometric_auth", checked)
|
putBoolean(PreferenceKeys.BIOMETRIC_AUTH, checked)
|
||||||
isEnabled = true
|
isEnabled = true
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
// If any error occurs, revert back to the previous state. This
|
// If any error occurs, revert back to the previous state. This
|
||||||
// catch-all clause includes the cancellation case.
|
// catch-all clause includes the cancellation case.
|
||||||
putBoolean("biometric_auth", !checked)
|
putBoolean(PreferenceKeys.BIOMETRIC_AUTH, !checked)
|
||||||
isChecked = !checked
|
isChecked = !checked
|
||||||
isEnabled = true
|
isEnabled = true
|
||||||
}
|
}
|
||||||
@@ -337,20 +339,20 @@ class UserPreference : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val prefCustomXkpwdDictionary = findPreference<Preference>("pref_key_custom_dict")
|
val prefCustomXkpwdDictionary = findPreference<Preference>(PreferenceKeys.PREF_KEY_CUSTOM_DICT)
|
||||||
prefCustomXkpwdDictionary?.onPreferenceClickListener = ClickListener {
|
prefCustomXkpwdDictionary?.onPreferenceClickListener = ClickListener {
|
||||||
callingActivity.storeCustomDictionaryPath()
|
callingActivity.storeCustomDictionaryPath()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
val dictUri = sharedPreferences.getString("pref_key_custom_dict", "")
|
val dictUri = sharedPreferences.getString(PreferenceKeys.PREF_KEY_CUSTOM_DICT, "")
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(dictUri)) {
|
if (!TextUtils.isEmpty(dictUri)) {
|
||||||
setCustomDictSummary(prefCustomXkpwdDictionary, Uri.parse(dictUri))
|
setCustomDictSummary(prefCustomXkpwdDictionary, Uri.parse(dictUri))
|
||||||
}
|
}
|
||||||
|
|
||||||
val prefIsCustomDict = findPreference<CheckBoxPreference>("pref_key_is_custom_dict")
|
val prefIsCustomDict = findPreference<CheckBoxPreference>(PreferenceKeys.PREF_KEY_IS_CUSTOM_DICT)
|
||||||
val prefCustomDictPicker = findPreference<Preference>("pref_key_custom_dict")
|
val prefCustomDictPicker = findPreference<Preference>(PreferenceKeys.PREF_KEY_CUSTOM_DICT)
|
||||||
val prefPwgenType = findPreference<ListPreference>("pref_key_pwgen_type")
|
val prefPwgenType = findPreference<ListPreference>(PreferenceKeys.PREF_KEY_PWGEN_TYPE)
|
||||||
updateXkPasswdPrefsVisibility(prefPwgenType?.value, prefIsCustomDict, prefCustomDictPicker)
|
updateXkPasswdPrefsVisibility(prefPwgenType?.value, prefIsCustomDict, prefCustomDictPicker)
|
||||||
|
|
||||||
prefPwgenType?.onPreferenceChangeListener = ChangeListener { _, newValue ->
|
prefPwgenType?.onPreferenceChangeListener = ChangeListener { _, newValue ->
|
||||||
@@ -371,7 +373,7 @@ class UserPreference : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateKeyIDsSummary(preference: Preference) {
|
private fun updateKeyIDsSummary(preference: Preference) {
|
||||||
val selectedKeys = (sharedPreferences.getStringSet("openpgp_key_ids_set", null)
|
val selectedKeys = (sharedPreferences.getStringSet(PreferenceKeys.OPENPGP_KEY_IDS_SET, null)
|
||||||
?: HashSet()).toTypedArray()
|
?: HashSet()).toTypedArray()
|
||||||
preference.summary = if (selectedKeys.isEmpty()) {
|
preference.summary = if (selectedKeys.isEmpty()) {
|
||||||
resources.getString(R.string.pref_no_key_selected)
|
resources.getString(R.string.pref_no_key_selected)
|
||||||
@@ -410,8 +412,8 @@ class UserPreference : AppCompatActivity() {
|
|||||||
|
|
||||||
private fun updateClearSavedPassphrasePrefs() {
|
private fun updateClearSavedPassphrasePrefs() {
|
||||||
clearSavedPassPreference?.apply {
|
clearSavedPassPreference?.apply {
|
||||||
val sshPass = encryptedPreferences.getString("ssh_key_local_passphrase", null)
|
val sshPass = encryptedPreferences.getString(PreferenceKeys.SSH_KEY_LOCAL_PASSPHRASE, null)
|
||||||
val httpsPass = encryptedPreferences.getString("https_password", null)
|
val httpsPass = encryptedPreferences.getString(PreferenceKeys.HTTPS_PASSWORD, null)
|
||||||
if (sshPass == null && httpsPass == null) {
|
if (sshPass == null && httpsPass == null) {
|
||||||
isVisible = false
|
isVisible = false
|
||||||
return@apply
|
return@apply
|
||||||
@@ -654,8 +656,8 @@ class UserPreference : AppCompatActivity() {
|
|||||||
).show()
|
).show()
|
||||||
val prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext)
|
val prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext)
|
||||||
|
|
||||||
prefs.edit { putBoolean("use_generated_key", false) }
|
prefs.edit { putBoolean(PreferenceKeys.USE_GENERATED_KEY, false) }
|
||||||
getEncryptedPrefs("git_operation").edit { remove("ssh_key_local_passphrase") }
|
getEncryptedPrefs("git_operation").edit { remove(PreferenceKeys.SSH_KEY_LOCAL_PASSPHRASE) }
|
||||||
|
|
||||||
// Delete the public key from generation
|
// Delete the public key from generation
|
||||||
File("""$filesDir/.ssh_key.pub""").delete()
|
File("""$filesDir/.ssh_key.pub""").delete()
|
||||||
@@ -688,12 +690,12 @@ class UserPreference : AppCompatActivity() {
|
|||||||
.setTitle(getString(R.string.sdcard_root_warning_title))
|
.setTitle(getString(R.string.sdcard_root_warning_title))
|
||||||
.setMessage(getString(R.string.sdcard_root_warning_message))
|
.setMessage(getString(R.string.sdcard_root_warning_message))
|
||||||
.setPositiveButton("Remove everything") { _, _ ->
|
.setPositiveButton("Remove everything") { _, _ ->
|
||||||
prefs.edit { putString("git_external_repo", uri?.path) }
|
prefs.edit { putString(PreferenceKeys.GIT_EXTERNAL_REPO, uri?.path) }
|
||||||
}
|
}
|
||||||
.setNegativeButton(R.string.dialog_cancel, null)
|
.setNegativeButton(R.string.dialog_cancel, null)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
prefs.edit { putString("git_external_repo", repoPath) }
|
prefs.edit { putString(PreferenceKeys.GIT_EXTERNAL_REPO, repoPath) }
|
||||||
}
|
}
|
||||||
EXPORT_PASSWORDS -> {
|
EXPORT_PASSWORDS -> {
|
||||||
val uri = data.data
|
val uri = data.data
|
||||||
@@ -716,9 +718,9 @@ class UserPreference : AppCompatActivity() {
|
|||||||
).show()
|
).show()
|
||||||
val prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext)
|
val prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext)
|
||||||
|
|
||||||
prefs.edit { putString("pref_key_custom_dict", uri.toString()) }
|
prefs.edit { putString(PreferenceKeys.PREF_KEY_CUSTOM_DICT, uri.toString()) }
|
||||||
|
|
||||||
val customDictPref = prefsFragment.findPreference<Preference>("pref_key_custom_dict")
|
val customDictPref = prefsFragment.findPreference<Preference>(PreferenceKeys.PREF_KEY_CUSTOM_DICT)
|
||||||
setCustomDictSummary(customDictPref, uri)
|
setCustomDictSummary(customDictPref, uri)
|
||||||
// copy user selected file to internal storage
|
// copy user selected file to internal storage
|
||||||
val inputStream = contentResolver.openInputStream(uri)
|
val inputStream = contentResolver.openInputStream(uri)
|
||||||
|
@@ -31,6 +31,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|||||||
import com.zeapo.pwdstore.R
|
import com.zeapo.pwdstore.R
|
||||||
import com.zeapo.pwdstore.model.PasswordEntry
|
import com.zeapo.pwdstore.model.PasswordEntry
|
||||||
import com.zeapo.pwdstore.utils.PasswordRepository
|
import com.zeapo.pwdstore.utils.PasswordRepository
|
||||||
|
import com.zeapo.pwdstore.utils.PreferenceKeys
|
||||||
import com.zeapo.pwdstore.utils.splitLines
|
import com.zeapo.pwdstore.utils.splitLines
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
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
|
// if autofill_always checked, show dialog even if no matches (automatic
|
||||||
// or otherwise)
|
// or otherwise)
|
||||||
if (items.isEmpty() && !settings!!.getBoolean("autofill_always", false)) {
|
if (items.isEmpty() && !settings!!.getBoolean(PreferenceKeys.AUTOFILL_ALWAYS, false)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
showSelectPasswordDialog(packageName, appName, isWeb)
|
showSelectPasswordDialog(packageName, appName, isWeb)
|
||||||
@@ -268,7 +269,7 @@ class AutofillService : AccessibilityService(), CoroutineScope by CoroutineScope
|
|||||||
var settingsURL = webViewURL
|
var settingsURL = webViewURL
|
||||||
|
|
||||||
// if autofill_default is checked and prefs.getString DNE, 'Automatically match with password'/"first" otherwise "never"
|
// 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)
|
val prefs: SharedPreferences = getSharedPreferences("autofill_web", Context.MODE_PRIVATE)
|
||||||
var preference: String
|
var preference: String
|
||||||
|
|
||||||
@@ -305,7 +306,7 @@ class AutofillService : AccessibilityService(), CoroutineScope by CoroutineScope
|
|||||||
|
|
||||||
private fun setAppMatchingPasswords(appName: String, packageName: String) {
|
private fun setAppMatchingPasswords(appName: String, packageName: String) {
|
||||||
// if autofill_default is checked and prefs.getString DNE, 'Automatically match with password'/"first" otherwise "never"
|
// 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 prefs: SharedPreferences = getSharedPreferences("autofill", Context.MODE_PRIVATE)
|
||||||
val preference: String?
|
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)
|
// make it optional (or make height a setting for the same effect)
|
||||||
val itemNames = arrayOfNulls<CharSequence>(items.size + 2)
|
val itemNames = arrayOfNulls<CharSequence>(items.size + 2)
|
||||||
val passwordDirectory = PasswordRepository.getRepositoryDirectory(applicationContext).toString()
|
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) {
|
for (i in items.indices) {
|
||||||
if (autofillFullPath) {
|
if (autofillFullPath) {
|
||||||
itemNames[i] = items[i].path.replace(".gpg", "")
|
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
|
// save password entry for pasting the username as well
|
||||||
if (entry?.hasUsername() == true) {
|
if (entry?.hasUsername() == true) {
|
||||||
lastPassword = entry
|
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() }
|
withContext(Dispatchers.Main) { Toast.makeText(applicationContext, getString(R.string.autofill_toast_username, ttl), Toast.LENGTH_LONG).show() }
|
||||||
lastPasswordMaxDate = System.currentTimeMillis() + ttl * 1000L
|
lastPasswordMaxDate = System.currentTimeMillis() + ttl * 1000L
|
||||||
}
|
}
|
||||||
|
@@ -22,6 +22,7 @@ import com.github.ajalt.timberkt.e
|
|||||||
import com.zeapo.pwdstore.R
|
import com.zeapo.pwdstore.R
|
||||||
import com.zeapo.pwdstore.model.PasswordEntry
|
import com.zeapo.pwdstore.model.PasswordEntry
|
||||||
import com.zeapo.pwdstore.utils.PasswordRepository
|
import com.zeapo.pwdstore.utils.PasswordRepository
|
||||||
|
import com.zeapo.pwdstore.utils.PreferenceKeys
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
|
|
||||||
@@ -39,7 +40,7 @@ private fun ByteArray.base64(): String {
|
|||||||
private fun Context.getDefaultUsername(): String? {
|
private fun Context.getDefaultUsername(): String? {
|
||||||
return PreferenceManager
|
return PreferenceManager
|
||||||
.getDefaultSharedPreferences(this)
|
.getDefaultSharedPreferences(this)
|
||||||
.getString("oreo_autofill_default_username", null)
|
.getString(PreferenceKeys.OREO_AUTOFILL_DEFAULT_USERNAME, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun stableHash(array: Collection<ByteArray>): String {
|
private fun stableHash(array: Collection<ByteArray>): String {
|
||||||
|
@@ -7,6 +7,7 @@ package com.zeapo.pwdstore.autofill.oreo
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.Patterns
|
import android.util.Patterns
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
|
import com.zeapo.pwdstore.utils.PreferenceKeys
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import mozilla.components.lib.publicsuffixlist.PublicSuffixList
|
import mozilla.components.lib.publicsuffixlist.PublicSuffixList
|
||||||
|
|
||||||
@@ -67,7 +68,7 @@ fun getSuffixPlusUpToOne(domain: String, suffix: String): String? {
|
|||||||
|
|
||||||
fun getCustomSuffixes(context: Context): Sequence<String> {
|
fun getCustomSuffixes(context: Context): Sequence<String> {
|
||||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
return prefs.getString("oreo_autofill_custom_public_suffixes", "")!!
|
return prefs.getString(PreferenceKeys.OREO_AUTOFILL_CUSTOM_PUBLIC_SUFFIXES, "")!!
|
||||||
.splitToSequence('\n')
|
.splitToSequence('\n')
|
||||||
.filter { it.isNotBlank() && it.first() != '.' && it.last() != '.' }
|
.filter { it.isNotBlank() && it.first() != '.' && it.last() != '.' }
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,7 @@ import com.google.android.material.snackbar.Snackbar
|
|||||||
import com.zeapo.pwdstore.ClipboardService
|
import com.zeapo.pwdstore.ClipboardService
|
||||||
import com.zeapo.pwdstore.R
|
import com.zeapo.pwdstore.R
|
||||||
import com.zeapo.pwdstore.UserPreference
|
import com.zeapo.pwdstore.UserPreference
|
||||||
|
import com.zeapo.pwdstore.utils.PreferenceKeys
|
||||||
import com.zeapo.pwdstore.utils.clipboard
|
import com.zeapo.pwdstore.utils.clipboard
|
||||||
import com.zeapo.pwdstore.utils.snackbar
|
import com.zeapo.pwdstore.utils.snackbar
|
||||||
import me.msfjarvis.openpgpktx.util.OpenPgpApi
|
import me.msfjarvis.openpgpktx.util.OpenPgpApi
|
||||||
@@ -94,7 +95,7 @@ open class BasePgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBou
|
|||||||
window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
|
window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
|
||||||
tag(TAG)
|
tag(TAG)
|
||||||
|
|
||||||
keyIDs = settings.getStringSet("openpgp_key_ids_set", null) ?: emptySet()
|
keyIDs = settings.getStringSet(PreferenceKeys.OPENPGP_KEY_IDS_SET, null) ?: emptySet()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -133,7 +134,7 @@ open class BasePgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBou
|
|||||||
* [startActivityForResult].
|
* [startActivityForResult].
|
||||||
*/
|
*/
|
||||||
fun bindToOpenKeychain(onBoundListener: OpenPgpServiceConnection.OnBound, activityResult: ActivityResultLauncher<Intent>) {
|
fun bindToOpenKeychain(onBoundListener: OpenPgpServiceConnection.OnBound, activityResult: ActivityResultLauncher<Intent>) {
|
||||||
val providerPackageName = settings.getString("openpgp_provider_list", "")
|
val providerPackageName = settings.getString(PreferenceKeys.OPENPGP_PROVIDER_LIST, "")
|
||||||
if (providerPackageName.isNullOrEmpty()) {
|
if (providerPackageName.isNullOrEmpty()) {
|
||||||
Toast.makeText(this, resources.getString(R.string.provider_toast_text), Toast.LENGTH_LONG).show()
|
Toast.makeText(this, resources.getString(R.string.provider_toast_text), Toast.LENGTH_LONG).show()
|
||||||
activityResult.launch(Intent(this, UserPreference::class.java))
|
activityResult.launch(Intent(this, UserPreference::class.java))
|
||||||
@@ -215,7 +216,8 @@ open class BasePgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBou
|
|||||||
|
|
||||||
var clearAfter = 45
|
var clearAfter = 45
|
||||||
try {
|
try {
|
||||||
clearAfter = (settings.getString("general_show_time", "45") ?: "45").toInt()
|
clearAfter = (settings.getString(PreferenceKeys.GENERAL_SHOW_TIME, "45")
|
||||||
|
?: "45").toInt()
|
||||||
} catch (_: NumberFormatException) {
|
} catch (_: NumberFormatException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,6 +21,7 @@ import com.zeapo.pwdstore.R
|
|||||||
import com.zeapo.pwdstore.databinding.DecryptLayoutBinding
|
import com.zeapo.pwdstore.databinding.DecryptLayoutBinding
|
||||||
import com.zeapo.pwdstore.model.PasswordEntry
|
import com.zeapo.pwdstore.model.PasswordEntry
|
||||||
import com.zeapo.pwdstore.utils.Otp
|
import com.zeapo.pwdstore.utils.Otp
|
||||||
|
import com.zeapo.pwdstore.utils.PreferenceKeys
|
||||||
import com.zeapo.pwdstore.utils.viewBinding
|
import com.zeapo.pwdstore.utils.viewBinding
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
@@ -148,8 +149,8 @@ class DecryptActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
|
|||||||
when (result?.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
|
when (result?.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
|
||||||
OpenPgpApi.RESULT_CODE_SUCCESS -> {
|
OpenPgpApi.RESULT_CODE_SUCCESS -> {
|
||||||
try {
|
try {
|
||||||
val showPassword = settings.getBoolean("show_password", true)
|
val showPassword = settings.getBoolean(PreferenceKeys.SHOW_PASSWORD, true)
|
||||||
val showExtraContent = settings.getBoolean("show_extra_content", true)
|
val showExtraContent = settings.getBoolean(PreferenceKeys.SHOW_EXTRA_CONTENT, true)
|
||||||
val monoTypeface = Typeface.createFromAsset(assets, "fonts/sourcecodepro.ttf")
|
val monoTypeface = Typeface.createFromAsset(assets, "fonts/sourcecodepro.ttf")
|
||||||
val entry = PasswordEntry(outputStream)
|
val entry = PasswordEntry(outputStream)
|
||||||
|
|
||||||
@@ -211,7 +212,7 @@ class DecryptActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.getBoolean("copy_on_decrypt", true)) {
|
if (settings.getBoolean(PreferenceKeys.COPY_ON_DECRYPT, true)) {
|
||||||
copyPasswordToClipboard(entry.password)
|
copyPasswordToClipboard(entry.password)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
@@ -14,6 +14,7 @@ import androidx.core.content.edit
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.github.ajalt.timberkt.Timber
|
import com.github.ajalt.timberkt.Timber
|
||||||
import com.github.ajalt.timberkt.e
|
import com.github.ajalt.timberkt.e
|
||||||
|
import com.zeapo.pwdstore.utils.PreferenceKeys
|
||||||
import com.zeapo.pwdstore.utils.snackbar
|
import com.zeapo.pwdstore.utils.snackbar
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -69,7 +70,7 @@ class GetKeyIdsActivity : BasePgpActivity() {
|
|||||||
?: LongArray(0)
|
?: LongArray(0)
|
||||||
val keys = ids.map { it.toString() }.toSet()
|
val keys = ids.map { it.toString() }.toSet()
|
||||||
// use Long
|
// use Long
|
||||||
settings.edit { putStringSet("openpgp_key_ids_set", keys) }
|
settings.edit { putStringSet(PreferenceKeys.OPENPGP_KEY_IDS_SET, keys) }
|
||||||
snackbar(message = "PGP keys selected")
|
snackbar(message = "PGP keys selected")
|
||||||
setResult(RESULT_OK)
|
setResult(RESULT_OK)
|
||||||
finish()
|
finish()
|
||||||
|
@@ -27,6 +27,7 @@ import com.zeapo.pwdstore.model.PasswordEntry
|
|||||||
import com.zeapo.pwdstore.ui.dialogs.PasswordGeneratorDialogFragment
|
import com.zeapo.pwdstore.ui.dialogs.PasswordGeneratorDialogFragment
|
||||||
import com.zeapo.pwdstore.ui.dialogs.XkPasswordGeneratorDialogFragment
|
import com.zeapo.pwdstore.ui.dialogs.XkPasswordGeneratorDialogFragment
|
||||||
import com.zeapo.pwdstore.utils.PasswordRepository
|
import com.zeapo.pwdstore.utils.PasswordRepository
|
||||||
|
import com.zeapo.pwdstore.utils.PreferenceKeys
|
||||||
import com.zeapo.pwdstore.utils.commitChange
|
import com.zeapo.pwdstore.utils.commitChange
|
||||||
import com.zeapo.pwdstore.utils.isInsideRepository
|
import com.zeapo.pwdstore.utils.isInsideRepository
|
||||||
import com.zeapo.pwdstore.utils.snackbar
|
import com.zeapo.pwdstore.utils.snackbar
|
||||||
@@ -175,7 +176,7 @@ class PasswordCreationActivity : BasePgpActivity(), OpenPgpServiceConnection.OnB
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun generatePassword() {
|
private fun generatePassword() {
|
||||||
when (settings.getString("pref_key_pwgen_type", KEY_PWGEN_TYPE_CLASSIC)) {
|
when (settings.getString(PreferenceKeys.PREF_KEY_PWGEN_TYPE, KEY_PWGEN_TYPE_CLASSIC)) {
|
||||||
KEY_PWGEN_TYPE_CLASSIC -> PasswordGeneratorDialogFragment()
|
KEY_PWGEN_TYPE_CLASSIC -> PasswordGeneratorDialogFragment()
|
||||||
.show(supportFragmentManager, "generator")
|
.show(supportFragmentManager, "generator")
|
||||||
KEY_PWGEN_TYPE_XKPASSWD -> XkPasswordGeneratorDialogFragment()
|
KEY_PWGEN_TYPE_XKPASSWD -> XkPasswordGeneratorDialogFragment()
|
||||||
|
@@ -22,6 +22,7 @@ import com.zeapo.pwdstore.git.config.ConnectionMode
|
|||||||
import com.zeapo.pwdstore.git.config.Protocol
|
import com.zeapo.pwdstore.git.config.Protocol
|
||||||
import com.zeapo.pwdstore.git.config.SshApiSessionFactory
|
import com.zeapo.pwdstore.git.config.SshApiSessionFactory
|
||||||
import com.zeapo.pwdstore.utils.PasswordRepository
|
import com.zeapo.pwdstore.utils.PasswordRepository
|
||||||
|
import com.zeapo.pwdstore.utils.PreferenceKeys
|
||||||
import com.zeapo.pwdstore.utils.getEncryptedPrefs
|
import com.zeapo.pwdstore.utils.getEncryptedPrefs
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
@@ -53,14 +54,14 @@ abstract class BaseGitActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
settings = PreferenceManager.getDefaultSharedPreferences(this)
|
settings = PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
encryptedSettings = getEncryptedPrefs("git_operation")
|
encryptedSettings = getEncryptedPrefs("git_operation")
|
||||||
protocol = Protocol.fromString(settings.getString("git_remote_protocol", null))
|
protocol = Protocol.fromString(settings.getString(PreferenceKeys.GIT_REMOTE_PROTOCOL, null))
|
||||||
connectionMode = ConnectionMode.fromString(settings.getString("git_remote_auth", null))
|
connectionMode = ConnectionMode.fromString(settings.getString(PreferenceKeys.GIT_REMOTE_AUTH, null))
|
||||||
serverHostname = settings.getString("git_remote_server", null) ?: ""
|
serverHostname = settings.getString(PreferenceKeys.GIT_REMOTE_SERVER, null) ?: ""
|
||||||
serverPort = settings.getString("git_remote_port", null) ?: ""
|
serverPort = settings.getString(PreferenceKeys.GIT_REMOTE_PORT, null) ?: ""
|
||||||
serverUser = settings.getString("git_remote_username", null) ?: ""
|
serverUser = settings.getString(PreferenceKeys.GIT_REMOTE_USERNAME, null) ?: ""
|
||||||
serverPath = settings.getString("git_remote_location", null) ?: ""
|
serverPath = settings.getString(PreferenceKeys.GIT_REMOTE_LOCATION, null) ?: ""
|
||||||
username = settings.getString("git_config_user_name", null) ?: ""
|
username = settings.getString(PreferenceKeys.GIT_CONFIG_USER_NAME, null) ?: ""
|
||||||
email = settings.getString("git_config_user_email", null) ?: ""
|
email = settings.getString(PreferenceKeys.GIT_CONFIG_USER_EMAIL, null) ?: ""
|
||||||
updateUrl()
|
updateUrl()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +149,7 @@ abstract class BaseGitActivity : AppCompatActivity() {
|
|||||||
PasswordRepository.addRemote("origin", newUrl, true)
|
PasswordRepository.addRemote("origin", newUrl, true)
|
||||||
// When the server changes, remote password and host key file should be deleted.
|
// When the server changes, remote password and host key file should be deleted.
|
||||||
if (previousUrl.isNotEmpty() && newUrl != previousUrl) {
|
if (previousUrl.isNotEmpty() && newUrl != previousUrl) {
|
||||||
encryptedSettings.edit { remove("https_password") }
|
encryptedSettings.edit { remove(PreferenceKeys.HTTPS_PASSWORD) }
|
||||||
File("$filesDir/.host_key").delete()
|
File("$filesDir/.host_key").delete()
|
||||||
}
|
}
|
||||||
url = newUrl
|
url = newUrl
|
||||||
|
@@ -14,6 +14,7 @@ import com.google.android.material.snackbar.Snackbar
|
|||||||
import com.zeapo.pwdstore.R
|
import com.zeapo.pwdstore.R
|
||||||
import com.zeapo.pwdstore.databinding.ActivityGitConfigBinding
|
import com.zeapo.pwdstore.databinding.ActivityGitConfigBinding
|
||||||
import com.zeapo.pwdstore.utils.PasswordRepository
|
import com.zeapo.pwdstore.utils.PasswordRepository
|
||||||
|
import com.zeapo.pwdstore.utils.PreferenceKeys
|
||||||
import com.zeapo.pwdstore.utils.viewBinding
|
import com.zeapo.pwdstore.utils.viewBinding
|
||||||
import org.eclipse.jgit.lib.Constants
|
import org.eclipse.jgit.lib.Constants
|
||||||
|
|
||||||
@@ -58,8 +59,8 @@ class GitConfigActivity : BaseGitActivity() {
|
|||||||
.show()
|
.show()
|
||||||
} else {
|
} else {
|
||||||
settings.edit {
|
settings.edit {
|
||||||
putString("git_config_user_email", email)
|
putString(PreferenceKeys.GIT_CONFIG_USER_EMAIL, email)
|
||||||
putString("git_config_user_name", name)
|
putString(PreferenceKeys.GIT_CONFIG_USER_NAME, name)
|
||||||
}
|
}
|
||||||
PasswordRepository.setUserName(name)
|
PasswordRepository.setUserName(name)
|
||||||
PasswordRepository.setUserEmail(email)
|
PasswordRepository.setUserEmail(email)
|
||||||
|
@@ -23,6 +23,7 @@ import com.zeapo.pwdstore.git.config.SshApiSessionFactory
|
|||||||
import com.zeapo.pwdstore.git.config.SshAuthData
|
import com.zeapo.pwdstore.git.config.SshAuthData
|
||||||
import com.zeapo.pwdstore.git.config.SshjSessionFactory
|
import com.zeapo.pwdstore.git.config.SshjSessionFactory
|
||||||
import com.zeapo.pwdstore.utils.PasswordRepository
|
import com.zeapo.pwdstore.utils.PasswordRepository
|
||||||
|
import com.zeapo.pwdstore.utils.PreferenceKeys
|
||||||
import com.zeapo.pwdstore.utils.getEncryptedPrefs
|
import com.zeapo.pwdstore.utils.getEncryptedPrefs
|
||||||
import com.zeapo.pwdstore.utils.requestInputFocusOnView
|
import com.zeapo.pwdstore.utils.requestInputFocusOnView
|
||||||
import net.schmizz.sshj.userauth.password.PasswordFinder
|
import net.schmizz.sshj.userauth.password.PasswordFinder
|
||||||
@@ -50,7 +51,7 @@ private class GitOperationCredentialFinder(val callingActivity: Activity, val co
|
|||||||
@StringRes val errorRes: Int
|
@StringRes val errorRes: Int
|
||||||
when (connectionMode) {
|
when (connectionMode) {
|
||||||
ConnectionMode.SshKey -> {
|
ConnectionMode.SshKey -> {
|
||||||
credentialPref = "ssh_key_local_passphrase"
|
credentialPref = PreferenceKeys.SSH_KEY_LOCAL_PASSPHRASE
|
||||||
messageRes = R.string.passphrase_dialog_text
|
messageRes = R.string.passphrase_dialog_text
|
||||||
hintRes = R.string.ssh_keygen_passphrase
|
hintRes = R.string.ssh_keygen_passphrase
|
||||||
rememberRes = R.string.git_operation_remember_passphrase
|
rememberRes = R.string.git_operation_remember_passphrase
|
||||||
@@ -58,7 +59,7 @@ private class GitOperationCredentialFinder(val callingActivity: Activity, val co
|
|||||||
}
|
}
|
||||||
ConnectionMode.Password -> {
|
ConnectionMode.Password -> {
|
||||||
// Could be either an SSH or an HTTPS password
|
// Could be either an SSH or an HTTPS password
|
||||||
credentialPref = "https_password"
|
credentialPref = PreferenceKeys.HTTPS_PASSWORD
|
||||||
messageRes = R.string.password_dialog_text
|
messageRes = R.string.password_dialog_text
|
||||||
hintRes = R.string.git_operation_hint_password
|
hintRes = R.string.git_operation_hint_password
|
||||||
rememberRes = R.string.git_operation_remember_password
|
rememberRes = R.string.git_operation_remember_password
|
||||||
@@ -222,14 +223,14 @@ abstract class GitOperation(gitDir: File, internal val callingActivity: Activity
|
|||||||
when (SshSessionFactory.getInstance()) {
|
when (SshSessionFactory.getInstance()) {
|
||||||
is SshApiSessionFactory -> {
|
is SshApiSessionFactory -> {
|
||||||
PreferenceManager.getDefaultSharedPreferences(callingActivity.applicationContext)
|
PreferenceManager.getDefaultSharedPreferences(callingActivity.applicationContext)
|
||||||
.edit { remove("ssh_openkeystore_keyid") }
|
.edit { remove(PreferenceKeys.SSH_OPENKEYSTORE_KEYID) }
|
||||||
}
|
}
|
||||||
is SshjSessionFactory -> {
|
is SshjSessionFactory -> {
|
||||||
callingActivity.applicationContext
|
callingActivity.applicationContext
|
||||||
.getEncryptedPrefs("git_operation")
|
.getEncryptedPrefs("git_operation")
|
||||||
.edit {
|
.edit {
|
||||||
remove("ssh_key_local_passphrase")
|
remove(PreferenceKeys.SSH_KEY_LOCAL_PASSPHRASE)
|
||||||
remove("https_password")
|
remove(PreferenceKeys.HTTPS_PASSWORD)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,7 @@ import com.zeapo.pwdstore.databinding.ActivityGitCloneBinding
|
|||||||
import com.zeapo.pwdstore.git.config.ConnectionMode
|
import com.zeapo.pwdstore.git.config.ConnectionMode
|
||||||
import com.zeapo.pwdstore.git.config.Protocol
|
import com.zeapo.pwdstore.git.config.Protocol
|
||||||
import com.zeapo.pwdstore.utils.PasswordRepository
|
import com.zeapo.pwdstore.utils.PasswordRepository
|
||||||
|
import com.zeapo.pwdstore.utils.PreferenceKeys
|
||||||
import com.zeapo.pwdstore.utils.viewBinding
|
import com.zeapo.pwdstore.utils.viewBinding
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
@@ -107,12 +108,12 @@ class GitServerConfigActivity : BaseGitActivity() {
|
|||||||
when (val result = updateUrl()) {
|
when (val result = updateUrl()) {
|
||||||
GitUpdateUrlResult.Ok -> {
|
GitUpdateUrlResult.Ok -> {
|
||||||
settings.edit {
|
settings.edit {
|
||||||
putString("git_remote_protocol", protocol.pref)
|
putString(PreferenceKeys.GIT_REMOTE_PROTOCOL, protocol.pref)
|
||||||
putString("git_remote_auth", connectionMode.pref)
|
putString(PreferenceKeys.GIT_REMOTE_AUTH, connectionMode.pref)
|
||||||
putString("git_remote_server", serverHostname)
|
putString(PreferenceKeys.GIT_REMOTE_SERVER, serverHostname)
|
||||||
putString("git_remote_port", serverPort)
|
putString(PreferenceKeys.GIT_REMOTE_PORT, serverPort)
|
||||||
putString("git_remote_username", serverUser)
|
putString(PreferenceKeys.GIT_REMOTE_USERNAME, serverUser)
|
||||||
putString("git_remote_location", serverPath)
|
putString(PreferenceKeys.GIT_REMOTE_LOCATION, serverPath)
|
||||||
}
|
}
|
||||||
if (!isClone) {
|
if (!isClone) {
|
||||||
Snackbar.make(binding.root, getString(R.string.git_server_config_save_success), Snackbar.LENGTH_SHORT).show()
|
Snackbar.make(binding.root, getString(R.string.git_server_config_save_success), Snackbar.LENGTH_SHORT).show()
|
||||||
|
@@ -21,6 +21,7 @@ import com.jcraft.jsch.Session;
|
|||||||
import com.jcraft.jsch.UserInfo;
|
import com.jcraft.jsch.UserInfo;
|
||||||
import com.zeapo.pwdstore.R;
|
import com.zeapo.pwdstore.R;
|
||||||
import com.zeapo.pwdstore.git.BaseGitActivity;
|
import com.zeapo.pwdstore.git.BaseGitActivity;
|
||||||
|
import com.zeapo.pwdstore.utils.PreferenceKeys;
|
||||||
|
|
||||||
import org.eclipse.jgit.errors.UnsupportedCredentialItem;
|
import org.eclipse.jgit.errors.UnsupportedCredentialItem;
|
||||||
import org.eclipse.jgit.transport.CredentialItem;
|
import org.eclipse.jgit.transport.CredentialItem;
|
||||||
@@ -51,8 +52,8 @@ public class SshApiSessionFactory extends JschConfigSessionFactory {
|
|||||||
*/
|
*/
|
||||||
public static final int POST_SIGNATURE = 301;
|
public static final int POST_SIGNATURE = 301;
|
||||||
|
|
||||||
private String username;
|
private final String username;
|
||||||
private Identity identity;
|
private final Identity identity;
|
||||||
|
|
||||||
public SshApiSessionFactory(String username, Identity identity) {
|
public SshApiSessionFactory(String username, Identity identity) {
|
||||||
this.username = username;
|
this.username = username;
|
||||||
@@ -108,12 +109,12 @@ public class SshApiSessionFactory extends JschConfigSessionFactory {
|
|||||||
* build.
|
* build.
|
||||||
*/
|
*/
|
||||||
public static class IdentityBuilder {
|
public static class IdentityBuilder {
|
||||||
private SshAuthenticationConnection connection;
|
private final SshAuthenticationConnection connection;
|
||||||
private SshAuthenticationApi api;
|
private SshAuthenticationApi api;
|
||||||
private String keyId, description, alg;
|
private String keyId, description, alg;
|
||||||
private byte[] publicKey;
|
private byte[] publicKey;
|
||||||
private BaseGitActivity callingActivity;
|
private final BaseGitActivity callingActivity;
|
||||||
private SharedPreferences settings;
|
private final SharedPreferences settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new IdentityBuilder
|
* Construct a new IdentityBuilder
|
||||||
@@ -137,7 +138,7 @@ public class SshApiSessionFactory extends JschConfigSessionFactory {
|
|||||||
settings =
|
settings =
|
||||||
PreferenceManager.getDefaultSharedPreferences(
|
PreferenceManager.getDefaultSharedPreferences(
|
||||||
callingActivity.getApplicationContext());
|
callingActivity.getApplicationContext());
|
||||||
keyId = settings.getString("ssh_openkeystore_keyid", null);
|
keyId = settings.getString(PreferenceKeys.SSH_OPENKEYSTORE_KEYID, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -163,7 +164,7 @@ public class SshApiSessionFactory extends JschConfigSessionFactory {
|
|||||||
SshAuthenticationApiError error =
|
SshAuthenticationApiError error =
|
||||||
result.getParcelableExtra(SshAuthenticationApi.EXTRA_ERROR);
|
result.getParcelableExtra(SshAuthenticationApi.EXTRA_ERROR);
|
||||||
// On an OpenKeychain SSH API error, clear out the stored keyid
|
// On an OpenKeychain SSH API error, clear out the stored keyid
|
||||||
settings.edit().putString("ssh_openkeystore_keyid", null).apply();
|
settings.edit().putString(PreferenceKeys.SSH_OPENKEYSTORE_KEYID, null).apply();
|
||||||
|
|
||||||
switch (error.getError()) {
|
switch (error.getError()) {
|
||||||
// If the problem was just a bad keyid, reset to allow them to choose a
|
// If the problem was just a bad keyid, reset to allow them to choose a
|
||||||
@@ -214,7 +215,7 @@ public class SshApiSessionFactory extends JschConfigSessionFactory {
|
|||||||
if (intent.hasExtra(SshAuthenticationApi.EXTRA_KEY_ID)) {
|
if (intent.hasExtra(SshAuthenticationApi.EXTRA_KEY_ID)) {
|
||||||
keyId = intent.getStringExtra(SshAuthenticationApi.EXTRA_KEY_ID);
|
keyId = intent.getStringExtra(SshAuthenticationApi.EXTRA_KEY_ID);
|
||||||
description = intent.getStringExtra(SshAuthenticationApi.EXTRA_KEY_DESCRIPTION);
|
description = intent.getStringExtra(SshAuthenticationApi.EXTRA_KEY_DESCRIPTION);
|
||||||
settings.edit().putString("ssh_openkeystore_keyid", keyId).apply();
|
settings.edit().putString(PreferenceKeys.SSH_OPENKEYSTORE_KEYID, keyId).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (intent.hasExtra(SshAuthenticationApi.EXTRA_SSH_PUBLIC_KEY)) {
|
if (intent.hasExtra(SshAuthenticationApi.EXTRA_SSH_PUBLIC_KEY)) {
|
||||||
@@ -284,10 +285,12 @@ public class SshApiSessionFactory extends JschConfigSessionFactory {
|
|||||||
* A Jsch identity that delegates key operations via the OpenKeychain SSH API
|
* A Jsch identity that delegates key operations via the OpenKeychain SSH API
|
||||||
*/
|
*/
|
||||||
public static class ApiIdentity implements Identity {
|
public static class ApiIdentity implements Identity {
|
||||||
private String keyId, description, alg;
|
private final String keyId;
|
||||||
private byte[] publicKey;
|
private final String description;
|
||||||
private Activity callingActivity;
|
private final String alg;
|
||||||
private SshAuthenticationApi api;
|
private final byte[] publicKey;
|
||||||
|
private final Activity callingActivity;
|
||||||
|
private final SshAuthenticationApi api;
|
||||||
private CountDownLatch latch;
|
private CountDownLatch latch;
|
||||||
private byte[] signature;
|
private byte[] signature;
|
||||||
|
|
||||||
|
@@ -7,6 +7,7 @@ package com.zeapo.pwdstore.pwgen
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import com.zeapo.pwdstore.R
|
import com.zeapo.pwdstore.R
|
||||||
|
import com.zeapo.pwdstore.utils.PreferenceKeys
|
||||||
import com.zeapo.pwdstore.utils.clearFlag
|
import com.zeapo.pwdstore.utils.clearFlag
|
||||||
import com.zeapo.pwdstore.utils.hasFlag
|
import com.zeapo.pwdstore.utils.hasFlag
|
||||||
|
|
||||||
@@ -102,7 +103,7 @@ object PasswordGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val length = prefs.getInt("length", DEFAULT_LENGTH)
|
val length = prefs.getInt(PreferenceKeys.LENGTH, DEFAULT_LENGTH)
|
||||||
if (pwgenFlags.clearFlag(NO_AMBIGUOUS) == 0) {
|
if (pwgenFlags.clearFlag(NO_AMBIGUOUS) == 0) {
|
||||||
throw PasswordGeneratorException(ctx.resources.getString(R.string.pwgen_no_chars_error))
|
throw PasswordGeneratorException(ctx.resources.getString(R.string.pwgen_no_chars_error))
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,7 @@ package com.zeapo.pwdstore.pwgenxkpwd
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import com.zeapo.pwdstore.R
|
import com.zeapo.pwdstore.R
|
||||||
|
import com.zeapo.pwdstore.utils.PreferenceKeys
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class XkpwdDictionary(context: Context) {
|
class XkpwdDictionary(context: Context) {
|
||||||
@@ -14,10 +15,10 @@ class XkpwdDictionary(context: Context) {
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
val uri = prefs.getString("pref_key_custom_dict", "")!!
|
val uri = prefs.getString(PreferenceKeys.PREF_KEY_CUSTOM_DICT, "")!!
|
||||||
val customDictFile = File(context.filesDir, XKPWD_CUSTOM_DICT_FILE)
|
val customDictFile = File(context.filesDir, XKPWD_CUSTOM_DICT_FILE)
|
||||||
|
|
||||||
val lines = if (prefs.getBoolean("pref_key_is_custom_dict", false) &&
|
val lines = if (prefs.getBoolean(PreferenceKeys.PREF_KEY_IS_CUSTOM_DICT, false) &&
|
||||||
uri.isNotEmpty() && customDictFile.canRead()) {
|
uri.isNotEmpty() && customDictFile.canRead()) {
|
||||||
customDictFile.readLines()
|
customDictFile.readLines()
|
||||||
} else {
|
} else {
|
||||||
|
@@ -18,6 +18,7 @@ import com.zeapo.pwdstore.R
|
|||||||
import com.zeapo.pwdstore.SearchableRepositoryAdapter
|
import com.zeapo.pwdstore.SearchableRepositoryAdapter
|
||||||
import com.zeapo.pwdstore.stableId
|
import com.zeapo.pwdstore.stableId
|
||||||
import com.zeapo.pwdstore.utils.PasswordItem
|
import com.zeapo.pwdstore.utils.PasswordItem
|
||||||
|
import com.zeapo.pwdstore.utils.PreferenceKeys
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
open class PasswordItemRecyclerAdapter :
|
open class PasswordItemRecyclerAdapter :
|
||||||
@@ -50,7 +51,7 @@ open class PasswordItemRecyclerAdapter :
|
|||||||
fun bind(item: PasswordItem) {
|
fun bind(item: PasswordItem) {
|
||||||
val settings =
|
val settings =
|
||||||
PreferenceManager.getDefaultSharedPreferences(itemView.context.applicationContext)
|
PreferenceManager.getDefaultSharedPreferences(itemView.context.applicationContext)
|
||||||
val showHidden = settings.getBoolean("show_hidden_folders", false)
|
val showHidden = settings.getBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, false)
|
||||||
name.text = item.toString()
|
name.text = item.toString()
|
||||||
if (item.type == PasswordItem.TYPE_CATEGORY) {
|
if (item.type == PasswordItem.TYPE_CATEGORY) {
|
||||||
typeImage.setImageResource(R.drawable.ic_multiple_files_24dp)
|
typeImage.setImageResource(R.drawable.ic_multiple_files_24dp)
|
||||||
|
@@ -24,6 +24,7 @@ import com.zeapo.pwdstore.pwgen.PasswordGenerator.PasswordGeneratorException
|
|||||||
import com.zeapo.pwdstore.pwgen.PasswordGenerator.generate
|
import com.zeapo.pwdstore.pwgen.PasswordGenerator.generate
|
||||||
import com.zeapo.pwdstore.pwgen.PasswordGenerator.setPrefs
|
import com.zeapo.pwdstore.pwgen.PasswordGenerator.setPrefs
|
||||||
import com.zeapo.pwdstore.pwgen.PasswordOption
|
import com.zeapo.pwdstore.pwgen.PasswordOption
|
||||||
|
import com.zeapo.pwdstore.utils.PreferenceKeys
|
||||||
|
|
||||||
class PasswordGeneratorDialogFragment : DialogFragment() {
|
class PasswordGeneratorDialogFragment : DialogFragment() {
|
||||||
|
|
||||||
@@ -45,7 +46,7 @@ class PasswordGeneratorDialogFragment : DialogFragment() {
|
|||||||
view.findViewById<CheckBox>(R.id.pronounceable)?.isChecked = !prefs.getBoolean(PasswordOption.FullyRandom.key, true)
|
view.findViewById<CheckBox>(R.id.pronounceable)?.isChecked = !prefs.getBoolean(PasswordOption.FullyRandom.key, true)
|
||||||
|
|
||||||
val textView: AppCompatEditText = view.findViewById(R.id.lengthNumber)
|
val textView: AppCompatEditText = view.findViewById(R.id.lengthNumber)
|
||||||
textView.setText(prefs.getInt("length", 20).toString())
|
textView.setText(prefs.getInt(PreferenceKeys.LENGTH, 20).toString())
|
||||||
val passwordText: AppCompatTextView = view.findViewById(R.id.passwordText)
|
val passwordText: AppCompatTextView = view.findViewById(R.id.passwordText)
|
||||||
passwordText.typeface = monoTypeface
|
passwordText.typeface = monoTypeface
|
||||||
return MaterialAlertDialogBuilder(requireContext()).run {
|
return MaterialAlertDialogBuilder(requireContext()).run {
|
||||||
|
@@ -39,7 +39,8 @@ open class PasswordRepository protected constructor() {
|
|||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getSortOrder(settings: SharedPreferences): PasswordSortOrder {
|
fun getSortOrder(settings: SharedPreferences): PasswordSortOrder {
|
||||||
return valueOf(settings.getString("sort_order", null) ?: FOLDER_FIRST.name)
|
return valueOf(settings.getString(PreferenceKeys.SORT_ORDER, null)
|
||||||
|
?: FOLDER_FIRST.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,8 +155,8 @@ open class PasswordRepository protected constructor() {
|
|||||||
if (!::settings.isInitialized) {
|
if (!::settings.isInitialized) {
|
||||||
settings = PreferenceManager.getDefaultSharedPreferences(context.applicationContext)
|
settings = PreferenceManager.getDefaultSharedPreferences(context.applicationContext)
|
||||||
}
|
}
|
||||||
return if (settings.getBoolean("git_external", false)) {
|
return if (settings.getBoolean(PreferenceKeys.GIT_EXTERNAL, false)) {
|
||||||
val externalRepo = settings.getString("git_external_repo", null)
|
val externalRepo = settings.getString(PreferenceKeys.GIT_EXTERNAL_REPO, null)
|
||||||
if (externalRepo != null)
|
if (externalRepo != null)
|
||||||
File(externalRepo)
|
File(externalRepo)
|
||||||
else
|
else
|
||||||
@@ -174,9 +175,9 @@ open class PasswordRepository protected constructor() {
|
|||||||
// 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
|
||||||
settings.edit {
|
settings.edit {
|
||||||
if (!dir.exists() || !dir.isDirectory || dir.listFiles()!!.isEmpty()) {
|
if (!dir.exists() || !dir.isDirectory || dir.listFiles()!!.isEmpty()) {
|
||||||
putBoolean("repository_initialized", false)
|
putBoolean(PreferenceKeys.REPOSITORY_INITIALIZED, false)
|
||||||
} else {
|
} else {
|
||||||
putBoolean("repository_initialized", true)
|
putBoolean(PreferenceKeys.REPOSITORY_INITIALIZED, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,7 +218,7 @@ open class PasswordRepository protected constructor() {
|
|||||||
// We need to recover the passwords then parse the files
|
// We need to recover the passwords then parse the files
|
||||||
val passList = getFilesList(path).also { it.sortBy { f -> f.name } }
|
val passList = getFilesList(path).also { it.sortBy { f -> f.name } }
|
||||||
val passwordList = ArrayList<PasswordItem>()
|
val passwordList = ArrayList<PasswordItem>()
|
||||||
val showHiddenDirs = settings.getBoolean("show_hidden_folders", false)
|
val showHiddenDirs = settings.getBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, false)
|
||||||
|
|
||||||
if (passList.size == 0) return passwordList
|
if (passList.size == 0) return passwordList
|
||||||
if (showHiddenDirs) {
|
if (showHiddenDirs) {
|
||||||
|
60
app/src/main/java/com/zeapo/pwdstore/utils/PreferenceKeys.kt
Normal file
60
app/src/main/java/com/zeapo/pwdstore/utils/PreferenceKeys.kt
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
package com.zeapo.pwdstore.utils
|
||||||
|
|
||||||
|
object PreferenceKeys {
|
||||||
|
|
||||||
|
const val APP_THEME = "app_theme"
|
||||||
|
const val APP_VERSION = "app_version"
|
||||||
|
const val AUTOFILL_APPS = "autofill_apps"
|
||||||
|
const val AUTOFILL_ALWAYS = "autofill_always"
|
||||||
|
const val AUTOFILL_DEFAULT = "autofill_default"
|
||||||
|
const val AUTOFILL_ENABLE = "autofill_enable"
|
||||||
|
const val AUTOFILL_FULL_PATH = "autofill_full_path"
|
||||||
|
const val BIOMETRIC_AUTH = "biometric_auth"
|
||||||
|
const val CLEAR_CLIPBOARD_20X = "clear_clipboard_20x"
|
||||||
|
const val CLEAR_SAVED_PASS = "clear_saved_pass"
|
||||||
|
const val COPY_ON_DECRYPT = "copy_on_decrypt"
|
||||||
|
const val ENABLE_DEBUG_LOGGING = "enable_debug_logging"
|
||||||
|
const val EXPORT_PASSWORDS = "export_passwords"
|
||||||
|
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_EXTERNAL = "git_external"
|
||||||
|
const val GIT_EXTERNAL_REPO = "git_external_repo"
|
||||||
|
const val GIT_REMOTE_AUTH = "git_remote_auth"
|
||||||
|
const val GIT_REMOTE_LOCATION = "git_remote_location"
|
||||||
|
const val GIT_REMOTE_PORT = "git_remote_port"
|
||||||
|
const val GIT_REMOTE_PROTOCOL = "git_remote_protocol"
|
||||||
|
const val GIT_DELETE_REPO = "git_delete_repo"
|
||||||
|
const val GIT_REMOTE_SERVER = "git_remote_server"
|
||||||
|
const val GIT_REMOTE_USERNAME = "git_remote_username"
|
||||||
|
const val GIT_SERVER_INFO = "git_server_info"
|
||||||
|
const val HTTPS_PASSWORD = "https_password"
|
||||||
|
const val LENGTH = "length"
|
||||||
|
const val OPENPGP_KEY_IDS_SET = "openpgp_key_ids_set"
|
||||||
|
const val OPENPGP_KEY_ID_PREF = "openpgp_key_id_pref"
|
||||||
|
const val OPENPGP_PROVIDER_LIST = "openpgp_provider_list"
|
||||||
|
const val OREO_AUTOFILL_CUSTOM_PUBLIC_SUFFIXES = "oreo_autofill_custom_public_suffixes"
|
||||||
|
const val OREO_AUTOFILL_DEFAULT_USERNAME = "oreo_autofill_default_username"
|
||||||
|
const val OREO_AUTOFILL_DIRECTORY_STRUCTURE = "oreo_autofill_directory_structure"
|
||||||
|
const val PREF_KEY_CUSTOM_DICT = "pref_key_custom_dict"
|
||||||
|
const val PREF_KEY_IS_CUSTOM_DICT = "pref_key_is_custom_dict"
|
||||||
|
const val PREF_KEY_PWGEN_TYPE = "pref_key_pwgen_type"
|
||||||
|
const val PREF_SELECT_EXTERNAL = "pref_select_external"
|
||||||
|
const val REPOSITORY_INITIALIZED = "repository_initialized"
|
||||||
|
const val REPO_CHANGED = "repo_changed"
|
||||||
|
const val SEARCH_ON_START = "search_on_start"
|
||||||
|
const val SHOW_EXTRA_CONTENT = "show_extra_content"
|
||||||
|
const val SHOW_HIDDEN_FOLDERS = "show_hidden_folders"
|
||||||
|
const val SORT_ORDER = "sort_order"
|
||||||
|
const val SHOW_PASSWORD = "show_password"
|
||||||
|
const val SSH_KEY = "ssh_key"
|
||||||
|
const val SSH_KEYGEN = "ssh_keygen"
|
||||||
|
const val SSH_KEY_LOCAL_PASSPHRASE = "ssh_key_local_passphrase"
|
||||||
|
const val SSH_OPENKEYSTORE_CLEAR_KEY_ID = "ssh_openkeystore_clear_keyid"
|
||||||
|
const val SSH_OPENKEYSTORE_KEYID = "ssh_openkeystore_keyid"
|
||||||
|
const val SSH_SEE_KEY = "ssh_see_key"
|
||||||
|
const val USE_GENERATED_KEY = "use_generated_key"
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user