-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
persist notifications for duplicate filtering, handle group notificat…
…ions
- Loading branch information
Showing
11 changed files
with
216 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
android/app/src/main/kotlin/io/rebble/cobble/data/NotificationGroup.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.rebble.cobble.data | ||
|
||
import android.service.notification.StatusBarNotification | ||
import androidx.core.app.NotificationCompat | ||
|
||
data class NotificationGroup( | ||
val groupKey: String, | ||
val summary: StatusBarNotification?, | ||
val children: List<StatusBarNotification> | ||
) | ||
|
||
fun List<StatusBarNotification>.toNotificationGroup(): NotificationGroup { | ||
val mutable = toMutableList() | ||
val summary = mutable.firstOrNull { NotificationCompat.isGroupSummary(it.notification) } | ||
summary?.let { mutable.remove(it) } | ||
|
||
val groupKey = summary?.groupKey ?: mutable.first().groupKey | ||
?: throw IllegalArgumentException("Notification is not part of a group") | ||
|
||
return NotificationGroup( | ||
groupKey, | ||
summary, | ||
mutable | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
android/app/src/main/kotlin/io/rebble/cobble/notifications/NotificationExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.rebble.cobble.notifications | ||
|
||
import android.service.notification.StatusBarNotification | ||
import androidx.core.app.NotificationCompat | ||
|
||
val StatusBarNotification.shouldDisplayGroupSummary: Boolean | ||
get() { | ||
// Check if the group is from a package that should not display group summaries | ||
return when (packageName) { | ||
"com.google.android.gm" -> false | ||
else -> true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...ed/src/commonMain/kotlin/io/rebble/cobble/shared/database/dao/PersistedNotificationDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.rebble.cobble.shared.database.dao | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
import io.rebble.cobble.shared.database.entity.PersistedNotification | ||
|
||
@Dao | ||
interface PersistedNotificationDao { | ||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun insert(notification: PersistedNotification) | ||
|
||
@Query("SELECT * FROM PersistedNotification WHERE sbnKey = :key") | ||
suspend fun get(key: String): PersistedNotification? | ||
|
||
@Query("SELECT * FROM PersistedNotification WHERE sbnKey = :key AND packageName = :packageName AND title = :title AND text = :text") | ||
suspend fun getDuplicates(key:String, packageName: String, title: String, text: String): List<PersistedNotification> | ||
|
||
@Query("DELETE FROM PersistedNotification WHERE postTime < :time") | ||
suspend fun deleteOlderThan(time: Long) | ||
} |
15 changes: 15 additions & 0 deletions
15
...ed/src/commonMain/kotlin/io/rebble/cobble/shared/database/entity/PersistedNotification.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.rebble.cobble.shared.database.entity | ||
|
||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
|
||
@Entity | ||
data class PersistedNotification ( | ||
@PrimaryKey | ||
val sbnKey: String, | ||
val packageName: String, | ||
val postTime: Long, | ||
val title: String, | ||
val text: String, | ||
val groupKey: String?, | ||
) |