diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.kt b/app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.kt index 835c7c1b3..5f8c17014 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.kt @@ -117,8 +117,8 @@ class EntryActivity : LockingActivity() { // Get Entry from UUID try { intent.getParcelableExtra?>(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, 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) } } diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/fragments/EntryHistoryFragment.kt b/app/src/main/java/com/kunzisoft/keepass/activities/fragments/EntryHistoryFragment.kt index 5213b85ab..6c90c26af 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/fragments/EntryHistoryFragment.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/fragments/EntryHistoryFragment.kt @@ -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?) { + private fun assignHistory(history: List) { historyAdapter?.clear() - history?.let { - historyAdapter?.entryHistoryList?.addAll(history) - } + historyAdapter?.entryHistoryList?.addAll(history) historyAdapter?.onItemClickListener = { item, position -> mEntryViewModel.onHistorySelected(item, position) } diff --git a/app/src/main/java/com/kunzisoft/keepass/adapters/EntryHistoryAdapter.kt b/app/src/main/java/com/kunzisoft/keepass/adapters/EntryHistoryAdapter.kt index 42e216fc8..2075eae9b 100644 --- a/app/src/main/java/com/kunzisoft/keepass/adapters/EntryHistoryAdapter.kt +++ b/app/src/main/java/com/kunzisoft/keepass/adapters/EntryHistoryAdapter.kt @@ -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() { private val inflater: LayoutInflater = LayoutInflater.from(context) - var entryHistoryList: MutableList = ArrayList() - var onItemClickListener: ((item: Entry, position: Int)->Unit)? = null + var entryHistoryList: MutableList = 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)) diff --git a/app/src/main/java/com/kunzisoft/keepass/viewmodels/EntryViewModel.kt b/app/src/main/java/com/kunzisoft/keepass/viewmodels/EntryViewModel.kt index d250f0ecf..3bde71fd6 100644 --- a/app/src/main/java/com/kunzisoft/keepass/viewmodels/EntryViewModel.kt +++ b/app/src/main/java/com/kunzisoft/keepass/viewmodels/EntryViewModel.kt @@ -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 get() = _entryIsHistory private val _entryIsHistory = MutableLiveData() - val entryHistory : LiveData> get() = _entryHistory - private val _entryHistory = MutableLiveData>() + val entryHistory : LiveData> get() = _entryHistory + private val _entryHistory = MutableLiveData>() val onOtpElementUpdated : LiveData get() = _onOtpElementUpdated private val _onOtpElementUpdated = SingleLiveEvent() @@ -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) + val entryHistory: List) // Custom data class to manage entry to retrieve and define is it's an history item (!= -1) - data class EntryHistory(var nodeIdUUID: NodeId?, + data class EntryHistory(var nodeId: NodeId, var template: Template?, - var entry: Entry?, - var lastEntryVersion: Entry?, + var entryInfo: EntryInfo, var historyPosition: Int = -1) companion object {