Pin passwords

This commit is contained in:
Matéo Duparc 2022-04-17 17:38:49 +02:00
parent f1d4b07726
commit 53f28e9475
Signed by: hardcoresushi
GPG Key ID: AFE384344A45E13A
8 changed files with 55 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package sushi.hardcore.droidfs
import android.annotation.SuppressLint
import android.os.Build
import android.os.Bundle
import android.text.InputType
import android.view.MenuItem
import android.view.View
import android.widget.Toast
@ -39,6 +40,11 @@ class ChangePasswordActivity: BaseActivity() {
if (!usfFingerprint || fingerprintProtector == null) {
binding.checkboxSavePassword.visibility = View.GONE
}
if (sharedPrefs.getBoolean(ConstValues.PIN_PASSWORDS_KEY, false)) {
arrayOf(binding.editCurrentPassword, binding.editNewPassword, binding.editPasswordConfirm).forEach {
it.inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_VARIATION_PASSWORD
}
}
binding.editPasswordConfirm.setOnEditorActionListener { _, _, _ ->
changeVolumePassword()
true

View File

@ -16,6 +16,7 @@ object ConstValues {
const val DEFAULT_THEME_VALUE = "dark_green"
const val THUMBNAIL_MAX_SIZE_KEY = "thumbnail_max_size"
const val DEFAULT_THUMBNAIL_MAX_SIZE = 10_000L
const val PIN_PASSWORDS_KEY = "pin_passwords"
private val FILE_EXTENSIONS = mapOf(
Pair("image", listOf("png", "jpg", "jpeg", "gif", "webp", "bmp", "heic")),
Pair("video", listOf("mp4", "webm", "mkv", "mov")),

View File

@ -9,6 +9,7 @@ import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.IBinder
import android.text.InputType
import android.view.Menu
import android.view.MenuItem
import android.view.View
@ -524,11 +525,16 @@ class MainActivity : BaseActivity(), VolumeAdapter.Listener {
onPasswordSubmitted(volume, position, dialogBinding)
}
.create()
dialogBinding.editPassword.setOnEditorActionListener { _, _, _ ->
dialogBinding.editPassword.apply {
setOnEditorActionListener { _, _, _ ->
dialog.dismiss()
onPasswordSubmitted(volume, position, dialogBinding)
true
}
if (sharedPrefs.getBoolean(ConstValues.PIN_PASSWORDS_KEY, false)) {
inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_VARIATION_PASSWORD
}
}
dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
dialog.show()
}

View File

@ -3,6 +3,7 @@ package sushi.hardcore.droidfs.add_volume
import android.os.Bundle
import android.view.MenuItem
import sushi.hardcore.droidfs.BaseActivity
import sushi.hardcore.droidfs.ConstValues
import sushi.hardcore.droidfs.R
import sushi.hardcore.droidfs.databinding.ActivityAddVolumeBinding
@ -68,6 +69,7 @@ class AddVolumeActivity: BaseActivity() {
themeValue,
volumePath,
isHidden,
sharedPrefs.getBoolean(ConstValues.PIN_PASSWORDS_KEY, false),
sharedPrefs.getBoolean("usf_fingerprint", false),
)
)

View File

@ -3,6 +3,7 @@ package sushi.hardcore.droidfs.add_volume
import android.annotation.SuppressLint
import android.os.Build
import android.os.Bundle
import android.text.InputType
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -22,12 +23,14 @@ class CreateVolumeFragment: Fragment() {
private const val KEY_THEME_VALUE = "theme"
private const val KEY_VOLUME_PATH = "path"
private const val KEY_IS_HIDDEN = "hidden"
private const val KEY_PIN_PASSWORDS = ConstValues.PIN_PASSWORDS_KEY
private const val KEY_USF_FINGERPRINT = "fingerprint"
fun newInstance(
themeValue: String,
volumePath: String,
isHidden: Boolean,
pinPasswords: Boolean,
usfFingerprint: Boolean,
): CreateVolumeFragment {
return CreateVolumeFragment().apply {
@ -35,6 +38,7 @@ class CreateVolumeFragment: Fragment() {
putString(KEY_THEME_VALUE, themeValue)
putString(KEY_VOLUME_PATH, volumePath)
putBoolean(KEY_IS_HIDDEN, isHidden)
putBoolean(KEY_PIN_PASSWORDS, pinPasswords)
putBoolean(KEY_USF_FINGERPRINT, usfFingerprint)
}
}
@ -60,11 +64,12 @@ class CreateVolumeFragment: Fragment() {
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
requireArguments().let { arguments ->
val pinPasswords = requireArguments().let { arguments ->
arguments.getString(KEY_THEME_VALUE)?.let { themeValue = it }
volumePath = arguments.getString(KEY_VOLUME_PATH)!!
isHiddenVolume = arguments.getBoolean(KEY_IS_HIDDEN)
usfFingerprint = arguments.getBoolean(KEY_USF_FINGERPRINT)
arguments.getBoolean(KEY_PIN_PASSWORDS)
}
volumeDatabase = VolumeDatabase(requireContext())
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
@ -73,6 +78,11 @@ class CreateVolumeFragment: Fragment() {
if (!usfFingerprint || fingerprintProtector == null) {
binding.checkboxSavePassword.visibility = View.GONE
}
if (pinPasswords) {
arrayOf(binding.editPassword, binding.editPasswordConfirm).forEach {
it.inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_VARIATION_PASSWORD
}
}
binding.editPasswordConfirm.setOnEditorActionListener { _, _, _ ->
createVolume()
true

View File

@ -0,0 +1,16 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="20dp"
android:height="28dp"
android:viewportWidth="150"
android:viewportHeight="165">
<path android:fillColor="?attr/colorAccent" android:pathData="M62.539,0L87.461,0A7.539,7.539 0,0 1,95 7.539L95,22.461A7.539,7.539 0,0 1,87.461 30L62.539,30A7.539,7.539 0,0 1,55 22.461L55,7.539A7.539,7.539 0,0 1,62.539 0z"/>
<path android:fillColor="?attr/colorAccent" android:pathData="M7.539,0L32.461,0A7.539,7.539 0,0 1,40 7.539L40,22.461A7.539,7.539 0,0 1,32.461 30L7.539,30A7.539,7.539 0,0 1,0 22.461L0,7.539A7.539,7.539 0,0 1,7.539 0z"/>
<path android:fillColor="?attr/colorAccent" android:pathData="M117.539,-0L142.461,-0A7.539,7.539 0,0 1,150 7.539L150,22.461A7.539,7.539 0,0 1,142.461 30L117.539,30A7.539,7.539 0,0 1,110 22.461L110,7.539A7.539,7.539 0,0 1,117.539 -0z"/>
<path android:fillColor="?attr/colorAccent" android:pathData="M62.539,45L87.461,45A7.539,7.539 0,0 1,95 52.539L95,67.461A7.539,7.539 0,0 1,87.461 75L62.539,75A7.539,7.539 0,0 1,55 67.461L55,52.539A7.539,7.539 0,0 1,62.539 45z"/>
<path android:fillColor="?attr/colorAccent" android:pathData="M7.539,45L32.461,45A7.539,7.539 0,0 1,40 52.539L40,67.461A7.539,7.539 0,0 1,32.461 75L7.539,75A7.539,7.539 0,0 1,0 67.461L0,52.539A7.539,7.539 0,0 1,7.539 45z"/>
<path android:fillColor="?attr/colorAccent" android:pathData="M117.539,45L142.461,45A7.539,7.539 0,0 1,150 52.539L150,67.461A7.539,7.539 0,0 1,142.461 75L117.539,75A7.539,7.539 0,0 1,110 67.461L110,52.539A7.539,7.539 0,0 1,117.539 45z"/>
<path android:fillColor="?attr/colorAccent" android:pathData="M62.539,90L87.461,90A7.539,7.539 0,0 1,95 97.539L95,112.461A7.539,7.539 0,0 1,87.461 120L62.539,120A7.539,7.539 0,0 1,55 112.461L55,97.539A7.539,7.539 0,0 1,62.539 90z"/>
<path android:fillColor="?attr/colorAccent" android:pathData="M7.539,90L32.461,90A7.539,7.539 0,0 1,40 97.539L40,112.461A7.539,7.539 0,0 1,32.461 120L7.539,120A7.539,7.539 0,0 1,0 112.461L0,97.539A7.539,7.539 0,0 1,7.539 90z"/>
<path android:fillColor="?attr/colorAccent" android:pathData="M117.539,90L142.461,90A7.539,7.539 0,0 1,150 97.539L150,112.461A7.539,7.539 0,0 1,142.461 120L117.539,120A7.539,7.539 0,0 1,110 112.461L110,97.539A7.539,7.539 0,0 1,117.539 90z"/>
<path android:fillColor="?attr/colorAccent" android:pathData="M62.539,135L87.461,135A7.539,7.539 0,0 1,95 142.539L95,157.461A7.539,7.539 0,0 1,87.461 165L62.539,165A7.539,7.539 0,0 1,55 157.461L55,142.539A7.539,7.539 0,0 1,62.539 135z"/>
</vector>

View File

@ -240,4 +240,6 @@
<string name="default_open">Open this volume when launching the application</string>
<string name="remove_default_open">Don\'t open by default</string>
<string name="elements_selected">%d/%d selected</string>
<string name="pin_passwords_title">Numeric keypad layout</string>
<string name="pin_passwords_summary">Use a numeric keypad layout when entering volume passwords</string>
</resources>

View File

@ -26,6 +26,13 @@
android:defaultValue="false"
android:icon="@drawable/icon_mod"/>
<SwitchPreferenceCompat
android:title="@string/pin_passwords_title"
android:summary="@string/pin_passwords_summary"
android:key="pin_passwords"
android:defaultValue="false"
android:icon="@drawable/icon_num_pad"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/explorer">