Skip to content

Conversation

@CalvinKern
Copy link
Contributor

We don't have a submission service layer yet, but I was imagining that the view would have to start any kind of service as it holds a context. We will have to research the service layer further to get something that meets our needs. I was basing this work off of a JobIntentService, though we may need to use a foreground service so that the actions happen immediately.

Here's the example class I was thinking of:

class SubmissionService: JobIntentService() {

    override fun onHandleWork(intent: Intent) {
        when (intent.action) {
            SubmissionAction.SUBMIT_TEXT_ENTRY.name -> {
                val submission = apiAsync<Submission> {
                    SubmissionManager.postTextSubmission(
                            intent.getParcelableExtra(Const.CANVAS_CONTEXT),
                            intent.getLongExtra(Const.ASSIGNMENT_ID, -1),
                            intent.getStringExtra(Const.MESSAGE),
                            it)
                }
                // TODO: await submission and report back the results
            }
        }
    }

    companion object {
        private const val JOB_ID = 10249

        fun enqueueWork(context: Context, action: SubmissionAction, bundle: Bundle) {
            val intent = Intent(context, SubmissionService::class.java)
            intent.action = action.name
            intent.putExtras(bundle) // TODO: persist the bundle/action in local DB as well?

            enqueueWork(context, SubmissionService::class.java, JOB_ID, intent)
        }
    }
}

enum class SubmissionAction {
    SUBMIT_TEXT_ENTRY
}

@TrevorNeedham TrevorNeedham self-assigned this Apr 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants