diff options
author | Allan Wang <me@allanwang.ca> | 2018-12-25 22:14:56 -0500 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2018-12-25 22:14:56 -0500 |
commit | 49a67bc7c6d0ea38c88d8b424a2f188941dc609e (patch) | |
tree | fb01f3a4c2e17236bd229f7846b8f813e94c2a78 /app/src/main/kotlin/com/pitchedapps/frost/services/BaseJobService.kt | |
parent | 697e457da453568ca703c2b655a2dd490157b443 (diff) | |
download | frost-49a67bc7c6d0ea38c88d8b424a2f188941dc609e.tar.gz frost-49a67bc7c6d0ea38c88d8b424a2f188941dc609e.tar.bz2 frost-49a67bc7c6d0ea38c88d8b424a2f188941dc609e.zip |
Update imageactivity and add tests, resolves #1107
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/services/BaseJobService.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/services/BaseJobService.kt | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/BaseJobService.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/BaseJobService.kt new file mode 100644 index 00000000..3cc7deaf --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/services/BaseJobService.kt @@ -0,0 +1,59 @@ +/* + * Copyright 2018 Allan Wang + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +package com.pitchedapps.frost.services + +import android.app.job.JobParameters +import android.app.job.JobService +import androidx.annotation.CallSuper +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job +import kotlin.coroutines.CoroutineContext + +abstract class BaseJobService : JobService(), CoroutineScope { + + private lateinit var job: Job + override val coroutineContext: CoroutineContext + get() = Dispatchers.Main + job + + protected val startTime = System.currentTimeMillis() + + /** + * Note that if a job plans on running asynchronously, it should return true + */ + @CallSuper + override fun onStartJob(params: JobParameters?): Boolean { + job = Job() + return false + } + + @CallSuper + override fun onStopJob(params: JobParameters?): Boolean { + job.cancel() + return false + } +} + +/* + * Collection of ids for job services. + * These should all be unique + */ + +const val NOTIFICATION_JOB_NOW = 6 +const val NOTIFICATION_PERIODIC_JOB = 7 +const val LOCAL_SERVICE_BASE = 110 +const val REQUEST_SERVICE_BASE = 220 |