Created
August 28, 2018 10:25
-
-
Save mariusz-blaszczak/2e03ad8328c3d5cd3a888509eb54be01 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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