diff options
author | Isidro Henoch <imhenoch@protonmail.com> | 2021-12-28 15:54:15 -0600 |
---|---|---|
committer | Isidro Henoch <imhenoch@protonmail.com> | 2021-12-28 15:54:15 -0600 |
commit | 085b644ef248be85ef16550917e9c705e02b8f85 (patch) | |
tree | c4b2b322ac61ef63e4ea938a39cb7963363ce41b /androidApp/src/main/java | |
parent | f37c6de28b014af0cdbf278986a668030f54cc55 (diff) | |
download | etbsa-trackermap-mobile-085b644ef248be85ef16550917e9c705e02b8f85.tar.gz etbsa-trackermap-mobile-085b644ef248be85ef16550917e9c705e02b8f85.tar.bz2 etbsa-trackermap-mobile-085b644ef248be85ef16550917e9c705e02b8f85.zip |
Adds period selection UI
Diffstat (limited to 'androidApp/src/main/java')
-rw-r--r-- | androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt | 33 |
1 files changed, 33 insertions, 0 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 dfc0493..9131728 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 @@ -5,7 +5,9 @@ import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.PopupMenu 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 org.koin.androidx.viewmodel.ext.android.viewModel @@ -48,6 +50,9 @@ class UnitReportsFragment : Fragment() { else -> UnitReportsViewModel.ReportType.STOPS } } + binding.periodButton.setOnClickListener { + showPeriodPopUp(it) + } unitReportsViewModel.reportPeriod.value = UnitReportsViewModel.ReportPeriod.DAY unitReportsViewModel.reportType.value = UnitReportsViewModel.ReportType.POSITIONS } @@ -56,5 +61,33 @@ class UnitReportsFragment : Fragment() { unitReportsViewModel.report.observe(this) { report -> Log.d("UnitReportsFragment", "Report available: $report") } + unitReportsViewModel.reportPeriod.observe(this) { period -> + Log.d("UnitReportsFragment", "Period changed: $period") + if (period == null) { + return@observe + } + + binding.periodButton.text = context?.getString( + when (period) { + UnitReportsViewModel.ReportPeriod.DAY -> R.string.day_period + UnitReportsViewModel.ReportPeriod.WEEK -> R.string.week_period + UnitReportsViewModel.ReportPeriod.MONTH -> R.string.month_period + } + ) + } + } + + private fun showPeriodPopUp(view: View) { + val popOver = PopupMenu(context, view) + popOver.menuInflater.inflate(R.menu.report_period_options, popOver.menu) + popOver.setOnMenuItemClickListener { item -> + unitReportsViewModel.reportPeriod.value = when (item.itemId) { + R.id.dayOption -> UnitReportsViewModel.ReportPeriod.DAY + R.id.weekOption -> UnitReportsViewModel.ReportPeriod.WEEK + else -> UnitReportsViewModel.ReportPeriod.MONTH + } + true + } + popOver.show() } }
\ No newline at end of file |