diff options
author | Isidro Henoch <imhenoch@protonmail.com> | 2021-12-28 20:40:04 -0600 |
---|---|---|
committer | Isidro Henoch <imhenoch@protonmail.com> | 2021-12-28 20:40:04 -0600 |
commit | 81fc13c407fb5c2212b28e1e485da112a2f46a8e (patch) | |
tree | a7e703f8491ec899e307992847f29b197e045a3e /androidApp/src/main/java/mx/trackermap | |
parent | b1c56ed2de98b828a903f5c79e65a77ab2ceb0c8 (diff) | |
download | etbsa-trackermap-mobile-81fc13c407fb5c2212b28e1e485da112a2f46a8e.tar.gz etbsa-trackermap-mobile-81fc13c407fb5c2212b28e1e485da112a2f46a8e.tar.bz2 etbsa-trackermap-mobile-81fc13c407fb5c2212b28e1e485da112a2f46a8e.zip |
Diaplays the events report
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap')
2 files changed, 51 insertions, 3 deletions
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<Position>) { + Log.d("UnitReportsFragment", "Displaying positions: $positions") + + binding.eventsScroll.visibility = View.GONE + binding.reportMap.visibility = View.VISIBLE + } + + private fun display(events: Array<Event>) { + 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<Stop>) { + 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<Position>) : Report() - class EventsReport(events: Array<Event>) : Report() - class StopsReport(stops: Array<Stop>) : Report() + class PositionsReport(val positions: Array<Position>) : Report() + class EventsReport(val events: Array<Event>) : Report() + class StopsReport(val stops: Array<Stop>) : Report() } enum class ReportType { |