From 1c2761ac6bf1b3bb6e78fc3466c09aa6f0492de0 Mon Sep 17 00:00:00 2001 From: Isidro Henoch Date: Tue, 28 Dec 2021 20:40:04 -0600 Subject: Diaplays the events report --- .../android/details/reports/UnitReportsFragment.kt | 48 ++++++++++++++++++++++ .../details/reports/UnitReportsViewModel.kt | 6 +-- 2 files changed, 51 insertions(+), 3 deletions(-) (limited to 'androidApp/src/main/java') diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt index 9131728..9874a03 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt @@ -6,10 +6,15 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.PopupMenu +import android.widget.TableRow +import android.widget.TextView import androidx.fragment.app.Fragment import mx.trackermap.TrackerMap.android.R import mx.trackermap.TrackerMap.android.databinding.UnitDetailsReportsBinding import mx.trackermap.TrackerMap.android.details.UnitDetailsAdapter +import mx.trackermap.TrackerMap.client.models.Event +import mx.trackermap.TrackerMap.client.models.Position +import mx.trackermap.TrackerMap.client.models.Stop import org.koin.androidx.viewmodel.ext.android.viewModel class UnitReportsFragment : Fragment() { @@ -60,7 +65,14 @@ class UnitReportsFragment : Fragment() { private fun setupObservers() { unitReportsViewModel.report.observe(this) { report -> Log.d("UnitReportsFragment", "Report available: $report") + + when (report) { + is UnitReportsViewModel.Report.PositionsReport -> display(report.positions) + is UnitReportsViewModel.Report.EventsReport -> display(report.events) + is UnitReportsViewModel.Report.StopsReport -> display(report.stops) + } } + unitReportsViewModel.reportPeriod.observe(this) { period -> Log.d("UnitReportsFragment", "Period changed: $period") if (period == null) { @@ -90,4 +102,40 @@ class UnitReportsFragment : Fragment() { } popOver.show() } + + private fun display(positions: Array) { + Log.d("UnitReportsFragment", "Displaying positions: $positions") + + binding.eventsScroll.visibility = View.GONE + binding.reportMap.visibility = View.VISIBLE + } + + private fun display(events: Array) { + Log.d("UnitReportsFragment", "Displaying events: $events") + + binding.eventsScroll.visibility = View.VISIBLE + binding.reportMap.visibility = View.GONE + binding.eventsTable.removeViews(1, Math.max(0, binding.eventsTable.childCount - 1)) + + val context = context!! + events.forEach { event -> + val row = TableRow(context) + val eventText = TextView(context) + val datetimeText = TextView(context) + + row.addView(eventText) + row.addView(datetimeText) + binding.eventsTable.addView(row) + + eventText.text = event.type + datetimeText.text = event.eventTime + } + } + + private fun display(stops: Array) { + Log.d("UnitReportsFragment", "Displaying stops: $stops") + + binding.eventsScroll.visibility = View.GONE + binding.reportMap.visibility = View.VISIBLE + } } \ No newline at end of file diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt index 808bdda..35ef343 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt @@ -23,9 +23,9 @@ class UnitReportsViewModel( ) : ViewModel(), KoinComponent { sealed class Report { - class PositionsReport(positions: Array) : Report() - class EventsReport(events: Array) : Report() - class StopsReport(stops: Array) : Report() + class PositionsReport(val positions: Array) : Report() + class EventsReport(val events: Array) : Report() + class StopsReport(val stops: Array) : Report() } enum class ReportType { -- cgit v1.2.3