mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-21 17:41:50 -08:00
fix: Temporary data merge and menu #2541
This commit is contained in:
6 files changed
+148
-122
No files matched your search
@@ -206,7 +206,7 @@ class EntryActivity : DatabaseLockActivity() {
|
||||
val historyPosition = intent.getIntExtra(KEY_ENTRY_HISTORY_POSITION, -1)
|
||||
intent.removeExtra(KEY_ENTRY_HISTORY_POSITION)
|
||||
|
||||
mEntryViewModel.loadEntry(mDatabase, mainEntryId, historyPosition)
|
||||
mEntryViewModel.loadEntry(mainEntryId, historyPosition)
|
||||
}
|
||||
} catch (_: ClassCastException) {
|
||||
Log.e(TAG, "Unable to retrieve the entry key")
|
||||
@@ -487,11 +487,11 @@ class EntryActivity : DatabaseLockActivity() {
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
super.onCreateOptionsMenu(menu)
|
||||
if (mEntryViewModel.entryLoaded) {
|
||||
if (mEntryViewModel.databaseActionsAllowed()) {
|
||||
val inflater = menuInflater
|
||||
inflater.inflate(R.menu.database, menu)
|
||||
|
||||
if (mEntryViewModel.entryIsHistory && !mDatabaseReadOnly) {
|
||||
if (mEntryViewModel.entryHistoryActionsAllowed()) {
|
||||
inflater.inflate(R.menu.entry_history, menu)
|
||||
}
|
||||
|
||||
@@ -504,15 +504,15 @@ class EntryActivity : DatabaseLockActivity() {
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
|
||||
if (mEntryViewModel.entryIsHistory || mDatabaseReadOnly) {
|
||||
if (!mEntryViewModel.saveDatabaseActionAllowed()) {
|
||||
menu?.findItem(R.id.menu_save_database)?.isVisible = false
|
||||
}
|
||||
if (!mEntryViewModel.mergeDatabaseActionAllowed()
|
||||
|| mSpecialMode != SpecialMode.DEFAULT) {
|
||||
menu?.findItem(R.id.menu_merge_database)?.isVisible = false
|
||||
}
|
||||
if (!mMergeDataAllowed) {
|
||||
menu?.findItem(R.id.menu_merge_database)?.isVisible = false
|
||||
}
|
||||
if (mSpecialMode != SpecialMode.DEFAULT) {
|
||||
menu?.findItem(R.id.menu_merge_database)?.isVisible = false
|
||||
if (!mEntryViewModel.reloadDatabaseActionAllowed()
|
||||
|| mSpecialMode != SpecialMode.DEFAULT) {
|
||||
menu?.findItem(R.id.menu_reload_database)?.isVisible = false
|
||||
}
|
||||
mEntryViewModel.applyToolbarColors()
|
||||
|
||||
@@ -1108,75 +1108,78 @@ class GroupActivity : DatabaseLockActivity() {
|
||||
// depending on current mode
|
||||
val modeCondition = mSpecialMode == SpecialMode.DEFAULT
|
||||
menu.findItem(R.id.menu_app_settings)?.isVisible = modeCondition
|
||||
menu.findItem(R.id.menu_merge_from)?.isVisible = mMergeDataAllowed && modeCondition
|
||||
menu.findItem(R.id.menu_save_copy_to)?.isVisible = modeCondition
|
||||
menu.findItem(R.id.menu_merge_from)?.isVisible = mGroupViewModel.mergeFromDatabaseActionAllowed() && modeCondition
|
||||
menu.findItem(R.id.menu_save_copy_to)?.isVisible = mGroupViewModel.copyToDatabaseActionAllowed() && modeCondition
|
||||
menu.findItem(R.id.menu_about)?.isVisible = modeCondition
|
||||
menu.findItem(R.id.menu_contribute)?.isVisible = modeCondition
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
|
||||
val inflater = menuInflater
|
||||
inflater.inflate(R.menu.search, menu)
|
||||
inflater.inflate(R.menu.database, menu)
|
||||
if (mDatabaseReadOnly) {
|
||||
menu.findItem(R.id.menu_save_database)?.isVisible = false
|
||||
menu.findItem(R.id.menu_merge_database)?.isVisible = false
|
||||
}
|
||||
if (!mMergeDataAllowed) {
|
||||
menu.findItem(R.id.menu_merge_database)?.isVisible = false
|
||||
}
|
||||
if (mSpecialMode != SpecialMode.DEFAULT) {
|
||||
menu.findItem(R.id.menu_merge_database)?.isVisible = false
|
||||
menu.findItem(R.id.menu_reload_database)?.isVisible = false
|
||||
}
|
||||
// Menu for recycle bin
|
||||
if (mGroupViewModel.recycleBinActionsAllowed()) {
|
||||
inflater.inflate(R.menu.recycle_bin, menu)
|
||||
}
|
||||
|
||||
prepareDatabaseNavMenu()
|
||||
|
||||
// Get the SearchView and set the searchable configuration
|
||||
menu.findItem(R.id.menu_search)?.let {
|
||||
mGroupViewModel.mLockSearchListeners = true
|
||||
it.setOnActionExpandListener(mOnSearchActionExpandListener)
|
||||
searchView = it.actionView as SearchView?
|
||||
searchView?.apply {
|
||||
setOnQueryTextFocusChangeListener(mOnSearchTextFocusChangeListener)
|
||||
val searchManager = getSystemService(SEARCH_SERVICE) as SearchManager?
|
||||
(searchManager?.getSearchableInfo(
|
||||
ComponentName(this@GroupActivity, GroupActivity::class.java)
|
||||
))?.let { searchableInfo ->
|
||||
setSearchableInfo(searchableInfo)
|
||||
}
|
||||
val searchState = mGroupViewModel.mSearchState
|
||||
// already open
|
||||
if (searchState != null) {
|
||||
it.expandActionView()
|
||||
addSearchQueryInSearchView(searchState.searchParameters.searchQuery)
|
||||
if (mGroupViewModel.mTempSearchInfo.not()) {
|
||||
searchFiltersView?.searchParameters = searchState.searchParameters
|
||||
}
|
||||
}
|
||||
}
|
||||
if (it.isActionViewExpanded) {
|
||||
breadcrumbListView?.visibility = View.GONE
|
||||
searchFiltersView?.visibility = View.VISIBLE
|
||||
} else {
|
||||
searchFiltersView?.visibility = View.GONE
|
||||
breadcrumbListView?.visibility = View.VISIBLE
|
||||
}
|
||||
mGroupViewModel.mLockSearchListeners = false
|
||||
mGroupViewModel.mAutoSearch = false
|
||||
}
|
||||
|
||||
super.onCreateOptionsMenu(menu)
|
||||
|
||||
// Launch education screen
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
performedNextEducation(menu)
|
||||
if (mGroupViewModel.databaseActionsAllowed()) {
|
||||
val inflater = menuInflater
|
||||
inflater.inflate(R.menu.search, menu)
|
||||
inflater.inflate(R.menu.database, menu)
|
||||
if (!mGroupViewModel.saveDatabaseActionAllowed()) {
|
||||
menu.findItem(R.id.menu_save_database)?.isVisible = false
|
||||
}
|
||||
if (!mGroupViewModel.mergeDatabaseActionAllowed()
|
||||
|| mSpecialMode != SpecialMode.DEFAULT
|
||||
) {
|
||||
menu.findItem(R.id.menu_merge_database)?.isVisible = false
|
||||
}
|
||||
if (!mGroupViewModel.reloadDatabaseActionAllowed()
|
||||
|| mSpecialMode != SpecialMode.DEFAULT
|
||||
) {
|
||||
menu.findItem(R.id.menu_reload_database)?.isVisible = false
|
||||
}
|
||||
// Menu for recycle bin
|
||||
if (mGroupViewModel.recycleBinActionsAllowed()) {
|
||||
inflater.inflate(R.menu.recycle_bin, menu)
|
||||
}
|
||||
|
||||
prepareDatabaseNavMenu()
|
||||
|
||||
// Get the SearchView and set the searchable configuration
|
||||
menu.findItem(R.id.menu_search)?.let {
|
||||
mGroupViewModel.mLockSearchListeners = true
|
||||
it.setOnActionExpandListener(mOnSearchActionExpandListener)
|
||||
searchView = it.actionView as SearchView?
|
||||
searchView?.apply {
|
||||
setOnQueryTextFocusChangeListener(mOnSearchTextFocusChangeListener)
|
||||
val searchManager = getSystemService(SEARCH_SERVICE) as SearchManager?
|
||||
(searchManager?.getSearchableInfo(
|
||||
ComponentName(this@GroupActivity, GroupActivity::class.java)
|
||||
))?.let { searchableInfo ->
|
||||
setSearchableInfo(searchableInfo)
|
||||
}
|
||||
val searchState = mGroupViewModel.mSearchState
|
||||
// already open
|
||||
if (searchState != null) {
|
||||
it.expandActionView()
|
||||
addSearchQueryInSearchView(searchState.searchParameters.searchQuery)
|
||||
if (mGroupViewModel.mTempSearchInfo.not()) {
|
||||
searchFiltersView?.searchParameters = searchState.searchParameters
|
||||
}
|
||||
}
|
||||
}
|
||||
if (it.isActionViewExpanded) {
|
||||
breadcrumbListView?.visibility = View.GONE
|
||||
searchFiltersView?.visibility = View.VISIBLE
|
||||
} else {
|
||||
searchFiltersView?.visibility = View.GONE
|
||||
breadcrumbListView?.visibility = View.VISIBLE
|
||||
}
|
||||
mGroupViewModel.mLockSearchListeners = false
|
||||
mGroupViewModel.mAutoSearch = false
|
||||
}
|
||||
|
||||
// Launch education screen
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
performedNextEducation(menu)
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
@@ -67,10 +67,7 @@ abstract class DatabaseLockActivity : DatabaseModeActivity() {
|
||||
|
||||
private var mLockReceiver: LockReceiver? = null
|
||||
private var mExitLock: Boolean = false
|
||||
|
||||
protected var mDatabaseReadOnly: Boolean = true
|
||||
protected var mDatabaseAllowUserVerification: Boolean = true
|
||||
protected var mMergeDataAllowed: Boolean = false
|
||||
private var mAutoSaveEnable: Boolean = true
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@@ -147,9 +144,7 @@ abstract class DatabaseLockActivity : DatabaseModeActivity() {
|
||||
TimeoutHelper.recordTime(this, database.loaded)
|
||||
}
|
||||
|
||||
mDatabaseReadOnly = database.isReadOnly
|
||||
mDatabaseAllowUserVerification = database.allowUserVerification
|
||||
mMergeDataAllowed = database.isMergeDataAllowed()
|
||||
|
||||
checkRegister()
|
||||
}
|
||||
@@ -176,9 +171,19 @@ abstract class DatabaseLockActivity : DatabaseModeActivity() {
|
||||
// Reload the current activity
|
||||
if (result.isSuccess) {
|
||||
reloadActivity()
|
||||
if (actionTask == DatabaseTaskNotificationService.ACTION_DATABASE_MERGE_TASK) {
|
||||
Toast.makeText(this, R.string.merge_success, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
Toast.makeText(
|
||||
this,
|
||||
when (actionTask) {
|
||||
DatabaseTaskNotificationService.ACTION_DATABASE_MERGE_TASK ->
|
||||
if (database.isReadOnly || !PreferencesUtil.isAutoSaveDatabaseEnabled(this))
|
||||
R.string.temporary_merge_success
|
||||
else
|
||||
R.string.merge_success
|
||||
else ->
|
||||
R.string.reload_success
|
||||
},
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
} else {
|
||||
this.showActionErrorIfNeeded(result)
|
||||
finish()
|
||||
@@ -294,7 +299,7 @@ abstract class DatabaseLockActivity : DatabaseModeActivity() {
|
||||
|
||||
private fun checkRegister() {
|
||||
// If in registration mode, don't allow read only
|
||||
if (mSpecialMode == SpecialMode.REGISTRATION && mDatabaseReadOnly) {
|
||||
if (mSpecialMode == SpecialMode.REGISTRATION && mDatabase?.isReadOnly != false) {
|
||||
Toast.makeText(this, R.string.error_registration_read_only , Toast.LENGTH_LONG).show()
|
||||
intent.removeModes()
|
||||
finish()
|
||||
|
||||
@@ -52,14 +52,13 @@ import kotlinx.coroutines.withContext
|
||||
*/
|
||||
class EntryViewModel(application: Application): AndroidViewModel(application) {
|
||||
|
||||
private var mDatabase: ContextualDatabase? = null
|
||||
var mainEntryId: EntryId? = null
|
||||
private set
|
||||
var historyPosition: Int = -1
|
||||
private set
|
||||
var entryIsHistory: Boolean = false
|
||||
private set
|
||||
val entryLoaded: Boolean
|
||||
get() = entryUIState.value.loaded
|
||||
|
||||
@ColorInt
|
||||
var colorSecondary: Int = 0
|
||||
@@ -99,11 +98,11 @@ class EntryViewModel(application: Application): AndroidViewModel(application) {
|
||||
}
|
||||
|
||||
fun loadDatabase(database: ContextualDatabase?) {
|
||||
loadEntry(database, mainEntryId, historyPosition)
|
||||
this.mDatabase = database
|
||||
loadEntry(mainEntryId, historyPosition)
|
||||
}
|
||||
|
||||
fun loadEntry(
|
||||
database: ContextualDatabase?,
|
||||
mainEntryId: EntryId?,
|
||||
historyPosition: Int = -1,
|
||||
) {
|
||||
@@ -111,46 +110,50 @@ class EntryViewModel(application: Application): AndroidViewModel(application) {
|
||||
this.historyPosition = historyPosition
|
||||
|
||||
viewModelScope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
if (database != null && mainEntryId != null) {
|
||||
database.getEntryById(mainEntryId)?.let { mainEntry ->
|
||||
val isHistory = historyPosition > -1
|
||||
val currentEntry = if (isHistory) {
|
||||
mainEntry.getHistory()[historyPosition]
|
||||
} else {
|
||||
mainEntry
|
||||
}
|
||||
val entryInfo = database.getEntryInfoFrom(currentEntry)
|
||||
this@EntryViewModel.entryIsHistory = isHistory
|
||||
mDatabase?.let { database ->
|
||||
withContext(Dispatchers.IO) {
|
||||
if (mainEntryId != null) {
|
||||
database.getEntryById(mainEntryId)?.let { mainEntry ->
|
||||
val isHistory = historyPosition > -1
|
||||
val currentEntry = if (isHistory) {
|
||||
mainEntry.getHistory()[historyPosition]
|
||||
} else {
|
||||
mainEntry
|
||||
}
|
||||
val entryInfo = database.getEntryInfoFrom(currentEntry)
|
||||
this@EntryViewModel.entryIsHistory = isHistory
|
||||
|
||||
_entryEvents.emit(EntryEvent.EntryLoaded(entryInfo))
|
||||
_entryEvents.emit(EntryEvent.EntryLoaded(entryInfo))
|
||||
|
||||
// Assign colors
|
||||
backgroundColor = if (showEntryColors) entryInfo.backgroundColor else null
|
||||
foregroundColor = if (showEntryColors) entryInfo.foregroundColor else null
|
||||
// Assign colors
|
||||
backgroundColor =
|
||||
if (showEntryColors) entryInfo.backgroundColor else null
|
||||
foregroundColor =
|
||||
if (showEntryColors) entryInfo.foregroundColor else null
|
||||
|
||||
// To show Entry UI
|
||||
_entryUIState.update {
|
||||
it.copy(
|
||||
loaded = true,
|
||||
entryInfo = entryInfo,
|
||||
isReadOnly = database.isReadOnly,
|
||||
showFloatingActionButton = !isHistory,
|
||||
showHistoryView = isHistory,
|
||||
entryHistory = if (!isHistory)
|
||||
database.getHistoryEntryInfoFrom(mainEntryId) ?: listOf()
|
||||
else listOf()
|
||||
)
|
||||
}
|
||||
|
||||
// Manage entry to populate Magikeyboard and launch keyboard notification if allowed
|
||||
if (keyboardEntrySelectionEnabled) {
|
||||
_entryEvents.emit(
|
||||
EntryEvent.AddToMagikeyboard(
|
||||
// To show Entry UI
|
||||
_entryUIState.update {
|
||||
it.copy(
|
||||
loaded = true,
|
||||
entryInfo = entryInfo,
|
||||
autoSwitch = autoSwitchToMagikeyboard
|
||||
isReadOnly = database.isReadOnly,
|
||||
showFloatingActionButton = !isHistory,
|
||||
showHistoryView = isHistory,
|
||||
entryHistory = if (!isHistory)
|
||||
database.getHistoryEntryInfoFrom(mainEntryId) ?: listOf()
|
||||
else listOf()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// Manage entry to populate Magikeyboard and launch keyboard notification if allowed
|
||||
if (keyboardEntrySelectionEnabled) {
|
||||
_entryEvents.emit(
|
||||
EntryEvent.AddToMagikeyboard(
|
||||
entryInfo = entryInfo,
|
||||
autoSwitch = autoSwitchToMagikeyboard
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -244,7 +247,14 @@ class EntryViewModel(application: Application): AndroidViewModel(application) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
fun entryHistoryActionsAllowed(): Boolean = entryUIState.value.loaded && entryIsHistory && mDatabase?.isReadOnly == false
|
||||
|
||||
fun databaseActionsAllowed(): Boolean = entryUIState.value.loaded
|
||||
fun saveDatabaseActionAllowed(): Boolean = !entryIsHistory && mDatabase?.isReadOnly == false
|
||||
fun mergeDatabaseActionAllowed(): Boolean = !entryIsHistory && mDatabase?.isMergeDataAllowed() == true
|
||||
fun reloadDatabaseActionAllowed(): Boolean = !entryIsHistory
|
||||
|
||||
/**
|
||||
* Sealed class for entry events.
|
||||
*/
|
||||
sealed class EntryEvent {
|
||||
|
||||
@@ -67,7 +67,6 @@ class GroupViewModel(application: Application): AndroidViewModel(application) {
|
||||
|
||||
// Manage Recycle Bin
|
||||
|
||||
private var mRecycleBinActionsGloballyAllowed = false
|
||||
private var mRecyclingBinIsCurrentGroup = false
|
||||
|
||||
private var mAddGroupOrEntryAllowed = false
|
||||
@@ -135,7 +134,6 @@ class GroupViewModel(application: Application): AndroidViewModel(application) {
|
||||
|
||||
fun onDatabaseLoaded(database: ContextualDatabase) {
|
||||
this.mDatabase = database
|
||||
this.mRecycleBinActionsGloballyAllowed = !database.isReadOnly && database.isRecycleBinEnabled
|
||||
this.mNodeFilter = DefaultNodeFilter(
|
||||
database = mDatabase,
|
||||
showExpired = mShowExpiredEntries,
|
||||
@@ -564,7 +562,15 @@ class GroupViewModel(application: Application): AndroidViewModel(application) {
|
||||
_nodeActionState.value = NodeActionState()
|
||||
}
|
||||
|
||||
fun recycleBinActionsAllowed(): Boolean = mRecycleBinActionsGloballyAllowed && mRecyclingBinIsCurrentGroup
|
||||
fun databaseActionsAllowed(): Boolean = groupUIState.value.loaded
|
||||
fun saveDatabaseActionAllowed(): Boolean = mDatabase?.isReadOnly == false
|
||||
fun mergeDatabaseActionAllowed(): Boolean = mDatabase?.isMergeDataAllowed() == true
|
||||
fun reloadDatabaseActionAllowed(): Boolean = true
|
||||
fun mergeFromDatabaseActionAllowed(): Boolean = mergeDatabaseActionAllowed()
|
||||
fun copyToDatabaseActionAllowed(): Boolean = true
|
||||
|
||||
fun recycleBinActionsAllowed(): Boolean = saveDatabaseActionAllowed()
|
||||
&& mDatabase?.isRecycleBinEnabled == true && mRecyclingBinIsCurrentGroup
|
||||
|
||||
fun emptyRecycleBin() {
|
||||
viewModelScope.launch {
|
||||
|
||||
@@ -396,7 +396,9 @@
|
||||
<string name="warning_overwrite_data_description">This action will replace the existing data in the entry, you can retrieve the old data if the history is enabled.</string>
|
||||
<string name="later">Later</string>
|
||||
<string name="ask">Ask</string>
|
||||
<string name="temporary_merge_success">Temporary data merge successfully completed</string>
|
||||
<string name="merge_success">Merge successfully completed</string>
|
||||
<string name="reload_success">Reload successfully completed</string>
|
||||
<string name="permission">Permission</string>
|
||||
<string name="version_label">Version %1$s</string>
|
||||
<string name="build_label">Build %1$s</string>
|
||||
|
||||
Reference in new issue
Block a user