Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f6ce3af4 authored by Philipp Heckel's avatar Philipp Heckel
Browse files

Layouting icon Ahhhh

parent 35ea6de6
Loading
Loading
Loading
Loading
+31 −13
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ class DetailAdapter(private val activity: Activity, private val lifecycleScope:
        private val dateView: TextView = itemView.findViewById(R.id.detail_item_date_text)
        private val titleView: TextView = itemView.findViewById(R.id.detail_item_title_text)
        private val messageView: TextView = itemView.findViewById(R.id.detail_item_message_text)
        private val iconView: ImageView = itemView.findViewById(R.id.detail_item_icon)
        private val newDotImageView: View = itemView.findViewById(R.id.detail_item_new_dot)
        private val tagsView: TextView = itemView.findViewById(R.id.detail_item_tags_text)
        private val menuButton: ImageButton = itemView.findViewById(R.id.detail_item_menu_button)
@@ -130,11 +131,13 @@ class DetailAdapter(private val activity: Activity, private val lifecycleScope:
                cardView.setCardBackgroundColor(Colors.cardBackgroundColor(context))
            }
            val attachment = notification.attachment
            val exists = if (attachment?.contentUri != null) fileExists(context, attachment.contentUri) else false
            val attachmentExists = if (attachment?.contentUri != null) fileExists(context, attachment.contentUri) else false
            val iconExists = if (notification.icon?.contentUri != null) fileExists(context, notification.icon.contentUri) else false
            renderPriority(context, notification)
            resetCardButtons()
            maybeRenderMenu(context, notification, exists)
            maybeRenderAttachment(context, notification, exists)
            maybeRenderMenu(context, notification, attachmentExists)
            maybeRenderAttachment(context, notification, attachmentExists)
            maybeRenderIcon(context, notification, iconExists)
            maybeRenderActions(context, notification)
        }

@@ -162,20 +165,35 @@ class DetailAdapter(private val activity: Activity, private val lifecycleScope:
            }
        }

        private fun maybeRenderAttachment(context: Context, notification: Notification, exists: Boolean) {
        private fun maybeRenderAttachment(context: Context, notification: Notification, attachmentExists: Boolean) {
            if (notification.attachment == null) {
                attachmentImageView.visibility = View.GONE
                attachmentBoxView.visibility = View.GONE
                return
            }
            val attachment = notification.attachment
            val image = attachment.contentUri != null && exists && supportedImage(attachment.type)
            val image = attachment.contentUri != null && attachmentExists && supportedImage(attachment.type)
            maybeRenderAttachmentImage(context, attachment, image)
            maybeRenderAttachmentBox(context, notification, attachment, exists, image)
            maybeRenderAttachmentBox(context, notification, attachment, attachmentExists, image)
        }

        private fun maybeRenderMenu(context: Context, notification: Notification, exists: Boolean) {
            val menuButtonPopupMenu = maybeCreateMenuPopup(context, menuButton, notification, exists) // Heavy lifting not during on-click
        private fun maybeRenderIcon(context: Context, notification: Notification, iconExists: Boolean) {
            if (notification.icon == null || !iconExists) {
                iconView.visibility = View.GONE
                return
            }
            try {
                val icon = notification.icon
                val bitmap = icon.contentUri?.readBitmapFromUri(context) ?: throw Exception("uri empty")
                iconView.setImageBitmap(bitmap)
                iconView.visibility = View.VISIBLE
            } catch (_: Exception) {
                iconView.visibility = View.GONE
            }
        }

        private fun maybeRenderMenu(context: Context, notification: Notification, attachmentExists: Boolean) {
            val menuButtonPopupMenu = maybeCreateMenuPopup(context, menuButton, notification, attachmentExists) // Heavy lifting not during on-click
            if (menuButtonPopupMenu != null) {
                menuButton.setOnClickListener { menuButtonPopupMenu.show() }
                menuButton.visibility = View.VISIBLE
@@ -240,7 +258,7 @@ class DetailAdapter(private val activity: Activity, private val lifecycleScope:
            attachmentBoxView.visibility = View.VISIBLE
        }

        private fun maybeCreateMenuPopup(context: Context, anchor: View?, notification: Notification, exists: Boolean): PopupMenu? {
        private fun maybeCreateMenuPopup(context: Context, anchor: View?, notification: Notification, attachmentExists: Boolean): PopupMenu? {
            val popup = PopupMenu(context, anchor)
            popup.menuInflater.inflate(R.menu.menu_detail_attachment, popup.menu)
            val attachment = notification.attachment // May be null
@@ -266,10 +284,10 @@ class DetailAdapter(private val activity: Activity, private val lifecycleScope:
            if (hasClickLink) {
                copyContentsItem.setOnMenuItemClickListener { copyContents(context, notification) }
            }
            openItem.isVisible = hasAttachment && exists
            downloadItem.isVisible = hasAttachment && !exists && !expired && !inProgress
            deleteItem.isVisible = hasAttachment && exists
            saveFileItem.isVisible = hasAttachment && exists
            openItem.isVisible = hasAttachment && attachmentExists
            downloadItem.isVisible = hasAttachment && !attachmentExists && !expired && !inProgress
            deleteItem.isVisible = hasAttachment && attachmentExists
            saveFileItem.isVisible = hasAttachment && attachmentExists
            copyUrlItem.isVisible = hasAttachment && !expired
            cancelItem.isVisible = hasAttachment && inProgress
            copyContentsItem.isVisible = notification.click != ""
+9 −6
Original line number Diff line number Diff line
@@ -51,9 +51,9 @@
                android:layout_height="26dp" app:srcCompat="@drawable/ic_more_horiz_gray_24dp"
                android:id="@+id/detail_item_menu_button"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="7dp"
                android:layout_marginEnd="7dp"
                android:background="?android:attr/selectableItemBackground" android:paddingTop="-5dp"
        />
                app:layout_constraintEnd_toStartOf="@id/detail_item_icon"/>
        <TextView
                android:text="This is a very very very long message. It could be as long as 1024 charaters, which is a lot more than you'd think. No, really so far this message is barely 180 characters long. I can't believe how long 1024 bytes are. This is outrageous. Oh you know what, I think I won't type the whole thing. This seems a little too long for a sample text. Well, anyway, it was nice chatting. So far this message is about 400 bytes long. So maybe just double what you see and that's that."
                android:layout_width="0dp"
@@ -64,8 +64,7 @@
                android:autoLink="web"
                app:layout_constraintTop_toBottomOf="@id/detail_item_title_text"
                app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="12dp"
                app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="12dp"
                app:layout_constraintBottom_toTopOf="@id/detail_item_attachment_image"/>
                app:layout_constraintBottom_toTopOf="@id/detail_item_attachment_image" app:layout_constraintEnd_toStartOf="@id/detail_item_icon" android:layout_marginEnd="12dp"/>
        <TextView
                android:text="This is an optional title. It can also be a little longer but not too long."
                android:layout_width="0dp"
@@ -74,10 +73,9 @@
                android:textColor="?android:attr/textColorPrimary"
                android:textAppearance="@style/TextAppearance.AppCompat.Medium"
                android:autoLink="web"
                app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="12dp"
                app:layout_constraintStart_toStartOf="parent"
                android:layout_marginStart="12dp" android:textStyle="bold"
                app:layout_constraintTop_toBottomOf="@+id/detail_item_date_text"/>
                app:layout_constraintTop_toBottomOf="@+id/detail_item_date_text" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toStartOf="@id/detail_item_icon" android:layout_marginEnd="12dp"/>
        <ImageView
                android:layout_width="16dp"
                android:layout_height="16dp" app:srcCompat="@drawable/ic_priority_5_24dp"
@@ -193,5 +191,10 @@
                android:id="@+id/detail_item_padding_bottom"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/detail_item_actions_wrapper" app:layout_constraintBottom_toBottomOf="parent"/>
        <ImageView
                android:layout_width="wrap_content"
                android:layout_height="0dp" app:srcCompat="@drawable/ic_notification" android:id="@+id/detail_item_icon" app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="9dp" android:visibility="visible" android:maxHeight="48dp" android:maxWidth="48dp" android:adjustViewBounds="true" app:layout_constraintBottom_toTopOf="@+id/detail_item_attachment_image"
                android:scaleType="fitStart" android:padding="2dp" app:layout_constraintTop_toTopOf="parent" android:layout_marginTop="3dp"/>
        <androidx.constraintlayout.widget.Guideline android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/guideline2" app:layout_constraintGuide_begin="27dp" android:orientation="horizontal"/>
    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>