diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/services/FrostRequestService.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/services/FrostRequestService.kt | 50 |
1 files changed, 34 insertions, 16 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostRequestService.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostRequestService.kt index b2ccaea2..22acc9fb 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostRequestService.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostRequestService.kt @@ -1,3 +1,19 @@ +/* + * 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.JobInfo @@ -37,10 +53,10 @@ private enum class FrostRequestCommands : EnumBundle<FrostRequestCommands> { } override fun propagate(bundle: BaseBundle) = - FrostRunnable.prepareMarkNotificationRead( - bundle.getLong(ARG_0), - bundle.getCookie()) - + FrostRunnable.prepareMarkNotificationRead( + bundle.getLong(ARG_0), + bundle.getCookie() + ) }; override val bundleContract: EnumBundleCompanion<FrostRequestCommands> @@ -58,7 +74,6 @@ private enum class FrostRequestCommands : EnumBundle<FrostRequestCommands> { abstract fun propagate(bundle: BaseBundle): BaseBundle.() -> Unit companion object : EnumCompanion<FrostRequestCommands>("frost_arg_commands", values()) - } private const val ARG_COMMAND = "frost_request_command" @@ -99,8 +114,10 @@ object FrostRunnable { L.d { "Invalid notification id $id for marking as read" } return false } - return schedule(context, FrostRequestCommands.NOTIF_READ, - prepareMarkNotificationRead(id, cookie)) + return schedule( + context, FrostRequestCommands.NOTIF_READ, + prepareMarkNotificationRead(id, cookie) + ) } fun propagate(context: Context, intent: Intent?) { @@ -112,9 +129,11 @@ object FrostRunnable { schedule(context, command, builder) } - private fun schedule(context: Context, - command: FrostRequestCommands, - bundleBuilder: PersistableBundle.() -> Unit): Boolean { + private fun schedule( + context: Context, + command: FrostRequestCommands, + bundleBuilder: PersistableBundle.() -> Unit + ): Boolean { val scheduler = context.getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler val serviceComponent = ComponentName(context, FrostRequestService::class.java) val bundle = PersistableBundle() @@ -127,10 +146,10 @@ object FrostRunnable { } val builder = JobInfo.Builder(JOB_REQUEST_BASE + command.ordinal, serviceComponent) - .setMinimumLatency(0L) - .setExtras(bundle) - .setOverrideDeadline(2000L) - .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY) + .setMinimumLatency(0L) + .setExtras(bundle) + .setOverrideDeadline(2000L) + .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY) val result = scheduler.schedule(builder.build()) if (result <= 0) { L.eThrow("FrostRequestService scheduler failed for ${command.name}") @@ -139,7 +158,6 @@ object FrostRunnable { L.d { "Scheduled ${command.name}" } return true } - } class FrostRequestService : JobService() { @@ -183,4 +201,4 @@ class FrostRequestService : JobService() { } return true } -}
\ No newline at end of file +} |