mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-20 17:11:32 -08:00
Load history with entry info
This commit is contained in:
1 parent
cdeb49473b
commit
00a23119c5
4 files changed
+43
-24
No files matched your search
@@ -117,8 +117,8 @@ class EntryActivity : LockingActivity() {
|
||||
// Get Entry from UUID
|
||||
try {
|
||||
intent.getParcelableExtra<NodeId<UUID>?>(KEY_ENTRY)?.let { entryId ->
|
||||
val historyPosition = intent.getIntExtra(KEY_ENTRY_HISTORY_POSITION, -1)
|
||||
intent.removeExtra(KEY_ENTRY)
|
||||
val historyPosition = intent.getIntExtra(KEY_ENTRY_HISTORY_POSITION, -1)
|
||||
intent.removeExtra(KEY_ENTRY_HISTORY_POSITION)
|
||||
mEntryViewModel.loadEntry(entryId, historyPosition)
|
||||
}
|
||||
@@ -197,9 +197,10 @@ class EntryActivity : LockingActivity() {
|
||||
}
|
||||
|
||||
mEntryViewModel.historySelected.observe(this) { historySelected ->
|
||||
historySelected.entry?.let { entry ->
|
||||
launch(this, entry, mReadOnly, historySelected.historyPosition)
|
||||
}
|
||||
launch(this,
|
||||
historySelected.nodeId,
|
||||
historySelected.historyPosition,
|
||||
mReadOnly)
|
||||
}
|
||||
|
||||
mProgressDatabaseTaskProvider?.onActionFinish = { actionTask, result ->
|
||||
@@ -396,13 +397,27 @@ class EntryActivity : LockingActivity() {
|
||||
|
||||
const val ENTRY_FRAGMENT_TAG = "ENTRY_FRAGMENT_TAG"
|
||||
|
||||
fun launch(activity: Activity, entry: Entry, readOnly: Boolean, historyPosition: Int? = null) {
|
||||
/**
|
||||
* Open standard Entry activity
|
||||
*/
|
||||
fun launch(activity: Activity, entry: Entry, readOnly: Boolean) {
|
||||
if (TimeoutHelper.checkTimeAndLockIfTimeout(activity)) {
|
||||
val intent = Intent(activity, EntryActivity::class.java)
|
||||
intent.putExtra(KEY_ENTRY, entry.nodeId)
|
||||
ReadOnlyHelper.putReadOnlyInIntent(intent, readOnly)
|
||||
if (historyPosition != null)
|
||||
intent.putExtra(KEY_ENTRY_HISTORY_POSITION, historyPosition)
|
||||
activity.startActivityForResult(intent, EntryEditActivity.ADD_OR_UPDATE_ENTRY_REQUEST_CODE)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open history Entry activity
|
||||
*/
|
||||
fun launch(activity: Activity, entryId: NodeId<UUID>, historyPosition: Int, readOnly: Boolean) {
|
||||
if (TimeoutHelper.checkTimeAndLockIfTimeout(activity)) {
|
||||
val intent = Intent(activity, EntryActivity::class.java)
|
||||
intent.putExtra(KEY_ENTRY, entryId)
|
||||
intent.putExtra(KEY_ENTRY_HISTORY_POSITION, historyPosition)
|
||||
ReadOnlyHelper.putReadOnlyInIntent(intent, readOnly)
|
||||
activity.startActivityForResult(intent, EntryEditActivity.ADD_OR_UPDATE_ENTRY_REQUEST_CODE)
|
||||
}
|
||||
}
|
||||
|
||||
+3
-5
@@ -10,7 +10,7 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.activities.stylish.StylishFragment
|
||||
import com.kunzisoft.keepass.adapters.EntryHistoryAdapter
|
||||
import com.kunzisoft.keepass.database.element.Entry
|
||||
import com.kunzisoft.keepass.model.EntryInfo
|
||||
import com.kunzisoft.keepass.viewmodels.EntryViewModel
|
||||
|
||||
class EntryHistoryFragment: StylishFragment() {
|
||||
@@ -55,11 +55,9 @@ class EntryHistoryFragment: StylishFragment() {
|
||||
* History
|
||||
* -------------
|
||||
*/
|
||||
private fun assignHistory(history: List<Entry>?) {
|
||||
private fun assignHistory(history: List<EntryInfo>) {
|
||||
historyAdapter?.clear()
|
||||
history?.let {
|
||||
historyAdapter?.entryHistoryList?.addAll(history)
|
||||
}
|
||||
historyAdapter?.entryHistoryList?.addAll(history)
|
||||
historyAdapter?.onItemClickListener = { item, position ->
|
||||
mEntryViewModel.onHistorySelected(item, position)
|
||||
}
|
||||
|
||||
@@ -26,13 +26,13 @@ import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.database.element.Entry
|
||||
import com.kunzisoft.keepass.model.EntryInfo
|
||||
|
||||
class EntryHistoryAdapter(val context: Context) : RecyclerView.Adapter<EntryHistoryAdapter.EntryHistoryViewHolder>() {
|
||||
|
||||
private val inflater: LayoutInflater = LayoutInflater.from(context)
|
||||
var entryHistoryList: MutableList<Entry> = ArrayList()
|
||||
var onItemClickListener: ((item: Entry, position: Int)->Unit)? = null
|
||||
var entryHistoryList: MutableList<EntryInfo> = ArrayList()
|
||||
var onItemClickListener: ((item: EntryInfo, position: Int)->Unit)? = null
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EntryHistoryViewHolder {
|
||||
return EntryHistoryViewHolder(inflater.inflate(R.layout.item_list_entry_history, parent, false))
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.kunzisoft.keepass.database.element.Attachment
|
||||
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.NodeIdUUID
|
||||
import com.kunzisoft.keepass.database.element.template.Template
|
||||
import com.kunzisoft.keepass.model.EntryAttachmentState
|
||||
import com.kunzisoft.keepass.model.EntryInfo
|
||||
@@ -33,8 +34,8 @@ class EntryViewModel: ViewModel() {
|
||||
val entryIsHistory : LiveData<Boolean> get() = _entryIsHistory
|
||||
private val _entryIsHistory = MutableLiveData<Boolean>()
|
||||
|
||||
val entryHistory : LiveData<List<Entry>> get() = _entryHistory
|
||||
private val _entryHistory = MutableLiveData<List<Entry>>()
|
||||
val entryHistory : LiveData<List<EntryInfo>> get() = _entryHistory
|
||||
private val _entryHistory = MutableLiveData<List<EntryInfo>>()
|
||||
|
||||
val onOtpElementUpdated : LiveData<OtpElement> get() = _onOtpElementUpdated
|
||||
private val _onOtpElementUpdated = SingleLiveEvent<OtpElement>()
|
||||
@@ -70,10 +71,16 @@ class EntryViewModel: ViewModel() {
|
||||
mDatabase?.decodeEntryWithTemplateConfiguration(entry)?.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),
|
||||
it.getHistory()
|
||||
entryInfoHistory
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -127,18 +134,17 @@ class EntryViewModel: ViewModel() {
|
||||
_onAttachmentAction.value = entryAttachmentState
|
||||
}
|
||||
|
||||
fun onHistorySelected(item: Entry, position: Int) {
|
||||
_historySelected.value = EntryHistory(item.nodeId, null, item, null, position)
|
||||
fun onHistorySelected(item: EntryInfo, position: Int) {
|
||||
_historySelected.value = EntryHistory(NodeIdUUID(item.id), null, item, position)
|
||||
}
|
||||
|
||||
data class EntryInfoHistory(val template: Template,
|
||||
val entryInfo: EntryInfo,
|
||||
val entryHistory: List<Entry>)
|
||||
val entryHistory: List<EntryInfo>)
|
||||
// Custom data class to manage entry to retrieve and define is it's an history item (!= -1)
|
||||
data class EntryHistory(var nodeIdUUID: NodeId<UUID>?,
|
||||
data class EntryHistory(var nodeId: NodeId<UUID>,
|
||||
var template: Template?,
|
||||
var entry: Entry?,
|
||||
var lastEntryVersion: Entry?,
|
||||
var entryInfo: EntryInfo,
|
||||
var historyPosition: Int = -1)
|
||||
|
||||
companion object {
|
||||
|
||||
Reference in new issue
Block a user