1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2024-09-20 01:19:08 -05:00

Different notification for notes and praises (#952)

This commit is contained in:
Mateusz Idziejczak 2020-09-25 15:46:08 +02:00 committed by GitHub
parent e08abc1fc2
commit bafe52e310
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 90 additions and 3 deletions

View File

@ -14,6 +14,9 @@ import io.github.wulkanowy.data.db.entities.Semester
import io.github.wulkanowy.data.db.entities.Student
import io.github.wulkanowy.data.repositories.note.NoteRepository
import io.github.wulkanowy.data.repositories.preferences.PreferencesRepository
import io.github.wulkanowy.sdk.scrapper.notes.NoteCategory
import io.github.wulkanowy.sdk.scrapper.notes.NoteCategory.NEUTRAL
import io.github.wulkanowy.sdk.scrapper.notes.NoteCategory.POSITIVE
import io.github.wulkanowy.services.sync.channels.NewNotesChannel
import io.github.wulkanowy.ui.modules.main.MainActivity
import io.github.wulkanowy.ui.modules.main.MainView
@ -41,8 +44,20 @@ class NoteWork @Inject constructor(
private fun notify(notes: List<Note>) {
notificationManager.notify(Random.nextInt(Int.MAX_VALUE), NotificationCompat.Builder(context, NewNotesChannel.CHANNEL_ID)
.setContentTitle(context.resources.getQuantityString(R.plurals.note_new_items, notes.size, notes.size))
.setContentText(context.resources.getQuantityString(R.plurals.note_notify_new_items, notes.size, notes.size))
.setContentTitle(
when (NoteCategory.getByValue(notes.first().categoryType)) {
POSITIVE -> context.resources.getQuantityString(R.plurals.praise_new_items, notes.size, notes.size)
NEUTRAL -> context.resources.getQuantityString(R.plurals.neutral_note_new_items, notes.size, notes.size)
else -> context.resources.getQuantityString(R.plurals.note_new_items, notes.size, notes.size)
}
)
.setContentText(
when (NoteCategory.getByValue(notes.first().categoryType)) {
POSITIVE -> context.resources.getQuantityString(R.plurals.praise_notify_new_items, notes.size, notes.size)
NEUTRAL -> context.resources.getQuantityString(R.plurals.neutral_note_notify_new_items, notes.size, notes.size)
else -> context.resources.getQuantityString(R.plurals.note_notify_new_items, notes.size, notes.size)
}
)
.setSmallIcon(R.drawable.ic_stat_note)
.setAutoCancel(true)
.setDefaults(DEFAULT_ALL)
@ -52,7 +67,13 @@ class NoteWork @Inject constructor(
PendingIntent.getActivity(context, MainView.Section.NOTE.id,
MainActivity.getStartIntent(context, MainView.Section.NOTE, true), FLAG_UPDATE_CURRENT))
.setStyle(NotificationCompat.InboxStyle().run {
setSummaryText(context.resources.getQuantityString(R.plurals.note_number_item, notes.size, notes.size))
setSummaryText(
when (NoteCategory.getByValue(notes.first().categoryType)) {
POSITIVE -> context.resources.getQuantityString(R.plurals.praise_number_item, notes.size, notes.size)
NEUTRAL -> context.resources.getQuantityString(R.plurals.neutral_note_number_item, notes.size, notes.size)
else -> context.resources.getQuantityString(R.plurals.note_number_item, notes.size, notes.size)
}
)
notes.forEach { addLine("${it.teacher}: ${it.category}") }
this
})

View File

@ -252,6 +252,44 @@
<item quantity="many">Masz %1$d nowych uwag</item>
<item quantity="other">Masz %1$d nowych uwag</item>
</plurals>
<!--Praise-->
<plurals name="praise_number_item">
<item quantity="one">%d pochwała</item>
<item quantity="few">%d pochwały</item>
<item quantity="many">%d pochwał</item>
<item quantity="other">%d pochwał</item>
</plurals>
<plurals name="praise_new_items">
<item quantity="one">Nowa pochwała</item>
<item quantity="few">Nowe pochwały</item>
<item quantity="many">Nowe pochwały</item>
<item quantity="other">Nowe pochwały</item>
</plurals>
<plurals name="praise_notify_new_items">
<item quantity="one">Masz %1$d nową pochwałę</item>
<item quantity="few">Masz %1$d nowe pochwały</item>
<item quantity="many">Masz %1$d nowych pochwał</item>
<item quantity="other">Masz %1$d nowych pochwał</item>
</plurals>
<!--Neutral notes-->
<plurals name="neutral_note_number_item">
<item quantity="one">%d neutralna uwaga</item>
<item quantity="few">%d neutralne uwagi</item>
<item quantity="many">%d neutralnych uwag</item>
<item quantity="other">%d neutralnych uwag</item>
</plurals>
<plurals name="neutral_note_new_items">
<item quantity="one">Nowa neutralna uwaga</item>
<item quantity="few">Nowe neutralne uwagi</item>
<item quantity="many">Nowe neutralne uwagi</item>
<item quantity="other">Nowe neutralne uwagi</item>
</plurals>
<plurals name="neutral_note_notify_new_items">
<item quantity="one">Masz %1$d nową neutralną uwagę</item>
<item quantity="few">Masz %1$d nowe neutralne uwagi</item>
<item quantity="many">Masz %1$d nowych neutralnych uwag</item>
<item quantity="other">Masz %1$d nowych neutralnych uwag</item>
</plurals>
<!--Homework-->
<string name="homework_no_items">Brak zadań domowych</string>
<string name="homework_mark_as_done">Wykonane</string>

View File

@ -249,6 +249,34 @@
<item quantity="other">You received %1$d notes</item>
</plurals>
<!--Praise-->
<plurals name="praise_number_item">
<item quantity="one">%d praise</item>
<item quantity="other">%d praises</item>
</plurals>
<plurals name="praise_new_items">
<item quantity="one">New praise</item>
<item quantity="other">New praises</item>
</plurals>
<plurals name="praise_notify_new_items">
<item quantity="one">You received %1$d praise</item>
<item quantity="other">You received %1$d praises</item>
</plurals>
<!--Neutral notes-->
<plurals name="neutral_note_number_item">
<item quantity="one">%d neutral note</item>
<item quantity="other">%d neutral notes</item>
</plurals>
<plurals name="neutral_note_new_items">
<item quantity="one">New neutral note</item>
<item quantity="other">New neutral notes</item>
</plurals>
<plurals name="neutral_note_notify_new_items">
<item quantity="one">You received %1$d neutral note</item>
<item quantity="other">You received %1$d neutral notes</item>
</plurals>
<!--Homework-->
<string name="homework_no_items">No info about homework</string>