mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-17 13:18:26 +00:00
Merge pull request #1492 from simophin/ses-1931-fix-debouncer
[SES-1931] - Fix debouncer crash
This commit is contained in:
commit
410e298bca
@ -5,9 +5,9 @@ import android.content.Context
|
|||||||
import org.session.libsession.utilities.Debouncer
|
import org.session.libsession.utilities.Debouncer
|
||||||
import org.thoughtcrime.securesms.ApplicationContext
|
import org.thoughtcrime.securesms.ApplicationContext
|
||||||
|
|
||||||
class ConversationNotificationDebouncer(private val context: Context) {
|
class ConversationNotificationDebouncer(private val context: ApplicationContext) {
|
||||||
private val threadIDs = mutableSetOf<Long>()
|
private val threadIDs = mutableSetOf<Long>()
|
||||||
private val handler = (context.applicationContext as ApplicationContext).conversationListNotificationHandler
|
private val handler = context.conversationListNotificationHandler
|
||||||
private val debouncer = Debouncer(handler, 100)
|
private val debouncer = Debouncer(handler, 100)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@ -17,20 +17,28 @@ class ConversationNotificationDebouncer(private val context: Context) {
|
|||||||
@Synchronized
|
@Synchronized
|
||||||
fun get(context: Context): ConversationNotificationDebouncer {
|
fun get(context: Context): ConversationNotificationDebouncer {
|
||||||
if (::shared.isInitialized) { return shared }
|
if (::shared.isInitialized) { return shared }
|
||||||
shared = ConversationNotificationDebouncer(context)
|
shared = ConversationNotificationDebouncer(context.applicationContext as ApplicationContext)
|
||||||
return shared
|
return shared
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun notify(threadID: Long) {
|
fun notify(threadID: Long) {
|
||||||
threadIDs.add(threadID)
|
synchronized(threadIDs) {
|
||||||
|
threadIDs.add(threadID)
|
||||||
|
}
|
||||||
|
|
||||||
debouncer.publish { publish() }
|
debouncer.publish { publish() }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun publish() {
|
private fun publish() {
|
||||||
for (threadID in threadIDs.toList()) {
|
val toNotify = synchronized(threadIDs) {
|
||||||
|
val copy = threadIDs.toList()
|
||||||
|
threadIDs.clear()
|
||||||
|
copy
|
||||||
|
}
|
||||||
|
|
||||||
|
for (threadID in toNotify) {
|
||||||
context.contentResolver.notifyChange(DatabaseContentProviders.Conversation.getUriForThread(threadID), null)
|
context.contentResolver.notifyChange(DatabaseContentProviders.Conversation.getUriForThread(threadID), null)
|
||||||
}
|
}
|
||||||
threadIDs.clear()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user