Merge branch 'dev' of https://github.com/oxen-io/session-android into ONS-name-1
commit
0e89d88459
@ -0,0 +1,37 @@
|
||||
package org.thoughtcrime.securesms.database
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import org.session.libsession.utilities.Debouncer
|
||||
import org.thoughtcrime.securesms.ApplicationContext
|
||||
|
||||
class ConversationNotificationDebouncer(private val context: Context) {
|
||||
private val threadIDs = mutableSetOf<Long>()
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private val debouncer = Debouncer(handler, 250);
|
||||
|
||||
companion object {
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
lateinit var shared: ConversationNotificationDebouncer
|
||||
|
||||
fun get(context: Context): ConversationNotificationDebouncer {
|
||||
if (::shared.isInitialized) { return shared }
|
||||
shared = ConversationNotificationDebouncer(context)
|
||||
return shared
|
||||
}
|
||||
}
|
||||
|
||||
fun notify(threadID: Long) {
|
||||
threadIDs.add(threadID)
|
||||
debouncer.publish { publish() }
|
||||
}
|
||||
|
||||
private fun publish() {
|
||||
for (threadID in threadIDs) {
|
||||
context.contentResolver.notifyChange(DatabaseContentProviders.Conversation.getUriForThread(threadID), null)
|
||||
}
|
||||
threadIDs.clear()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue