diff --git a/app/build.gradle b/app/build.gradle index 2b1b457..4b4163b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -93,4 +93,7 @@ dependencies { // LiveData implementation "androidx.lifecycle:lifecycle-livedata-ktx:$rootProject.liveDataVersion" implementation 'androidx.legacy:legacy-support-v4:1.0.0' + + // Image viewer + implementation 'com.github.stfalcon-studio:StfalconImageViewer:v1.0.1' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f869faa..6dd5ca7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,7 +13,8 @@ - + + Unit, private val onLongClick: (Notification) -> Unit) : @@ -131,21 +132,13 @@ class DetailAdapter(private val onClick: (Notification) -> Unit, private val onL } val attachment = notification.attachment val exists = if (attachment.contentUri != null) fileExists(context, attachment.contentUri) else false - maybeRenderAttachmentImage(context, attachment, exists) - renderAttachmentBox(context, notification, attachment, exists) + val image = attachment.contentUri != null && exists && supportedImage(attachment.type) + maybeRenderMenu(context, notification, attachment, exists) + maybeRenderAttachmentImage(context, attachment, image) + maybeRenderAttachmentBox(context, notification, attachment, exists, image) } - private fun renderAttachmentBox(context: Context, notification: Notification, attachment: Attachment, exists: Boolean) { - attachmentInfoView.text = formatAttachmentDetails(context, attachment, exists) - attachmentIconView.setImageResource(if (attachment.type?.startsWith("image/") == true) { - R.drawable.ic_file_image_gray_24dp - } else if (attachment.type?.startsWith("video/") == true) { - R.drawable.ic_file_video_gray_24dp - } else if (attachment.type?.startsWith("audio/") == true) { - R.drawable.ic_file_audio_gray_24dp - } else { - R.drawable.ic_file_document_gray_24dp - }) + private fun maybeRenderMenu(context: Context, notification: Notification, attachment: Attachment, exists: Boolean) { val menuButtonPopupMenu = createAttachmentPopup(context, menuButton, notification, attachment, exists) // Heavy lifting not during on-click if (menuButtonPopupMenu != null) { menuButton.setOnClickListener { menuButtonPopupMenu.show() } @@ -153,6 +146,25 @@ class DetailAdapter(private val onClick: (Notification) -> Unit, private val onL } else { menuButton.visibility = View.GONE } + } + + private fun maybeRenderAttachmentBox(context: Context, notification: Notification, attachment: Attachment, exists: Boolean, image: Boolean) { + if (image) { + attachmentBoxView.visibility = View.GONE + return + } + attachmentInfoView.text = formatAttachmentDetails(context, attachment, exists) + attachmentIconView.setImageResource(if (attachment.type?.startsWith("image/") == true) { + R.drawable.ic_file_image_red_24dp + } else if (attachment.type?.startsWith("video/") == true) { + R.drawable.ic_file_video_orange_24dp + } else if (attachment.type?.startsWith("audio/") == true) { + R.drawable.ic_file_audio_purple_24dp + } else if ("application/vnd.android.package-archive" == attachment.type) { + R.drawable.ic_file_app_gray_24dp + } else { + R.drawable.ic_file_document_blue_24dp + }) val attachmentBoxPopupMenu = createAttachmentPopup(context, attachmentBoxView, notification, attachment, exists) // Heavy lifting not during on-click if (attachmentBoxPopupMenu != null) { attachmentBoxView.setOnClickListener { attachmentBoxPopupMenu.show() } @@ -231,7 +243,7 @@ class DetailAdapter(private val onClick: (Notification) -> Unit, private val onL if (expired) { infos.add("not downloaded, link expired") } else if (expires) { - infos.add("not downloaded, link expires ${formatDateShort(attachment.expires!!)}") + infos.add("not downloaded, expires ${formatDateShort(attachment.expires!!)}") } else { infos.add("not downloaded") } @@ -270,17 +282,24 @@ class DetailAdapter(private val onClick: (Notification) -> Unit, private val onL } } - private fun maybeRenderAttachmentImage(context: Context, att: Attachment, exists: Boolean) { - val fileIsImage = att.contentUri != null && exists && supportedImage(att.type) - if (!fileIsImage) { + private fun maybeRenderAttachmentImage(context: Context, attachment: Attachment, image: Boolean) { + if (!image) { attachmentImageView.visibility = View.GONE return } try { val resolver = context.applicationContext.contentResolver - val bitmapStream = resolver.openInputStream(Uri.parse(att.contentUri)) + val bitmapStream = resolver.openInputStream(Uri.parse(attachment.contentUri)) val bitmap = BitmapFactory.decodeStream(bitmapStream) attachmentImageView.setImageBitmap(bitmap) + attachmentImageView.setOnClickListener { + val loadImage = { view: ImageView, image: Bitmap -> view.setImageBitmap(image) } + StfalconImageViewer.Builder(context, listOf(bitmap), loadImage) + .allowZooming(true) + .withTransitionFrom(attachmentImageView) + .withHiddenStatusBar(false) + .show() + } attachmentImageView.visibility = View.VISIBLE } catch (_: Exception) { attachmentImageView.visibility = View.GONE diff --git a/app/src/main/res/drawable/ic_file_app_gray_24dp.xml b/app/src/main/res/drawable/ic_file_app_gray_24dp.xml new file mode 100644 index 0000000..9bdfa1a --- /dev/null +++ b/app/src/main/res/drawable/ic_file_app_gray_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_file_audio_gray_24dp.xml b/app/src/main/res/drawable/ic_file_audio_gray_24dp.xml deleted file mode 100644 index 7d36262..0000000 --- a/app/src/main/res/drawable/ic_file_audio_gray_24dp.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/ic_file_audio_purple_24dp.xml b/app/src/main/res/drawable/ic_file_audio_purple_24dp.xml new file mode 100644 index 0000000..a748d7c --- /dev/null +++ b/app/src/main/res/drawable/ic_file_audio_purple_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_file_document_gray_24dp.xml b/app/src/main/res/drawable/ic_file_document_blue_24dp.xml similarity index 91% rename from app/src/main/res/drawable/ic_file_document_gray_24dp.xml rename to app/src/main/res/drawable/ic_file_document_blue_24dp.xml index 92fe4e3..b3ed80e 100644 --- a/app/src/main/res/drawable/ic_file_document_gray_24dp.xml +++ b/app/src/main/res/drawable/ic_file_document_blue_24dp.xml @@ -5,5 +5,5 @@ android:viewportHeight="24"> + android:fillColor="#00ADFF"/> diff --git a/app/src/main/res/drawable/ic_file_image_gray_24dp.xml b/app/src/main/res/drawable/ic_file_image_red_24dp.xml similarity index 91% rename from app/src/main/res/drawable/ic_file_image_gray_24dp.xml rename to app/src/main/res/drawable/ic_file_image_red_24dp.xml index 4ed0a1c..480d7b0 100644 --- a/app/src/main/res/drawable/ic_file_image_gray_24dp.xml +++ b/app/src/main/res/drawable/ic_file_image_red_24dp.xml @@ -5,5 +5,5 @@ android:viewportHeight="24"> + android:fillColor="#E30000"/> diff --git a/app/src/main/res/drawable/ic_file_video_gray_24dp.xml b/app/src/main/res/drawable/ic_file_video_gray_24dp.xml deleted file mode 100644 index 9486dfe..0000000 --- a/app/src/main/res/drawable/ic_file_video_gray_24dp.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/ic_file_video_orange_24dp.xml b/app/src/main/res/drawable/ic_file_video_orange_24dp.xml new file mode 100644 index 0000000..740cff2 --- /dev/null +++ b/app/src/main/res/drawable/ic_file_video_orange_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/fragment_detail_item.xml b/app/src/main/res/layout/fragment_detail_item.xml index a463ae9..5206cd7 100644 --- a/app/src/main/res/layout/fragment_detail_item.xml +++ b/app/src/main/res/layout/fragment_detail_item.xml @@ -89,7 +89,7 @@ app:layout_constraintTop_toBottomOf="@id/detail_item_attachment_image" app:layout_constraintBottom_toTopOf="@id/detail_item_attachment_box" app:layout_constraintHorizontal_bias="0.0" android:layout_marginTop="2dp" - android:layout_marginBottom="3dp"/> + /> \ No newline at end of file diff --git a/assets/movie_black_24dp.svg b/assets/movie_black_24dp.svg new file mode 100644 index 0000000..4f415d5 --- /dev/null +++ b/assets/movie_black_24dp.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/music_note_black_24dp.svg b/assets/music_note_black_24dp.svg new file mode 100644 index 0000000..f0410d3 --- /dev/null +++ b/assets/music_note_black_24dp.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 3df7b17..2963adf 100644 --- a/build.gradle +++ b/build.gradle @@ -18,6 +18,7 @@ allprojects { repositories { google() jcenter() + maven { url "https://jitpack.io" } // For StfalconImageViewer } }