-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SES-1931] - Fix debouncer crash #1492
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,9 @@ import android.content.Context | |
import org.session.libsession.utilities.Debouncer | ||
import org.thoughtcrime.securesms.ApplicationContext | ||
|
||
class ConversationNotificationDebouncer(private val context: Context) { | ||
class ConversationNotificationDebouncer(private val context: ApplicationContext) { | ||
private val threadIDs = mutableSetOf<Long>() | ||
private val handler = (context.applicationContext as ApplicationContext).conversationListNotificationHandler | ||
private val handler = context.conversationListNotificationHandler | ||
private val debouncer = Debouncer(handler, 100) | ||
|
||
companion object { | ||
|
@@ -17,20 +17,28 @@ class ConversationNotificationDebouncer(private val context: Context) { | |
@Synchronized | ||
fun get(context: Context): ConversationNotificationDebouncer { | ||
if (::shared.isInitialized) { return shared } | ||
shared = ConversationNotificationDebouncer(context) | ||
shared = ConversationNotificationDebouncer(context.applicationContext as ApplicationContext) | ||
return shared | ||
} | ||
} | ||
|
||
fun notify(threadID: Long) { | ||
threadIDs.add(threadID) | ||
synchronized(threadIDs) { | ||
threadIDs.add(threadID) | ||
} | ||
|
||
debouncer.publish { publish() } | ||
} | ||
|
||
private fun publish() { | ||
for (threadID in threadIDs.toList()) { | ||
val toNotify = synchronized(threadIDs) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was just thinking, you can save the list copy by making it a
but it needs the same Creating a new instance still needs an allocation, but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually went down this path to avoid the copying and using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also considered using a sorted |
||
val copy = threadIDs.toList() | ||
threadIDs.clear() | ||
copy | ||
} | ||
|
||
for (threadID in toNotify) { | ||
context.contentResolver.notifyChange(DatabaseContentProviders.Conversation.getUriForThread(threadID), null) | ||
} | ||
threadIDs.clear() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice