mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-05 00:02:27 -08:00
Perform binary preview animation
This commit is contained in:
1 parent
f135bdb905
commit
309380bdd5
5 files changed
+26
-33
No files matched your search
@@ -369,10 +369,8 @@ class EntryEditActivity : LockingActivity(),
|
||||
entryEditFragment?.putAttachment(entryAttachmentState)
|
||||
}
|
||||
AttachmentState.COMPLETE -> {
|
||||
entryEditFragment?.apply {
|
||||
putAttachment(entryAttachmentState)
|
||||
// Scroll to the attachment position
|
||||
getAttachmentViewPosition(entryAttachmentState) {
|
||||
entryEditFragment?.putAttachment(entryAttachmentState) {
|
||||
entryEditFragment?.getAttachmentViewPosition(entryAttachmentState) {
|
||||
scrollView?.smoothScrollTo(0, it.toInt())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -505,9 +505,13 @@ class EntryEditFragment: StylishFragment() {
|
||||
return attachmentsAdapter.contains(attachment)
|
||||
}
|
||||
|
||||
fun putAttachment(attachment: EntryAttachmentState) {
|
||||
fun putAttachment(attachment: EntryAttachmentState,
|
||||
onPreviewLoaded: (()-> Unit)? = null) {
|
||||
attachmentsContainerView.visibility = View.VISIBLE
|
||||
attachmentsAdapter.putItem(attachment)
|
||||
attachmentsAdapter.onBinaryPreviewLoaded = {
|
||||
onPreviewLoaded?.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
fun removeAttachment(attachment: EntryAttachmentState) {
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm
|
||||
import com.kunzisoft.keepass.model.AttachmentState
|
||||
import com.kunzisoft.keepass.model.EntryAttachmentState
|
||||
import com.kunzisoft.keepass.model.StreamDirection
|
||||
import com.kunzisoft.keepass.view.expand
|
||||
|
||||
|
||||
class EntryAttachmentsItemsAdapter(context: Context)
|
||||
@@ -45,6 +46,7 @@ class EntryAttachmentsItemsAdapter(context: Context)
|
||||
|
||||
var binaryCipherKey: Database.LoadedKey? = null
|
||||
var onItemClickListener: ((item: EntryAttachmentState)->Unit)? = null
|
||||
var onBinaryPreviewLoaded: ((item: EntryAttachmentState) -> Unit)? = null
|
||||
|
||||
private var mTitleColor: Int
|
||||
|
||||
@@ -67,35 +69,27 @@ class EntryAttachmentsItemsAdapter(context: Context)
|
||||
|
||||
holder.itemView.visibility = View.VISIBLE
|
||||
holder.binaryFileThumbnail.apply {
|
||||
// Show the bitmap image if loaded
|
||||
when (entryAttachmentState.previewItemState) {
|
||||
AttachmentState.NULL -> {
|
||||
visibility = View.GONE
|
||||
entryAttachmentState.previewItemState = AttachmentState.IN_PROGRESS
|
||||
// Perform image loading only if upload is finished
|
||||
if (entryAttachmentState.downloadState != AttachmentState.START
|
||||
&& entryAttachmentState.downloadState != AttachmentState.IN_PROGRESS) {
|
||||
// Show the bitmap image if loaded
|
||||
if (entryAttachmentState.previewState == AttachmentState.NULL) {
|
||||
entryAttachmentState.previewState = AttachmentState.IN_PROGRESS
|
||||
// Load the bitmap image
|
||||
Attachment.loadBitmap(entryAttachmentState.attachment, binaryCipherKey) { imageLoaded ->
|
||||
entryAttachmentState.previewItem = imageLoaded
|
||||
if (imageLoaded == null) {
|
||||
entryAttachmentState.previewItemState = AttachmentState.ERROR
|
||||
entryAttachmentState.previewState = AttachmentState.ERROR
|
||||
visibility = View.GONE
|
||||
onBinaryPreviewLoaded?.invoke(entryAttachmentState)
|
||||
} else {
|
||||
entryAttachmentState.previewItemState = AttachmentState.COMPLETE
|
||||
entryAttachmentState.previewState = AttachmentState.COMPLETE
|
||||
setImageBitmap(imageLoaded)
|
||||
expand(true, resources.getDimensionPixelSize(R.dimen.item_file_info_height)) {
|
||||
onBinaryPreviewLoaded?.invoke(entryAttachmentState)
|
||||
}
|
||||
}
|
||||
notifyItemChanged(position)
|
||||
}
|
||||
}
|
||||
AttachmentState.IN_PROGRESS,
|
||||
AttachmentState.START -> {
|
||||
// Do nothing if in progress
|
||||
}
|
||||
AttachmentState.COMPLETE -> {
|
||||
setImageBitmap(entryAttachmentState.previewItem)
|
||||
visibility = View.VISIBLE
|
||||
entryAttachmentState.previewItemState = AttachmentState.NULL
|
||||
}
|
||||
AttachmentState.ERROR -> {
|
||||
visibility = View.GONE
|
||||
entryAttachmentState.previewItemState = AttachmentState.NULL
|
||||
}
|
||||
}
|
||||
this.setOnClickListener {
|
||||
ImageViewerActivity.getInstance(context, entryAttachmentState.attachment)
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.model
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.element.Attachment
|
||||
@@ -31,15 +30,13 @@ data class EntryAttachmentState(var attachment: Attachment,
|
||||
var streamDirection: StreamDirection,
|
||||
var downloadState: AttachmentState = AttachmentState.NULL,
|
||||
var downloadProgression: Int = 0,
|
||||
var previewItem: Bitmap? = null,
|
||||
var previewItemState: AttachmentState = AttachmentState.NULL) : Parcelable {
|
||||
var previewState: AttachmentState = AttachmentState.NULL) : Parcelable {
|
||||
|
||||
constructor(parcel: Parcel) : this(
|
||||
parcel.readParcelable(Attachment::class.java.classLoader) ?: Attachment("", BinaryAttachment()),
|
||||
parcel.readEnum<StreamDirection>() ?: StreamDirection.DOWNLOAD,
|
||||
parcel.readEnum<AttachmentState>() ?: AttachmentState.NULL,
|
||||
parcel.readInt(),
|
||||
parcel.readParcelable(Bitmap::class.java.classLoader),
|
||||
parcel.readEnum<AttachmentState>() ?: AttachmentState.NULL)
|
||||
|
||||
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
||||
@@ -47,8 +44,7 @@ data class EntryAttachmentState(var attachment: Attachment,
|
||||
parcel.writeEnum(streamDirection)
|
||||
parcel.writeEnum(downloadState)
|
||||
parcel.writeInt(downloadProgression)
|
||||
parcel.writeParcelable(previewItem, flags)
|
||||
parcel.writeEnum(previewItemState)
|
||||
parcel.writeEnum(previewState)
|
||||
}
|
||||
|
||||
override fun describeContents(): Int {
|
||||
|
||||
Reference in new issue
Block a user