fix ANR caused by direct message badge (#4182)
Saw an ANR (app not responding) error being reported in the Play console and then found this. Sorry but `runBlocking` in production code is an absolute no go.
This commit is contained in:
parent
d8c436c268
commit
9781e43441
|
@ -141,6 +141,7 @@ import dagger.android.DispatchingAndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import de.c1710.filemojicompat_ui.helpers.EMOJI_PREFERENCE
|
import de.c1710.filemojicompat_ui.helpers.EMOJI_PREFERENCE
|
||||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@ -329,7 +330,7 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
|
||||||
updateAnnouncementsBadge()
|
updateAnnouncementsBadge()
|
||||||
}
|
}
|
||||||
is NewNotificationsEvent -> {
|
is NewNotificationsEvent -> {
|
||||||
directMessageTab?.let { tab ->
|
directMessageTab?.let {
|
||||||
if (event.accountId == activeAccount.accountId) {
|
if (event.accountId == activeAccount.accountId) {
|
||||||
val hasDirectMessageNotification =
|
val hasDirectMessageNotification =
|
||||||
event.notifications.any { it.type == Notification.Type.MENTION && it.status?.visibility == Status.Visibility.DIRECT }
|
event.notifications.any { it.type == Notification.Type.MENTION && it.status?.visibility == Status.Visibility.DIRECT }
|
||||||
|
@ -400,10 +401,12 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
|
||||||
tab.badge?.isVisible = showBadge
|
tab.badge?.isVisible = showBadge
|
||||||
|
|
||||||
// TODO a bit cumbersome (also for resetting)
|
// TODO a bit cumbersome (also for resetting)
|
||||||
accountManager.activeAccount?.let {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
if (it.hasDirectMessageBadge != showBadge) {
|
accountManager.activeAccount?.let {
|
||||||
it.hasDirectMessageBadge = showBadge
|
if (it.hasDirectMessageBadge != showBadge) {
|
||||||
accountManager.saveAccount(it)
|
it.hasDirectMessageBadge = showBadge
|
||||||
|
accountManager.saveAccount(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,6 @@ import com.mikepenz.iconics.utils.sizeDp
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.time.DurationUnit
|
import kotlin.time.DurationUnit
|
||||||
import kotlin.time.toDuration
|
import kotlin.time.toDuration
|
||||||
|
@ -132,7 +131,7 @@ class ConversationsFragment :
|
||||||
binding.progressBar.hide()
|
binding.progressBar.hide()
|
||||||
|
|
||||||
if (loadState.isAnyLoading()) {
|
if (loadState.isAnyLoading()) {
|
||||||
runBlocking {
|
lifecycleScope.launch {
|
||||||
eventHub.dispatch(ConversationsLoadingEvent(accountManager.activeAccount?.accountId ?: ""))
|
eventHub.dispatch(ConversationsLoadingEvent(accountManager.activeAccount?.accountId ?: ""))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue