aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main/java/mx
diff options
context:
space:
mode:
authorIsidro Henoch <imhenoch@protonmail.com>2021-12-28 20:40:04 -0600
committerIsidro Henoch <imhenoch@protonmail.com>2021-12-28 20:40:04 -0600
commit1c2761ac6bf1b3bb6e78fc3466c09aa6f0492de0 (patch)
tree2866445a813b486e544fe0183287435f0b72ebc2 /androidApp/src/main/java/mx
parent085b644ef248be85ef16550917e9c705e02b8f85 (diff)
downloadetbsa-trackermap-mobile-1c2761ac6bf1b3bb6e78fc3466c09aa6f0492de0.tar.gz
etbsa-trackermap-mobile-1c2761ac6bf1b3bb6e78fc3466c09aa6f0492de0.tar.bz2
etbsa-trackermap-mobile-1c2761ac6bf1b3bb6e78fc3466c09aa6f0492de0.zip
Diaplays the events report
Diffstat (limited to 'androidApp/src/main/java/mx')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt48
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt6
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 {