mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Attachment viewer
This commit is contained in:
@@ -19,11 +19,16 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.activities
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.BitmapFactory
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.widget.ImageView
|
||||
import com.igreenwood.loupe.Loupe
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.activities.lock.LockingActivity
|
||||
import com.kunzisoft.keepass.database.element.Attachment
|
||||
import kotlinx.android.synthetic.main.activity_image_viewer.*
|
||||
|
||||
class ImageViewerActivity : LockingActivity() {
|
||||
@@ -32,8 +37,20 @@ class ImageViewerActivity : LockingActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
setContentView(R.layout.activity_image_viewer)
|
||||
val imageView: ImageView = findViewById(R.id.image_viewer_image)
|
||||
|
||||
Loupe.create(image_viewer_image, image_viewer_container) {
|
||||
try {
|
||||
intent.getParcelableExtra<Attachment>(IMAGE_ATTACHMENT_TAG)?.let { attachment ->
|
||||
BitmapFactory.decodeStream(attachment.binaryAttachment.getUnGzipInputDataStream())?.let { imageBitmap ->
|
||||
imageView.setImageBitmap(imageBitmap)
|
||||
} ?: finish()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Unable to view the binary", e)
|
||||
finish()
|
||||
}
|
||||
|
||||
Loupe.create(imageView, image_viewer_container) {
|
||||
onViewTranslateListener = object : Loupe.OnViewTranslateListener {
|
||||
|
||||
override fun onStart(view: ImageView) {
|
||||
@@ -55,4 +72,17 @@ class ImageViewerActivity : LockingActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private val TAG = ImageViewerActivity::class.simpleName
|
||||
|
||||
private const val IMAGE_ATTACHMENT_TAG = "IMAGE_ATTACHMENT_TAG"
|
||||
|
||||
fun getInstance(context: Context, imageAttachment: Attachment) {
|
||||
context.startActivity(Intent(context, ImageViewerActivity::class.java).apply {
|
||||
putExtra(IMAGE_ATTACHMENT_TAG, imageAttachment)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,8 @@
|
||||
package com.kunzisoft.keepass.adapters
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.res.TypedArray
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Color
|
||||
import android.text.format.Formatter
|
||||
import android.util.TypedValue
|
||||
@@ -65,10 +65,14 @@ class EntryAttachmentsItemsAdapter(context: Context)
|
||||
|
||||
holder.itemView.visibility = View.VISIBLE
|
||||
holder.binaryFileThumbnail.apply {
|
||||
setOnClickListener {
|
||||
context.startActivity(Intent(context, ImageViewerActivity::class.java).apply {
|
||||
|
||||
})
|
||||
BitmapFactory.decodeStream(entryAttachmentState.attachment.binaryAttachment.getUnGzipInputDataStream())?.let { imageBitmap ->
|
||||
setImageBitmap(imageBitmap)
|
||||
setOnClickListener {
|
||||
ImageViewerActivity.getInstance(context, entryAttachmentState.attachment)
|
||||
}
|
||||
visibility = View.VISIBLE
|
||||
} ?: run {
|
||||
visibility = View.GONE
|
||||
}
|
||||
}
|
||||
holder.binaryFileBroken.apply {
|
||||
|
||||
@@ -10,7 +10,5 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:contentDescription="@string/entry_attachments"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/keepassdx_logo"/>
|
||||
android:contentDescription="@string/entry_attachments" />
|
||||
</FrameLayout>
|
||||
@@ -34,8 +34,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_above="@+id/constraintLayout"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@drawable/keepassdx_logo" />
|
||||
android:scaleType="centerCrop" />
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/constraintLayout"
|
||||
|
||||
Reference in New Issue
Block a user