Setting to show the lock button

This commit is contained in:
J-Jamet
2020-04-04 18:25:48 +02:00
parent 78354473fa
commit 47fffbadb5
8 changed files with 57 additions and 10 deletions

View File

@@ -73,6 +73,7 @@ class EntryActivity : LockingActivity() {
private var historyView: View? = null private var historyView: View? = null
private var entryContentsView: EntryContentsView? = null private var entryContentsView: EntryContentsView? = null
private var entryProgress: ProgressBar? = null private var entryProgress: ProgressBar? = null
private var lockView: View? = null
private var toolbar: Toolbar? = null private var toolbar: Toolbar? = null
private var mDatabase: Database? = null private var mDatabase: Database? = null
@@ -124,8 +125,9 @@ class EntryActivity : LockingActivity() {
entryContentsView = findViewById(R.id.entry_contents) entryContentsView = findViewById(R.id.entry_contents)
entryContentsView?.applyFontVisibilityToFields(PreferencesUtil.fieldFontIsInVisibility(this)) entryContentsView?.applyFontVisibilityToFields(PreferencesUtil.fieldFontIsInVisibility(this))
entryProgress = findViewById(R.id.entry_progress) entryProgress = findViewById(R.id.entry_progress)
lockView = findViewById(R.id.lock_button)
findViewById<View>(R.id.lock_button)?.setOnClickListener { lockView?.setOnClickListener {
lockAndExit() lockAndExit()
} }
@@ -152,6 +154,13 @@ class EntryActivity : LockingActivity() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
// Show the lock button
lockView?.visibility = if (PreferencesUtil.showLockDatabaseButton(this)) {
View.VISIBLE
} else {
View.GONE
}
// Get Entry from UUID // Get Entry from UUID
try { try {
val keyEntry: NodeId<UUID>? = intent.getParcelableExtra(KEY_ENTRY) val keyEntry: NodeId<UUID>? = intent.getParcelableExtra(KEY_ENTRY)

View File

@@ -81,6 +81,7 @@ class EntryEditActivity : LockingActivity(),
private var entryEditContentsView: EntryEditContentsView? = null private var entryEditContentsView: EntryEditContentsView? = null
private var entryEditAddToolBar: ActionMenuView? = null private var entryEditAddToolBar: ActionMenuView? = null
private var saveView: View? = null private var saveView: View? = null
private var lockView: View? = null
// Education // Education
private var entryEditActivityEducation: EntryEditActivityEducation? = null private var entryEditActivityEducation: EntryEditActivityEducation? = null
@@ -113,7 +114,8 @@ class EntryEditActivity : LockingActivity(),
} }
} }
findViewById<View>(R.id.lock_button)?.setOnClickListener { lockView = findViewById(R.id.lock_button)
lockView?.setOnClickListener {
lockAndExit() lockAndExit()
} }
@@ -246,6 +248,16 @@ class EntryEditActivity : LockingActivity(),
} }
} }
override fun onResume() {
super.onResume()
lockView?.visibility = if (PreferencesUtil.showLockDatabaseButton(this)) {
View.VISIBLE
} else {
View.GONE
}
}
private fun populateViewsWithEntry(newEntry: Entry) { private fun populateViewsWithEntry(newEntry: Entry) {
// Don't start the field reference manager, we want to see the raw ref // Don't start the field reference manager, we want to see the raw ref
mDatabase?.stopManageEntry(newEntry) mDatabase?.stopManageEntry(newEntry)

View File

@@ -638,6 +638,13 @@ class GroupActivity : LockingActivity(),
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
// Show the lock button
lockView?.visibility = if (PreferencesUtil.showLockDatabaseButton(this)) {
View.VISIBLE
} else {
View.GONE
}
// Refresh the elements // Refresh the elements
assignGroupViewElements() assignGroupViewElements()
// Refresh suggestions to change preferences // Refresh suggestions to change preferences

View File

@@ -199,6 +199,12 @@ object PreferencesUtil {
context.resources.getBoolean(R.bool.lock_database_back_root_default)) context.resources.getBoolean(R.bool.lock_database_back_root_default))
} }
fun showLockDatabaseButton(context: Context): Boolean {
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
return prefs.getBoolean(context.getString(R.string.lock_database_show_button_key),
context.resources.getBoolean(R.bool.lock_database_show_button_default))
}
fun isAutoSaveDatabaseEnabled(context: Context): Boolean { fun isAutoSaveDatabaseEnabled(context: Context): Boolean {
val prefs = PreferenceManager.getDefaultSharedPreferences(context) val prefs = PreferenceManager.getDefaultSharedPreferences(context)
return prefs.getBoolean(context.getString(R.string.enable_auto_save_database_key), return prefs.getBoolean(context.getString(R.string.enable_auto_save_database_key),

View File

@@ -163,15 +163,19 @@ open class SettingsActivity
} }
private fun hideOrShowLockButton(key: NestedSettingsFragment.Screen) { private fun hideOrShowLockButton(key: NestedSettingsFragment.Screen) {
when (key) { if (PreferencesUtil.showLockDatabaseButton(this)) {
NestedSettingsFragment.Screen.DATABASE, when (key) {
NestedSettingsFragment.Screen.DATABASE_MASTER_KEY, NestedSettingsFragment.Screen.DATABASE,
NestedSettingsFragment.Screen.DATABASE_SECURITY -> { NestedSettingsFragment.Screen.DATABASE_MASTER_KEY,
lockView?.visibility = View.VISIBLE NestedSettingsFragment.Screen.DATABASE_SECURITY -> {
} lockView?.visibility = View.VISIBLE
else -> { }
lockView?.visibility = View.GONE else -> {
lockView?.visibility = View.GONE
}
} }
} else {
lockView?.visibility = View.GONE
} }
} }

View File

@@ -77,6 +77,8 @@
<bool name="lock_database_screen_off_default" translatable="false">true</bool> <bool name="lock_database_screen_off_default" translatable="false">true</bool>
<string name="lock_database_back_root_key" translatable="false">lock_database_back_root_key</string> <string name="lock_database_back_root_key" translatable="false">lock_database_back_root_key</string>
<bool name="lock_database_back_root_default" translatable="false">false</bool> <bool name="lock_database_back_root_default" translatable="false">false</bool>
<string name="lock_database_show_button_key" translatable="false">lock_database_show_button_key</string>
<bool name="lock_database_show_button_default" translatable="false">true</bool>
<string name="password_length_key" translatable="false">password_length_key</string> <string name="password_length_key" translatable="false">password_length_key</string>
<string name="list_password_generator_options_key" translatable="false">list_password_generator_options_key</string> <string name="list_password_generator_options_key" translatable="false">list_password_generator_options_key</string>
<string name="hide_password_key" translatable="false">hide_password_key</string> <string name="hide_password_key" translatable="false">hide_password_key</string>

View File

@@ -298,6 +298,8 @@
<string name="lock_database_screen_off_summary">Lock the database when the screen is off</string> <string name="lock_database_screen_off_summary">Lock the database when the screen is off</string>
<string name="lock_database_back_root_title">Press \'Back\' to lock</string> <string name="lock_database_back_root_title">Press \'Back\' to lock</string>
<string name="lock_database_back_root_summary">Lock the database when the user clicks the back button on the root screen</string> <string name="lock_database_back_root_summary">Lock the database when the user clicks the back button on the root screen</string>
<string name="lock_database_show_button_title">Show lock button</string>
<string name="lock_database_show_button_summary">Displays the lock button in the user interface</string>
<string name="advanced_unlock">Advanced unlock</string> <string name="advanced_unlock">Advanced unlock</string>
<string name="advanced_unlock_explanation_summary">Use advanced unlocking to open a database more easily</string> <string name="advanced_unlock_explanation_summary">Use advanced unlocking to open a database more easily</string>
<string name="biometric_unlock_enable_title">Biometric unlocking</string> <string name="biometric_unlock_enable_title">Biometric unlocking</string>

View File

@@ -83,6 +83,11 @@
android:title="@string/lock_database_back_root_title" android:title="@string/lock_database_back_root_title"
android:summary="@string/lock_database_back_root_summary" android:summary="@string/lock_database_back_root_summary"
android:defaultValue="@bool/lock_database_back_root_default"/> android:defaultValue="@bool/lock_database_back_root_default"/>
<SwitchPreference
android:key="@string/lock_database_show_button_key"
android:title="@string/lock_database_show_button_title"
android:summary="@string/lock_database_show_button_summary"
android:defaultValue="@bool/lock_database_show_button_default"/>
</PreferenceCategory> </PreferenceCategory>