Refactor progress dialog thread / save database menu

This commit is contained in:
J-Jamet
2019-11-18 17:54:13 +01:00
parent 02feb478e8
commit fa9d8ad6ad
25 changed files with 163 additions and 158 deletions

View File

@@ -329,9 +329,9 @@ class EntryActivity : LockingHideActivity() {
val inflater = menuInflater val inflater = menuInflater
MenuUtil.contributionMenuInflater(inflater, menu) MenuUtil.contributionMenuInflater(inflater, menu)
inflater.inflate(R.menu.entry, menu) inflater.inflate(R.menu.entry, menu)
inflater.inflate(R.menu.database_lock, menu) inflater.inflate(R.menu.database, menu)
if (mReadOnly) { if (mReadOnly) {
menu.findItem(R.id.menu_save_database)?.isVisible = false
menu.findItem(R.id.menu_edit)?.isVisible = false menu.findItem(R.id.menu_edit)?.isVisible = false
} }
@@ -400,21 +400,18 @@ class EntryActivity : LockingHideActivity() {
MenuUtil.onContributionItemSelected(this) MenuUtil.onContributionItemSelected(this)
return true return true
} }
R.id.menu_toggle_pass -> { R.id.menu_toggle_pass -> {
mShowPassword = !mShowPassword mShowPassword = !mShowPassword
changeShowPasswordIcon(item) changeShowPasswordIcon(item)
entryContentsView?.setHiddenPasswordStyle(!mShowPassword) entryContentsView?.setHiddenPasswordStyle(!mShowPassword)
return true return true
} }
R.id.menu_edit -> { R.id.menu_edit -> {
mEntry?.let { mEntry?.let {
EntryEditActivity.launch(this@EntryActivity, it) EntryEditActivity.launch(this@EntryActivity, it)
} }
return true return true
} }
R.id.menu_goto_url -> { R.id.menu_goto_url -> {
var url: String = mEntry?.url ?: "" var url: String = mEntry?.url ?: ""
@@ -424,18 +421,17 @@ class EntryActivity : LockingHideActivity() {
} }
UriUtil.gotoUrl(this, url) UriUtil.gotoUrl(this, url)
return true return true
} }
R.id.menu_lock -> { R.id.menu_lock -> {
lockAndExit() lockAndExit()
return true return true
} }
R.id.menu_save_database -> {
mProgressDialogThread?.startDatabaseSave(!mReadOnly)
}
android.R.id.home -> finish() // close this activity and return to preview activity (if there is any) android.R.id.home -> finish() // close this activity and return to preview activity (if there is any)
} }
return super.onOptionsItemSelected(item) return super.onOptionsItemSelected(item)
} }

View File

@@ -33,7 +33,6 @@ import com.kunzisoft.keepass.activities.dialogs.SetOTPDialogFragment
import com.kunzisoft.keepass.activities.dialogs.GeneratePasswordDialogFragment import com.kunzisoft.keepass.activities.dialogs.GeneratePasswordDialogFragment
import com.kunzisoft.keepass.activities.dialogs.IconPickerDialogFragment import com.kunzisoft.keepass.activities.dialogs.IconPickerDialogFragment
import com.kunzisoft.keepass.activities.lock.LockingHideActivity import com.kunzisoft.keepass.activities.lock.LockingHideActivity
import com.kunzisoft.keepass.database.action.ProgressDialogThread
import com.kunzisoft.keepass.database.element.* import com.kunzisoft.keepass.database.element.*
import com.kunzisoft.keepass.education.EntryEditActivityEducation import com.kunzisoft.keepass.education.EntryEditActivityEducation
import com.kunzisoft.keepass.notifications.ClipboardEntryNotificationService import com.kunzisoft.keepass.notifications.ClipboardEntryNotificationService
@@ -67,9 +66,6 @@ class EntryEditActivity : LockingHideActivity(),
private var entryEditContentsView: EntryEditContentsView? = null private var entryEditContentsView: EntryEditContentsView? = null
private var saveView: View? = null private var saveView: View? = null
// Dialog thread
private var progressDialogThread: ProgressDialogThread? = null
// Education // Education
private var entryEditActivityEducation: EntryEditActivityEducation? = null private var entryEditActivityEducation: EntryEditActivityEducation? = null
@@ -176,7 +172,7 @@ class EntryEditActivity : LockingHideActivity(),
entryEditActivityEducation = EntryEditActivityEducation(this) entryEditActivityEducation = EntryEditActivityEducation(this)
// Create progress dialog // Create progress dialog
progressDialogThread = ProgressDialogThread(this) { actionTask, result -> mProgressDialogThread?.onActionFinish = { actionTask, result ->
when (actionTask) { when (actionTask) {
ACTION_DATABASE_CREATE_ENTRY_TASK, ACTION_DATABASE_CREATE_ENTRY_TASK,
ACTION_DATABASE_UPDATE_ENTRY_TASK -> { ACTION_DATABASE_UPDATE_ENTRY_TASK -> {
@@ -273,18 +269,18 @@ class EntryEditActivity : LockingHideActivity(),
// Open a progress dialog and save entry // Open a progress dialog and save entry
if (mIsNew) { if (mIsNew) {
mParent?.let { parent -> mParent?.let { parent ->
progressDialogThread?.startDatabaseCreateEntry( mProgressDialogThread?.startDatabaseCreateEntry(
newEntry, newEntry,
parent, parent,
!mReadOnly !mReadOnly && mAutoSaveEnable
) )
} }
} else { } else {
mEntry?.let { oldEntry -> mEntry?.let { oldEntry ->
progressDialogThread?.startDatabaseUpdateEntry( mProgressDialogThread?.startDatabaseUpdateEntry(
oldEntry, oldEntry,
newEntry, newEntry,
!mReadOnly !mReadOnly && mAutoSaveEnable
) )
} }
} }
@@ -292,23 +288,13 @@ class EntryEditActivity : LockingHideActivity(),
} }
} }
override fun onResume() {
super.onResume()
progressDialogThread?.registerProgressTask()
}
override fun onPause() {
progressDialogThread?.unregisterProgressTask()
super.onPause()
}
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {
super.onCreateOptionsMenu(menu) super.onCreateOptionsMenu(menu)
val inflater = menuInflater val inflater = menuInflater
inflater.inflate(R.menu.database_lock, menu) inflater.inflate(R.menu.database, menu)
// Save database not needed here
menu.findItem(R.id.menu_save_database)?.isVisible = false
MenuUtil.contributionMenuInflater(inflater, menu) MenuUtil.contributionMenuInflater(inflater, menu)
if (mDatabase?.allowOTP == true) if (mDatabase?.allowOTP == true)
inflater.inflate(R.menu.entry_otp, menu) inflater.inflate(R.menu.entry_otp, menu)
@@ -352,12 +338,13 @@ class EntryEditActivity : LockingHideActivity(),
lockAndExit() lockAndExit()
return true return true
} }
R.id.menu_save_database -> {
mProgressDialogThread?.startDatabaseSave(!mReadOnly)
}
R.id.menu_contribute -> { R.id.menu_contribute -> {
MenuUtil.onContributionItemSelected(this) MenuUtil.onContributionItemSelected(this)
return true return true
} }
R.id.menu_add_otp -> { R.id.menu_add_otp -> {
// Retrieve the current otpElement if exists // Retrieve the current otpElement if exists
// and open the dialog to set up the OTP // and open the dialog to set up the OTP
@@ -365,7 +352,6 @@ class EntryEditActivity : LockingHideActivity(),
.show(supportFragmentManager, "addOTPDialog") .show(supportFragmentManager, "addOTPDialog")
return true return true
} }
android.R.id.home -> finish() android.R.id.home -> finish()
} }

View File

@@ -76,7 +76,7 @@ class FileDatabaseSelectActivity : StylishActivity(),
private var mOpenFileHelper: OpenFileHelper? = null private var mOpenFileHelper: OpenFileHelper? = null
private var progressDialogThread: ProgressDialogThread? = null private var mProgressDialogThread: ProgressDialogThread? = null
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@@ -163,7 +163,7 @@ class FileDatabaseSelectActivity : StylishActivity(),
} }
// Attach the dialog thread to this activity // Attach the dialog thread to this activity
progressDialogThread = ProgressDialogThread(this) { actionTask, _ -> mProgressDialogThread?.onActionFinish = { actionTask, _ ->
when (actionTask) { when (actionTask) {
ACTION_DATABASE_CREATE_TASK -> { ACTION_DATABASE_CREATE_TASK -> {
// TODO Check // TODO Check
@@ -296,12 +296,12 @@ class FileDatabaseSelectActivity : StylishActivity(),
} }
// Register progress task // Register progress task
progressDialogThread?.registerProgressTask() mProgressDialogThread?.registerProgressTask()
} }
override fun onPause() { override fun onPause() {
// Unregister progress task // Unregister progress task
progressDialogThread?.unregisterProgressTask() mProgressDialogThread?.unregisterProgressTask()
super.onPause() super.onPause()
} }
@@ -329,7 +329,7 @@ class FileDatabaseSelectActivity : StylishActivity(),
mDatabaseFileUri?.let { databaseUri -> mDatabaseFileUri?.let { databaseUri ->
// Create the new database // Create the new database
progressDialogThread?.startDatabaseCreate( mProgressDialogThread?.startDatabaseCreate(
databaseUri, databaseUri,
masterPasswordChecked, masterPasswordChecked,
masterPassword, masterPassword,

View File

@@ -49,7 +49,6 @@ import com.kunzisoft.keepass.activities.lock.LockingActivity
import com.kunzisoft.keepass.adapters.SearchEntryCursorAdapter import com.kunzisoft.keepass.adapters.SearchEntryCursorAdapter
import com.kunzisoft.keepass.autofill.AutofillHelper import com.kunzisoft.keepass.autofill.AutofillHelper
import com.kunzisoft.keepass.database.SortNodeEnum import com.kunzisoft.keepass.database.SortNodeEnum
import com.kunzisoft.keepass.database.action.ProgressDialogThread
import com.kunzisoft.keepass.database.element.* import com.kunzisoft.keepass.database.element.*
import com.kunzisoft.keepass.education.GroupActivityEducation import com.kunzisoft.keepass.education.GroupActivityEducation
import com.kunzisoft.keepass.icons.assignDatabaseIcon import com.kunzisoft.keepass.icons.assignDatabaseIcon
@@ -94,8 +93,6 @@ class GroupActivity : LockingActivity(),
private var mListNodesFragment: ListNodesFragment? = null private var mListNodesFragment: ListNodesFragment? = null
private var mCurrentGroupIsASearch: Boolean = false private var mCurrentGroupIsASearch: Boolean = false
private var progressDialogThread: ProgressDialogThread? = null
// Nodes // Nodes
private var mRootGroup: GroupVersioned? = null private var mRootGroup: GroupVersioned? = null
private var mCurrentGroup: GroupVersioned? = null private var mCurrentGroup: GroupVersioned? = null
@@ -205,7 +202,7 @@ class GroupActivity : LockingActivity(),
mSearchSuggestionAdapter = SearchEntryCursorAdapter(this, database) mSearchSuggestionAdapter = SearchEntryCursorAdapter(this, database)
// Init dialog thread // Init dialog thread
progressDialogThread = ProgressDialogThread(this) { actionTask, result -> mProgressDialogThread?.onActionFinish = { actionTask, result ->
var oldNodes: List<NodeVersioned> = ArrayList() var oldNodes: List<NodeVersioned> = ArrayList()
result.data?.getBundle(OLD_NODES_KEY)?.let { oldNodesBundle -> result.data?.getBundle(OLD_NODES_KEY)?.let { oldNodesBundle ->
@@ -569,20 +566,20 @@ class GroupActivity : LockingActivity(),
ListNodesFragment.PasteMode.PASTE_FROM_COPY -> { ListNodesFragment.PasteMode.PASTE_FROM_COPY -> {
// Copy // Copy
mCurrentGroup?.let { newParent -> mCurrentGroup?.let { newParent ->
progressDialogThread?.startDatabaseCopyNodes( mProgressDialogThread?.startDatabaseCopyNodes(
nodes, nodes,
newParent, newParent,
!mReadOnly !mReadOnly && mAutoSaveEnable
) )
} }
} }
ListNodesFragment.PasteMode.PASTE_FROM_MOVE -> { ListNodesFragment.PasteMode.PASTE_FROM_MOVE -> {
// Move // Move
mCurrentGroup?.let { newParent -> mCurrentGroup?.let { newParent ->
progressDialogThread?.startDatabaseMoveNodes( mProgressDialogThread?.startDatabaseMoveNodes(
nodes, nodes,
newParent, newParent,
!mReadOnly !mReadOnly && mAutoSaveEnable
) )
} }
} }
@@ -598,9 +595,9 @@ class GroupActivity : LockingActivity(),
&& database.isRecycleBinEnabled && database.isRecycleBinEnabled
&& database.recycleBin != mCurrentGroup) { && database.recycleBin != mCurrentGroup) {
// If recycle bin enabled and not in recycle bin, move in recycle bin // If recycle bin enabled and not in recycle bin, move in recycle bin
progressDialogThread?.startDatabaseDeleteNodes( mProgressDialogThread?.startDatabaseDeleteNodes(
nodes, nodes,
!mReadOnly !mReadOnly && mAutoSaveEnable
) )
} else { } else {
// open the dialog to confirm deletion // open the dialog to confirm deletion
@@ -612,9 +609,9 @@ class GroupActivity : LockingActivity(),
} }
override fun permanentlyDeleteNodes(nodes: List<NodeVersioned>) { override fun permanentlyDeleteNodes(nodes: List<NodeVersioned>) {
progressDialogThread?.startDatabaseDeleteNodes( mProgressDialogThread?.startDatabaseDeleteNodes(
nodes, nodes,
!mReadOnly !mReadOnly && mAutoSaveEnable
) )
} }
@@ -624,13 +621,9 @@ class GroupActivity : LockingActivity(),
assignGroupViewElements() assignGroupViewElements()
// Refresh suggestions to change preferences // Refresh suggestions to change preferences
mSearchSuggestionAdapter?.reInit(this) mSearchSuggestionAdapter?.reInit(this)
progressDialogThread?.registerProgressTask()
} }
override fun onPause() { override fun onPause() {
progressDialogThread?.unregisterProgressTask()
super.onPause() super.onPause()
finishNodeAction() finishNodeAction()
@@ -640,7 +633,10 @@ class GroupActivity : LockingActivity(),
val inflater = menuInflater val inflater = menuInflater
inflater.inflate(R.menu.search, menu) inflater.inflate(R.menu.search, menu)
inflater.inflate(R.menu.database_lock, menu) inflater.inflate(R.menu.database, menu)
if (mReadOnly) {
menu.findItem(R.id.menu_save_database)?.isVisible = false
}
if (!mSelectionMode) { if (!mSelectionMode) {
inflater.inflate(R.menu.default_menu, menu) inflater.inflate(R.menu.default_menu, menu)
MenuUtil.contributionMenuInflater(inflater, menu) MenuUtil.contributionMenuInflater(inflater, menu)
@@ -760,6 +756,10 @@ class GroupActivity : LockingActivity(),
lockAndExit() lockAndExit()
return true return true
} }
R.id.menu_save_database -> {
mProgressDialogThread?.startDatabaseSave(!mReadOnly)
return true
}
R.id.menu_empty_recycle_bin -> { R.id.menu_empty_recycle_bin -> {
mCurrentGroup?.getChildren()?.let { listChildren -> mCurrentGroup?.getChildren()?.let { listChildren ->
// Automatically delete all elements // Automatically delete all elements
@@ -791,8 +791,11 @@ class GroupActivity : LockingActivity(),
// Not really needed here because added in runnable but safe // Not really needed here because added in runnable but safe
newGroup.parent = currentGroup newGroup.parent = currentGroup
progressDialogThread?.startDatabaseCreateGroup( mProgressDialogThread?.startDatabaseCreateGroup(
newGroup, currentGroup, !mReadOnly) newGroup,
currentGroup,
!mReadOnly && mAutoSaveEnable
)
} }
} }
} }
@@ -810,8 +813,11 @@ class GroupActivity : LockingActivity(),
} }
} }
// If group updated save it in the database // If group updated save it in the database
progressDialogThread?.startDatabaseUpdateGroup( mProgressDialogThread?.startDatabaseUpdateGroup(
oldGroupToUpdate, updateGroup, !mReadOnly) oldGroupToUpdate,
updateGroup,
!mReadOnly && mAutoSaveEnable
)
} }
} }
else -> {} else -> {}

View File

@@ -163,7 +163,8 @@ class PasswordActivity : StylishActivity() {
enableOrNotTheConfirmationButton() enableOrNotTheConfirmationButton()
} }
progressDialogThread = ProgressDialogThread(this) { actionTask, result -> progressDialogThread = ProgressDialogThread(this).apply {
onActionFinish = { actionTask, result ->
when (actionTask) { when (actionTask) {
ACTION_DATABASE_LOAD_TASK -> { ACTION_DATABASE_LOAD_TASK -> {
// Recheck biometric if error // Recheck biometric if error
@@ -231,6 +232,7 @@ class PasswordActivity : StylishActivity() {
} }
} }
} }
}
private fun launchGroupActivity() { private fun launchGroupActivity() {
EntrySelectionHelper.doEntrySelectionAction(intent, EntrySelectionHelper.doEntrySelectionAction(intent,

View File

@@ -32,6 +32,7 @@ import android.view.ViewGroup
import com.kunzisoft.keepass.activities.helpers.EntrySelectionHelper import com.kunzisoft.keepass.activities.helpers.EntrySelectionHelper
import com.kunzisoft.keepass.activities.helpers.ReadOnlyHelper import com.kunzisoft.keepass.activities.helpers.ReadOnlyHelper
import com.kunzisoft.keepass.activities.stylish.StylishActivity import com.kunzisoft.keepass.activities.stylish.StylishActivity
import com.kunzisoft.keepass.database.action.ProgressDialogThread
import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.notifications.KeyboardEntryNotificationService import com.kunzisoft.keepass.notifications.KeyboardEntryNotificationService
import com.kunzisoft.keepass.magikeyboard.MagikIME import com.kunzisoft.keepass.magikeyboard.MagikIME
@@ -63,6 +64,10 @@ abstract class LockingActivity : StylishActivity() {
return field || mSelectionMode return field || mSelectionMode
} }
protected var mSelectionMode: Boolean = false protected var mSelectionMode: Boolean = false
protected var mAutoSaveEnable: Boolean = true
var mProgressDialogThread: ProgressDialogThread? = null
private set
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@@ -86,6 +91,9 @@ abstract class LockingActivity : StylishActivity() {
mExitLock = false mExitLock = false
mReadOnly = ReadOnlyHelper.retrieveReadOnlyFromInstanceStateOrIntent(savedInstanceState, intent) mReadOnly = ReadOnlyHelper.retrieveReadOnlyFromInstanceStateOrIntent(savedInstanceState, intent)
mAutoSaveEnable = PreferencesUtil.isAutoSaveDatabaseEnabled(this)
mProgressDialogThread = ProgressDialogThread(this)
} }
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
@@ -120,6 +128,8 @@ abstract class LockingActivity : StylishActivity() {
TimeoutHelper.recordTime(this) TimeoutHelper.recordTime(this)
} }
mProgressDialogThread?.registerProgressTask()
invalidateOptionsMenu() invalidateOptionsMenu()
} }
@@ -130,6 +140,8 @@ abstract class LockingActivity : StylishActivity() {
} }
override fun onPause() { override fun onPause() {
mProgressDialogThread?.unregisterProgressTask()
super.onPause() super.onPause()
if (mTimeoutEnable) { if (mTimeoutEnable) {

View File

@@ -45,10 +45,10 @@ import com.kunzisoft.keepass.utils.DATABASE_STOP_TASK_ACTION
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
class ProgressDialogThread(private val activity: FragmentActivity) {
class ProgressDialogThread(private val activity: FragmentActivity, var onActionFinish: ((actionTask: String,
var onActionFinish: (actionTask: String, result: ActionRunnable.Result) -> Unit)? = null
result: ActionRunnable.Result) -> Unit) {
private var intentDatabaseTask = Intent(activity, DatabaseTaskNotificationService::class.java) private var intentDatabaseTask = Intent(activity, DatabaseTaskNotificationService::class.java)
@@ -69,7 +69,7 @@ class ProgressDialogThread(private val activity: FragmentActivity,
} }
override fun onStopAction(actionTask: String, result: ActionRunnable.Result) { override fun onStopAction(actionTask: String, result: ActionRunnable.Result) {
onActionFinish.invoke(actionTask, result) onActionFinish?.invoke(actionTask, result)
// Remove the progress task // Remove the progress task
ProgressTaskDialogFragment.stop(activity) ProgressTaskDialogFragment.stop(activity)
TimeoutHelper.releaseTemporarilyDisableTimeoutAndLockIfTimeout(activity) TimeoutHelper.releaseTemporarilyDisableTimeoutAndLockIfTimeout(activity)

View File

@@ -20,6 +20,7 @@
package com.kunzisoft.keepass.settings package com.kunzisoft.keepass.settings
import android.content.ActivityNotFoundException import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.res.Resources import android.content.res.Resources
import android.graphics.Color import android.graphics.Color
@@ -77,6 +78,7 @@ class NestedSettingsFragment : PreferenceFragmentCompat() {
private var mDatabase: Database = Database.getInstance() private var mDatabase: Database = Database.getInstance()
private var mDatabaseReadOnly: Boolean = false private var mDatabaseReadOnly: Boolean = false
private var mDatabaseAutoSaveEnabled: Boolean = true
private var mCount = 0 private var mCount = 0
@@ -110,6 +112,7 @@ class NestedSettingsFragment : PreferenceFragmentCompat() {
&& autofillManager.hasEnabledAutofillServices() && autofillManager.hasEnabledAutofillServices()
} }
} }
mDatabaseAutoSaveEnabled = PreferencesUtil.isAutoSaveDatabaseEnabled(activity)
} }
} }
@@ -471,7 +474,8 @@ class NestedSettingsFragment : PreferenceFragmentCompat() {
} }
refreshRecycleBinGroup() refreshRecycleBinGroup()
// Save the database if not in readonly mode // Save the database if not in readonly mode
(context as SettingsActivity?)?.progressDialogThread?.startDatabaseSave(true) (context as SettingsActivity?)?.
mProgressDialogThread?.startDatabaseSave(mDatabaseAutoSaveEnabled)
true true
} }
true true

View File

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

View File

@@ -33,7 +33,6 @@ import com.kunzisoft.keepass.activities.dialogs.AssignMasterKeyDialogFragment
import com.kunzisoft.keepass.activities.dialogs.PasswordEncodingDialogFragment import com.kunzisoft.keepass.activities.dialogs.PasswordEncodingDialogFragment
import com.kunzisoft.keepass.activities.helpers.ReadOnlyHelper import com.kunzisoft.keepass.activities.helpers.ReadOnlyHelper
import com.kunzisoft.keepass.activities.lock.LockingActivity import com.kunzisoft.keepass.activities.lock.LockingActivity
import com.kunzisoft.keepass.database.action.ProgressDialogThread
import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.timeout.TimeoutHelper import com.kunzisoft.keepass.timeout.TimeoutHelper
@@ -46,8 +45,6 @@ open class SettingsActivity
private var toolbar: Toolbar? = null private var toolbar: Toolbar? = null
var progressDialogThread: ProgressDialogThread? = null
companion object { companion object {
private const val TAG_NESTED = "TAG_NESTED" private const val TAG_NESTED = "TAG_NESTED"
@@ -90,7 +87,7 @@ open class SettingsActivity
backupManager = BackupManager(this) backupManager = BackupManager(this)
progressDialogThread = ProgressDialogThread(this) { actionTask, result -> mProgressDialogThread?.onActionFinish = { actionTask, result ->
// Call result in fragment // Call result in fragment
(supportFragmentManager (supportFragmentManager
.findFragmentByTag(TAG_NESTED) as NestedSettingsFragment?) .findFragmentByTag(TAG_NESTED) as NestedSettingsFragment?)
@@ -98,19 +95,6 @@ open class SettingsActivity
} }
} }
override fun onResume() {
super.onResume()
progressDialogThread?.registerProgressTask()
}
override fun onPause() {
progressDialogThread?.unregisterProgressTask()
super.onPause()
}
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
android.R.id.home -> onBackPressed() android.R.id.home -> onBackPressed()
@@ -132,7 +116,7 @@ open class SettingsActivity
database.fileUri?.let { databaseUri -> database.fileUri?.let { databaseUri ->
// Show the progress dialog now or after dialog confirmation // Show the progress dialog now or after dialog confirmation
if (database.validatePasswordEncoding(masterPassword, keyFileChecked)) { if (database.validatePasswordEncoding(masterPassword, keyFileChecked)) {
progressDialogThread?.startDatabaseAssignPassword( mProgressDialogThread?.startDatabaseAssignPassword(
databaseUri, databaseUri,
masterPasswordChecked, masterPasswordChecked,
masterPassword, masterPassword,
@@ -142,7 +126,7 @@ open class SettingsActivity
} else { } else {
PasswordEncodingDialogFragment().apply { PasswordEncodingDialogFragment().apply {
positiveButtonClickListener = DialogInterface.OnClickListener { _, _ -> positiveButtonClickListener = DialogInterface.OnClickListener { _, _ ->
progressDialogThread?.startDatabaseAssignPassword( mProgressDialogThread?.startDatabaseAssignPassword(
databaseUri, databaseUri,
masterPasswordChecked, masterPasswordChecked,
masterPassword, masterPassword,

View File

@@ -87,7 +87,7 @@ class DatabaseColorPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialog
} }
val oldColor = database.customColor val oldColor = database.customColor
database.customColor = newColor database.customColor = newColor
progressDialogThread?.startDatabaseSaveColor(oldColor, newColor, true) mProgressDialogThread?.startDatabaseSaveColor(oldColor, newColor, mDatabaseAutoSaveEnable)
} }
onDialogClosed(true) onDialogClosed(true)

View File

@@ -64,7 +64,7 @@ class DatabaseDataCompressionPreferenceDialogFragmentCompat
database.compressionAlgorithm = newCompression database.compressionAlgorithm = newCompression
if (oldCompression != null && newCompression != null) if (oldCompression != null && newCompression != null)
progressDialogThread?.startDatabaseSaveCompression(oldCompression, newCompression, true) mProgressDialogThread?.startDatabaseSaveCompression(oldCompression, newCompression, mDatabaseAutoSaveEnable)
} }
} }
} }

View File

@@ -36,7 +36,7 @@ class DatabaseDefaultUsernamePreferenceDialogFragmentCompat : DatabaseSavePrefer
val newDefaultUsername = inputText val newDefaultUsername = inputText
val oldDefaultUsername = database.defaultUsername val oldDefaultUsername = database.defaultUsername
database.defaultUsername = newDefaultUsername database.defaultUsername = newDefaultUsername
progressDialogThread?.startDatabaseSaveDefaultUsername(oldDefaultUsername, newDefaultUsername, true) mProgressDialogThread?.startDatabaseSaveDefaultUsername(oldDefaultUsername, newDefaultUsername, mDatabaseAutoSaveEnable)
} }
} }
} }

View File

@@ -36,7 +36,7 @@ class DatabaseDescriptionPreferenceDialogFragmentCompat : DatabaseSavePreference
val newDescription = inputText val newDescription = inputText
val oldDescription = database.description val oldDescription = database.description
database.description = newDescription database.description = newDescription
progressDialogThread?.startDatabaseSaveDescription(oldDescription, newDescription, true) mProgressDialogThread?.startDatabaseSaveDescription(oldDescription, newDescription, mDatabaseAutoSaveEnable)
} }
} }
} }

View File

@@ -65,7 +65,7 @@ class DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat
database.encryptionAlgorithm = newAlgorithm database.encryptionAlgorithm = newAlgorithm
if (oldAlgorithm != null && newAlgorithm != null) if (oldAlgorithm != null && newAlgorithm != null)
progressDialogThread?.startDatabaseSaveEncryption(oldAlgorithm, newAlgorithm, true) mProgressDialogThread?.startDatabaseSaveEncryption(oldAlgorithm, newAlgorithm, mDatabaseAutoSaveEnable)
} }
} }
} }

View File

@@ -66,7 +66,7 @@ class DatabaseKeyDerivationPreferenceDialogFragmentCompat
val oldKdfEngine = database.kdfEngine val oldKdfEngine = database.kdfEngine
if (newKdfEngine != null && oldKdfEngine != null) { if (newKdfEngine != null && oldKdfEngine != null) {
database.kdfEngine = newKdfEngine database.kdfEngine = newKdfEngine
progressDialogThread?.startDatabaseSaveKeyDerivation(oldKdfEngine, newKdfEngine, true) mProgressDialogThread?.startDatabaseSaveKeyDerivation(oldKdfEngine, newKdfEngine, mDatabaseAutoSaveEnable)
} }
} }
} }

View File

@@ -36,7 +36,7 @@ class DatabaseNamePreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogF
val newName = inputText val newName = inputText
val oldName = database.name val oldName = database.name
database.name = newName database.name = newName
progressDialogThread?.startDatabaseSaveName(oldName, newName, true) mProgressDialogThread?.startDatabaseSaveName(oldName, newName, mDatabaseAutoSaveEnable)
} }
} }
} }

View File

@@ -23,13 +23,14 @@ import android.content.Context
import android.os.Bundle import android.os.Bundle
import com.kunzisoft.keepass.database.action.ProgressDialogThread import com.kunzisoft.keepass.database.action.ProgressDialogThread
import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.settings.SettingsActivity import com.kunzisoft.keepass.settings.SettingsActivity
abstract class DatabaseSavePreferenceDialogFragmentCompat : InputPreferenceDialogFragmentCompat() { abstract class DatabaseSavePreferenceDialogFragmentCompat : InputPreferenceDialogFragmentCompat() {
protected var database: Database? = null protected var database: Database? = null
protected var mDatabaseAutoSaveEnable = true
protected var progressDialogThread: ProgressDialogThread? = null protected var mProgressDialogThread: ProgressDialogThread? = null
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@@ -41,8 +42,10 @@ abstract class DatabaseSavePreferenceDialogFragmentCompat : InputPreferenceDialo
super.onAttach(context) super.onAttach(context)
// Attach dialog thread to start action // Attach dialog thread to start action
if (context is SettingsActivity) { if (context is SettingsActivity) {
progressDialogThread = context.progressDialogThread mProgressDialogThread = context.mProgressDialogThread
} }
this.mDatabaseAutoSaveEnable = PreferencesUtil.isAutoSaveDatabaseEnabled(context)
} }
companion object { companion object {

View File

@@ -60,7 +60,7 @@ class MaxHistoryItemsPreferenceDialogFragmentCompat : DatabaseSavePreferenceDial
// Remove all history items // Remove all history items
database.removeOldestHistoryForEachEntry() database.removeOldestHistoryForEachEntry()
progressDialogThread?.startDatabaseSaveMaxHistoryItems(oldMaxHistoryItems, maxHistoryItems, true) mProgressDialogThread?.startDatabaseSaveMaxHistoryItems(oldMaxHistoryItems, maxHistoryItems, mDatabaseAutoSaveEnable)
} }
} }
} }

View File

@@ -56,7 +56,7 @@ class MaxHistorySizePreferenceDialogFragmentCompat : DatabaseSavePreferenceDialo
val oldMaxHistorySize = database.historyMaxSize val oldMaxHistorySize = database.historyMaxSize
database.historyMaxSize = maxHistorySize database.historyMaxSize = maxHistorySize
progressDialogThread?.startDatabaseSaveMaxHistorySize(oldMaxHistorySize, maxHistorySize, true) mProgressDialogThread?.startDatabaseSaveMaxHistorySize(oldMaxHistorySize, maxHistorySize, mDatabaseAutoSaveEnable)
} }
} }
} }

View File

@@ -48,7 +48,7 @@ class MemoryUsagePreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFr
val oldMemoryUsage = database.memoryUsage val oldMemoryUsage = database.memoryUsage
database.memoryUsage = memoryUsage database.memoryUsage = memoryUsage
progressDialogThread?.startDatabaseSaveMemoryUsage(oldMemoryUsage, memoryUsage, true) mProgressDialogThread?.startDatabaseSaveMemoryUsage(oldMemoryUsage, memoryUsage, mDatabaseAutoSaveEnable)
} }
} }
} }

View File

@@ -48,7 +48,7 @@ class ParallelismPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFr
val oldParallelism = database.parallelism val oldParallelism = database.parallelism
database.parallelism = parallelism database.parallelism = parallelism
progressDialogThread?.startDatabaseSaveParallelism(oldParallelism, parallelism, true) mProgressDialogThread?.startDatabaseSaveParallelism(oldParallelism, parallelism, mDatabaseAutoSaveEnable)
} }
} }
} }

View File

@@ -54,7 +54,7 @@ class RoundsPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmen
database.numberKeyEncryptionRounds = Long.MAX_VALUE database.numberKeyEncryptionRounds = Long.MAX_VALUE
} }
progressDialogThread?.startDatabaseSaveIterations(oldRounds, rounds, true) mProgressDialogThread?.startDatabaseSaveIterations(oldRounds, rounds, mDatabaseAutoSaveEnable)
} }
} }
} }

View File

@@ -24,4 +24,9 @@
android:title="@string/menu_lock" android:title="@string/menu_lock"
android:orderInCategory="81" android:orderInCategory="81"
app:showAsAction="always" /> app:showAsAction="always" />
<item android:id="@+id/menu_save_database"
android:icon="@drawable/ic_save_white_24dp"
android:title="@string/menu_save_database"
android:orderInCategory="95"
app:showAsAction="ifRoom" />
</menu> </menu>

View File

@@ -176,6 +176,7 @@
<string name="menu_cancel">Cancel</string> <string name="menu_cancel">Cancel</string>
<string name="menu_hide_password">Hide password</string> <string name="menu_hide_password">Hide password</string>
<string name="menu_lock">Lock database</string> <string name="menu_lock">Lock database</string>
<string name="menu_save_database">Save database</string>
<string name="menu_open">Open</string> <string name="menu_open">Open</string>
<string name="menu_search">Search</string> <string name="menu_search">Search</string>
<string name="menu_showpass">Show password</string> <string name="menu_showpass">Show password</string>