From 634ef16bc5cd2c1c1ac362ffdd598f565d46876d Mon Sep 17 00:00:00 2001 From: Mateusz Idziejczak Date: Mon, 12 Apr 2021 17:17:52 +0200 Subject: [PATCH] [UI] Add notification icons. (#23) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add notification icons * Change color of icons * [Notifications] Update icon colors. * [Notifications] Update lucky number icon. * Add icons to Notifications List Fragment * Update notifications_list_item.xml * Move the gravity to the LinearLayout * add paddingLeft * Change IconicsImageView to View. * Rearrange XML attributes. Co-authored-by: Kuba Szczodrzyński --- .../data/api/task/PostNotifications.kt | 14 ++++++++++ .../edziennik/data/db/entity/Notification.kt | 17 ++++++++++++ .../notifications/NotificationsAdapter.kt | 6 +++++ .../res/layout/notifications_list_item.xml | 26 +++++++++++++++---- 4 files changed, 58 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/task/PostNotifications.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/task/PostNotifications.kt index 843f2174..28e62d59 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/task/PostNotifications.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/task/PostNotifications.kt @@ -8,6 +8,9 @@ import android.util.SparseIntArray import androidx.core.app.NotificationCompat import androidx.core.util.forEach import androidx.core.util.set +import com.mikepenz.iconics.IconicsDrawable +import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial +import com.mikepenz.iconics.utils.* import pl.szczodrzynski.edziennik.* import pl.szczodrzynski.edziennik.data.db.entity.Notification.Companion.TYPE_SERVER_MESSAGE import pl.szczodrzynski.edziennik.utils.models.Time @@ -107,6 +110,10 @@ class PostNotifications(val app: App, nList: List) { .setContentText(buildSummaryText(summaryCounts)) .setTicker(newNotificationsText) .setSmallIcon(R.drawable.ic_notification) + .setLargeIcon(IconicsDrawable(app).apply { + icon = CommunityMaterial.Icon.cmd_bell_ring_outline + colorRes = R.color.colorPrimary + }.toBitmap()) .setStyle(NotificationCompat.InboxStyle() .also { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { @@ -137,6 +144,9 @@ class PostNotifications(val app: App, nList: List) { .setSubText(if (it.type == TYPE_SERVER_MESSAGE) null else it.title) .setTicker("${it.profileName}: ${it.title}") .setSmallIcon(R.drawable.ic_notification) + .setLargeIcon(IconicsDrawable(app, it.getLargeIcon()).apply { + colorRes = R.color.colorPrimary + }.toBitmap()) .setStyle(NotificationCompat.BigTextStyle() .bigText(it.text)) .setWhen(it.addedDate) @@ -160,6 +170,10 @@ class PostNotifications(val app: App, nList: List) { .setContentText(buildSummaryText(summaryCounts)) .setTicker(newNotificationsText) .setSmallIcon(R.drawable.ic_notification) + .setLargeIcon(IconicsDrawable(app).apply { + icon = CommunityMaterial.Icon.cmd_bell_ring_outline + colorRes = R.color.colorPrimary + }.toBitmap()) .addDefaults() .setGroupSummary(true) .setContentIntent(summaryIntent) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/entity/Notification.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/entity/Notification.kt index 1e8b8e0e..6a2a787b 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/entity/Notification.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/entity/Notification.kt @@ -10,6 +10,8 @@ import android.content.Intent import androidx.room.Entity import androidx.room.PrimaryKey import com.google.gson.JsonObject +import com.mikepenz.iconics.typeface.IIcon +import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial import pl.szczodrzynski.edziennik.MainActivity @Entity(tableName = "notifications") @@ -96,4 +98,19 @@ data class Notification( fillIntent(intent) return PendingIntent.getActivity(context, id.toInt(), intent, PendingIntent.FLAG_ONE_SHOT) } + + fun getLargeIcon(): IIcon = when (type) { + TYPE_TIMETABLE_LESSON_CHANGE -> CommunityMaterial.Icon3.cmd_timetable + TYPE_NEW_GRADE -> CommunityMaterial.Icon3.cmd_numeric_5_box_outline + TYPE_NEW_EVENT -> CommunityMaterial.Icon.cmd_calendar_outline + TYPE_NEW_HOMEWORK -> CommunityMaterial.Icon3.cmd_notebook_outline + TYPE_NEW_SHARED_EVENT -> CommunityMaterial.Icon.cmd_calendar_outline + TYPE_NEW_SHARED_HOMEWORK -> CommunityMaterial.Icon3.cmd_notebook_outline + TYPE_NEW_MESSAGE -> CommunityMaterial.Icon.cmd_email_outline + TYPE_NEW_NOTICE -> CommunityMaterial.Icon.cmd_emoticon_outline + TYPE_NEW_ATTENDANCE -> CommunityMaterial.Icon.cmd_calendar_remove_outline + TYPE_LUCKY_NUMBER -> CommunityMaterial.Icon.cmd_emoticon_excited_outline + TYPE_NEW_ANNOUNCEMENT -> CommunityMaterial.Icon.cmd_bullhorn_outline + else -> CommunityMaterial.Icon.cmd_bell_ring_outline + } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/notifications/NotificationsAdapter.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/notifications/NotificationsAdapter.kt index 8df33a8c..6c0fe067 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/notifications/NotificationsAdapter.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/notifications/NotificationsAdapter.kt @@ -4,6 +4,8 @@ import android.view.LayoutInflater import android.view.ViewGroup import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.RecyclerView +import com.mikepenz.iconics.IconicsDrawable +import com.mikepenz.iconics.utils.colorRes import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -43,6 +45,10 @@ class NotificationsAdapter( val date = Date.fromMillis(item.addedDate).formattedString val colorSecondary = android.R.attr.textColorSecondary.resolveAttr(activity) + b.notificationIcon.background = IconicsDrawable(app, item.getLargeIcon()).apply { + colorRes = R.color.colorPrimary + } + b.title.text = item.text b.profileDate.text = listOf( item.profileName ?: "", diff --git a/app/src/main/res/layout/notifications_list_item.xml b/app/src/main/res/layout/notifications_list_item.xml index 498f7e21..13df88d1 100644 --- a/app/src/main/res/layout/notifications_list_item.xml +++ b/app/src/main/res/layout/notifications_list_item.xml @@ -9,12 +9,28 @@ android:orientation="vertical" android:padding="8dp"> - + android:gravity="center_vertical" + android:orientation="horizontal"> + + + + +