improving the unread messages counter badge
This commit is contained in:
parent
f511f35df0
commit
2e0d6a877d
6 changed files with 18 additions and 22 deletions
|
|
@ -452,23 +452,6 @@ fun Context.getNameAndPhotoFromPhoneNumber(number: String): NamePhoto? {
|
|||
return NamePhoto(number, null)
|
||||
}
|
||||
|
||||
fun Context.updateUnreadCountBadge(conversations : ArrayList<Conversation>){
|
||||
var count = 0
|
||||
|
||||
conversations.forEach {
|
||||
if(!it.read) {
|
||||
count++
|
||||
}
|
||||
}
|
||||
|
||||
if(count == 0) {
|
||||
ShortcutBadger.removeCount(this)
|
||||
} else {
|
||||
ShortcutBadger.applyCount(this,count)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun Context.insertNewSMS(address: String, subject: String, body: String, date: Long, read: Int, threadId: Long, type: Int, subscriptionId: Int): Int {
|
||||
val uri = Sms.CONTENT_URI
|
||||
val contentValues = ContentValues().apply {
|
||||
|
|
@ -540,6 +523,15 @@ fun Context.markThreadMessagesUnread(threadId: Int) {
|
|||
}
|
||||
}
|
||||
|
||||
fun Context.updateUnreadCountBadge(conversations: List<Conversation>) {
|
||||
val unreadCount = conversations.count { !it.read }
|
||||
if (unreadCount == 0) {
|
||||
ShortcutBadger.removeCount(this)
|
||||
} else {
|
||||
ShortcutBadger.applyCount(this, unreadCount)
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
fun Context.getThreadId(address: String): Long {
|
||||
return if (isMarshmallowPlus()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue