mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Fix entry history
This commit is contained in:
@@ -81,8 +81,10 @@ class EntryActivity : LockingActivity() {
|
|||||||
|
|
||||||
private val mEntryViewModel: EntryViewModel by viewModels()
|
private val mEntryViewModel: EntryViewModel by viewModels()
|
||||||
|
|
||||||
private var mEntryId: NodeId<UUID>? = null
|
private var mMainEntryId: NodeId<UUID>? = null
|
||||||
private var mHistoryPosition: Int = -1
|
private var mHistoryPosition: Int = -1
|
||||||
|
private var mEntryIsHistory: Boolean = false
|
||||||
|
private var mUrl: String? = null
|
||||||
|
|
||||||
private var mAttachmentFileBinderManager: AttachmentFileBinderManager? = null
|
private var mAttachmentFileBinderManager: AttachmentFileBinderManager? = null
|
||||||
private var mAttachmentsToDownload: HashMap<Int, Attachment> = HashMap()
|
private var mAttachmentsToDownload: HashMap<Int, Attachment> = HashMap()
|
||||||
@@ -122,7 +124,7 @@ class EntryActivity : LockingActivity() {
|
|||||||
// Get Entry from UUID
|
// Get Entry from UUID
|
||||||
try {
|
try {
|
||||||
intent.getParcelableExtra<NodeId<UUID>?>(KEY_ENTRY)?.let { entryId ->
|
intent.getParcelableExtra<NodeId<UUID>?>(KEY_ENTRY)?.let { entryId ->
|
||||||
mEntryId = entryId
|
mMainEntryId = entryId
|
||||||
intent.removeExtra(KEY_ENTRY)
|
intent.removeExtra(KEY_ENTRY)
|
||||||
mHistoryPosition = intent.getIntExtra(KEY_ENTRY_HISTORY_POSITION, -1)
|
mHistoryPosition = intent.getIntExtra(KEY_ENTRY_HISTORY_POSITION, -1)
|
||||||
intent.removeExtra(KEY_ENTRY_HISTORY_POSITION)
|
intent.removeExtra(KEY_ENTRY_HISTORY_POSITION)
|
||||||
@@ -140,6 +142,30 @@ class EntryActivity : LockingActivity() {
|
|||||||
lockAndExit()
|
lockAndExit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mEntryViewModel.mainEntryId.observe(this) { mainEntryId ->
|
||||||
|
this.mMainEntryId = mainEntryId
|
||||||
|
invalidateOptionsMenu()
|
||||||
|
}
|
||||||
|
|
||||||
|
mEntryViewModel.historyPosition.observe(this) { historyPosition ->
|
||||||
|
this.mHistoryPosition = historyPosition
|
||||||
|
val entryIsHistory = historyPosition > -1
|
||||||
|
this.mEntryIsHistory = entryIsHistory
|
||||||
|
// Assign history dedicated view
|
||||||
|
historyView?.visibility = if (entryIsHistory) View.VISIBLE else View.GONE
|
||||||
|
if (entryIsHistory) {
|
||||||
|
val taColorAccent = theme.obtainStyledAttributes(intArrayOf(R.attr.colorAccent))
|
||||||
|
collapsingToolbarLayout?.contentScrim = ColorDrawable(taColorAccent.getColor(0, Color.BLACK))
|
||||||
|
taColorAccent.recycle()
|
||||||
|
}
|
||||||
|
invalidateOptionsMenu()
|
||||||
|
}
|
||||||
|
|
||||||
|
mEntryViewModel.url.observe(this) { url ->
|
||||||
|
this.mUrl = url
|
||||||
|
invalidateOptionsMenu()
|
||||||
|
}
|
||||||
|
|
||||||
mEntryViewModel.entryInfo.observe(this) { entryInfo ->
|
mEntryViewModel.entryInfo.observe(this) { entryInfo ->
|
||||||
// Manage entry copy to start notification if allowed (at the first start)
|
// Manage entry copy to start notification if allowed (at the first start)
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
@@ -168,18 +194,6 @@ class EntryActivity : LockingActivity() {
|
|||||||
loadingView?.hideByFading()
|
loadingView?.hideByFading()
|
||||||
}
|
}
|
||||||
|
|
||||||
mEntryViewModel.entryIsHistory.observe(this) { entryIsHistory ->
|
|
||||||
// Assign history dedicated view
|
|
||||||
historyView?.visibility = if (entryIsHistory) View.VISIBLE else View.GONE
|
|
||||||
if (entryIsHistory) {
|
|
||||||
val taColorAccent = theme.obtainStyledAttributes(intArrayOf(R.attr.colorAccent))
|
|
||||||
collapsingToolbarLayout?.contentScrim = ColorDrawable(taColorAccent.getColor(0, Color.BLACK))
|
|
||||||
taColorAccent.recycle()
|
|
||||||
}
|
|
||||||
|
|
||||||
invalidateOptionsMenu()
|
|
||||||
}
|
|
||||||
|
|
||||||
mEntryViewModel.onOtpElementUpdated.observe(this) { otpElement ->
|
mEntryViewModel.onOtpElementUpdated.observe(this) { otpElement ->
|
||||||
if (otpElement == null)
|
if (otpElement == null)
|
||||||
entryProgress?.visibility = View.GONE
|
entryProgress?.visibility = View.GONE
|
||||||
@@ -219,7 +233,7 @@ class EntryActivity : LockingActivity() {
|
|||||||
coordinatorLayout?.resetAppTimeoutWhenViewFocusedOrChanged(this, database)
|
coordinatorLayout?.resetAppTimeoutWhenViewFocusedOrChanged(this, database)
|
||||||
|
|
||||||
mEntryViewModel.setDatabase(database)
|
mEntryViewModel.setDatabase(database)
|
||||||
mEntryViewModel.loadEntry(mEntryId, mHistoryPosition)
|
mEntryViewModel.loadEntry(mMainEntryId, mHistoryPosition)
|
||||||
|
|
||||||
// Assign title icon
|
// Assign title icon
|
||||||
mIcon?.let { icon ->
|
mIcon?.let { icon ->
|
||||||
@@ -306,16 +320,14 @@ class EntryActivity : LockingActivity() {
|
|||||||
inflater.inflate(R.menu.entry, menu)
|
inflater.inflate(R.menu.entry, menu)
|
||||||
inflater.inflate(R.menu.database, menu)
|
inflater.inflate(R.menu.database, menu)
|
||||||
|
|
||||||
if (mEntryViewModel.getEntry()?.url?.isEmpty() != false) {
|
if (mUrl?.isEmpty() != false) {
|
||||||
menu.findItem(R.id.menu_goto_url)?.isVisible = false
|
menu.findItem(R.id.menu_goto_url)?.isVisible = false
|
||||||
}
|
}
|
||||||
|
|
||||||
val entryIsHistory = mEntryViewModel.getEntryIsHistory()
|
if (mEntryIsHistory && !mReadOnly) {
|
||||||
|
|
||||||
if (entryIsHistory && !mReadOnly) {
|
|
||||||
inflater.inflate(R.menu.entry_history, menu)
|
inflater.inflate(R.menu.entry_history, menu)
|
||||||
}
|
}
|
||||||
if (entryIsHistory || mReadOnly) {
|
if (mEntryIsHistory || mReadOnly) {
|
||||||
menu.findItem(R.id.menu_save_database)?.isVisible = false
|
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
|
||||||
}
|
}
|
||||||
@@ -366,29 +378,29 @@ class EntryActivity : LockingActivity() {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.menu_edit -> {
|
R.id.menu_edit -> {
|
||||||
mEntryViewModel.getEntry()?.let { entry ->
|
mMainEntryId?.let { entryId ->
|
||||||
EntryEditActivity.launch(this@EntryActivity, entry)
|
EntryEditActivity.launch(this@EntryActivity, entryId)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.menu_goto_url -> {
|
R.id.menu_goto_url -> {
|
||||||
mEntryViewModel.getEntry()?.url?.let { url ->
|
mUrl?.let { url ->
|
||||||
UriUtil.gotoUrl(this, url)
|
UriUtil.gotoUrl(this, url)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.menu_restore_entry_history -> {
|
R.id.menu_restore_entry_history -> {
|
||||||
mEntryViewModel.getMainEntry()?.let { mainEntry ->
|
mMainEntryId?.let { mainEntryId ->
|
||||||
restoreEntryHistory(
|
restoreEntryHistory(
|
||||||
mainEntry,
|
mainEntryId,
|
||||||
mEntryViewModel.getEntryHistoryPosition())
|
mHistoryPosition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
R.id.menu_delete_entry_history -> {
|
R.id.menu_delete_entry_history -> {
|
||||||
mEntryViewModel.getMainEntry()?.let { mainEntry ->
|
mMainEntryId?.let { mainEntryId ->
|
||||||
deleteEntryHistory(
|
deleteEntryHistory(
|
||||||
mainEntry,
|
mainEntryId,
|
||||||
mEntryViewModel.getEntryHistoryPosition())
|
mHistoryPosition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
R.id.menu_save_database -> {
|
R.id.menu_save_database -> {
|
||||||
@@ -405,7 +417,7 @@ class EntryActivity : LockingActivity() {
|
|||||||
override fun finish() {
|
override fun finish() {
|
||||||
// Transit data in previous Activity after an update
|
// Transit data in previous Activity after an update
|
||||||
Intent().apply {
|
Intent().apply {
|
||||||
putExtra(EntryEditActivity.ADD_OR_UPDATE_ENTRY_KEY, mEntryViewModel.getEntry())
|
putExtra(EntryEditActivity.ADD_OR_UPDATE_ENTRY_KEY, mMainEntryId)
|
||||||
setResult(EntryEditActivity.UPDATE_ENTRY_RESULT_CODE, this)
|
setResult(EntryEditActivity.UPDATE_ENTRY_RESULT_CODE, this)
|
||||||
}
|
}
|
||||||
super.finish()
|
super.finish()
|
||||||
|
|||||||
@@ -661,7 +661,7 @@ class EntryEditActivity : LockingActivity(),
|
|||||||
try {
|
try {
|
||||||
val bundle = Bundle()
|
val bundle = Bundle()
|
||||||
val intentEntry = Intent()
|
val intentEntry = Intent()
|
||||||
bundle.putParcelable(ADD_OR_UPDATE_ENTRY_KEY, entry)
|
bundle.putParcelable(ADD_OR_UPDATE_ENTRY_KEY, entry.nodeId)
|
||||||
intentEntry.putExtras(bundle)
|
intentEntry.putExtras(bundle)
|
||||||
when (actionTask) {
|
when (actionTask) {
|
||||||
ACTION_DATABASE_CREATE_ENTRY_TASK -> {
|
ACTION_DATABASE_CREATE_ENTRY_TASK -> {
|
||||||
@@ -698,13 +698,13 @@ class EntryEditActivity : LockingActivity(),
|
|||||||
* Launch EntryEditActivity to update an existing entry
|
* Launch EntryEditActivity to update an existing entry
|
||||||
*
|
*
|
||||||
* @param activity from activity
|
* @param activity from activity
|
||||||
* @param entry Entry to update
|
* @param entryId Entry to update
|
||||||
*/
|
*/
|
||||||
fun launch(activity: Activity,
|
fun launch(activity: Activity,
|
||||||
entry: Entry) {
|
entryId: NodeId<UUID>) {
|
||||||
if (TimeoutHelper.checkTimeAndLockIfTimeout(activity)) {
|
if (TimeoutHelper.checkTimeAndLockIfTimeout(activity)) {
|
||||||
val intent = Intent(activity, EntryEditActivity::class.java)
|
val intent = Intent(activity, EntryEditActivity::class.java)
|
||||||
intent.putExtra(KEY_ENTRY, entry.nodeId)
|
intent.putExtra(KEY_ENTRY, entryId)
|
||||||
activity.startActivityForResult(intent, ADD_OR_UPDATE_ENTRY_REQUEST_CODE)
|
activity.startActivityForResult(intent, ADD_OR_UPDATE_ENTRY_REQUEST_CODE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -772,7 +772,7 @@ class GroupActivity : LockingActivity(),
|
|||||||
.show(supportFragmentManager,
|
.show(supportFragmentManager,
|
||||||
GroupEditDialogFragment.TAG_CREATE_GROUP)
|
GroupEditDialogFragment.TAG_CREATE_GROUP)
|
||||||
}
|
}
|
||||||
Type.ENTRY -> EntryEditActivity.launch(this@GroupActivity, node as Entry)
|
Type.ENTRY -> EntryEditActivity.launch(this@GroupActivity, (node as Entry).nodeId)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import com.kunzisoft.keepass.database.element.Database
|
|||||||
import com.kunzisoft.keepass.database.element.Group
|
import com.kunzisoft.keepass.database.element.Group
|
||||||
import com.kunzisoft.keepass.database.element.SortNodeEnum
|
import com.kunzisoft.keepass.database.element.SortNodeEnum
|
||||||
import com.kunzisoft.keepass.database.element.node.Node
|
import com.kunzisoft.keepass.database.element.node.Node
|
||||||
|
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||||
import com.kunzisoft.keepass.database.element.node.Type
|
import com.kunzisoft.keepass.database.element.node.Type
|
||||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||||
import com.kunzisoft.keepass.viewmodels.GroupViewModel
|
import com.kunzisoft.keepass.viewmodels.GroupViewModel
|
||||||
@@ -397,9 +398,9 @@ class ListNodesFragment : DatabaseFragment(), SortDialogFragment.SortSelectionLi
|
|||||||
EntryEditActivity.ADD_OR_UPDATE_ENTRY_REQUEST_CODE -> {
|
EntryEditActivity.ADD_OR_UPDATE_ENTRY_REQUEST_CODE -> {
|
||||||
if (resultCode == EntryEditActivity.ADD_ENTRY_RESULT_CODE
|
if (resultCode == EntryEditActivity.ADD_ENTRY_RESULT_CODE
|
||||||
|| resultCode == EntryEditActivity.UPDATE_ENTRY_RESULT_CODE) {
|
|| resultCode == EntryEditActivity.UPDATE_ENTRY_RESULT_CODE) {
|
||||||
data?.getParcelableExtra<Node>(EntryEditActivity.ADD_OR_UPDATE_ENTRY_KEY)?.let { changedNode ->
|
data?.getParcelableExtra<NodeId<UUID>>(EntryEditActivity.ADD_OR_UPDATE_ENTRY_KEY)?.let { changedNodeId ->
|
||||||
if (resultCode == EntryEditActivity.ADD_ENTRY_RESULT_CODE)
|
// TODO if (resultCode == EntryEditActivity.ADD_ENTRY_RESULT_CODE)
|
||||||
addNode(changedNode)
|
// addNode(changedNode)
|
||||||
if (resultCode == EntryEditActivity.UPDATE_ENTRY_RESULT_CODE)
|
if (resultCode == EntryEditActivity.UPDATE_ENTRY_RESULT_CODE)
|
||||||
mAdapter?.notifyDataSetChanged()
|
mAdapter?.notifyDataSetChanged()
|
||||||
} ?: Log.e(this.javaClass.name, "New node can be retrieve in Activity Result")
|
} ?: Log.e(this.javaClass.name, "New node can be retrieve in Activity Result")
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import com.kunzisoft.keepass.database.element.Database
|
|||||||
import com.kunzisoft.keepass.database.element.Entry
|
import com.kunzisoft.keepass.database.element.Entry
|
||||||
import com.kunzisoft.keepass.database.element.Group
|
import com.kunzisoft.keepass.database.element.Group
|
||||||
import com.kunzisoft.keepass.database.element.node.Node
|
import com.kunzisoft.keepass.database.element.node.Node
|
||||||
|
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||||
import com.kunzisoft.keepass.icons.IconDrawableFactory
|
import com.kunzisoft.keepass.icons.IconDrawableFactory
|
||||||
import com.kunzisoft.keepass.model.GroupInfo
|
import com.kunzisoft.keepass.model.GroupInfo
|
||||||
import com.kunzisoft.keepass.model.MainCredential
|
import com.kunzisoft.keepass.model.MainCredential
|
||||||
@@ -48,6 +49,7 @@ import com.kunzisoft.keepass.settings.PreferencesUtil
|
|||||||
import com.kunzisoft.keepass.tasks.ActionRunnable
|
import com.kunzisoft.keepass.tasks.ActionRunnable
|
||||||
import com.kunzisoft.keepass.timeout.TimeoutHelper
|
import com.kunzisoft.keepass.timeout.TimeoutHelper
|
||||||
import com.kunzisoft.keepass.utils.*
|
import com.kunzisoft.keepass.utils.*
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
abstract class LockingActivity : SpecialModeActivity(),
|
abstract class LockingActivity : SpecialModeActivity(),
|
||||||
PasswordEncodingDialogFragment.Listener,
|
PasswordEncodingDialogFragment.Listener,
|
||||||
@@ -256,14 +258,14 @@ abstract class LockingActivity : SpecialModeActivity(),
|
|||||||
updateDatabaseGroup(oldGroup, updateGroup, !mReadOnly && mAutoSaveEnable)
|
updateDatabaseGroup(oldGroup, updateGroup, !mReadOnly && mAutoSaveEnable)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun restoreEntryHistory(mainEntry: Entry,
|
fun restoreEntryHistory(mainEntryId: NodeId<UUID>,
|
||||||
entryHistoryPosition: Int,) {
|
entryHistoryPosition: Int) {
|
||||||
restoreDatabaseEntryHistory(mainEntry, entryHistoryPosition, !mReadOnly && mAutoSaveEnable)
|
restoreDatabaseEntryHistory(mainEntryId, entryHistoryPosition, !mReadOnly && mAutoSaveEnable)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteEntryHistory(mainEntry: Entry,
|
fun deleteEntryHistory(mainEntryId: NodeId<UUID>,
|
||||||
entryHistoryPosition: Int,) {
|
entryHistoryPosition: Int) {
|
||||||
deleteDatabaseEntryHistory(mainEntry, entryHistoryPosition, !mReadOnly && mAutoSaveEnable)
|
deleteDatabaseEntryHistory(mainEntryId, entryHistoryPosition, !mReadOnly && mAutoSaveEnable)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
|
|||||||
@@ -11,9 +11,11 @@ import com.kunzisoft.keepass.database.element.Database
|
|||||||
import com.kunzisoft.keepass.database.element.Entry
|
import com.kunzisoft.keepass.database.element.Entry
|
||||||
import com.kunzisoft.keepass.database.element.Group
|
import com.kunzisoft.keepass.database.element.Group
|
||||||
import com.kunzisoft.keepass.database.element.node.Node
|
import com.kunzisoft.keepass.database.element.node.Node
|
||||||
|
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||||
import com.kunzisoft.keepass.model.MainCredential
|
import com.kunzisoft.keepass.model.MainCredential
|
||||||
import com.kunzisoft.keepass.tasks.ActionRunnable
|
import com.kunzisoft.keepass.tasks.ActionRunnable
|
||||||
import com.kunzisoft.keepass.viewmodels.DatabaseViewModel
|
import com.kunzisoft.keepass.viewmodels.DatabaseViewModel
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
abstract class DatabaseActivity: StylishActivity(), DatabaseRetrieval {
|
abstract class DatabaseActivity: StylishActivity(), DatabaseRetrieval {
|
||||||
|
|
||||||
@@ -186,16 +188,16 @@ abstract class DatabaseActivity: StylishActivity(), DatabaseRetrieval {
|
|||||||
mDatabaseTaskProvider?.startDatabaseUpdateGroup(oldGroup, groupToUpdate, save)
|
mDatabaseTaskProvider?.startDatabaseUpdateGroup(oldGroup, groupToUpdate, save)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun restoreDatabaseEntryHistory(mainEntry: Entry,
|
fun restoreDatabaseEntryHistory(mainEntryId: NodeId<UUID>,
|
||||||
entryHistoryPosition: Int,
|
entryHistoryPosition: Int,
|
||||||
save: Boolean) {
|
save: Boolean) {
|
||||||
mDatabaseTaskProvider?.startDatabaseRestoreEntryHistory(mainEntry, entryHistoryPosition, save)
|
mDatabaseTaskProvider?.startDatabaseRestoreEntryHistory(mainEntryId, entryHistoryPosition, save)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteDatabaseEntryHistory(mainEntry: Entry,
|
fun deleteDatabaseEntryHistory(mainEntryId: NodeId<UUID>,
|
||||||
entryHistoryPosition: Int,
|
entryHistoryPosition: Int,
|
||||||
save: Boolean) {
|
save: Boolean) {
|
||||||
mDatabaseTaskProvider?.startDatabaseDeleteEntryHistory(mainEntry, entryHistoryPosition, save)
|
mDatabaseTaskProvider?.startDatabaseDeleteEntryHistory(mainEntryId, entryHistoryPosition, save)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
|
|||||||
@@ -447,22 +447,22 @@ class DatabaseTaskProvider(private val activity: FragmentActivity) {
|
|||||||
-----------------
|
-----------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fun startDatabaseRestoreEntryHistory(mainEntry: Entry,
|
fun startDatabaseRestoreEntryHistory(mainEntryId: NodeId<UUID>,
|
||||||
entryHistoryPosition: Int,
|
entryHistoryPosition: Int,
|
||||||
save: Boolean) {
|
save: Boolean) {
|
||||||
start(Bundle().apply {
|
start(Bundle().apply {
|
||||||
putParcelable(DatabaseTaskNotificationService.ENTRY_ID_KEY, mainEntry.nodeId)
|
putParcelable(DatabaseTaskNotificationService.ENTRY_ID_KEY, mainEntryId)
|
||||||
putInt(DatabaseTaskNotificationService.ENTRY_HISTORY_POSITION_KEY, entryHistoryPosition)
|
putInt(DatabaseTaskNotificationService.ENTRY_HISTORY_POSITION_KEY, entryHistoryPosition)
|
||||||
putBoolean(DatabaseTaskNotificationService.SAVE_DATABASE_KEY, save)
|
putBoolean(DatabaseTaskNotificationService.SAVE_DATABASE_KEY, save)
|
||||||
}
|
}
|
||||||
, ACTION_DATABASE_RESTORE_ENTRY_HISTORY)
|
, ACTION_DATABASE_RESTORE_ENTRY_HISTORY)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun startDatabaseDeleteEntryHistory(mainEntry: Entry,
|
fun startDatabaseDeleteEntryHistory(mainEntryId: NodeId<UUID>,
|
||||||
entryHistoryPosition: Int,
|
entryHistoryPosition: Int,
|
||||||
save: Boolean) {
|
save: Boolean) {
|
||||||
start(Bundle().apply {
|
start(Bundle().apply {
|
||||||
putParcelable(DatabaseTaskNotificationService.ENTRY_ID_KEY, mainEntry.nodeId)
|
putParcelable(DatabaseTaskNotificationService.ENTRY_ID_KEY, mainEntryId)
|
||||||
putInt(DatabaseTaskNotificationService.ENTRY_HISTORY_POSITION_KEY, entryHistoryPosition)
|
putInt(DatabaseTaskNotificationService.ENTRY_HISTORY_POSITION_KEY, entryHistoryPosition)
|
||||||
putBoolean(DatabaseTaskNotificationService.SAVE_DATABASE_KEY, save)
|
putBoolean(DatabaseTaskNotificationService.SAVE_DATABASE_KEY, save)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2021 Jeremy Jamet / Kunzisoft.
|
||||||
|
*
|
||||||
|
* This file is part of KeePassDX.
|
||||||
|
*
|
||||||
|
* KeePassDX is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* KeePassDX is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package com.kunzisoft.keepass.viewmodels
|
package com.kunzisoft.keepass.viewmodels
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
@@ -6,7 +25,6 @@ import androidx.lifecycle.ViewModel
|
|||||||
import com.kunzisoft.keepass.app.database.IOActionTask
|
import com.kunzisoft.keepass.app.database.IOActionTask
|
||||||
import com.kunzisoft.keepass.database.element.Attachment
|
import com.kunzisoft.keepass.database.element.Attachment
|
||||||
import com.kunzisoft.keepass.database.element.Database
|
import com.kunzisoft.keepass.database.element.Database
|
||||||
import com.kunzisoft.keepass.database.element.Entry
|
|
||||||
import com.kunzisoft.keepass.database.element.node.NodeId
|
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||||
import com.kunzisoft.keepass.database.element.node.NodeIdUUID
|
import com.kunzisoft.keepass.database.element.node.NodeIdUUID
|
||||||
import com.kunzisoft.keepass.database.element.template.Template
|
import com.kunzisoft.keepass.database.element.template.Template
|
||||||
@@ -19,20 +37,22 @@ import java.util.*
|
|||||||
class EntryViewModel: ViewModel() {
|
class EntryViewModel: ViewModel() {
|
||||||
|
|
||||||
private var mDatabase: Database? = null
|
private var mDatabase: Database? = null
|
||||||
private var mEntryTemplate: Template? = null
|
|
||||||
private var mEntry: Entry? = null
|
|
||||||
private var mLastEntryVersion: Entry? = null
|
|
||||||
private var mHistoryPosition: Int = -1
|
|
||||||
|
|
||||||
val template : LiveData<Template> get() = _template
|
val template : LiveData<Template> get() = _template
|
||||||
private val _template = MutableLiveData<Template>()
|
private val _template = MutableLiveData<Template>()
|
||||||
|
|
||||||
|
val mainEntryId : LiveData<NodeId<UUID>?> get() = _mainEntryId
|
||||||
|
private val _mainEntryId = MutableLiveData<NodeId<UUID>?>()
|
||||||
|
|
||||||
|
val historyPosition : LiveData<Int> get() = _historyPosition
|
||||||
|
private val _historyPosition = MutableLiveData<Int>()
|
||||||
|
|
||||||
|
val url : LiveData<String?> get() = _url
|
||||||
|
private val _url = MutableLiveData<String?>()
|
||||||
|
|
||||||
val entryInfo : LiveData<EntryInfo> get() = _entryInfo
|
val entryInfo : LiveData<EntryInfo> get() = _entryInfo
|
||||||
private val _entryInfo = MutableLiveData<EntryInfo>()
|
private val _entryInfo = MutableLiveData<EntryInfo>()
|
||||||
|
|
||||||
val entryIsHistory : LiveData<Boolean> get() = _entryIsHistory
|
|
||||||
private val _entryIsHistory = MutableLiveData<Boolean>()
|
|
||||||
|
|
||||||
val entryHistory : LiveData<List<EntryInfo>> get() = _entryHistory
|
val entryHistory : LiveData<List<EntryInfo>> get() = _entryHistory
|
||||||
private val _entryHistory = MutableLiveData<List<EntryInfo>>()
|
private val _entryHistory = MutableLiveData<List<EntryInfo>>()
|
||||||
|
|
||||||
@@ -55,81 +75,62 @@ class EntryViewModel: ViewModel() {
|
|||||||
if (entryId != null) {
|
if (entryId != null) {
|
||||||
IOActionTask(
|
IOActionTask(
|
||||||
{
|
{
|
||||||
// Manage current version and history
|
mDatabase?.getEntryById(entryId)
|
||||||
mLastEntryVersion = mDatabase?.getEntryById(entryId)
|
|
||||||
|
|
||||||
mEntry = if (historyPosition > -1) {
|
|
||||||
mLastEntryVersion?.getHistory()?.get(historyPosition)
|
|
||||||
} else {
|
|
||||||
mLastEntryVersion
|
|
||||||
}
|
|
||||||
|
|
||||||
mEntryTemplate = mEntry?.let {
|
|
||||||
mDatabase?.getTemplate(it)
|
|
||||||
} ?: Template.STANDARD
|
|
||||||
|
|
||||||
mHistoryPosition = historyPosition
|
|
||||||
|
|
||||||
// To simplify template field visibility
|
|
||||||
mEntry?.let { entry ->
|
|
||||||
// Add mLastEntryVersion to check the parent and define the template state
|
|
||||||
mDatabase?.decodeEntryWithTemplateConfiguration(entry, mLastEntryVersion)
|
|
||||||
?.let {
|
|
||||||
// To update current modification time
|
|
||||||
it.touch(modified = false, touchParents = false)
|
|
||||||
|
|
||||||
// Build history info
|
|
||||||
val entryInfoHistory = it.getHistory().map { entryHistory ->
|
|
||||||
entryHistory.getEntryInfo(mDatabase)
|
|
||||||
}
|
|
||||||
|
|
||||||
EntryInfoHistory(
|
|
||||||
mEntryTemplate ?: Template.STANDARD,
|
|
||||||
it.getEntryInfo(mDatabase),
|
|
||||||
entryInfoHistory
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{ entryInfoHistory ->
|
{ mainEntry ->
|
||||||
if (entryInfoHistory != null) {
|
// Manage current version and history
|
||||||
_template.value = entryInfoHistory.template
|
_mainEntryId.value = mainEntry?.nodeId
|
||||||
_entryInfo.value = entryInfoHistory.entryInfo
|
_historyPosition.value = historyPosition
|
||||||
_entryIsHistory.value = mHistoryPosition != -1
|
|
||||||
_entryHistory.value = entryInfoHistory.entryHistory
|
val currentEntry = if (historyPosition > -1) {
|
||||||
|
mainEntry?.getHistory()?.get(historyPosition)
|
||||||
|
} else {
|
||||||
|
mainEntry
|
||||||
}
|
}
|
||||||
|
_url.value = currentEntry?.url
|
||||||
|
|
||||||
|
IOActionTask(
|
||||||
|
{
|
||||||
|
val entryTemplate = currentEntry?.let {
|
||||||
|
mDatabase?.getTemplate(it)
|
||||||
|
} ?: Template.STANDARD
|
||||||
|
|
||||||
|
// To simplify template field visibility
|
||||||
|
currentEntry?.let { entry ->
|
||||||
|
// Add mainEntry to check the parent and define the template state
|
||||||
|
mDatabase?.decodeEntryWithTemplateConfiguration(entry, mainEntry)
|
||||||
|
?.let {
|
||||||
|
// To update current modification time
|
||||||
|
it.touch(modified = false, touchParents = false)
|
||||||
|
|
||||||
|
// Build history info
|
||||||
|
val entryInfoHistory = it.getHistory().map { entryHistory ->
|
||||||
|
entryHistory.getEntryInfo(mDatabase)
|
||||||
|
}
|
||||||
|
|
||||||
|
EntryInfoHistory(
|
||||||
|
entryTemplate,
|
||||||
|
it.getEntryInfo(mDatabase),
|
||||||
|
entryInfoHistory
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ entryInfoHistory ->
|
||||||
|
if (entryInfoHistory != null) {
|
||||||
|
_template.value = entryInfoHistory.template
|
||||||
|
_entryInfo.value = entryInfoHistory.entryInfo
|
||||||
|
_entryHistory.value = entryInfoHistory.entryHistory
|
||||||
|
}
|
||||||
|
}
|
||||||
|
).execute()
|
||||||
}
|
}
|
||||||
).execute()
|
).execute()
|
||||||
} else {
|
|
||||||
mEntryTemplate = null
|
|
||||||
mEntry = null
|
|
||||||
mLastEntryVersion = null
|
|
||||||
mHistoryPosition = -1
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateEntry() {
|
fun updateEntry() {
|
||||||
loadEntry(mEntry?.nodeId, mHistoryPosition)
|
loadEntry(_mainEntryId.value, _historyPosition.value ?: -1)
|
||||||
}
|
|
||||||
|
|
||||||
// TODO Remove
|
|
||||||
fun getEntry(): Entry? {
|
|
||||||
return mEntry
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO Remove
|
|
||||||
fun getMainEntry(): Entry? {
|
|
||||||
return mLastEntryVersion
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO Remove
|
|
||||||
fun getEntryHistoryPosition(): Int {
|
|
||||||
return mHistoryPosition
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO Remove
|
|
||||||
fun getEntryIsHistory(): Boolean {
|
|
||||||
return entryIsHistory.value ?: false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onOtpElementUpdated(optElement: OtpElement?) {
|
fun onOtpElementUpdated(optElement: OtpElement?) {
|
||||||
|
|||||||
Reference in New Issue
Block a user