Skip to content

Commit

Permalink
implement update task status
Browse files Browse the repository at this point in the history
  • Loading branch information
grantespo committed Mar 27, 2024
1 parent 7b940e0 commit 177783f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class HealthJourneyFragment : Fragment() {
return root
}

override fun onResume() {
super.onResume()
getTasks()
}

private fun setAdapter(taskResult: BWellResult<Task>) {
when (taskResult) {
is BWellResult.ResourceCollection -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.bwell.sampleapp.activities.ui.health_journey

import android.graphics.Color
import android.opengl.Visibility
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand All @@ -9,6 +11,8 @@ import androidx.fragment.app.FragmentManager
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import com.bwell.activity.requests.TasksRequest
import com.bwell.activity.requests.UpdateTaskRequest
import com.bwell.common.models.domain.task.enums.TaskStatus
import com.bwell.common.models.responses.BWellResult
import com.bwell.sampleapp.BWellSampleApplication
import com.bwell.sampleapp.R
Expand Down Expand Up @@ -97,6 +101,25 @@ class TaskDetailFragment : Fragment(), View.OnClickListener {
binding.taskButton.visibility = View.VISIBLE
}

binding.taskButton.setOnClickListener {
binding.taskStatusTitleTextView.visibility = View.VISIBLE

val taskUpdateRequest = UpdateTaskRequest.Builder()
.taskId(taskId)
.newStatus(TaskStatus.COMPLETED)
.build()

healthJourneyViewModel.updateTask(taskUpdateRequest) {
if (it?.success() == true) {
binding.taskStatusTitleTextView.setTextColor(Color.GREEN)
binding.taskStatusTitleTextView.text = "Success!"
} else {
binding.taskStatusTitleTextView.setTextColor(Color.RED)
binding.taskStatusTitleTextView.text = "Error"
}
}
}

// set references
healthJourneyViewModel.getContentReferences(task)?.let {
binding.taskReferencesWebview.loadDataWithBaseURL(null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.bwell.sampleapp.repository

import com.bwell.sampleapp.singletons.BWellSdk
import com.bwell.activity.requests.TasksRequest
import com.bwell.activity.requests.UpdateTaskRequest
import com.bwell.common.models.domain.task.Task
import com.bwell.common.models.responses.BWellResult
import kotlinx.coroutines.flow.Flow
Expand All @@ -17,4 +18,12 @@ class HealthJourneyRepository {
emit(null)
}
}

suspend fun updateTask(updateTaskRequest: UpdateTaskRequest): BWellResult<Task>? {
return try {
BWellSdk.activity.updateTaskStatus(updateTaskRequest)
} catch (e: Exception) {
null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.bwell.sampleapp.viewmodel
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.bwell.activity.requests.TasksRequest
import com.bwell.activity.requests.UpdateTaskRequest
import com.bwell.common.models.domain.task.Task
import com.bwell.common.models.responses.BWellResult
import com.bwell.sampleapp.repository.HealthJourneyRepository
Expand All @@ -26,6 +27,12 @@ class HealthJourneyViewModel (private val repository: HealthJourneyRepository?)
}
}
}
fun updateTask(updateTaskRequest: UpdateTaskRequest, callback: (BWellResult<Task>?) -> Unit) {
viewModelScope.launch {
val result = repository?.updateTask(updateTaskRequest)
callback(result)
}
}

fun getActivityName(task: Task?): String? {
return task?.identifier?.firstOrNull { it.system == "https://www.icanbwell.com/activityName" }?.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,21 @@
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginBottom="5dp"
android:text="Action Button"
app:layout_constraintBottom_toTopOf="@id/taskStatusTitleTextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<TextView
android:id="@+id/taskStatusTitleTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:textAlignment="center"
android:visibility="invisible"
android:textColor="#0076AB"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@id/taskReferencesTitleTextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
Expand Down

0 comments on commit 177783f

Please sign in to comment.