Skip to content
Snippets Groups Projects
Commit 5e6bd979 authored by Moch. Sofyan Firdaus's avatar Moch. Sofyan Firdaus
Browse files

feat: make pie entries non-nullable

parent 7ebc53ec
2 merge requests!8Merge dev into main,!7Graph Implementation
......@@ -8,6 +8,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import com.github.mikephil.charting.components.Legend
import com.github.mikephil.charting.data.PieData
......@@ -22,8 +23,8 @@ class GraphFragment : Fragment() {
private var _binding: FragmentGraphBinding? = null
private val binding get() = _binding!!
private var incomeEntry: PieEntry? = null
private var outcomeEntry: PieEntry? = null
private var incomeEntry = PieEntry(0f, "Income")
private var outcomeEntry = PieEntry(0f, "Outcome")
override fun onCreateView(
inflater: LayoutInflater,
......@@ -35,21 +36,13 @@ class GraphFragment : Fragment() {
ViewModelProvider(this)[GraphViewModel::class.java].apply {
incomes.observe(viewLifecycleOwner) {
if (it.isNotEmpty()) {
incomeEntry = PieEntry(it.sumOf { e -> e.amount }.toFloat(), "Income")
Log.d("DATA", "$it")
} else {
incomeEntry = null
}
incomeEntry = PieEntry(it.sumOf { e -> e.amount }.toFloat(), "Income")
Log.d("DATA", "$it")
refreshPieChart()
}
outcomes.observe(viewLifecycleOwner) {
if (it.isNotEmpty()) {
outcomeEntry = PieEntry(it.sumOf { e -> e.amount }.toFloat(), "Outcome")
Log.d("DATA", "$it")
} else {
outcomeEntry = null
}
outcomeEntry = PieEntry(it.sumOf { e -> e.amount }.toFloat(), "Outcome")
Log.d("DATA", "$it")
refreshPieChart()
}
}
......@@ -76,7 +69,7 @@ class GraphFragment : Fragment() {
private fun refreshPieChart() {
binding.apply {
if (incomeEntry == null || outcomeEntry == null) {
if (incomeEntry.value == 0f && outcomeEntry.value == 0f) {
textGraph.visibility = View.VISIBLE
pieChart.visibility = View.GONE
} else {
......
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