Skip to content

Instantly share code, notes, and snippets.

@mariusz-blaszczak
Created August 28, 2018 10:25
Show Gist options
  • Save mariusz-blaszczak/2e03ad8328c3d5cd3a888509eb54be01 to your computer and use it in GitHub Desktop.
Save mariusz-blaszczak/2e03ad8328c3d5cd3a888509eb54be01 to your computer and use it in GitHub Desktop.
class LockWidgetJobService : JobIntentService() {
companion object {
...
private val SUPPORTED_ACTIONS = listOf(ACTION_TOGGLE, ACTION_REFRESH)
fun handleAction(context: Context, action: String?) {
if (!canHandle(action)) return
enqueueWork(context, LockWidgetJobService::class.java, JOB_ID, Intent(action))
}
private fun canHandle(action: String?) = SUPPORTED_ACTIONS.contains(action)
}
override fun onHandleWork(intent: Intent) {
when (intent.action) {
ACTION_TOGGLE -> handleCall(ApiClient.getInstance(this).apiService.toggleLock())
ACTION_REFRESH -> handleCall(ApiClient.getInstance(this).apiService.readLock())
else -> Log.w("LockWidgetJobService", "Unhandled intent action: ${intent.action}.")
}
}
private fun handleCall(call: Call<LockResponse>) {
LockWidgetProvider.showLoading(this)
// request call
LockWidgetProvider.showLockState(this)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment