forked from github/szkolny
[UI] Add notification icons. (#23)
* 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 <kuba@szczodrzynski.pl>
This commit is contained in:
parent
ccf0bdaf05
commit
634ef16bc5
@ -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<AppNotification>) {
|
||||
.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<AppNotification>) {
|
||||
.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<AppNotification>) {
|
||||
.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)
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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 ?: "",
|
||||
|
@ -9,12 +9,28 @@
|
||||
android:orientation="vertical"
|
||||
android:padding="8dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<View
|
||||
android:id="@+id/notificationIcon"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:scaleType="centerInside"
|
||||
tools:background="@android:drawable/ic_menu_more" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingLeft="8dp"
|
||||
android:textAppearance="@style/NavView.TextView.Medium"
|
||||
tools:text="Dzisiaj 1 to szczęśliwy numerek" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
Loading…
Reference in New Issue
Block a user