mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-02 14:52:51 -08:00
Entry history first code
This commit is contained in:
1 parent
66051382f1
commit
a8ccb67a87
8 files changed
+174
-4
No files matched your search
@@ -257,6 +257,8 @@ class EntryActivity : LockingHideActivity() {
|
||||
// Assign special data
|
||||
entryContentsView?.assignUUID(entry.nodeId.id)
|
||||
|
||||
entryContentsView?.assignHistory(entry.getHistory())
|
||||
|
||||
database.stopManageEntry(entry)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.kunzisoft.keepass.adapters
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.database.element.EntryVersioned
|
||||
|
||||
class EntryHistoryAdapter(context: Context) : RecyclerView.Adapter<EntryHistoryAdapter.EntryHistoryViewHolder>() {
|
||||
|
||||
private val inflater: LayoutInflater = LayoutInflater.from(context)
|
||||
var entryHistoryList: MutableList<EntryVersioned> = ArrayList()
|
||||
var onItemClickListener: OnItemClickListener? = null
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EntryHistoryViewHolder {
|
||||
return EntryHistoryViewHolder(inflater.inflate(R.layout.item_list_entry_history, parent, false))
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: EntryHistoryViewHolder, position: Int) {
|
||||
val entryHistory = entryHistoryList[position]
|
||||
|
||||
holder.lastModifiedView.text = entryHistory.lastModificationTime.date.toString()
|
||||
holder.titleView.text = entryHistory.title
|
||||
holder.usernameView.text = entryHistory.username
|
||||
holder.urlView.text = entryHistory.url
|
||||
|
||||
holder.bind(entryHistory, onItemClickListener)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return entryHistoryList.size
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
entryHistoryList.clear()
|
||||
}
|
||||
|
||||
interface OnItemClickListener {
|
||||
fun onItemClick(item: EntryVersioned)
|
||||
}
|
||||
|
||||
inner class EntryHistoryViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
|
||||
var lastModifiedView: TextView = itemView.findViewById(R.id.entry_history_last_modified)
|
||||
var titleView: TextView = itemView.findViewById(R.id.entry_history_title)
|
||||
var usernameView: TextView = itemView.findViewById(R.id.entry_history_username)
|
||||
var urlView: TextView = itemView.findViewById(R.id.entry_history_url)
|
||||
|
||||
fun bind(item: EntryVersioned, listener: OnItemClickListener?) {
|
||||
itemView.setOnClickListener { listener?.onItemClick(item) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -723,7 +723,7 @@ class Database {
|
||||
while (true) {
|
||||
var histSize: Long = 0
|
||||
for (backup in history) {
|
||||
histSize += backup.size
|
||||
histSize += backup.getSize()
|
||||
}
|
||||
|
||||
if (histSize > maxSize) {
|
||||
|
||||
@@ -270,8 +270,17 @@ class EntryVersioned : NodeVersioned, PwEntryInterface<GroupVersioned> {
|
||||
pwEntryV4?.removeOldestEntryFromHistory()
|
||||
}
|
||||
|
||||
fun getHistory(): ArrayList<PwEntryV4> {
|
||||
return pwEntryV4?.history ?: ArrayList()
|
||||
fun getHistory(): ArrayList<EntryVersioned> {
|
||||
val history = ArrayList<EntryVersioned>()
|
||||
val entryV4History = pwEntryV4?.history ?: ArrayList()
|
||||
for (entryHistory in entryV4History) {
|
||||
history.add(EntryVersioned(entryHistory))
|
||||
}
|
||||
return history
|
||||
}
|
||||
|
||||
fun getSize(): Long {
|
||||
return pwEntryV4?.size ?: 0L
|
||||
}
|
||||
|
||||
fun containsCustomData(): Boolean {
|
||||
|
||||
@@ -29,7 +29,11 @@ import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.adapters.EntryHistoryAdapter
|
||||
import com.kunzisoft.keepass.database.element.EntryVersioned
|
||||
import com.kunzisoft.keepass.database.element.security.ProtectedString
|
||||
import java.text.DateFormat
|
||||
import java.util.*
|
||||
@@ -69,6 +73,9 @@ class EntryContentsView @JvmOverloads constructor(context: Context,
|
||||
|
||||
private val uuidView: TextView
|
||||
|
||||
private val historyView: RecyclerView
|
||||
private val historyAdapter = EntryHistoryAdapter(context)
|
||||
|
||||
val isUserNamePresent: Boolean
|
||||
get() = userNameContainerView.visibility == View.VISIBLE
|
||||
|
||||
@@ -103,6 +110,12 @@ class EntryContentsView @JvmOverloads constructor(context: Context,
|
||||
|
||||
uuidView = findViewById(R.id.entry_UUID)
|
||||
|
||||
historyView = findViewById(R.id.entry_history_list)
|
||||
historyView?.apply {
|
||||
layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, true)
|
||||
adapter = historyAdapter
|
||||
}
|
||||
|
||||
val attrColorAccent = intArrayOf(R.attr.colorAccent)
|
||||
val taColorAccent = context.theme.obtainStyledAttributes(attrColorAccent)
|
||||
colorAccent = taColorAccent.getColor(0, Color.BLACK)
|
||||
@@ -258,6 +271,11 @@ class EntryContentsView @JvmOverloads constructor(context: Context,
|
||||
uuidView.text = uuid.toString()
|
||||
}
|
||||
|
||||
fun assignHistory(history: ArrayList<EntryVersioned>) {
|
||||
historyAdapter.clear()
|
||||
historyAdapter.entryHistoryList.addAll(history)
|
||||
}
|
||||
|
||||
override fun generateDefaultLayoutParams(): LayoutParams {
|
||||
return LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user