mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Show counter and fix HOTP
This commit is contained in:
@@ -41,6 +41,8 @@ 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.NodeVersionedInterface
|
import com.kunzisoft.keepass.database.element.node.NodeVersionedInterface
|
||||||
import com.kunzisoft.keepass.database.element.node.Type
|
import com.kunzisoft.keepass.database.element.node.Type
|
||||||
|
import com.kunzisoft.keepass.otp.OtpElement
|
||||||
|
import com.kunzisoft.keepass.otp.OtpType
|
||||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||||
import com.kunzisoft.keepass.view.setTextSize
|
import com.kunzisoft.keepass.view.setTextSize
|
||||||
import com.kunzisoft.keepass.view.strikeOut
|
import com.kunzisoft.keepass.view.strikeOut
|
||||||
@@ -363,21 +365,19 @@ class NodeAdapter (private val context: Context,
|
|||||||
|
|
||||||
val otpElement = entry.getOtpElement()
|
val otpElement = entry.getOtpElement()
|
||||||
holder.otpContainer?.removeCallbacks(holder.otpRunnable)
|
holder.otpContainer?.removeCallbacks(holder.otpRunnable)
|
||||||
holder.otpRunnable = null
|
|
||||||
if (otpElement != null
|
if (otpElement != null
|
||||||
&& mShowOTP
|
&& mShowOTP
|
||||||
&& otpElement.token.isNotEmpty()) {
|
&& otpElement.token.isNotEmpty()) {
|
||||||
holder.otpProgress?.apply {
|
|
||||||
max = otpElement.period
|
// Execute runnable to show progress
|
||||||
progress = otpElement.secondsRemaining
|
holder.otpRunnable.action = {
|
||||||
|
populateOtpView(holder, otpElement)
|
||||||
}
|
}
|
||||||
holder.otpToken?.text = otpElement.token
|
if (otpElement.type == OtpType.TOTP) {
|
||||||
holder.otpRunnable = Runnable {
|
holder.otpRunnable.postDelayed()
|
||||||
holder.otpProgress?.progress = otpElement.secondsRemaining
|
|
||||||
holder.otpToken?.text = otpElement.token
|
|
||||||
holder.otpContainer?.postDelayed(holder.otpRunnable, 200)
|
|
||||||
}
|
}
|
||||||
holder.otpContainer?.postDelayed(holder.otpRunnable, 500)
|
populateOtpView(holder, otpElement)
|
||||||
|
|
||||||
holder.otpContainer?.visibility = View.VISIBLE
|
holder.otpContainer?.visibility = View.VISIBLE
|
||||||
} else {
|
} else {
|
||||||
holder.otpContainer?.visibility = View.GONE
|
holder.otpContainer?.visibility = View.GONE
|
||||||
@@ -411,7 +411,41 @@ class NodeAdapter (private val context: Context,
|
|||||||
mNodeClickCallback?.onNodeLongClick(database, subNode) ?: false
|
mNodeClickCallback?.onNodeLongClick(database, subNode) ?: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun populateOtpView(holder: NodeViewHolder?, otpElement: OtpElement?) {
|
||||||
|
when (otpElement?.type) {
|
||||||
|
OtpType.HOTP -> {
|
||||||
|
holder?.otpCounter?.text = otpElement.counter.toString()
|
||||||
|
holder?.otpProgress?.apply {
|
||||||
|
max = 100
|
||||||
|
progress = 100
|
||||||
|
}
|
||||||
|
}
|
||||||
|
OtpType.TOTP -> {
|
||||||
|
holder?.otpCounter?.text = otpElement.secondsRemaining.toString()
|
||||||
|
holder?.otpProgress?.apply {
|
||||||
|
max = otpElement.period
|
||||||
|
progress = otpElement.secondsRemaining
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
holder?.otpToken?.text = otpElement?.token
|
||||||
|
}
|
||||||
|
|
||||||
|
class OtpRunnable(val view: View?): Runnable {
|
||||||
|
|
||||||
|
var action: (() -> Unit)? = null
|
||||||
|
|
||||||
|
override fun run() {
|
||||||
|
action?.invoke()
|
||||||
|
postDelayed()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun postDelayed() {
|
||||||
|
view?.postDelayed(this, 500)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun getItemCount(): Int {
|
override fun getItemCount(): Int {
|
||||||
return mNodeSortedList.size()
|
return mNodeSortedList.size()
|
||||||
}
|
}
|
||||||
@@ -440,8 +474,9 @@ class NodeAdapter (private val context: Context,
|
|||||||
var meta: TextView = itemView.findViewById(R.id.node_meta)
|
var meta: TextView = itemView.findViewById(R.id.node_meta)
|
||||||
var otpContainer: ViewGroup? = itemView.findViewById(R.id.node_otp_container)
|
var otpContainer: ViewGroup? = itemView.findViewById(R.id.node_otp_container)
|
||||||
var otpProgress: ProgressBar? = itemView.findViewById(R.id.node_otp_progress)
|
var otpProgress: ProgressBar? = itemView.findViewById(R.id.node_otp_progress)
|
||||||
|
var otpCounter: TextView? = itemView.findViewById(R.id.node_otp_counter)
|
||||||
var otpToken: TextView? = itemView.findViewById(R.id.node_otp_token)
|
var otpToken: TextView? = itemView.findViewById(R.id.node_otp_token)
|
||||||
var otpRunnable: Runnable? = null
|
var otpRunnable: OtpRunnable = OtpRunnable(otpContainer)
|
||||||
var numberChildren: TextView? = itemView.findViewById(R.id.node_child_numbers)
|
var numberChildren: TextView? = itemView.findViewById(R.id.node_child_numbers)
|
||||||
var attachmentIcon: ImageView? = itemView.findViewById(R.id.node_attachment_icon)
|
var attachmentIcon: ImageView? = itemView.findViewById(R.id.node_attachment_icon)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,17 +132,30 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
tools:text="5136" />
|
tools:text="5136" />
|
||||||
|
<FrameLayout
|
||||||
<ProgressBar
|
android:layout_width="wrap_content"
|
||||||
android:id="@+id/node_otp_progress"
|
android:layout_height="wrap_content"
|
||||||
style="@style/KeepassDXStyle.ProgressBar.Circle.Secondary"
|
|
||||||
android:layout_width="18dp"
|
|
||||||
android:layout_height="18dp"
|
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:layout_marginStart="4dp"
|
android:layout_marginStart="4dp"
|
||||||
android:layout_marginLeft="4dp"
|
android:layout_marginLeft="4dp">
|
||||||
android:max="100"
|
<ProgressBar
|
||||||
android:progress="60" />
|
android:id="@+id/node_otp_progress"
|
||||||
|
style="@style/KeepassDXStyle.ProgressBar.Circle.Secondary"
|
||||||
|
android:layout_width="18dp"
|
||||||
|
android:layout_height="18dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:max="100"
|
||||||
|
android:progress="60" />
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/node_otp_counter"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
style="@style/KeepassDXStyle.TextAppearance.Entry.Info"
|
||||||
|
android:textSize="11sp"
|
||||||
|
tools:text="70" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatImageView
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
|
|||||||
Reference in New Issue
Block a user