Commit daaa1083 authored by Lukas Bersinger's avatar Lukas Bersinger
Browse files

hightlight tasks that are done

parent f45680cd
package ch.ost.rj.mge.miniproject.tasktracker.adapters
import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.TextView
import androidx.cardview.widget.CardView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import ch.ost.rj.mge.miniproject.tasktracker.R
import ch.ost.rj.mge.miniproject.tasktracker.models.Task
import java.text.DateFormat
class TaskListAdapter(private val dataset: List<Task>, private val clickListener: OnItemClickListener) :
class TaskListAdapter(
private val dataset: List<Task>,
private val context: Context,
private val clickListener: OnItemClickListener
) :
RecyclerView.Adapter<TaskListAdapter.TaskListViewHolder>() {
class TaskListViewHolder(val cardView: CardView) : RecyclerView.ViewHolder(cardView)
......@@ -33,6 +37,12 @@ class TaskListAdapter(private val dataset: List<Task>, private val clickListener
val dueDateView = holder.cardView.findViewById<TextView>(R.id.txtCardDueDate)
dueDateView.text = DateFormat.getDateInstance().format(activeTask.dueDate!!.time)
if (activeTask.isCompleted) {
holder.cardView.setCardBackgroundColor(
ContextCompat.getColor(context, R.color.colorDone)
)
}
holder.cardView.setOnClickListener {
clickListener.onItemClick(activeTask)
}
......
......@@ -45,7 +45,7 @@ class TaskListFragment : Fragment(), TaskListAdapter.OnItemClickListener {
val fragment = inflater.inflate(R.layout.fragment_task_list, container, false)
viewManager = LinearLayoutManager(context)
viewAdapter = tasks?.let { TaskListAdapter(it, this) }!!
viewAdapter = tasks?.let { TaskListAdapter(it, this.context!!, this) }!!
recyclerView = fragment.findViewById(R.id.rvTaskList)
recyclerView.apply {
......
......@@ -5,4 +5,5 @@
<color name="colorSecondary">#F9A825</color>
<color name="colorSuccess">#4CAF50</color>
<color name="colorError">#F44336</color>
<color name="colorDone">#DCEDC8</color>
</resources>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment