Advertisement
fakhrycodepolitan

TaskCompleteFragment.kt

Nov 25th, 2022
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 2.00 KB | Source Code | 0 0
  1. package com.mch.ktm.kerjaanku.view.taskComplete
  2.  
  3. import android.os.Bundle
  4. import android.view.LayoutInflater
  5. import android.view.View
  6. import android.view.ViewGroup
  7. import androidx.fragment.app.Fragment
  8. import com.mch.ktm.kerjaanku.R
  9. import com.mch.ktm.kerjaanku.adapter.TaskAdapter
  10. import com.mch.ktm.kerjaanku.model.SubTask
  11. import com.mch.ktm.kerjaanku.model.Task
  12. import com.mch.ktm.kerjaanku.model.Tasks
  13. import com.mch.ktm.kerjaanku.repository.TaskRepository
  14. import kotlinx.android.synthetic.main.fragment_task_complete.*
  15.  
  16.  
  17. class TaskCompleteFragment : Fragment() {
  18.  
  19.     override fun onCreateView(
  20.         inflater: LayoutInflater,
  21.         container: ViewGroup?,
  22.         savedInstanceState: Bundle?
  23.     ): View? {
  24.         return inflater.inflate(R.layout.fragment_task_complete, container, false)
  25.     }
  26.  
  27.     override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
  28.         super.onViewCreated(view, savedInstanceState)
  29.  
  30.         val tasks: Tasks? = TaskRepository.getDataTasks(context)
  31.  
  32.         if (tasks != null) {
  33.             for (task: Task in tasks.tasks!!) {
  34.                 task.mainTask?.isComplete = true
  35.  
  36.                 if (task.subTasks != null) {
  37.                     for (subTask: SubTask in task.subTasks) {
  38.                         subTask.isComplete = true
  39.                     }
  40.                 }
  41.             }
  42.  
  43.             showTaskComplete()
  44.             val taskAdapter = TaskAdapter()
  45.             taskAdapter.setData(tasks.tasks)
  46.  
  47.             rvTaskComplete.adapter = taskAdapter
  48.         } else {
  49.             hideTaskComplete()
  50.         }
  51.  
  52.     }
  53.  
  54.     private fun hideTaskComplete() {
  55.         rvTaskComplete.visibility = View.GONE
  56.         layoutEmptyTaskComplete.visibility = View.VISIBLE
  57.         fabDeleteCompleteTask.visibility = View.GONE
  58.     }
  59.  
  60.     private fun showTaskComplete() {
  61.         rvTaskComplete.visibility = View.VISIBLE
  62.         layoutEmptyTaskComplete.visibility = View.GONE
  63.         fabDeleteCompleteTask.visibility = View.VISIBLE
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement