Show history by click

This commit is contained in:
J-Jamet committed 2019-09-18 22:14:50 +02:00
1 parent f5dc94bfec
commit 6d46fccdcd
7 files changed
+74 -21

No files matched your search

@@ -21,6 +21,7 @@ package com.kunzisoft.keepass.activities
import android.app.Activity
import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.os.Handler
import com.google.android.material.appbar.CollapsingToolbarLayout
@@ -54,10 +55,13 @@ class EntryActivity : LockingHideActivity() {
private var collapsingToolbarLayout: CollapsingToolbarLayout? = null
private var titleIconView: ImageView? = null
private var historyView: View? = null
private var entryContentsView: EntryContentsView? = null
private var toolbar: Toolbar? = null
private var mEntry: EntryVersioned? = null
private var mIsHistory: Boolean = false
private var mShowPassword: Boolean = false
private var clipboardHelper: ClipboardHelper? = null
@@ -88,6 +92,12 @@ class EntryActivity : LockingHideActivity() {
Log.e(TAG, "Unable to retrieve the entry key")
}
val historyPosition = intent.getIntExtra(KEY_ENTRY_HISTORY_POSITION, -1)
if (historyPosition >= 0) {
mIsHistory = true
mEntry = mEntry?.getHistory()?.get(historyPosition)
}
if (mEntry == null) {
Toast.makeText(this, R.string.entry_not_found, Toast.LENGTH_LONG).show()
finish()
@@ -108,6 +118,7 @@ class EntryActivity : LockingHideActivity() {
// Get views
collapsingToolbarLayout = findViewById(R.id.toolbar_layout)
titleIconView = findViewById(R.id.entry_icon)
historyView = findViewById(R.id.history_container)
entryContentsView = findViewById(R.id.entry_contents)
entryContentsView?.applyFontVisibilityToFields(PreferencesUtil.fieldFontIsInVisibility(this))
@@ -250,7 +261,23 @@ class EntryActivity : LockingHideActivity() {
// Assign special data
entryContentsView?.assignUUID(entry.nodeId.id)
entryContentsView?.assignHistory(entry.getHistory())
// Manage history
historyView?.visibility = if (mIsHistory) View.VISIBLE else View.GONE
if (mIsHistory) {
val taColorAccent = theme.obtainStyledAttributes(intArrayOf(R.attr.colorAccent))
collapsingToolbarLayout?.contentScrim = ColorDrawable(taColorAccent.getColor(0, Color.BLACK))
taColorAccent.recycle()
}
val entryHistory = entry.getHistory()
// isMainEntry = not an history
val isMainEntryAndContainsEntry = !mIsHistory && entryHistory.isNotEmpty()
entryContentsView?.showHistory(isMainEntryAndContainsEntry)
if (isMainEntryAndContainsEntry) {
entryContentsView?.assignHistory(entryHistory)
entryContentsView?.onHistoryClick { historyItem, position ->
launch(this, historyItem, true, position)
}
}
database.stopManageEntry(entry)
}
@@ -407,13 +434,16 @@ class EntryActivity : LockingHideActivity() {
companion object {
private val TAG = EntryActivity::class.java.name
const val KEY_ENTRY = "entry"
const val KEY_ENTRY = "KEY_ENTRY"
const val KEY_ENTRY_HISTORY_POSITION = "KEY_ENTRY_HISTORY_POSITION"
fun launch(activity: Activity, pw: EntryVersioned, readOnly: Boolean) {
fun launch(activity: Activity, entry: EntryVersioned, readOnly: Boolean, historyPosition: Int? = null) {
if (TimeoutHelper.checkTimeAndLockIfTimeout(activity)) {
val intent = Intent(activity, EntryActivity::class.java)
intent.putExtra(KEY_ENTRY, pw.nodeId)
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)
}
}
@@ -13,7 +13,7 @@ class EntryHistoryAdapter(val context: Context) : RecyclerView.Adapter<EntryHist
private val inflater: LayoutInflater = LayoutInflater.from(context)
var entryHistoryList: MutableList<EntryVersioned> = ArrayList()
var onItemClickListener: OnItemClickListener? = null
var onItemClickListener: ((item: EntryVersioned, position: Int)->Unit)? = null
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EntryHistoryViewHolder {
return EntryHistoryViewHolder(inflater.inflate(R.layout.item_list_entry_history, parent, false))
@@ -27,7 +27,9 @@ class EntryHistoryAdapter(val context: Context) : RecyclerView.Adapter<EntryHist
holder.usernameView.text = entryHistory.username
holder.urlView.text = entryHistory.url
holder.bind(entryHistory, onItemClickListener)
holder.itemView.setOnClickListener {
onItemClickListener?.invoke(entryHistory, position)
}
}
override fun getItemCount(): Int {
@@ -38,19 +40,11 @@ class EntryHistoryAdapter(val context: Context) : RecyclerView.Adapter<EntryHist
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) }
}
}
}
@@ -70,7 +70,8 @@ class EntryContentsView @JvmOverloads constructor(context: Context,
private val uuidView: TextView
private val historyView: RecyclerView
private val historyContainerView: View
private val historyListView: RecyclerView
private val historyAdapter = EntryHistoryAdapter(context)
val isUserNamePresent: Boolean
@@ -107,8 +108,9 @@ class EntryContentsView @JvmOverloads constructor(context: Context,
uuidView = findViewById(R.id.entry_UUID)
historyView = findViewById(R.id.entry_history_list)
historyView?.apply {
historyContainerView = findViewById(R.id.entry_history_container)
historyListView = findViewById(R.id.entry_history_list)
historyListView?.apply {
layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, true)
adapter = historyAdapter
}
@@ -264,11 +266,21 @@ class EntryContentsView @JvmOverloads constructor(context: Context,
uuidView.text = uuid.toString()
}
fun showHistory(show: Boolean) {
historyContainerView.visibility = if (show) View.VISIBLE else View.GONE
}
fun assignHistory(history: ArrayList<EntryVersioned>) {
historyAdapter.clear()
historyAdapter.entryHistoryList.addAll(history)
}
fun onHistoryClick(action: (historyItem: EntryVersioned, position: Int)->Unit) {
historyAdapter.onItemClickListener = { item, position ->
action.invoke(item, position)
}
}
override fun generateDefaultLayoutParams(): LayoutParams {
return LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
}
+19 -2
View File
@@ -75,7 +75,6 @@
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/entry_scroll"
android:layout_width="match_parent"
@@ -86,12 +85,30 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/history_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:background="?attr/colorAccent"
android:padding="12dp"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:textColor="?attr/textColorInverse"
android:text="@string/history"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.kunzisoft.keepass.view.EntryContentsView
android:id="@+id/entry_contents"
android:layout_height="match_parent"
android:layout_width="0dp"
app:layout_constraintWidth_percent="@dimen/content_percent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toBottomOf="@+id/history_container"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
@@ -6,6 +6,7 @@
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp">
@@ -295,7 +295,7 @@
android:id="@+id/entry_history_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/entry_history"
android:text="@string/history"
style="@style/KeepassDXStyle.TextAppearance.LabelTextStyle" />
<androidx.constraintlayout.widget.ConstraintLayout
-1
View File
@@ -81,7 +81,6 @@
<string name="entry_created">Created</string>
<string name="entry_expires">Expires</string>
<string name="entry_UUID">UUID</string>
<string name="entry_history">History</string>
<string name="entry_keyfile">Keyfile</string>
<string name="entry_modified">Modified</string>
<string name="entry_not_found">Could not find entry data.</string>