Skip to content

Commit

Permalink
Run getting bailey news on background thread on notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Hafizzle committed Sep 25, 2023
1 parent f34514e commit 59fae2c
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import com.habitrpg.common.habitica.models.notifications.QuestInvitationData
import com.habitrpg.common.habitica.models.notifications.UnallocatedPointsData
import com.habitrpg.common.habitica.views.PixelArtView
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -228,7 +229,7 @@ class NotificationsActivity : BaseActivity(), androidx.swiperefreshlayout.widget
)
}

private suspend fun createNewStuffNotification(notification: Notification): View? = withContext(ExceptionHandler.coroutine()) {
private suspend fun createNewStuffNotification(notification: Notification): View? = withContext(Dispatchers.IO) {
var baileyNotification = notification
val data = notification.data as? NewStuffData
val text = if (data?.title != null) {
Expand All @@ -240,13 +241,16 @@ class NotificationsActivity : BaseActivity(), androidx.swiperefreshlayout.widget
}
baileyNotification.id = notification.id

return@withContext createDismissableNotificationItem(
baileyNotification,
text,
R.drawable.notifications_bailey
)
return@withContext withContext(Dispatchers.Main) {
createDismissableNotificationItem(
baileyNotification,
text,
R.drawable.notifications_bailey
)
}
}


private fun createUnallocatedStatsNotification(notification: Notification): View? {
val level = userLvl ?: return null
return if (level >= 10) {
Expand Down

0 comments on commit 59fae2c

Please sign in to comment.