aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-03-05 21:06:24 -0500
committerAllan Wang <me@allanwang.ca>2019-03-05 21:06:24 -0500
commit65bb9233b2a0d8734c1d13e8f3a01bee0f6c3b17 (patch)
treeabe5c5db1b05757375d63c32ec8afae9893a9dee /app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt
parent5c4400975450c9739f0986561075983e08afae89 (diff)
downloadfrost-65bb9233b2a0d8734c1d13e8f3a01bee0f6c3b17.tar.gz
frost-65bb9233b2a0d8734c1d13e8f3a01bee0f6c3b17.tar.bz2
frost-65bb9233b2a0d8734c1d13e8f3a01bee0f6c3b17.zip
Convert fbcookies to room entities
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt11
1 files changed, 7 insertions, 4 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt
index a895900f..088d8e0a 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt
@@ -21,8 +21,8 @@ import androidx.core.app.NotificationManagerCompat
import ca.allanwang.kau.utils.string
import com.pitchedapps.frost.BuildConfig
import com.pitchedapps.frost.R
-import com.pitchedapps.frost.db.CookieModel
-import com.pitchedapps.frost.db.loadFbCookiesSync
+import com.pitchedapps.frost.db.CookieDao
+import com.pitchedapps.frost.db.CookieEntity
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.frostEvent
@@ -31,6 +31,7 @@ import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.coroutines.yield
+import org.koin.android.ext.android.inject
/**
* Created by Allan Wang on 2017-06-14.
@@ -42,6 +43,8 @@ import kotlinx.coroutines.yield
*/
class NotificationService : BaseJobService() {
+ val cookieDao: CookieDao by inject()
+
override fun onStopJob(params: JobParameters?): Boolean {
super.onStopJob(params)
prepareFinish(true)
@@ -81,7 +84,7 @@ class NotificationService : BaseJobService() {
private suspend fun sendNotifications(params: JobParameters?): Unit = withContext(Dispatchers.Default) {
val currentId = Prefs.userId
- val cookies = loadFbCookiesSync()
+ val cookies = cookieDao.selectAll()
yield()
val jobId = params?.extras?.getInt(NOTIFICATION_PARAM_ID, -1) ?: -1
var notifCount = 0
@@ -107,7 +110,7 @@ class NotificationService : BaseJobService() {
* Implemented fetch to also notify when an error occurs
* Also normalized the output to return the number of notifications received
*/
- private fun fetch(jobId: Int, type: NotificationType, cookie: CookieModel): Int {
+ private fun fetch(jobId: Int, type: NotificationType, cookie: CookieEntity): Int {
val count = type.fetch(this, cookie)
if (count < 0) {
if (jobId == NOTIFICATION_JOB_NOW)