From 7076b6445fc9f741eeaeaf476a14a3c91738792d Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Thu, 4 Mar 2021 22:10:46 +0100 Subject: [PATCH 01/30] Refactoring - Add basic setup for attendee and organizer - Renaming and re-packing for already implemented screens --- .../res/navigation/test_nav_graph.xml | 2 +- .../EventRegistrationUIModule.kt | 8 +++---- .../confirm}/ConfirmCheckInFragment.kt | 6 ++--- .../confirm}/ConfirmCheckInModule.kt | 2 +- .../confirm/ConfirmCheckInNavigation.kt | 6 +++++ .../confirm}/ConfirmCheckInViewModel.kt | 8 +++---- .../scan/ScanCheckInQrCodeFragment.kt | 6 ++--- .../scan/ScanCheckInQrCodeModule.kt | 2 +- .../scan/ScanCheckInQrCodeNavigation.kt | 6 +++++ .../scan/ScanCheckInQrCodeViewModel.kt | 8 +++---- .../checkin/ConfirmCheckInEvent.kt | 6 ----- .../scan/ScanCheckInQrCodeEvent.kt | 6 ----- .../res/layout/fragment_confrim_check_in.xml | 2 +- .../navigation/event_attendee_nav_graph.xml | 23 +++++++++++++++++++ .../navigation/event_organizer_nav_graph.xml | 6 +++++ .../src/main/res/navigation/nav_graph.xml | 20 +++------------- .../confirm}/ConfirmCheckInViewModelTest.kt | 10 ++++---- .../scan/ScanCheckInQrCodeViewModelTest.kt | 6 ++--- 18 files changed, 75 insertions(+), 58 deletions(-) rename Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/{checkin => attendee/confirm}/ConfirmCheckInFragment.kt (88%) rename Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/{checkin => attendee/confirm}/ConfirmCheckInModule.kt (88%) create mode 100644 Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInNavigation.kt rename Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/{checkin => attendee/confirm}/ConfirmCheckInViewModel.kt (84%) rename Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/{ => attendee}/scan/ScanCheckInQrCodeFragment.kt (95%) rename Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/{ => attendee}/scan/ScanCheckInQrCodeModule.kt (89%) create mode 100644 Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeNavigation.kt rename Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/{ => attendee}/scan/ScanCheckInQrCodeViewModel.kt (67%) delete mode 100644 Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/checkin/ConfirmCheckInEvent.kt delete mode 100644 Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/scan/ScanCheckInQrCodeEvent.kt create mode 100644 Corona-Warn-App/src/main/res/navigation/event_attendee_nav_graph.xml create mode 100644 Corona-Warn-App/src/main/res/navigation/event_organizer_nav_graph.xml rename Corona-Warn-App/src/test/java/de/rki/coronawarnapp/{ui/eventregistration/checkin => eventregistration/attendee/confirm}/ConfirmCheckInViewModelTest.kt (79%) rename Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ui/eventregistration/{ => attendee}/scan/ScanCheckInQrCodeViewModelTest.kt (85%) diff --git a/Corona-Warn-App/src/deviceForTesters/res/navigation/test_nav_graph.xml b/Corona-Warn-App/src/deviceForTesters/res/navigation/test_nav_graph.xml index f3101f22b74..2793401c8fe 100644 --- a/Corona-Warn-App/src/deviceForTesters/res/navigation/test_nav_graph.xml +++ b/Corona-Warn-App/src/deviceForTesters/res/navigation/test_nav_graph.xml @@ -148,7 +148,7 @@ tools:layout="@layout/fragment_test_qrcode_creation" /> diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/EventRegistrationUIModule.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/EventRegistrationUIModule.kt index e4e97fea4ad..56b80f8df05 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/EventRegistrationUIModule.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/EventRegistrationUIModule.kt @@ -2,10 +2,10 @@ package de.rki.coronawarnapp.ui.eventregistration import dagger.Module import dagger.android.ContributesAndroidInjector -import de.rki.coronawarnapp.ui.eventregistration.checkin.ConfirmCheckInFragment -import de.rki.coronawarnapp.ui.eventregistration.checkin.ConfirmCheckInModule -import de.rki.coronawarnapp.ui.eventregistration.scan.ScanCheckInQrCodeFragment -import de.rki.coronawarnapp.ui.eventregistration.scan.ScanCheckInQrCodeModule +import de.rki.coronawarnapp.ui.eventregistration.attendee.confirm.ConfirmCheckInFragment +import de.rki.coronawarnapp.ui.eventregistration.attendee.confirm.ConfirmCheckInModule +import de.rki.coronawarnapp.ui.eventregistration.attendee.scan.ScanCheckInQrCodeFragment +import de.rki.coronawarnapp.ui.eventregistration.attendee.scan.ScanCheckInQrCodeModule @Module internal abstract class EventRegistrationUIModule { diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/checkin/ConfirmCheckInFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInFragment.kt similarity index 88% rename from Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/checkin/ConfirmCheckInFragment.kt rename to Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInFragment.kt index c1389bd4136..36e56dc7924 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/checkin/ConfirmCheckInFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInFragment.kt @@ -1,4 +1,4 @@ -package de.rki.coronawarnapp.ui.eventregistration.checkin +package de.rki.coronawarnapp.ui.eventregistration.attendee.confirm import android.os.Bundle import android.view.View @@ -33,8 +33,8 @@ class ConfirmCheckInFragment : Fragment(R.layout.fragment_confrim_check_in), Aut viewModel.decodeEvent(args.encodedEvent) viewModel.navigationEvents.observe2(this) { navEvent -> when (navEvent) { - ConfirmCheckInEvent.BackEvent -> popBackStack() - ConfirmCheckInEvent.ConfirmEvent -> popBackStack() // TODO Do something else + ConfirmCheckInNavigation.BackNavigation -> popBackStack() + ConfirmCheckInNavigation.ConfirmNavigation -> popBackStack() // TODO Do something else } } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/checkin/ConfirmCheckInModule.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInModule.kt similarity index 88% rename from Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/checkin/ConfirmCheckInModule.kt rename to Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInModule.kt index 46d8d528229..fa18d2e2e0c 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/checkin/ConfirmCheckInModule.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInModule.kt @@ -1,4 +1,4 @@ -package de.rki.coronawarnapp.ui.eventregistration.checkin +package de.rki.coronawarnapp.ui.eventregistration.attendee.confirm import dagger.Binds import dagger.Module diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInNavigation.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInNavigation.kt new file mode 100644 index 00000000000..0620735ed73 --- /dev/null +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInNavigation.kt @@ -0,0 +1,6 @@ +package de.rki.coronawarnapp.ui.eventregistration.attendee.confirm + +sealed class ConfirmCheckInNavigation { + object BackNavigation : ConfirmCheckInNavigation() + object ConfirmNavigation : ConfirmCheckInNavigation() +} diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/checkin/ConfirmCheckInViewModel.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInViewModel.kt similarity index 84% rename from Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/checkin/ConfirmCheckInViewModel.kt rename to Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInViewModel.kt index 5bcac425f11..6e107129f3a 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/checkin/ConfirmCheckInViewModel.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInViewModel.kt @@ -1,4 +1,4 @@ -package de.rki.coronawarnapp.ui.eventregistration.checkin +package de.rki.coronawarnapp.ui.eventregistration.attendee.confirm import androidx.lifecycle.MutableLiveData import dagger.assisted.AssistedFactory @@ -14,7 +14,7 @@ import org.joda.time.Instant class ConfirmCheckInViewModel @AssistedInject constructor() : CWAViewModel() { private val eventLiveData = MutableLiveData() val eventData = eventLiveData - val navigationEvents = SingleLiveEvent() + val navigationEvents = SingleLiveEvent() fun decodeEvent(encodedEvent: String) = launch { // TODO Verify event(EXPOSUREAPP-5423) @@ -25,11 +25,11 @@ class ConfirmCheckInViewModel @AssistedInject constructor() : CWAViewModel() { } fun onClose() { - navigationEvents.value = ConfirmCheckInEvent.BackEvent + navigationEvents.value = ConfirmCheckInNavigation.BackNavigation } fun onConfirmEvent() { - navigationEvents.value = ConfirmCheckInEvent.ConfirmEvent + navigationEvents.value = ConfirmCheckInNavigation.ConfirmNavigation } private fun EventOuterClass.Event.toEventQrCode() = EventQRCode( diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/scan/ScanCheckInQrCodeFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeFragment.kt similarity index 95% rename from Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/scan/ScanCheckInQrCodeFragment.kt rename to Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeFragment.kt index cdf5b1045d6..6269b0d7739 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/scan/ScanCheckInQrCodeFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeFragment.kt @@ -1,4 +1,4 @@ -package de.rki.coronawarnapp.ui.eventregistration.scan +package de.rki.coronawarnapp.ui.eventregistration.attendee.scan import android.Manifest import android.content.pm.PackageManager @@ -48,8 +48,8 @@ class ScanCheckInQrCodeFragment : viewModel.navigationEvents.observe2(this) { navEvent -> when (navEvent) { - is ScanCheckInQrCodeEvent.BackEvent -> popBackStack() - is ScanCheckInQrCodeEvent.ConfirmCheckInEvent -> findNavController().navigate( + is ScanCheckInQrCodeNavigation.BackNavigation -> popBackStack() + is ScanCheckInQrCodeNavigation.ScanResultNavigation -> findNavController().navigate( navEvent.url.toUri().navUri ) } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/scan/ScanCheckInQrCodeModule.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeModule.kt similarity index 89% rename from Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/scan/ScanCheckInQrCodeModule.kt rename to Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeModule.kt index 64d7a0813e9..37349adb9a5 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/scan/ScanCheckInQrCodeModule.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeModule.kt @@ -1,4 +1,4 @@ -package de.rki.coronawarnapp.ui.eventregistration.scan +package de.rki.coronawarnapp.ui.eventregistration.attendee.scan import dagger.Binds import dagger.Module diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeNavigation.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeNavigation.kt new file mode 100644 index 00000000000..69ff3f03e6a --- /dev/null +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeNavigation.kt @@ -0,0 +1,6 @@ +package de.rki.coronawarnapp.ui.eventregistration.attendee.scan + +sealed class ScanCheckInQrCodeNavigation { + object BackNavigation : ScanCheckInQrCodeNavigation() + data class ScanResultNavigation(val url: String) : ScanCheckInQrCodeNavigation() +} diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/scan/ScanCheckInQrCodeViewModel.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeViewModel.kt similarity index 67% rename from Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/scan/ScanCheckInQrCodeViewModel.kt rename to Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeViewModel.kt index a9f29b9d39a..e1f8fe6554e 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/scan/ScanCheckInQrCodeViewModel.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeViewModel.kt @@ -1,4 +1,4 @@ -package de.rki.coronawarnapp.ui.eventregistration.scan +package de.rki.coronawarnapp.ui.eventregistration.attendee.scan import com.journeyapps.barcodescanner.BarcodeResult import dagger.assisted.AssistedFactory @@ -8,14 +8,14 @@ import de.rki.coronawarnapp.util.viewmodel.CWAViewModel import de.rki.coronawarnapp.util.viewmodel.SimpleCWAViewModelFactory class ScanCheckInQrCodeViewModel @AssistedInject constructor() : CWAViewModel() { - val navigationEvents = SingleLiveEvent() + val navigationEvents = SingleLiveEvent() fun onNavigateUp() { - navigationEvents.value = ScanCheckInQrCodeEvent.BackEvent + navigationEvents.value = ScanCheckInQrCodeNavigation.BackNavigation } fun onScanResult(barcodeResult: BarcodeResult) { - navigationEvents.value = ScanCheckInQrCodeEvent.ConfirmCheckInEvent( + navigationEvents.value = ScanCheckInQrCodeNavigation.ScanResultNavigation( barcodeResult.result.text ) } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/checkin/ConfirmCheckInEvent.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/checkin/ConfirmCheckInEvent.kt deleted file mode 100644 index 120c3ce2238..00000000000 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/checkin/ConfirmCheckInEvent.kt +++ /dev/null @@ -1,6 +0,0 @@ -package de.rki.coronawarnapp.ui.eventregistration.checkin - -sealed class ConfirmCheckInEvent { - object BackEvent : ConfirmCheckInEvent() - object ConfirmEvent : ConfirmCheckInEvent() -} diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/scan/ScanCheckInQrCodeEvent.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/scan/ScanCheckInQrCodeEvent.kt deleted file mode 100644 index d833a241f3a..00000000000 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/scan/ScanCheckInQrCodeEvent.kt +++ /dev/null @@ -1,6 +0,0 @@ -package de.rki.coronawarnapp.ui.eventregistration.scan - -sealed class ScanCheckInQrCodeEvent { - object BackEvent : ScanCheckInQrCodeEvent() - data class ConfirmCheckInEvent(val url: String) : ScanCheckInQrCodeEvent() -} diff --git a/Corona-Warn-App/src/main/res/layout/fragment_confrim_check_in.xml b/Corona-Warn-App/src/main/res/layout/fragment_confrim_check_in.xml index 5f80dbeffee..b5b111f19b1 100644 --- a/Corona-Warn-App/src/main/res/layout/fragment_confrim_check_in.xml +++ b/Corona-Warn-App/src/main/res/layout/fragment_confrim_check_in.xml @@ -4,7 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".ui.eventregistration.checkin.ConfirmCheckInFragment"> + tools:context=".ui.eventregistration.attendee.confirm.ConfirmCheckInFragment"> + + + + + + + + + \ No newline at end of file diff --git a/Corona-Warn-App/src/main/res/navigation/event_organizer_nav_graph.xml b/Corona-Warn-App/src/main/res/navigation/event_organizer_nav_graph.xml new file mode 100644 index 00000000000..35744089a26 --- /dev/null +++ b/Corona-Warn-App/src/main/res/navigation/event_organizer_nav_graph.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/Corona-Warn-App/src/main/res/navigation/nav_graph.xml b/Corona-Warn-App/src/main/res/navigation/nav_graph.xml index 7dbf6fe4d96..e73f5df586f 100644 --- a/Corona-Warn-App/src/main/res/navigation/nav_graph.xml +++ b/Corona-Warn-App/src/main/res/navigation/nav_graph.xml @@ -9,6 +9,9 @@ + + + - - - - - - - diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ui/eventregistration/checkin/ConfirmCheckInViewModelTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/eventregistration/attendee/confirm/ConfirmCheckInViewModelTest.kt similarity index 79% rename from Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ui/eventregistration/checkin/ConfirmCheckInViewModelTest.kt rename to Corona-Warn-App/src/test/java/de/rki/coronawarnapp/eventregistration/attendee/confirm/ConfirmCheckInViewModelTest.kt index bb02e9962b5..a94d7f595e7 100644 --- a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ui/eventregistration/checkin/ConfirmCheckInViewModelTest.kt +++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/eventregistration/attendee/confirm/ConfirmCheckInViewModelTest.kt @@ -1,6 +1,8 @@ -package de.rki.coronawarnapp.ui.eventregistration.checkin +package de.rki.coronawarnapp.eventregistration.attendee.confirm -import de.rki.coronawarnapp.eventregistration.checkins.qrcode.EventQRCode +import de.rki.coronawarnapp.eventregistration.qrcode.EventQRCode +import de.rki.coronawarnapp.ui.eventregistration.attendee.confirm.ConfirmCheckInNavigation +import de.rki.coronawarnapp.ui.eventregistration.attendee.confirm.ConfirmCheckInViewModel import io.kotest.matchers.shouldBe import org.joda.time.Instant import org.junit.jupiter.api.BeforeEach @@ -38,12 +40,12 @@ class ConfirmCheckInViewModelTest : BaseTest() { @Test fun onClose() { viewModel.onClose() - viewModel.navigationEvents.getOrAwaitValue() shouldBe ConfirmCheckInEvent.BackEvent + viewModel.navigationEvents.getOrAwaitValue() shouldBe ConfirmCheckInNavigation.BackNavigation } @Test fun onConfirmEvent() { viewModel.onConfirmEvent() - viewModel.navigationEvents.getOrAwaitValue() shouldBe ConfirmCheckInEvent.ConfirmEvent + viewModel.navigationEvents.getOrAwaitValue() shouldBe ConfirmCheckInNavigation.ConfirmNavigation } } diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ui/eventregistration/scan/ScanCheckInQrCodeViewModelTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeViewModelTest.kt similarity index 85% rename from Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ui/eventregistration/scan/ScanCheckInQrCodeViewModelTest.kt rename to Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeViewModelTest.kt index e855bf05570..a8d97033039 100644 --- a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ui/eventregistration/scan/ScanCheckInQrCodeViewModelTest.kt +++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeViewModelTest.kt @@ -1,4 +1,4 @@ -package de.rki.coronawarnapp.ui.eventregistration.scan +package de.rki.coronawarnapp.ui.eventregistration.attendee.scan import com.google.zxing.Result import com.journeyapps.barcodescanner.BarcodeResult @@ -25,7 +25,7 @@ class ScanCheckInQrCodeViewModelTest : BaseTest() { @Test fun `onNavigateUp goes back`() { viewModel.onNavigateUp() - viewModel.navigationEvents.getOrAwaitValue() shouldBe ScanCheckInQrCodeEvent.BackEvent + viewModel.navigationEvents.getOrAwaitValue() shouldBe ScanCheckInQrCodeNavigation.BackNavigation } @Test @@ -37,6 +37,6 @@ class ScanCheckInQrCodeViewModelTest : BaseTest() { } viewModel.onScanResult(mockedResult) viewModel.navigationEvents.getOrAwaitValue() shouldBe - ScanCheckInQrCodeEvent.ConfirmCheckInEvent("https://coronawarn.app/E1/SOME_PATH_GOES_HERE") + ScanCheckInQrCodeNavigation.ScanResultNavigation("https://coronawarn.app/E1/SOME_PATH_GOES_HERE") } } From fbb77fb6099b9db33731c2370973c7c867610fd4 Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Thu, 4 Mar 2021 22:14:20 +0100 Subject: [PATCH 02/30] Rename --- .../src/main/res/navigation/event_attendee_nav_graph.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Corona-Warn-App/src/main/res/navigation/event_attendee_nav_graph.xml b/Corona-Warn-App/src/main/res/navigation/event_attendee_nav_graph.xml index bd02e7161fd..d04cdc695da 100644 --- a/Corona-Warn-App/src/main/res/navigation/event_attendee_nav_graph.xml +++ b/Corona-Warn-App/src/main/res/navigation/event_attendee_nav_graph.xml @@ -4,9 +4,9 @@ xmlns:tools="http://schemas.android.com/tools" android:id="@+id/event_attendee_nav_graph"> Date: Thu, 4 Mar 2021 22:54:53 +0100 Subject: [PATCH 03/30] Add check in tab --- Corona-Warn-App/build.gradle | 2 ++ .../de/rki/coronawarnapp/ui/UIExtensions.kt | 1 + .../EventRegistrationUIModule.kt | 5 +++ .../attendee/checkin/CheckInsFragment.kt | 20 +++++++++++ .../attendee/checkin/CheckInsModule.kt | 18 ++++++++++ .../attendee/checkin/CheckInsViewModel.kt | 15 ++++++++ .../confirm/ConfirmCheckInFragment.kt | 2 -- .../src/main/res/drawable/ic_nav_check_in.xml | 9 +++++ .../main/res/layout/fragment_check_ins.xml | 36 +++++++++++++++++++ .../src/main/res/menu/menu_bottom_nav.xml | 5 +++ .../navigation/event_attendee_nav_graph.xml | 28 ++++++++++----- .../src/main/res/values-de/strings.xml | 2 ++ .../src/main/res/values/strings.xml | 5 ++- 13 files changed, 135 insertions(+), 13 deletions(-) create mode 100644 Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt create mode 100644 Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsModule.kt create mode 100644 Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt create mode 100644 Corona-Warn-App/src/main/res/drawable/ic_nav_check_in.xml create mode 100644 Corona-Warn-App/src/main/res/layout/fragment_check_ins.xml diff --git a/Corona-Warn-App/build.gradle b/Corona-Warn-App/build.gradle index dff24f01a83..401553b7fd6 100644 --- a/Corona-Warn-App/build.gradle +++ b/Corona-Warn-App/build.gradle @@ -294,6 +294,8 @@ configurations.all { } dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + // KOTLIN def coroutineVersion = "1.4.2" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineVersion" diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/UIExtensions.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/UIExtensions.kt index 3863ee8015d..4a8dea0d8b2 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/UIExtensions.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/UIExtensions.kt @@ -54,6 +54,7 @@ fun BottomNavigationView.setupWithNavController2( // For destinations that always show the bottom bar val inShowList = destination.id in listOf( R.id.mainFragment, + R.id.checkInsFragment, R.id.contactDiaryOverviewFragment ) // For destinations that can show or hide the bottom bar in different cases diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/EventRegistrationUIModule.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/EventRegistrationUIModule.kt index 56b80f8df05..a87ab34f421 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/EventRegistrationUIModule.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/EventRegistrationUIModule.kt @@ -2,6 +2,8 @@ package de.rki.coronawarnapp.ui.eventregistration import dagger.Module import dagger.android.ContributesAndroidInjector +import de.rki.coronawarnapp.ui.eventregistration.attendee.checkin.CheckInsFragment +import de.rki.coronawarnapp.ui.eventregistration.attendee.checkin.CheckInsModule import de.rki.coronawarnapp.ui.eventregistration.attendee.confirm.ConfirmCheckInFragment import de.rki.coronawarnapp.ui.eventregistration.attendee.confirm.ConfirmCheckInModule import de.rki.coronawarnapp.ui.eventregistration.attendee.scan.ScanCheckInQrCodeFragment @@ -15,4 +17,7 @@ internal abstract class EventRegistrationUIModule { @ContributesAndroidInjector(modules = [ConfirmCheckInModule::class]) abstract fun confirmCheckInFragment(): ConfirmCheckInFragment + + @ContributesAndroidInjector(modules = [CheckInsModule::class]) + abstract fun checkInsFragment(): CheckInsFragment } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt new file mode 100644 index 00000000000..4261d3ade2b --- /dev/null +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt @@ -0,0 +1,20 @@ +package de.rki.coronawarnapp.ui.eventregistration.attendee.checkin + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.View +import de.rki.coronawarnapp.R +import de.rki.coronawarnapp.util.di.AutoInject +import de.rki.coronawarnapp.util.viewmodel.CWAViewModelFactoryProvider +import de.rki.coronawarnapp.util.viewmodel.cwaViewModels +import javax.inject.Inject + +class CheckInsFragment : Fragment(R.layout.fragment_check_ins), AutoInject { + + @Inject lateinit var viewModelFactory: CWAViewModelFactoryProvider.Factory + private val viewModel: CheckInsViewModel by cwaViewModels { viewModelFactory } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + } +} diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsModule.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsModule.kt new file mode 100644 index 00000000000..d4b68e13ea3 --- /dev/null +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsModule.kt @@ -0,0 +1,18 @@ +package de.rki.coronawarnapp.ui.eventregistration.attendee.checkin + +import dagger.Binds +import dagger.Module +import dagger.multibindings.IntoMap +import de.rki.coronawarnapp.util.viewmodel.CWAViewModel +import de.rki.coronawarnapp.util.viewmodel.CWAViewModelFactory +import de.rki.coronawarnapp.util.viewmodel.CWAViewModelKey + +@Module +abstract class CheckInsModule { + @Binds + @IntoMap + @CWAViewModelKey(CheckInsViewModel::class) + abstract fun checkInsFragment( + factory: CheckInsViewModel.Factory + ): CWAViewModelFactory +} diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt new file mode 100644 index 00000000000..79ca7e5ccf9 --- /dev/null +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt @@ -0,0 +1,15 @@ +package de.rki.coronawarnapp.ui.eventregistration.attendee.checkin + +import dagger.assisted.AssistedFactory +import dagger.assisted.AssistedInject +import de.rki.coronawarnapp.util.coroutine.DispatcherProvider +import de.rki.coronawarnapp.util.viewmodel.CWAViewModel +import de.rki.coronawarnapp.util.viewmodel.SimpleCWAViewModelFactory + +class CheckInsViewModel @AssistedInject constructor( + private val dispatcherProvider: DispatcherProvider +) : CWAViewModel(dispatcherProvider) { + + @AssistedFactory + interface Factory : SimpleCWAViewModelFactory +} diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInFragment.kt index 36e56dc7924..fb09d9b2382 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInFragment.kt @@ -20,7 +20,6 @@ class ConfirmCheckInFragment : Fragment(R.layout.fragment_confrim_check_in), Aut private val viewModel: ConfirmCheckInViewModel by cwaViewModels { viewModelFactory } private val binding: FragmentConfrimCheckInBinding by viewBindingLazy() - private val args by navArgs() override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -30,7 +29,6 @@ class ConfirmCheckInFragment : Fragment(R.layout.fragment_confrim_check_in), Aut confirmButton.setOnClickListener { viewModel.onConfirmEvent() } } - viewModel.decodeEvent(args.encodedEvent) viewModel.navigationEvents.observe2(this) { navEvent -> when (navEvent) { ConfirmCheckInNavigation.BackNavigation -> popBackStack() diff --git a/Corona-Warn-App/src/main/res/drawable/ic_nav_check_in.xml b/Corona-Warn-App/src/main/res/drawable/ic_nav_check_in.xml new file mode 100644 index 00000000000..a0597989a33 --- /dev/null +++ b/Corona-Warn-App/src/main/res/drawable/ic_nav_check_in.xml @@ -0,0 +1,9 @@ + + + diff --git a/Corona-Warn-App/src/main/res/layout/fragment_check_ins.xml b/Corona-Warn-App/src/main/res/layout/fragment_check_ins.xml new file mode 100644 index 00000000000..bb660fd31c1 --- /dev/null +++ b/Corona-Warn-App/src/main/res/layout/fragment_check_ins.xml @@ -0,0 +1,36 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Corona-Warn-App/src/main/res/menu/menu_bottom_nav.xml b/Corona-Warn-App/src/main/res/menu/menu_bottom_nav.xml index 3c598525006..c7e211b35af 100644 --- a/Corona-Warn-App/src/main/res/menu/menu_bottom_nav.xml +++ b/Corona-Warn-App/src/main/res/menu/menu_bottom_nav.xml @@ -6,6 +6,11 @@ android:icon="@drawable/ic_nav_home" android:title="@string/bottom_nav_home_title" /> + + + android:id="@+id/event_attendee_nav_graph" + app:startDestination="@id/checkInsFragment"> - - - - + tools:layout="@layout/fragment_confrim_check_in" /> + + + + + + + \ No newline at end of file diff --git a/Corona-Warn-App/src/main/res/values-de/strings.xml b/Corona-Warn-App/src/main/res/values-de/strings.xml index 4fb850acfa2..99906b3c3f1 100644 --- a/Corona-Warn-App/src/main/res/values-de/strings.xml +++ b/Corona-Warn-App/src/main/res/values-de/strings.xml @@ -1777,6 +1777,8 @@ Startseite Tagebuch + + Check In @@ -1792,6 +1789,8 @@ "Start Screen" "Journal" + + Check In + + - + \ No newline at end of file From 0a25643065cc64cc74056ff51843468301278587 Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Fri, 5 Mar 2021 16:33:59 +0100 Subject: [PATCH 07/30] Fix import --- .../attendee/confirm/ConfirmCheckInViewModelTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/eventregistration/attendee/confirm/ConfirmCheckInViewModelTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/eventregistration/attendee/confirm/ConfirmCheckInViewModelTest.kt index a94d7f595e7..293ce7ed553 100644 --- a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/eventregistration/attendee/confirm/ConfirmCheckInViewModelTest.kt +++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/eventregistration/attendee/confirm/ConfirmCheckInViewModelTest.kt @@ -1,6 +1,6 @@ package de.rki.coronawarnapp.eventregistration.attendee.confirm -import de.rki.coronawarnapp.eventregistration.qrcode.EventQRCode +import de.rki.coronawarnapp.eventregistration.checkins.qrcode.EventQRCode import de.rki.coronawarnapp.ui.eventregistration.attendee.confirm.ConfirmCheckInNavigation import de.rki.coronawarnapp.ui.eventregistration.attendee.confirm.ConfirmCheckInViewModel import io.kotest.matchers.shouldBe From 85083d6f9a5d48c439120f27d9903b2791bb3570 Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Fri, 5 Mar 2021 16:37:07 +0100 Subject: [PATCH 08/30] lint --- .../ui/eventregistration/attendee/checkin/CheckInsFragment.kt | 3 --- .../attendee/confirm/ConfirmCheckInFragment.kt | 1 - .../attendee/scan/ScanCheckInQrCodeFragment.kt | 3 +-- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt index d0f13913c97..416e9d82ba1 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt @@ -3,13 +3,10 @@ package de.rki.coronawarnapp.ui.eventregistration.attendee.checkin import android.os.Bundle import androidx.fragment.app.Fragment import android.view.View -import androidx.navigation.fragment.findNavController -import androidx.navigation.fragment.navArgs import de.rki.coronawarnapp.R import de.rki.coronawarnapp.databinding.FragmentCheckInsBinding import de.rki.coronawarnapp.util.di.AutoInject import de.rki.coronawarnapp.util.ui.doNavigate -import de.rki.coronawarnapp.util.ui.observe2 import de.rki.coronawarnapp.util.ui.viewBindingLazy import de.rki.coronawarnapp.util.viewmodel.CWAViewModelFactoryProvider import de.rki.coronawarnapp.util.viewmodel.cwaViewModels diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInFragment.kt index 1e98f1846ad..fe5c65b371d 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInFragment.kt @@ -2,7 +2,6 @@ package de.rki.coronawarnapp.ui.eventregistration.attendee.confirm import android.os.Bundle import android.view.View -import androidx.fragment.app.DialogFragment import androidx.fragment.app.Fragment import androidx.navigation.fragment.navArgs import de.rki.coronawarnapp.R diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeFragment.kt index 0dc083d9cac..09e0c3f5ceb 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeFragment.kt @@ -51,7 +51,7 @@ class ScanCheckInQrCodeFragment : viewModel.navigationEvents.observe2(this) { navEvent -> when (navEvent) { is ScanCheckInQrCodeNavigation.BackNavigation -> popBackStack() - is ScanCheckInQrCodeNavigation.ScanResultNavigation ->{ + is ScanCheckInQrCodeNavigation.ScanResultNavigation -> { Timber.i(navEvent.url) findNavController().navigate( navEvent.url.toUri().navUri, @@ -60,7 +60,6 @@ class ScanCheckInQrCodeFragment : .build() ) } - } } } From 2f0b5039ad6b37722caf069f540b0ad45ad9423a Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Sun, 7 Mar 2021 05:43:11 +0100 Subject: [PATCH 09/30] Add FAB text --- Corona-Warn-App/src/main/res/values-de/strings.xml | 7 ++++--- Corona-Warn-App/src/main/res/values/strings.xml | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Corona-Warn-App/src/main/res/values-de/strings.xml b/Corona-Warn-App/src/main/res/values-de/strings.xml index 99906b3c3f1..060cebddcbe 100644 --- a/Corona-Warn-App/src/main/res/values-de/strings.xml +++ b/Corona-Warn-App/src/main/res/values-de/strings.xml @@ -612,9 +612,6 @@ "Die Angaben können nicht mit Ihrer Person verknüpft werden. Ihre Identität bleibt weiterhin geheim.\nDie Angaben werden statistisch ausgewertet, sie werden nicht zu einem Profil gespeichert." - - - @@ -1896,4 +1893,8 @@ OK 00:00 + + + + QR-Code scannen diff --git a/Corona-Warn-App/src/main/res/values/strings.xml b/Corona-Warn-App/src/main/res/values/strings.xml index fec2bba5987..fbecda45dbd 100644 --- a/Corona-Warn-App/src/main/res/values/strings.xml +++ b/Corona-Warn-App/src/main/res/values/strings.xml @@ -1908,4 +1908,8 @@ OK 00:00 + + + + Scan QR-Code From 70c4cb505b0335f67c8e1fe0846e939bea3656f5 Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Sun, 7 Mar 2021 05:43:28 +0100 Subject: [PATCH 10/30] Update MDC version --- Corona-Warn-App/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Corona-Warn-App/build.gradle b/Corona-Warn-App/build.gradle index dff24f01a83..fe696278452 100644 --- a/Corona-Warn-App/build.gradle +++ b/Corona-Warn-App/build.gradle @@ -307,7 +307,7 @@ dependencies { def nav_version = "2.3.3" implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.core:core-ktx:1.3.2' - implementation 'com.google.android.material:material:1.2.1' + implementation 'com.google.android.material:material:1.3.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation "androidx.navigation:navigation-fragment-ktx:$nav_version" implementation "androidx.navigation:navigation-ui-ktx:$nav_version" From 2478b6977f55006fea26004d02986a4494a23054 Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Sun, 7 Mar 2021 05:43:50 +0100 Subject: [PATCH 11/30] Catch error --- .../attendee/confirm/ConfirmCheckInViewModel.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInViewModel.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInViewModel.kt index 6e107129f3a..b7c323bd13f 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInViewModel.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInViewModel.kt @@ -17,11 +17,14 @@ class ConfirmCheckInViewModel @AssistedInject constructor() : CWAViewModel() { val navigationEvents = SingleLiveEvent() fun decodeEvent(encodedEvent: String) = launch { - // TODO Verify event(EXPOSUREAPP-5423) - // and finalise event parsing logic - val decodedEventString = encodedEvent.split(".")[0].decodeBase32() - val parseEvent = EventOuterClass.Event.parseFrom(decodedEventString.toByteArray()) - eventLiveData.postValue(parseEvent.toEventQrCode()) + try { + // TODO Verify event(EXPOSUREAPP-5423) + // and finalise event parsing logic + val parseEvent = EventOuterClass.Event.parseFrom(encodedEvent.decodeBase32().toByteArray()) + eventLiveData.postValue(parseEvent.toEventQrCode()) + } catch (e: Exception) { + e.printStackTrace() + } } fun onClose() { From 1ba716e74d72d37255f63ee08ce3e5b541422070 Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Sun, 7 Mar 2021 05:44:18 +0100 Subject: [PATCH 12/30] Animate transition --- .../attendee/checkin/CheckInsFragment.kt | 42 +++++++++++++------ .../scan/ScanCheckInQrCodeFragment.kt | 10 ++++- .../main/res/layout/fragment_check_ins.xml | 3 +- .../layout/fragment_scan_check_in_qr_code.xml | 3 +- 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt index 416e9d82ba1..c607728c434 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt @@ -3,6 +3,9 @@ package de.rki.coronawarnapp.ui.eventregistration.attendee.checkin import android.os.Bundle import androidx.fragment.app.Fragment import android.view.View +import androidx.navigation.fragment.FragmentNavigatorExtras +import androidx.navigation.fragment.findNavController +import com.google.android.material.transition.Hold import de.rki.coronawarnapp.R import de.rki.coronawarnapp.databinding.FragmentCheckInsBinding import de.rki.coronawarnapp.util.di.AutoInject @@ -18,23 +21,38 @@ class CheckInsFragment : Fragment(R.layout.fragment_check_ins), AutoInject { @Inject lateinit var viewModelFactory: CWAViewModelFactoryProvider.Factory private val viewModel: CheckInsViewModel by cwaViewModels { viewModelFactory } private val binding: FragmentCheckInsBinding by viewBindingLazy() + private val encodedEvent: String? + get() = CheckInsFragmentArgs + .fromBundle(requireArguments()) + .encodedEvent + .also { + requireArguments().clear() + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + exitTransition = Hold() + } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - binding.scanCheckinQrcodeFab.setOnClickListener { - doNavigate( - CheckInsFragmentDirections.actionCheckInsFragmentToScanCheckInQrCodeFragment() - ) - } - CheckInsFragmentArgs - .fromBundle(requireArguments()) - .encodedEvent?.let { - Timber.i("encodedEvent:$it") - doNavigate( - CheckInsFragmentDirections.actionCheckInsFragmentToConfirmCheckInFragment(it) + with(binding.scanCheckinQrcodeFab) { + setOnClickListener { + findNavController().navigate( + R.id.action_checkInsFragment_to_scanCheckInQrCodeFragment, + null, + null, + FragmentNavigatorExtras(this to transitionName) ) - requireArguments().clear() } + } + + encodedEvent?.let { + Timber.i("encodedEvent:$it") + doNavigate( + CheckInsFragmentDirections.actionCheckInsFragmentToConfirmCheckInFragment(it) + ) + } } } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeFragment.kt index 09e0c3f5ceb..7eb6c913ccf 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeFragment.kt @@ -3,12 +3,13 @@ package de.rki.coronawarnapp.ui.eventregistration.attendee.scan import android.Manifest import android.content.pm.PackageManager import android.os.Bundle -import androidx.fragment.app.Fragment import android.view.View import android.view.accessibility.AccessibilityEvent.TYPE_ANNOUNCEMENT import androidx.core.net.toUri +import androidx.fragment.app.Fragment import androidx.navigation.NavOptions import androidx.navigation.fragment.findNavController +import com.google.android.material.transition.MaterialContainerTransform import com.google.zxing.BarcodeFormat import com.journeyapps.barcodescanner.DefaultDecoderFactory import de.rki.coronawarnapp.R @@ -35,6 +36,13 @@ class ScanCheckInQrCodeFragment : private val binding: FragmentScanCheckInQrCodeBinding by viewBindingLazy() private var showsPermissionDialog = false + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + sharedElementEnterTransition = MaterialContainerTransform() + sharedElementReturnTransition = MaterialContainerTransform() + } + override fun onViewCreated( view: View, savedInstanceState: Bundle? diff --git a/Corona-Warn-App/src/main/res/layout/fragment_check_ins.xml b/Corona-Warn-App/src/main/res/layout/fragment_check_ins.xml index bb660fd31c1..1053da359f4 100644 --- a/Corona-Warn-App/src/main/res/layout/fragment_check_ins.xml +++ b/Corona-Warn-App/src/main/res/layout/fragment_check_ins.xml @@ -28,7 +28,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="@dimen/spacing_normal" - android:text="Scan Qr code" + android:text="@string/scan_check_in_qr_code" + android:transitionName="shared_element_container" app:icon="@drawable/ic_nav_check_in" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" /> diff --git a/Corona-Warn-App/src/main/res/layout/fragment_scan_check_in_qr_code.xml b/Corona-Warn-App/src/main/res/layout/fragment_scan_check_in_qr_code.xml index aa0768d4aed..b14d08f71b9 100644 --- a/Corona-Warn-App/src/main/res/layout/fragment_scan_check_in_qr_code.xml +++ b/Corona-Warn-App/src/main/res/layout/fragment_scan_check_in_qr_code.xml @@ -4,7 +4,8 @@ android:id="@+id/check_in_qr_code_scan_container" android:layout_width="match_parent" android:layout_height="match_parent" - android:contentDescription="@string/submission_qr_code_scan_title"> + android:contentDescription="@string/submission_qr_code_scan_title" + android:transitionName="shared_element_container"> Date: Sun, 7 Mar 2021 05:53:12 +0100 Subject: [PATCH 13/30] Add space --- .../ui/eventregistration/attendee/checkin/CheckInsFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt index c607728c434..e9926ad1abf 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt @@ -49,7 +49,7 @@ class CheckInsFragment : Fragment(R.layout.fragment_check_ins), AutoInject { } encodedEvent?.let { - Timber.i("encodedEvent:$it") + Timber.i("encodedEvent: $it") doNavigate( CheckInsFragmentDirections.actionCheckInsFragmentToConfirmCheckInFragment(it) ) From 267a3d31c615efcf9a90075d8f02107b5f4cb584 Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Sun, 7 Mar 2021 12:57:10 +0100 Subject: [PATCH 14/30] Connect check-in flow --- .../EventRegistrationModule.kt | 9 ++++-- .../checkins/qrcode/DefaultQRCodeVerifier.kt | 15 ++++++++++ .../checkins/qrcode/EventQRCode.kt | 7 ++--- .../checkins/qrcode/QRCodeVerifier.kt | 2 +- .../attendee/checkin/CheckInsFragment.kt | 15 ++++++++-- .../attendee/checkin/CheckInsViewModel.kt | 23 ++++++++++++++- .../attendee/checkin/VerifiedEvent.kt | 28 +++++++++++++++++++ .../confirm/ConfirmCheckInFragment.kt | 21 ++++---------- .../confirm/ConfirmCheckInViewModel.kt | 21 -------------- .../navigation/event_attendee_nav_graph.xml | 5 ++-- .../confirm/ConfirmCheckInViewModelTest.kt | 16 ----------- 11 files changed, 95 insertions(+), 67 deletions(-) create mode 100644 Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifier.kt create mode 100644 Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEvent.kt diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/EventRegistrationModule.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/EventRegistrationModule.kt index b9234ea0f4f..65ab558e125 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/EventRegistrationModule.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/EventRegistrationModule.kt @@ -1,9 +1,12 @@ package de.rki.coronawarnapp.eventregistration +import dagger.Binds import dagger.Module +import de.rki.coronawarnapp.eventregistration.checkins.qrcode.DefaultQRCodeVerifier +import de.rki.coronawarnapp.eventregistration.checkins.qrcode.QRCodeVerifier -@Suppress("EmptyClassBlock") @Module -class EventRegistrationModule { - // TODO +abstract class EventRegistrationModule { + @Binds + abstract fun qrCodeVerifier(qrCodeVerifier: DefaultQRCodeVerifier): QRCodeVerifier } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifier.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifier.kt new file mode 100644 index 00000000000..2ffd4b8e525 --- /dev/null +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifier.kt @@ -0,0 +1,15 @@ +package de.rki.coronawarnapp.eventregistration.checkins.qrcode + +import de.rki.coronawarnapp.eventregistration.common.decodeBase32 +import de.rki.coronawarnapp.server.protocols.internal.evreg.EventOuterClass +import javax.inject.Inject + +class DefaultQRCodeVerifier @Inject constructor() : QRCodeVerifier { + override suspend fun verify(encodedEvent: String): EventQRCode { + // TODO Implement verification + // For now just parse + return EventQRCode( + event = EventOuterClass.Event.parseFrom(encodedEvent.decodeBase32().toByteArray()) + ) + } +} diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/EventQRCode.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/EventQRCode.kt index 69edb248ef9..3c913a275f6 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/EventQRCode.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/EventQRCode.kt @@ -1,10 +1,7 @@ package de.rki.coronawarnapp.eventregistration.checkins.qrcode -import org.joda.time.Instant +import de.rki.coronawarnapp.server.protocols.internal.evreg.EventOuterClass data class EventQRCode( - val guid: String, - val description: String? = null, - val start: Instant? = null, - val end: Instant? = null, + val event: EventOuterClass.Event ) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/QRCodeVerifier.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/QRCodeVerifier.kt index 910b6237eb3..4ae74a1548a 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/QRCodeVerifier.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/QRCodeVerifier.kt @@ -2,5 +2,5 @@ package de.rki.coronawarnapp.eventregistration.checkins.qrcode interface QRCodeVerifier { - suspend fun verify(code: EventQRCode): Boolean + suspend fun verify(encodedEvent: String): EventQRCode } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt index e9926ad1abf..0c601fb4f17 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt @@ -5,11 +5,14 @@ import androidx.fragment.app.Fragment import android.view.View import androidx.navigation.fragment.FragmentNavigatorExtras import androidx.navigation.fragment.findNavController +import androidx.navigation.fragment.navArgs import com.google.android.material.transition.Hold +import com.google.android.play.core.internal.by import de.rki.coronawarnapp.R import de.rki.coronawarnapp.databinding.FragmentCheckInsBinding import de.rki.coronawarnapp.util.di.AutoInject import de.rki.coronawarnapp.util.ui.doNavigate +import de.rki.coronawarnapp.util.ui.observe2 import de.rki.coronawarnapp.util.ui.viewBindingLazy import de.rki.coronawarnapp.util.viewmodel.CWAViewModelFactoryProvider import de.rki.coronawarnapp.util.viewmodel.cwaViewModels @@ -21,6 +24,8 @@ class CheckInsFragment : Fragment(R.layout.fragment_check_ins), AutoInject { @Inject lateinit var viewModelFactory: CWAViewModelFactoryProvider.Factory private val viewModel: CheckInsViewModel by cwaViewModels { viewModelFactory } private val binding: FragmentCheckInsBinding by viewBindingLazy() + + // Encoded event is a one-time use data and then cleared private val encodedEvent: String? get() = CheckInsFragmentArgs .fromBundle(requireArguments()) @@ -49,9 +54,15 @@ class CheckInsFragment : Fragment(R.layout.fragment_check_ins), AutoInject { } encodedEvent?.let { - Timber.i("encodedEvent: $it") + Timber.i("onViewCreated") + viewModel.verifyEvent(it) + } + + viewModel.navigationData.observe2(this) { doNavigate( - CheckInsFragmentDirections.actionCheckInsFragmentToConfirmCheckInFragment(it) + CheckInsFragmentDirections.actionCheckInsFragmentToConfirmCheckInFragment( + it.toVerifiedEvent() + ) ) } } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt index 79ca7e5ccf9..ad21d15f380 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt @@ -2,14 +2,35 @@ package de.rki.coronawarnapp.ui.eventregistration.attendee.checkin import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject +import de.rki.coronawarnapp.eventregistration.checkins.qrcode.EventQRCode +import de.rki.coronawarnapp.eventregistration.checkins.qrcode.QRCodeVerifier +import de.rki.coronawarnapp.exception.ExceptionCategory +import de.rki.coronawarnapp.exception.reporting.report import de.rki.coronawarnapp.util.coroutine.DispatcherProvider +import de.rki.coronawarnapp.util.ui.SingleLiveEvent import de.rki.coronawarnapp.util.viewmodel.CWAViewModel import de.rki.coronawarnapp.util.viewmodel.SimpleCWAViewModelFactory +import timber.log.Timber class CheckInsViewModel @AssistedInject constructor( - private val dispatcherProvider: DispatcherProvider + dispatcherProvider: DispatcherProvider, + private val qrCodeVerifier: QRCodeVerifier, ) : CWAViewModel(dispatcherProvider) { + val navigationData = SingleLiveEvent() + + fun verifyEvent(encodedEvent: String) = launch { + try { + Timber.i("encodedEvent: $encodedEvent") + val eventQRCode = qrCodeVerifier.verify(encodedEvent) + Timber.i("eventQRCode: $eventQRCode") + navigationData.postValue(eventQRCode) + } catch (e: Exception) { + Timber.d(e, "Event verification failed") + e.report(ExceptionCategory.INTERNAL) + } + } + @AssistedFactory interface Factory : SimpleCWAViewModelFactory } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEvent.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEvent.kt new file mode 100644 index 00000000000..1278f5c54cc --- /dev/null +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEvent.kt @@ -0,0 +1,28 @@ +package de.rki.coronawarnapp.ui.eventregistration.attendee.checkin + +import android.os.Parcelable +import de.rki.coronawarnapp.eventregistration.checkins.qrcode.EventQRCode +import kotlinx.parcelize.Parcelize +import org.joda.time.Instant + +@Parcelize +data class VerifiedEvent( + val guid: String, + val description: String?, + val start: Instant?, + val end: Instant?, + val defaultCheckInLengthInMinutes: Int +) : Parcelable + +fun EventQRCode.toVerifiedEvent() = with(event) { + VerifiedEvent( + guid = String(guid.toByteArray()), + start = start.instant(), + end = end.instant(), + description = description, + defaultCheckInLengthInMinutes = defaultCheckInLengthInMinutes + ) +} + +private fun Int.instant() = + if (this == 0) null else Instant.ofEpochMilli(this.toLong()) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInFragment.kt index fe5c65b371d..35ee011cae4 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInFragment.kt @@ -12,14 +12,13 @@ import de.rki.coronawarnapp.util.ui.popBackStack import de.rki.coronawarnapp.util.ui.viewBindingLazy import de.rki.coronawarnapp.util.viewmodel.CWAViewModelFactoryProvider import de.rki.coronawarnapp.util.viewmodel.cwaViewModels -import timber.log.Timber import javax.inject.Inject class ConfirmCheckInFragment : Fragment(R.layout.fragment_confirm_check_in), AutoInject { @Inject lateinit var viewModelFactory: CWAViewModelFactoryProvider.Factory - private val viewModel: ConfirmCheckInViewModel by cwaViewModels { viewModelFactory } + private val viewModel: ConfirmCheckInViewModel by cwaViewModels { viewModelFactory } private val binding: FragmentConfirmCheckInBinding by viewBindingLazy() private val args by navArgs() @@ -29,26 +28,18 @@ class ConfirmCheckInFragment : Fragment(R.layout.fragment_confirm_check_in), Aut with(binding) { toolbar.setNavigationOnClickListener { viewModel.onClose() } confirmButton.setOnClickListener { viewModel.onConfirmEvent() } + // TODO bind final UI + eventGuid.text = "GUID: %s".format(args.event.guid) + startTime.text = "Start time: %s".format(args.event.start) + endTime.text = "End time: %s".format(args.event.end) + description.text = "Description: %s".format(args.event.description) } - Timber.tag("DEEP").i(args.encodedEvent) - viewModel.decodeEvent(args.encodedEvent) viewModel.navigationEvents.observe2(this) { navEvent -> - Timber.tag("DEEP").i(navEvent.toString()) when (navEvent) { ConfirmCheckInNavigation.BackNavigation -> popBackStack() ConfirmCheckInNavigation.ConfirmNavigation -> popBackStack() // TODO Do something else } } - - // TODO bind data to actual UI - viewModel.eventData.observe2(this) { - with(binding) { - eventGuid.text = "GUID: %s".format(it.guid) - startTime.text = "Start time: %s".format(it.start) - endTime.text = "End time: %s".format(it.end) - description.text = "Description: %s".format(it.description) - } - } } } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInViewModel.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInViewModel.kt index b7c323bd13f..d1225e9cc9d 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInViewModel.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInViewModel.kt @@ -4,29 +4,15 @@ import androidx.lifecycle.MutableLiveData import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import de.rki.coronawarnapp.eventregistration.checkins.qrcode.EventQRCode -import de.rki.coronawarnapp.eventregistration.common.decodeBase32 -import de.rki.coronawarnapp.server.protocols.internal.evreg.EventOuterClass import de.rki.coronawarnapp.ui.SingleLiveEvent import de.rki.coronawarnapp.util.viewmodel.CWAViewModel import de.rki.coronawarnapp.util.viewmodel.SimpleCWAViewModelFactory -import org.joda.time.Instant class ConfirmCheckInViewModel @AssistedInject constructor() : CWAViewModel() { private val eventLiveData = MutableLiveData() val eventData = eventLiveData val navigationEvents = SingleLiveEvent() - fun decodeEvent(encodedEvent: String) = launch { - try { - // TODO Verify event(EXPOSUREAPP-5423) - // and finalise event parsing logic - val parseEvent = EventOuterClass.Event.parseFrom(encodedEvent.decodeBase32().toByteArray()) - eventLiveData.postValue(parseEvent.toEventQrCode()) - } catch (e: Exception) { - e.printStackTrace() - } - } - fun onClose() { navigationEvents.value = ConfirmCheckInNavigation.BackNavigation } @@ -35,13 +21,6 @@ class ConfirmCheckInViewModel @AssistedInject constructor() : CWAViewModel() { navigationEvents.value = ConfirmCheckInNavigation.ConfirmNavigation } - private fun EventOuterClass.Event.toEventQrCode() = EventQRCode( - guid = String(guid.toByteArray()), - description = description, - start = Instant.ofEpochMilli(start.toLong()), - end = Instant.ofEpochMilli(end.toLong()) - ) - @AssistedFactory interface Factory : SimpleCWAViewModelFactory } diff --git a/Corona-Warn-App/src/main/res/navigation/event_attendee_nav_graph.xml b/Corona-Warn-App/src/main/res/navigation/event_attendee_nav_graph.xml index 8b1561615db..7a326f919f7 100644 --- a/Corona-Warn-App/src/main/res/navigation/event_attendee_nav_graph.xml +++ b/Corona-Warn-App/src/main/res/navigation/event_attendee_nav_graph.xml @@ -9,10 +9,9 @@ android:name="de.rki.coronawarnapp.ui.eventregistration.attendee.confirm.ConfirmCheckInFragment" android:label="fragment_confirm_check_in" tools:layout="@layout/fragment_confirm_check_in"> - + android:name="event" + app:argType="de.rki.coronawarnapp.ui.eventregistration.attendee.checkin.VerifiedEvent" /> Date: Sun, 7 Mar 2021 15:52:00 +0100 Subject: [PATCH 15/30] Parse signed event --- .../checkins/qrcode/DefaultQRCodeVerifier.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifier.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifier.kt index 2ffd4b8e525..a9034df43e1 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifier.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifier.kt @@ -2,14 +2,17 @@ package de.rki.coronawarnapp.eventregistration.checkins.qrcode import de.rki.coronawarnapp.eventregistration.common.decodeBase32 import de.rki.coronawarnapp.server.protocols.internal.evreg.EventOuterClass +import de.rki.coronawarnapp.server.protocols.internal.evreg.SignedEventOuterClass +import timber.log.Timber import javax.inject.Inject class DefaultQRCodeVerifier @Inject constructor() : QRCodeVerifier { override suspend fun verify(encodedEvent: String): EventQRCode { + Timber.i("encodedEvent: $encodedEvent") // TODO Implement verification // For now just parse return EventQRCode( - event = EventOuterClass.Event.parseFrom(encodedEvent.decodeBase32().toByteArray()) + event = SignedEventOuterClass.SignedEvent.parseFrom(encodedEvent.decodeBase32().toByteArray()).event ) } } From 20235be87c53bb748f516a31f5c2d8c0bf568a10 Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Sun, 7 Mar 2021 16:18:17 +0100 Subject: [PATCH 16/30] Import SingleLiveData --- .../attendee/confirm/ConfirmCheckInViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInViewModel.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInViewModel.kt index d1225e9cc9d..06c8398a1f9 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInViewModel.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInViewModel.kt @@ -4,7 +4,7 @@ import androidx.lifecycle.MutableLiveData import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import de.rki.coronawarnapp.eventregistration.checkins.qrcode.EventQRCode -import de.rki.coronawarnapp.ui.SingleLiveEvent +import de.rki.coronawarnapp.util.ui.SingleLiveEvent import de.rki.coronawarnapp.util.viewmodel.CWAViewModel import de.rki.coronawarnapp.util.viewmodel.SimpleCWAViewModelFactory From 00d24a0965bcf0d7d44ab640f86a82c4723c610a Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Sun, 7 Mar 2021 17:40:34 +0100 Subject: [PATCH 17/30] Add test --- .../attendee/checkin/VerifiedEventKtTest.kt | 42 +++++++++++++++++++ .../attendee/checkin/VerifiedEvent.kt | 4 +- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEventKtTest.kt diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEventKtTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEventKtTest.kt new file mode 100644 index 00000000000..65d58bfb84e --- /dev/null +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEventKtTest.kt @@ -0,0 +1,42 @@ +package de.rki.coronawarnapp.ui.eventregistration.attendee.checkin + +import de.rki.coronawarnapp.eventregistration.checkins.qrcode.EventQRCode +import de.rki.coronawarnapp.eventregistration.common.decodeBase32 +import de.rki.coronawarnapp.server.protocols.internal.evreg.SignedEventOuterClass +import io.kotest.assertions.throwables.shouldNotThrowAny +import io.kotest.matchers.shouldBe +import org.joda.time.Instant +import org.junit.After +import org.junit.Before +import org.junit.Test + +import org.junit.Assert.* +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import testhelpers.BaseTestInstrumentation + +@RunWith(JUnit4::class) +class VerifiedEventKtTest : BaseTestInstrumentation() { + + @Test + fun testVerifiedEventMapping() { + shouldNotThrowAny { + val signedEvent = SignedEventOuterClass.SignedEvent.parseFrom(DECODED_EVENT.decodeBase32().toByteArray()) + val verifiedEvent = EventQRCode(event = signedEvent.event).toVerifiedEvent() + verifiedEvent shouldBe VerifiedEvent( + guid = "Yc48RFi/hfyXKlF4DEDs/w==", + start = Instant.parse("1970-01-01T00:44:47.955Z"), + end = Instant.parse("1970-01-01T00:44:47.991Z"), + defaultCheckInLengthInMinutes = 30, + description = "CWA Launch Party" + ) + } + } + + companion object { + private const val DECODED_EVENT = + "BIYAUEDBZY6EIWF7QX6JOKSRPAGEB3H7CIIEGV2BEBGGC5LOMNUCAUDBOJ2HSGGTQ6SACIHXQ6SAC" + + "KA6CJEDARQCEEAPHGEZ5JI2K2T422L5U3SMZY5DGCPUZ2RQACAYEJ3HQYMAFFBU2SQCEEAJAUCJSQJ7WDM6" + + "75MCMOD3L2UL7ECJU7TYERH23B746RQTABO3CTI=" + } +} \ No newline at end of file diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEvent.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEvent.kt index 1278f5c54cc..885721b9f22 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEvent.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEvent.kt @@ -3,6 +3,7 @@ package de.rki.coronawarnapp.ui.eventregistration.attendee.checkin import android.os.Parcelable import de.rki.coronawarnapp.eventregistration.checkins.qrcode.EventQRCode import kotlinx.parcelize.Parcelize +import okio.ByteString.Companion.toByteString import org.joda.time.Instant @Parcelize @@ -15,8 +16,9 @@ data class VerifiedEvent( ) : Parcelable fun EventQRCode.toVerifiedEvent() = with(event) { + VerifiedEvent( - guid = String(guid.toByteArray()), + guid = guid.toByteArray().toByteString().base64(), start = start.instant(), end = end.instant(), description = description, From c1e3101265996ec527c9396c17391ed726104756 Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Sun, 7 Mar 2021 18:04:42 +0100 Subject: [PATCH 18/30] Clean-up --- .../attendee/checkin/VerifiedEventKtTest.kt | 6 +----- .../checkins/qrcode/DefaultQRCodeVerifier.kt | 1 - .../attendee/checkin/CheckInsFragment.kt | 15 +++++---------- .../attendee/checkin/CheckInsViewModel.kt | 4 ++-- .../attendee/checkin/VerifiedEvent.kt | 1 - .../attendee/confirm/ConfirmCheckInFragment.kt | 5 ++++- 6 files changed, 12 insertions(+), 20 deletions(-) diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEventKtTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEventKtTest.kt index 65d58bfb84e..08f9adb8de7 100644 --- a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEventKtTest.kt +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEventKtTest.kt @@ -6,11 +6,7 @@ import de.rki.coronawarnapp.server.protocols.internal.evreg.SignedEventOuterClas import io.kotest.assertions.throwables.shouldNotThrowAny import io.kotest.matchers.shouldBe import org.joda.time.Instant -import org.junit.After -import org.junit.Before import org.junit.Test - -import org.junit.Assert.* import org.junit.runner.RunWith import org.junit.runners.JUnit4 import testhelpers.BaseTestInstrumentation @@ -39,4 +35,4 @@ class VerifiedEventKtTest : BaseTestInstrumentation() { "KA6CJEDARQCEEAPHGEZ5JI2K2T422L5U3SMZY5DGCPUZ2RQACAYEJ3HQYMAFFBU2SQCEEAJAUCJSQJ7WDM6" + "75MCMOD3L2UL7ECJU7TYERH23B746RQTABO3CTI=" } -} \ No newline at end of file +} diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifier.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifier.kt index a9034df43e1..48bb0508e3c 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifier.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifier.kt @@ -1,7 +1,6 @@ package de.rki.coronawarnapp.eventregistration.checkins.qrcode import de.rki.coronawarnapp.eventregistration.common.decodeBase32 -import de.rki.coronawarnapp.server.protocols.internal.evreg.EventOuterClass import de.rki.coronawarnapp.server.protocols.internal.evreg.SignedEventOuterClass import timber.log.Timber import javax.inject.Inject diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt index 0c601fb4f17..bfc610224b5 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt @@ -7,7 +7,6 @@ import androidx.navigation.fragment.FragmentNavigatorExtras import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs import com.google.android.material.transition.Hold -import com.google.android.play.core.internal.by import de.rki.coronawarnapp.R import de.rki.coronawarnapp.databinding.FragmentCheckInsBinding import de.rki.coronawarnapp.util.di.AutoInject @@ -27,12 +26,9 @@ class CheckInsFragment : Fragment(R.layout.fragment_check_ins), AutoInject { // Encoded event is a one-time use data and then cleared private val encodedEvent: String? - get() = CheckInsFragmentArgs - .fromBundle(requireArguments()) + get() = navArgs().value .encodedEvent - .also { - requireArguments().clear() - } + .also { arguments?.clear() } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -58,11 +54,10 @@ class CheckInsFragment : Fragment(R.layout.fragment_check_ins), AutoInject { viewModel.verifyEvent(it) } - viewModel.navigationData.observe2(this) { + viewModel.navigationRoutes.observe2(this) { doNavigate( - CheckInsFragmentDirections.actionCheckInsFragmentToConfirmCheckInFragment( - it.toVerifiedEvent() - ) + CheckInsFragmentDirections + .actionCheckInsFragmentToConfirmCheckInFragment(it.toVerifiedEvent()) ) } } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt index ad21d15f380..96c2d66876b 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt @@ -17,14 +17,14 @@ class CheckInsViewModel @AssistedInject constructor( private val qrCodeVerifier: QRCodeVerifier, ) : CWAViewModel(dispatcherProvider) { - val navigationData = SingleLiveEvent() + val navigationRoutes = SingleLiveEvent() fun verifyEvent(encodedEvent: String) = launch { try { Timber.i("encodedEvent: $encodedEvent") val eventQRCode = qrCodeVerifier.verify(encodedEvent) Timber.i("eventQRCode: $eventQRCode") - navigationData.postValue(eventQRCode) + navigationRoutes.postValue(eventQRCode) } catch (e: Exception) { Timber.d(e, "Event verification failed") e.report(ExceptionCategory.INTERNAL) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEvent.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEvent.kt index 885721b9f22..0030677d42b 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEvent.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEvent.kt @@ -16,7 +16,6 @@ data class VerifiedEvent( ) : Parcelable fun EventQRCode.toVerifiedEvent() = with(event) { - VerifiedEvent( guid = guid.toByteArray().toByteString().base64(), start = start.instant(), diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInFragment.kt index 35ee011cae4..dfe5521a50e 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInFragment.kt @@ -38,7 +38,10 @@ class ConfirmCheckInFragment : Fragment(R.layout.fragment_confirm_check_in), Aut viewModel.navigationEvents.observe2(this) { navEvent -> when (navEvent) { ConfirmCheckInNavigation.BackNavigation -> popBackStack() - ConfirmCheckInNavigation.ConfirmNavigation -> popBackStack() // TODO Do something else + ConfirmCheckInNavigation.ConfirmNavigation -> { + // TODO Navigate to the rightful destination + popBackStack() + } } } } From 498b447093bfe3f302414ba76eede6a58385159f Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Mon, 8 Mar 2021 09:28:04 +0100 Subject: [PATCH 19/30] Delete ConfirmCheckInViewModel.kt --- .../ui/eventregistration/checkin/ConfirmCheckInViewModel.kt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/checkin/ConfirmCheckInViewModel.kt diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/checkin/ConfirmCheckInViewModel.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/checkin/ConfirmCheckInViewModel.kt deleted file mode 100644 index e69de29bb2d..00000000000 From b18f5f70a0b67d6620207bc782b59d7386ed28f1 Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Mon, 8 Mar 2021 19:08:27 +0100 Subject: [PATCH 20/30] Support new deeplink host and requirements --- .../java/de/rki/coronawarnapp/util/UriTest.kt | 45 ------------------- .../deviceForTesters/res/values/strings.xml | 2 +- Corona-Warn-App/src/main/AndroidManifest.xml | 7 +-- .../checkins/qrcode/UriValidator.kt | 24 ++++++++++ .../attendee/checkin/CheckInsFragment.kt | 13 ++++-- .../attendee/checkin/CheckInsViewModel.kt | 4 +- .../scan/ScanCheckInQrCodeFragment.kt | 7 ++- .../scan/ScanCheckInQrCodeNavigation.kt | 2 +- .../rki/coronawarnapp/ui/main/MainActivity.kt | 5 +-- .../java/de/rki/coronawarnapp/util/Uri.kt | 16 ------- .../navigation/event_attendee_nav_graph.xml | 4 +- .../checkins/qrcode/InvalidUrlProvider.kt | 32 +++++++++++++ .../checkins/qrcode/UriValidatorTest.kt | 29 ++++++++++++ .../checkins/qrcode/ValidUrlProvider.kt | 23 ++++++++++ 14 files changed, 131 insertions(+), 82 deletions(-) delete mode 100644 Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/util/UriTest.kt create mode 100644 Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/UriValidator.kt delete mode 100644 Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/Uri.kt create mode 100644 Corona-Warn-App/src/test/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/InvalidUrlProvider.kt create mode 100644 Corona-Warn-App/src/test/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/UriValidatorTest.kt create mode 100644 Corona-Warn-App/src/test/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/ValidUrlProvider.kt diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/util/UriTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/util/UriTest.kt deleted file mode 100644 index 300fc6c3289..00000000000 --- a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/util/UriTest.kt +++ /dev/null @@ -1,45 +0,0 @@ -package de.rki.coronawarnapp.util - -import androidx.core.net.toUri -import io.kotest.matchers.shouldBe -import org.junit.Test -import testhelpers.BaseTestInstrumentation - -class UriTest : BaseTestInstrumentation() { - - @Test - fun navUriConvertsSchemeAndAuthorityToLowercase() { - val uri = "HTTPS://CORONAWARN.APP/E1/SOME_PATH_GOES_HERE".toUri() - uri.navUri.toString() shouldBe "https://coronawarn.app/E1/SOME_PATH_GOES_HERE" - - val uri2 = "HTTPS://CORONAWARN.APP/e1/some_path_goes_here".toUri() - uri2.navUri.toString() shouldBe "https://coronawarn.app/e1/some_path_goes_here" - } - - @Test - fun navUriDoesNotChangePath() { - val uri = "https://coronawarn.app/E1/SOME_PATH_GOES_HERE".toUri() - uri.navUri.toString() shouldBe "https://coronawarn.app/E1/SOME_PATH_GOES_HERE" - - val uri2 = "https://coronawarn.app/e1/some_path_goes_here".toUri() - uri2.navUri.toString() shouldBe "https://coronawarn.app/e1/some_path_goes_here" - } - - @Test - fun navUriConvertsSchemeAndAuthorityToLowercaseWithWWW() { - val uri = "HTTPS://WWW.CORONAWARN.APP/E1/SOME_PATH_GOES_HERE".toUri() - uri.navUri.toString() shouldBe "https://www.coronawarn.app/E1/SOME_PATH_GOES_HERE" - - val uri2 = "HTTPS://WWW.CORONAWARN.APP/e1/some_path_goes_here".toUri() - uri2.navUri.toString() shouldBe "https://www.coronawarn.app/e1/some_path_goes_here" - } - - @Test - fun navUriDoesNotChangePathWithWWW() { - val uri = "https://www.coronawarn.app/E1/SOME_PATH_GOES_HERE".toUri() - uri.navUri.toString() shouldBe "https://www.coronawarn.app/E1/SOME_PATH_GOES_HERE" - - val uri2 = "https://www.coronawarn.app/e1/some_path_goes_here".toUri() - uri2.navUri.toString() shouldBe "https://www.coronawarn.app/e1/some_path_goes_here" - } -} diff --git a/Corona-Warn-App/src/deviceForTesters/res/values/strings.xml b/Corona-Warn-App/src/deviceForTesters/res/values/strings.xml index 8a8f0e4c755..80f10691d6b 100644 --- a/Corona-Warn-App/src/deviceForTesters/res/values/strings.xml +++ b/Corona-Warn-App/src/deviceForTesters/res/values/strings.xml @@ -1,4 +1,4 @@ - "HTTPS://CORONAWARN.APP/E1/BIPEY33SMVWSA2LQON2W2IDEN5WG64RAONUXIIDBNVSXILBAMNXRBCM4UQARRKM6UQASAHRKCC7CTDWGQ4JCO7RVZSWVIMQK4UPA.GBCAEIA7TEORBTUA25QHBOCWT26BCA5PORBS2E4FFWMJ3UU3P6SXOL7SHUBCA7UEZBDDQ2R6VRJH7WBJKVF7GZYJA6YMRN27IPEP7NKGGJSWX3XQ" + "HTTPS://E.CORONAWARN.APP/C1/BIYAUEDBZY6EIWF7QX6JOKSRPAGEB3H7CIIEGV2BEBGGC5LOMNUCAUDBOJ2HSGGTQ6SACIHXQ6SACKA6CJEDARQCEEAPHGEZ5JI2K2T422L5U3SMZY5DGCPUZ2RQACAYEJ3HQYMAFFBU2SQCEEAJAUCJSQJ7WDM675MCMOD3L2UL7ECJU7TYERH23B746RQTABO3CTI=" \ No newline at end of file diff --git a/Corona-Warn-App/src/main/AndroidManifest.xml b/Corona-Warn-App/src/main/AndroidManifest.xml index e70468167e6..2a68d8aca15 100644 --- a/Corona-Warn-App/src/main/AndroidManifest.xml +++ b/Corona-Warn-App/src/main/AndroidManifest.xml @@ -69,12 +69,7 @@ - - diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/UriValidator.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/UriValidator.kt new file mode 100644 index 00000000000..48af21b1416 --- /dev/null +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/UriValidator.kt @@ -0,0 +1,24 @@ +package de.rki.coronawarnapp.eventregistration.checkins.qrcode + +import java.net.URI + +private const val SCHEME = "https" +private const val AUTHORITY = "e.coronawarn.app" +private const val PATH_PREFIX = "/c1" +private const val SIGNED_TRACE_LOCATION_BASE_32_REGEX = + "^(?:[A-Z2-7]{8})*(?:[A-Z2-7]{2}={6}|[A-Z2-7]{4}={4}|[A-Z2-7]{5}={3}|[A-Z2-7]{7}=)?\$" + +/** + * Validate that QRCode scanned uri matches the following formulas: + * https://e.coronawarn.app/c1/SIGNED_TRACE_LOCATION_BASE32 + * HTTPS://E.CORONAWARN.APP/C1/SIGNED_TRACE_LOCATION_BASE32 + */ +fun String.isValidQRCodeUri(): Boolean = + URI.create(this).run { + scheme.equals(SCHEME, true) && + authority.equals(AUTHORITY, true) && + path.substringBeforeLast("/") + .equals(PATH_PREFIX, true) && + path.substringAfterLast("/") + .matches(Regex(SIGNED_TRACE_LOCATION_BASE_32_REGEX)) + } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt index bfc610224b5..7a39dfa8eda 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt @@ -1,8 +1,10 @@ package de.rki.coronawarnapp.ui.eventregistration.attendee.checkin +import android.net.Uri import android.os.Bundle import androidx.fragment.app.Fragment import android.view.View +import androidx.core.net.toUri import androidx.navigation.fragment.FragmentNavigatorExtras import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs @@ -25,9 +27,9 @@ class CheckInsFragment : Fragment(R.layout.fragment_check_ins), AutoInject { private val binding: FragmentCheckInsBinding by viewBindingLazy() // Encoded event is a one-time use data and then cleared - private val encodedEvent: String? + private val uri: String? get() = navArgs().value - .encodedEvent + .uri .also { arguments?.clear() } override fun onCreate(savedInstanceState: Bundle?) { @@ -49,7 +51,8 @@ class CheckInsFragment : Fragment(R.layout.fragment_check_ins), AutoInject { } } - encodedEvent?.let { + // TODO validate uri + uri?.toUri()?.lastPathSegment?.let { Timber.i("onViewCreated") viewModel.verifyEvent(it) } @@ -61,4 +64,8 @@ class CheckInsFragment : Fragment(R.layout.fragment_check_ins), AutoInject { ) } } + + companion object { + fun uri(rootUri: String): Uri = "coronawarnapp://check-ins/$rootUri".toUri() + } } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt index 96c2d66876b..00ba2bd3dac 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt @@ -4,6 +4,7 @@ import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import de.rki.coronawarnapp.eventregistration.checkins.qrcode.EventQRCode import de.rki.coronawarnapp.eventregistration.checkins.qrcode.QRCodeVerifier +import de.rki.coronawarnapp.eventregistration.checkins.qrcode.isValidQRCodeUri import de.rki.coronawarnapp.exception.ExceptionCategory import de.rki.coronawarnapp.exception.reporting.report import de.rki.coronawarnapp.util.coroutine.DispatcherProvider @@ -14,13 +15,14 @@ import timber.log.Timber class CheckInsViewModel @AssistedInject constructor( dispatcherProvider: DispatcherProvider, - private val qrCodeVerifier: QRCodeVerifier, + private val qrCodeVerifier: QRCodeVerifier ) : CWAViewModel(dispatcherProvider) { val navigationRoutes = SingleLiveEvent() fun verifyEvent(encodedEvent: String) = launch { try { + encodedEvent.isValidQRCodeUri() Timber.i("encodedEvent: $encodedEvent") val eventQRCode = qrCodeVerifier.verify(encodedEvent) Timber.i("eventQRCode: $eventQRCode") diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeFragment.kt index 7eb6c913ccf..ba1f0aef7a7 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeFragment.kt @@ -5,7 +5,6 @@ import android.content.pm.PackageManager import android.os.Bundle import android.view.View import android.view.accessibility.AccessibilityEvent.TYPE_ANNOUNCEMENT -import androidx.core.net.toUri import androidx.fragment.app.Fragment import androidx.navigation.NavOptions import androidx.navigation.fragment.findNavController @@ -14,10 +13,10 @@ import com.google.zxing.BarcodeFormat import com.journeyapps.barcodescanner.DefaultDecoderFactory import de.rki.coronawarnapp.R import de.rki.coronawarnapp.databinding.FragmentScanCheckInQrCodeBinding +import de.rki.coronawarnapp.ui.eventregistration.attendee.checkin.CheckInsFragment import de.rki.coronawarnapp.util.CameraPermissionHelper import de.rki.coronawarnapp.util.DialogHelper import de.rki.coronawarnapp.util.di.AutoInject -import de.rki.coronawarnapp.util.navUri import de.rki.coronawarnapp.util.ui.observe2 import de.rki.coronawarnapp.util.ui.popBackStack import de.rki.coronawarnapp.util.ui.viewBindingLazy @@ -60,9 +59,9 @@ class ScanCheckInQrCodeFragment : when (navEvent) { is ScanCheckInQrCodeNavigation.BackNavigation -> popBackStack() is ScanCheckInQrCodeNavigation.ScanResultNavigation -> { - Timber.i(navEvent.url) + Timber.i(navEvent.uri) findNavController().navigate( - navEvent.url.toUri().navUri, + CheckInsFragment.uri(navEvent.uri), NavOptions.Builder() .setPopUpTo(R.id.checkInsFragment, true) .build() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeNavigation.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeNavigation.kt index 69ff3f03e6a..db3c562d827 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeNavigation.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeNavigation.kt @@ -2,5 +2,5 @@ package de.rki.coronawarnapp.ui.eventregistration.attendee.scan sealed class ScanCheckInQrCodeNavigation { object BackNavigation : ScanCheckInQrCodeNavigation() - data class ScanResultNavigation(val url: String) : ScanCheckInQrCodeNavigation() + data class ScanResultNavigation(val uri: String) : ScanCheckInQrCodeNavigation() } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/MainActivity.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/MainActivity.kt index 4c5cc0b68f2..88b36e0a77f 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/MainActivity.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/main/MainActivity.kt @@ -24,6 +24,7 @@ import de.rki.coronawarnapp.datadonation.analytics.worker.DataDonationAnalyticsS import de.rki.coronawarnapp.deadman.DeadmanNotificationScheduler import de.rki.coronawarnapp.storage.LocalData import de.rki.coronawarnapp.ui.base.startActivitySafely +import de.rki.coronawarnapp.ui.eventregistration.attendee.checkin.CheckInsFragment import de.rki.coronawarnapp.ui.setupWithNavController2 import de.rki.coronawarnapp.util.AppShortcuts import de.rki.coronawarnapp.util.CWADebug @@ -31,7 +32,6 @@ import de.rki.coronawarnapp.util.ConnectivityHelper import de.rki.coronawarnapp.util.DialogHelper import de.rki.coronawarnapp.util.device.PowerManagement import de.rki.coronawarnapp.util.di.AppInjector -import de.rki.coronawarnapp.util.navUri import de.rki.coronawarnapp.util.shortcuts.AppShortcutsHelper.Companion.getShortcutExtra import de.rki.coronawarnapp.util.ui.findNavController import de.rki.coronawarnapp.util.viewmodel.CWAViewModelFactoryProvider @@ -156,8 +156,7 @@ class MainActivity : AppCompatActivity(), HasAndroidInjector { private fun navigateByIntentUri(intent: Intent?) { val uri = intent?.data ?: return Timber.i("Uri:$uri") - Timber.i("NavUri:%s", uri.navUri) - navController.navigate(uri.navUri) + navController.navigate(CheckInsFragment.uri(uri.toString())) } /** diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/Uri.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/Uri.kt deleted file mode 100644 index 93ab36f1c82..00000000000 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/Uri.kt +++ /dev/null @@ -1,16 +0,0 @@ -package de.rki.coronawarnapp.util - -import android.net.Uri -import androidx.navigation.NavController -import java.util.Locale - -/** - * [NavController.navigate] by Uri is case sensitive. When authority and/or scheme are - * in Uppercase letter an Exception will thrown. - * To avoid such cases [navUri] is converting Uri schema and authority to lowercase always. - */ -val Uri.navUri: Uri - get() = Uri.Builder() - .authority(authority?.toLowerCase(Locale.ROOT)) - .scheme(scheme?.toLowerCase(Locale.ROOT)) - .path(path).build() diff --git a/Corona-Warn-App/src/main/res/navigation/event_attendee_nav_graph.xml b/Corona-Warn-App/src/main/res/navigation/event_attendee_nav_graph.xml index 7a326f919f7..9e1d9ff31cd 100644 --- a/Corona-Warn-App/src/main/res/navigation/event_attendee_nav_graph.xml +++ b/Corona-Warn-App/src/main/res/navigation/event_attendee_nav_graph.xml @@ -24,7 +24,7 @@ android:name="de.rki.coronawarnapp.ui.eventregistration.attendee.checkin.CheckInsFragment" android:label="CheckInsFragment" tools:layout="@layout/fragment_check_ins"> - + @@ -32,7 +32,7 @@ android:id="@+id/action_checkInsFragment_to_confirmCheckInFragment" app:destination="@id/confirmCheckInFragment" /> diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/InvalidUrlProvider.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/InvalidUrlProvider.kt new file mode 100644 index 00000000000..62e33419136 --- /dev/null +++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/InvalidUrlProvider.kt @@ -0,0 +1,32 @@ +package de.rki.coronawarnapp.eventregistration.checkins.qrcode + +import org.junit.jupiter.api.extension.ExtensionContext +import org.junit.jupiter.params.provider.Arguments +import org.junit.jupiter.params.provider.ArgumentsProvider +import java.util.stream.Stream + +class InvalidUrlProvider : ArgumentsProvider { + override fun provideArguments(context: ExtensionContext?): Stream { + return Stream.of( + Arguments.of( + "https://e.coronawarn.app/e1/BIYAUEDBZY6EIWF7QX6JOKSRPAGEB3H7CIIEGV2BEBGGC5LOMNUCAUDBO" + + "J2HSGGTQ6SACIHXQ6SACKA6CJEDARQCEEAPHGEZ5JI2K2T422L5U3SMZY5DGCPUZ2RQACAYEJ3HQYMAFFBU2" + + "SQCEEAJAUCJSQJ7WDM675MCMOD3L2UL7ECJU7TYERH23B746RQTABO3CTI=" + ), + Arguments.of( + "https://e.coronawarn.app/c1/SINGED_ENCODED_LOCATION" + ), + Arguments.of( + "HTTPS://E.CORONAWARN.APP/C1/BIPEY33SMVWSA2LQON2W2IDEN5WG64RAONUXIIDBNVSXILBAMNXRBCM4UQARRKM6UQASAHR" + + "KCC7CTDWGQ4JCO7RVZSWVIMQK4UPA.GBCAEIA7TEORBTUA25QHBOCWT26BCA5PORBS2E4FFWMJ3UU3P6SXOL" + + "7SHUBCA7UEZBDDQ2R6VRJH7WBJKVF7GZYJA6YMRN27IPEP7NKGGJSWX3XQ" + ), + Arguments.of( + "HTTPS://E.CORONAWARN.APP/C1/BIYAUEDBZY6EIWF7QX6JOKSRPAGEB3H7CIIEGV2BEBGGC5LOMNUCAUDBO" + + "J2HSGGTQ6SACIHXQ6SACKA6CJEDARQCEEAPHGEZ5JI2K2T422L5U3SMZY5DGCPUZ2RQACAYEJ3HQYMAFFBU2" + + "SQCEEAJAUCJSQJ7WDM675MCMOD3L2UL7ECJU7TYERH23B746RQTABO3CTI" + ), + Arguments.of("") + ) + } +} diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/UriValidatorTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/UriValidatorTest.kt new file mode 100644 index 00000000000..d0f30a69b74 --- /dev/null +++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/UriValidatorTest.kt @@ -0,0 +1,29 @@ +package de.rki.coronawarnapp.eventregistration.checkins.qrcode + +import io.kotest.assertions.throwables.shouldThrow +import io.kotest.matchers.shouldBe +import org.junit.Test +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.ArgumentsSource + +class UriValidatorTest { + + @ParameterizedTest + @ArgumentsSource(ValidUrlProvider::class) + fun `Valid URLs`(input: String) { + input.isValidQRCodeUri() shouldBe true + } + + @ParameterizedTest + @ArgumentsSource(InvalidUrlProvider::class) + fun `Invalid URLs`(input: String) { + input.isValidQRCodeUri() shouldBe false + } + + @Test + fun `Invalid URL string`() { + shouldThrow { + "Hello World!".isValidQRCodeUri() + } + } +} diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/ValidUrlProvider.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/ValidUrlProvider.kt new file mode 100644 index 00000000000..6b8b83fbe79 --- /dev/null +++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/ValidUrlProvider.kt @@ -0,0 +1,23 @@ +package de.rki.coronawarnapp.eventregistration.checkins.qrcode + +import org.junit.jupiter.api.extension.ExtensionContext +import org.junit.jupiter.params.provider.Arguments +import org.junit.jupiter.params.provider.ArgumentsProvider +import java.util.stream.Stream + +class ValidUrlProvider : ArgumentsProvider { + override fun provideArguments(context: ExtensionContext?): Stream { + return Stream.of( + Arguments.of( + "HTTPS://E.CORONAWARN.APP/C1/BIYAUEDBZY6EIWF7QX6JOKSRPAGEB3H7CIIEGV2BEBGGC5LOMNUCAUDBO" + + "J2HSGGTQ6SACIHXQ6SACKA6CJEDARQCEEAPHGEZ5JI2K2T422L5U3SMZY5DGCPUZ2RQACAYEJ3HQYMAFFBU2" + + "SQCEEAJAUCJSQJ7WDM675MCMOD3L2UL7ECJU7TYERH23B746RQTABO3CTI=" + ), + Arguments.of( + "https://e.coronawarn.app/c1/BIYAUEDBZY6EIWF7QX6JOKSRPAGEB3H7CIIEGV2BEBGGC5LOMNUCAUDBO" + + "J2HSGGTQ6SACIHXQ6SACKA6CJEDARQCEEAPHGEZ5JI2K2T422L5U3SMZY5DGCPUZ2RQACAYEJ3HQYMAFFBU2" + + "SQCEEAJAUCJSQJ7WDM675MCMOD3L2UL7ECJU7TYERH23B746RQTABO3CTI=" + ) + ) + } +} From 1a1c028ff2ba93cd9e2bcba90b887a67345aa9f9 Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Mon, 8 Mar 2021 19:40:20 +0100 Subject: [PATCH 21/30] Validate uri --- .../checkins/qrcode/DefaultQRCodeVerifier.kt | 7 ++++++- .../eventregistration/checkins/qrcode/QRCodeVerifier.kt | 2 +- .../attendee/checkin/CheckInsFragment.kt | 3 +-- .../attendee/checkin/CheckInsViewModel.kt | 8 +++----- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifier.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifier.kt index 48bb0508e3c..7746b9a8a12 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifier.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifier.kt @@ -3,10 +3,15 @@ package de.rki.coronawarnapp.eventregistration.checkins.qrcode import de.rki.coronawarnapp.eventregistration.common.decodeBase32 import de.rki.coronawarnapp.server.protocols.internal.evreg.SignedEventOuterClass import timber.log.Timber +import java.lang.IllegalArgumentException import javax.inject.Inject class DefaultQRCodeVerifier @Inject constructor() : QRCodeVerifier { - override suspend fun verify(encodedEvent: String): EventQRCode { + override suspend fun verify(uri: String): EventQRCode { + if (!uri.isValidQRCodeUri()) { + throw IllegalArgumentException("Invalid QRCode Uri:$uri") + } + val encodedEvent = uri.substringAfterLast("/") Timber.i("encodedEvent: $encodedEvent") // TODO Implement verification // For now just parse diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/QRCodeVerifier.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/QRCodeVerifier.kt index 4ae74a1548a..9b59d402f75 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/QRCodeVerifier.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/QRCodeVerifier.kt @@ -2,5 +2,5 @@ package de.rki.coronawarnapp.eventregistration.checkins.qrcode interface QRCodeVerifier { - suspend fun verify(encodedEvent: String): EventQRCode + suspend fun verify(uri: String): EventQRCode } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt index 7a39dfa8eda..50019d28db8 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt @@ -51,8 +51,7 @@ class CheckInsFragment : Fragment(R.layout.fragment_check_ins), AutoInject { } } - // TODO validate uri - uri?.toUri()?.lastPathSegment?.let { + uri?.let { Timber.i("onViewCreated") viewModel.verifyEvent(it) } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt index 00ba2bd3dac..afd4adc95cd 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt @@ -4,7 +4,6 @@ import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import de.rki.coronawarnapp.eventregistration.checkins.qrcode.EventQRCode import de.rki.coronawarnapp.eventregistration.checkins.qrcode.QRCodeVerifier -import de.rki.coronawarnapp.eventregistration.checkins.qrcode.isValidQRCodeUri import de.rki.coronawarnapp.exception.ExceptionCategory import de.rki.coronawarnapp.exception.reporting.report import de.rki.coronawarnapp.util.coroutine.DispatcherProvider @@ -20,11 +19,10 @@ class CheckInsViewModel @AssistedInject constructor( val navigationRoutes = SingleLiveEvent() - fun verifyEvent(encodedEvent: String) = launch { + fun verifyEvent(uri: String) = launch { try { - encodedEvent.isValidQRCodeUri() - Timber.i("encodedEvent: $encodedEvent") - val eventQRCode = qrCodeVerifier.verify(encodedEvent) + Timber.i("uri: $uri") + val eventQRCode = qrCodeVerifier.verify(uri) Timber.i("eventQRCode: $eventQRCode") navigationRoutes.postValue(eventQRCode) } catch (e: Exception) { From a84ffa621b3bdda61b2dda86a9bb76cd4d741baf Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Mon, 8 Mar 2021 19:59:58 +0100 Subject: [PATCH 22/30] Update LauncherActivityTest.kt --- .../rki/coronawarnapp/ui/launcher/LauncherActivityTest.kt | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/launcher/LauncherActivityTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/launcher/LauncherActivityTest.kt index d21f63c72f2..9d6924d1d16 100644 --- a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/launcher/LauncherActivityTest.kt +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/launcher/LauncherActivityTest.kt @@ -59,13 +59,7 @@ class LauncherActivityTest : BaseUITest() { @Test fun testDeepLinkLowercase() { - val uri = Uri.parse("https://coronawarn.app/E1/SOME_PATH_GOES_HERE") - launchActivity(getIntent(uri)) - } - - @Test - fun testDeepLinkLowercaseWww() { - val uri = Uri.parse("https://www.coronawarn.app/E1/SOME_PATH_GOES_HERE") + val uri = Uri.parse("https://e.coronawarn.app/c1/SOME_PATH_GOES_HERE") launchActivity(getIntent(uri)) } From d13213e38ed642d5e20c9e027efd411a6d595952 Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Tue, 9 Mar 2021 09:30:07 +0100 Subject: [PATCH 23/30] Renaming --- ...ntKtTest.kt => VerifiedTraceLocationKtTest.kt} | 15 ++++++++------- .../checkins/CheckInsRepository.kt | 4 ++-- .../{EventCheckIn.kt => TraceLocationCheckIn.kt} | 3 +-- .../checkins/download/CheckInsPackage.kt | 4 ++-- .../checkins/qrcode/DefaultQRCodeVerifier.kt | 13 ++++++++----- .../checkins/qrcode/QRCodeVerifier.kt | 2 +- .../{EventQRCode.kt => TraceLocationQRCode.kt} | 4 ++-- .../attendee/checkin/CheckInsFragment.kt | 11 +++-------- .../attendee/checkin/CheckInsViewModel.kt | 14 +++++++------- ...{VerifiedEvent.kt => VerifiedTraceLocation.kt} | 8 ++++---- .../attendee/confirm/ConfirmCheckInFragment.kt | 12 ++++++------ .../attendee/confirm/ConfirmCheckInViewModel.kt | 12 ++++-------- .../attendee/scan/ScanCheckInQrCodeFragment.kt | 2 +- .../attendee/scan/ScanCheckInQrCodeViewModel.kt | 6 +++--- .../src/main/res/menu/menu_bottom_nav.xml | 2 +- .../src/main/res/navigation/nav_graph.xml | 4 ++-- ....xml => trace_location_attendee_nav_graph.xml} | 6 +++--- ...xml => trace_location_organizer_nav_graph.xml} | 0 .../confirm/ConfirmCheckInViewModelTest.kt | 6 +++--- .../scan/ScanCheckInQrCodeViewModelTest.kt | 4 ++-- 20 files changed, 63 insertions(+), 69 deletions(-) rename Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/{VerifiedEventKtTest.kt => VerifiedTraceLocationKtTest.kt} (65%) rename Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/{EventCheckIn.kt => TraceLocationCheckIn.kt} (84%) rename Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/{EventQRCode.kt => TraceLocationQRCode.kt} (65%) rename Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/{VerifiedEvent.kt => VerifiedTraceLocation.kt} (76%) rename Corona-Warn-App/src/main/res/navigation/{event_attendee_nav_graph.xml => trace_location_attendee_nav_graph.xml} (92%) rename Corona-Warn-App/src/main/res/navigation/{event_organizer_nav_graph.xml => trace_location_organizer_nav_graph.xml} (100%) diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEventKtTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocationKtTest.kt similarity index 65% rename from Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEventKtTest.kt rename to Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocationKtTest.kt index 08f9adb8de7..5dfcd2faca5 100644 --- a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEventKtTest.kt +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocationKtTest.kt @@ -1,6 +1,6 @@ package de.rki.coronawarnapp.ui.eventregistration.attendee.checkin -import de.rki.coronawarnapp.eventregistration.checkins.qrcode.EventQRCode +import de.rki.coronawarnapp.eventregistration.checkins.qrcode.TraceLocationQRCode import de.rki.coronawarnapp.eventregistration.common.decodeBase32 import de.rki.coronawarnapp.server.protocols.internal.evreg.SignedEventOuterClass import io.kotest.assertions.throwables.shouldNotThrowAny @@ -12,14 +12,15 @@ import org.junit.runners.JUnit4 import testhelpers.BaseTestInstrumentation @RunWith(JUnit4::class) -class VerifiedEventKtTest : BaseTestInstrumentation() { +class VerifiedTraceLocationKtTest : BaseTestInstrumentation() { @Test - fun testVerifiedEventMapping() { + fun testVerifiedTraceLocationMapping() { shouldNotThrowAny { - val signedEvent = SignedEventOuterClass.SignedEvent.parseFrom(DECODED_EVENT.decodeBase32().toByteArray()) - val verifiedEvent = EventQRCode(event = signedEvent.event).toVerifiedEvent() - verifiedEvent shouldBe VerifiedEvent( + val signedTraceLocation = + SignedEventOuterClass.SignedEvent.parseFrom(DECODED_TRACE_LOCATION.decodeBase32().toByteArray()) + val verifiedTraceLocation = TraceLocationQRCode(traceLocation = signedTraceLocation.event).toVerifiedTraceLocation() + verifiedTraceLocation shouldBe VerifiedTraceLocation( guid = "Yc48RFi/hfyXKlF4DEDs/w==", start = Instant.parse("1970-01-01T00:44:47.955Z"), end = Instant.parse("1970-01-01T00:44:47.991Z"), @@ -30,7 +31,7 @@ class VerifiedEventKtTest : BaseTestInstrumentation() { } companion object { - private const val DECODED_EVENT = + private const val DECODED_TRACE_LOCATION = "BIYAUEDBZY6EIWF7QX6JOKSRPAGEB3H7CIIEGV2BEBGGC5LOMNUCAUDBOJ2HSGGTQ6SACIHXQ6SAC" + "KA6CJEDARQCEEAPHGEZ5JI2K2T422L5U3SMZY5DGCPUZ2RQACAYEJ3HQYMAFFBU2SQCEEAJAUCJSQJ7WDM6" + "75MCMOD3L2UL7ECJU7TYERH23B746RQTABO3CTI=" diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/CheckInsRepository.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/CheckInsRepository.kt index 0121e668d67..143b2c34af7 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/CheckInsRepository.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/CheckInsRepository.kt @@ -4,7 +4,7 @@ import kotlinx.coroutines.flow.Flow interface CheckInsRepository { - val allCheckIns: Flow> + val allCheckIns: Flow> - suspend fun addCheckIn(checkIn: EventCheckIn) + suspend fun addCheckIn(checkIn: TraceLocationCheckIn) } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/EventCheckIn.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/TraceLocationCheckIn.kt similarity index 84% rename from Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/EventCheckIn.kt rename to Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/TraceLocationCheckIn.kt index f906e906ad5..8453f61bda4 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/EventCheckIn.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/TraceLocationCheckIn.kt @@ -2,8 +2,7 @@ package de.rki.coronawarnapp.eventregistration.checkins import org.joda.time.Instant -interface EventCheckIn { - +interface TraceLocationCheckIn { val id: Long val guid: String val startTime: Instant diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/download/CheckInsPackage.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/download/CheckInsPackage.kt index 6a48064f1ef..fe8a3a92892 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/download/CheckInsPackage.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/download/CheckInsPackage.kt @@ -1,11 +1,11 @@ package de.rki.coronawarnapp.eventregistration.checkins.download -import de.rki.coronawarnapp.eventregistration.checkins.EventCheckIn +import de.rki.coronawarnapp.eventregistration.checkins.TraceLocationCheckIn interface CheckInsPackage { /** * Hides the file reading */ - suspend fun extractCheckIns(): List + suspend fun extractCheckIns(): List } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifier.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifier.kt index 7746b9a8a12..c97771618d4 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifier.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/DefaultQRCodeVerifier.kt @@ -7,16 +7,19 @@ import java.lang.IllegalArgumentException import javax.inject.Inject class DefaultQRCodeVerifier @Inject constructor() : QRCodeVerifier { - override suspend fun verify(uri: String): EventQRCode { + override suspend fun verify(uri: String): TraceLocationQRCode { if (!uri.isValidQRCodeUri()) { throw IllegalArgumentException("Invalid QRCode Uri:$uri") } - val encodedEvent = uri.substringAfterLast("/") - Timber.i("encodedEvent: $encodedEvent") + val encodedTraceLocation = uri.substringAfterLast("/") + Timber.i("encodedTraceLocation: $encodedTraceLocation") // TODO Implement verification // For now just parse - return EventQRCode( - event = SignedEventOuterClass.SignedEvent.parseFrom(encodedEvent.decodeBase32().toByteArray()).event + return TraceLocationQRCode( + traceLocation = SignedEventOuterClass.SignedEvent + .parseFrom( + encodedTraceLocation.decodeBase32().toByteArray() + ).event ) } } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/QRCodeVerifier.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/QRCodeVerifier.kt index 9b59d402f75..7178e06e16b 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/QRCodeVerifier.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/QRCodeVerifier.kt @@ -2,5 +2,5 @@ package de.rki.coronawarnapp.eventregistration.checkins.qrcode interface QRCodeVerifier { - suspend fun verify(uri: String): EventQRCode + suspend fun verify(uri: String): TraceLocationQRCode } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/EventQRCode.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/TraceLocationQRCode.kt similarity index 65% rename from Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/EventQRCode.kt rename to Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/TraceLocationQRCode.kt index 3c913a275f6..8e6e87487b9 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/EventQRCode.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/TraceLocationQRCode.kt @@ -2,6 +2,6 @@ package de.rki.coronawarnapp.eventregistration.checkins.qrcode import de.rki.coronawarnapp.server.protocols.internal.evreg.EventOuterClass -data class EventQRCode( - val event: EventOuterClass.Event +data class TraceLocationQRCode( + val traceLocation: EventOuterClass.Event ) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt index 50019d28db8..4699b60bb67 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt @@ -17,7 +17,6 @@ import de.rki.coronawarnapp.util.ui.observe2 import de.rki.coronawarnapp.util.ui.viewBindingLazy import de.rki.coronawarnapp.util.viewmodel.CWAViewModelFactoryProvider import de.rki.coronawarnapp.util.viewmodel.cwaViewModels -import timber.log.Timber import javax.inject.Inject class CheckInsFragment : Fragment(R.layout.fragment_check_ins), AutoInject { @@ -26,7 +25,7 @@ class CheckInsFragment : Fragment(R.layout.fragment_check_ins), AutoInject { private val viewModel: CheckInsViewModel by cwaViewModels { viewModelFactory } private val binding: FragmentCheckInsBinding by viewBindingLazy() - // Encoded event is a one-time use data and then cleared + // Encoded uri is a one-time use data and then cleared private val uri: String? get() = navArgs().value .uri @@ -51,15 +50,11 @@ class CheckInsFragment : Fragment(R.layout.fragment_check_ins), AutoInject { } } - uri?.let { - Timber.i("onViewCreated") - viewModel.verifyEvent(it) - } - + uri?.let { viewModel.verifyTraceLocation(it) } viewModel.navigationRoutes.observe2(this) { doNavigate( CheckInsFragmentDirections - .actionCheckInsFragmentToConfirmCheckInFragment(it.toVerifiedEvent()) + .actionCheckInsFragmentToConfirmCheckInFragment(it.toVerifiedTraceLocation()) ) } } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt index afd4adc95cd..b4a16d71f56 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt @@ -2,8 +2,8 @@ package de.rki.coronawarnapp.ui.eventregistration.attendee.checkin import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject -import de.rki.coronawarnapp.eventregistration.checkins.qrcode.EventQRCode import de.rki.coronawarnapp.eventregistration.checkins.qrcode.QRCodeVerifier +import de.rki.coronawarnapp.eventregistration.checkins.qrcode.TraceLocationQRCode import de.rki.coronawarnapp.exception.ExceptionCategory import de.rki.coronawarnapp.exception.reporting.report import de.rki.coronawarnapp.util.coroutine.DispatcherProvider @@ -17,16 +17,16 @@ class CheckInsViewModel @AssistedInject constructor( private val qrCodeVerifier: QRCodeVerifier ) : CWAViewModel(dispatcherProvider) { - val navigationRoutes = SingleLiveEvent() + val navigationRoutes = SingleLiveEvent() - fun verifyEvent(uri: String) = launch { + fun verifyTraceLocation(uri: String) = launch { try { Timber.i("uri: $uri") - val eventQRCode = qrCodeVerifier.verify(uri) - Timber.i("eventQRCode: $eventQRCode") - navigationRoutes.postValue(eventQRCode) + val traceLocationQRCode = qrCodeVerifier.verify(uri) + Timber.i("traceLocationQRCode: $traceLocationQRCode") + navigationRoutes.postValue(traceLocationQRCode) } catch (e: Exception) { - Timber.d(e, "Event verification failed") + Timber.d(e, "TraceLocation verification failed") e.report(ExceptionCategory.INTERNAL) } } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEvent.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocation.kt similarity index 76% rename from Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEvent.kt rename to Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocation.kt index 0030677d42b..383a868f464 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedEvent.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocation.kt @@ -1,13 +1,13 @@ package de.rki.coronawarnapp.ui.eventregistration.attendee.checkin import android.os.Parcelable -import de.rki.coronawarnapp.eventregistration.checkins.qrcode.EventQRCode +import de.rki.coronawarnapp.eventregistration.checkins.qrcode.TraceLocationQRCode import kotlinx.parcelize.Parcelize import okio.ByteString.Companion.toByteString import org.joda.time.Instant @Parcelize -data class VerifiedEvent( +data class VerifiedTraceLocation( val guid: String, val description: String?, val start: Instant?, @@ -15,8 +15,8 @@ data class VerifiedEvent( val defaultCheckInLengthInMinutes: Int ) : Parcelable -fun EventQRCode.toVerifiedEvent() = with(event) { - VerifiedEvent( +fun TraceLocationQRCode.toVerifiedTraceLocation() = with(traceLocation) { + VerifiedTraceLocation( guid = guid.toByteArray().toByteString().base64(), start = start.instant(), end = end.instant(), diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInFragment.kt index dfe5521a50e..804b57eb9cb 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInFragment.kt @@ -27,15 +27,15 @@ class ConfirmCheckInFragment : Fragment(R.layout.fragment_confirm_check_in), Aut with(binding) { toolbar.setNavigationOnClickListener { viewModel.onClose() } - confirmButton.setOnClickListener { viewModel.onConfirmEvent() } + confirmButton.setOnClickListener { viewModel.onConfirmTraceLocation() } // TODO bind final UI - eventGuid.text = "GUID: %s".format(args.event.guid) - startTime.text = "Start time: %s".format(args.event.start) - endTime.text = "End time: %s".format(args.event.end) - description.text = "Description: %s".format(args.event.description) + eventGuid.text = "GUID: %s".format(args.traceLocation.guid) + startTime.text = "Start time: %s".format(args.traceLocation.start) + endTime.text = "End time: %s".format(args.traceLocation.end) + description.text = "Description: %s".format(args.traceLocation.description) } - viewModel.navigationEvents.observe2(this) { navEvent -> + viewModel.events.observe2(this) { navEvent -> when (navEvent) { ConfirmCheckInNavigation.BackNavigation -> popBackStack() ConfirmCheckInNavigation.ConfirmNavigation -> { diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInViewModel.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInViewModel.kt index 06c8398a1f9..b3931016005 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInViewModel.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/confirm/ConfirmCheckInViewModel.kt @@ -1,24 +1,20 @@ package de.rki.coronawarnapp.ui.eventregistration.attendee.confirm -import androidx.lifecycle.MutableLiveData import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject -import de.rki.coronawarnapp.eventregistration.checkins.qrcode.EventQRCode import de.rki.coronawarnapp.util.ui.SingleLiveEvent import de.rki.coronawarnapp.util.viewmodel.CWAViewModel import de.rki.coronawarnapp.util.viewmodel.SimpleCWAViewModelFactory class ConfirmCheckInViewModel @AssistedInject constructor() : CWAViewModel() { - private val eventLiveData = MutableLiveData() - val eventData = eventLiveData - val navigationEvents = SingleLiveEvent() + val events = SingleLiveEvent() fun onClose() { - navigationEvents.value = ConfirmCheckInNavigation.BackNavigation + events.value = ConfirmCheckInNavigation.BackNavigation } - fun onConfirmEvent() { - navigationEvents.value = ConfirmCheckInNavigation.ConfirmNavigation + fun onConfirmTraceLocation() { + events.value = ConfirmCheckInNavigation.ConfirmNavigation } @AssistedFactory diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeFragment.kt index ba1f0aef7a7..c8d757c662b 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeFragment.kt @@ -55,7 +55,7 @@ class ScanCheckInQrCodeFragment : checkInQrCodeScanViewfinderView.setCameraPreview(binding.checkInQrCodeScanPreview) } - viewModel.navigationEvents.observe2(this) { navEvent -> + viewModel.events.observe2(this) { navEvent -> when (navEvent) { is ScanCheckInQrCodeNavigation.BackNavigation -> popBackStack() is ScanCheckInQrCodeNavigation.ScanResultNavigation -> { diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeViewModel.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeViewModel.kt index 7f5e8424f4c..5452829bd49 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeViewModel.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/scan/ScanCheckInQrCodeViewModel.kt @@ -8,14 +8,14 @@ import de.rki.coronawarnapp.util.viewmodel.CWAViewModel import de.rki.coronawarnapp.util.viewmodel.SimpleCWAViewModelFactory class ScanCheckInQrCodeViewModel @AssistedInject constructor() : CWAViewModel() { - val navigationEvents = SingleLiveEvent() + val events = SingleLiveEvent() fun onNavigateUp() { - navigationEvents.value = ScanCheckInQrCodeNavigation.BackNavigation + events.value = ScanCheckInQrCodeNavigation.BackNavigation } fun onScanResult(barcodeResult: BarcodeResult) { - navigationEvents.value = ScanCheckInQrCodeNavigation.ScanResultNavigation( + events.value = ScanCheckInQrCodeNavigation.ScanResultNavigation( barcodeResult.result.text ) } diff --git a/Corona-Warn-App/src/main/res/menu/menu_bottom_nav.xml b/Corona-Warn-App/src/main/res/menu/menu_bottom_nav.xml index c7e211b35af..bef4a123a6e 100644 --- a/Corona-Warn-App/src/main/res/menu/menu_bottom_nav.xml +++ b/Corona-Warn-App/src/main/res/menu/menu_bottom_nav.xml @@ -7,7 +7,7 @@ android:title="@string/bottom_nav_home_title" /> diff --git a/Corona-Warn-App/src/main/res/navigation/nav_graph.xml b/Corona-Warn-App/src/main/res/navigation/nav_graph.xml index e73f5df586f..edff51e6cdb 100644 --- a/Corona-Warn-App/src/main/res/navigation/nav_graph.xml +++ b/Corona-Warn-App/src/main/res/navigation/nav_graph.xml @@ -10,8 +10,8 @@ - - + + + android:name="traceLocation" + app:argType="de.rki.coronawarnapp.ui.eventregistration.attendee.checkin.VerifiedTraceLocation" /> Date: Tue, 9 Mar 2021 09:43:18 +0100 Subject: [PATCH 24/30] Trace location times are in seconds --- .../attendee/checkin/VerifiedTraceLocationKtTest.kt | 7 ++++--- .../attendee/checkin/VerifiedTraceLocation.kt | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocationKtTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocationKtTest.kt index 5dfcd2faca5..a17aaaba973 100644 --- a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocationKtTest.kt +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocationKtTest.kt @@ -19,11 +19,12 @@ class VerifiedTraceLocationKtTest : BaseTestInstrumentation() { shouldNotThrowAny { val signedTraceLocation = SignedEventOuterClass.SignedEvent.parseFrom(DECODED_TRACE_LOCATION.decodeBase32().toByteArray()) - val verifiedTraceLocation = TraceLocationQRCode(traceLocation = signedTraceLocation.event).toVerifiedTraceLocation() + val verifiedTraceLocation = + TraceLocationQRCode(traceLocation = signedTraceLocation.event).toVerifiedTraceLocation() verifiedTraceLocation shouldBe VerifiedTraceLocation( guid = "Yc48RFi/hfyXKlF4DEDs/w==", - start = Instant.parse("1970-01-01T00:44:47.955Z"), - end = Instant.parse("1970-01-01T00:44:47.991Z"), + start = Instant.parse("1970-02-01T02:39:15.000Z"), + end = Instant.parse("1970-02-01T02:39:51.000Z"), defaultCheckInLengthInMinutes = 30, description = "CWA Launch Party" ) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocation.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocation.kt index 383a868f464..464ecd9725b 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocation.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocation.kt @@ -5,6 +5,7 @@ import de.rki.coronawarnapp.eventregistration.checkins.qrcode.TraceLocationQRCod import kotlinx.parcelize.Parcelize import okio.ByteString.Companion.toByteString import org.joda.time.Instant +import java.util.concurrent.TimeUnit @Parcelize data class VerifiedTraceLocation( @@ -25,5 +26,8 @@ fun TraceLocationQRCode.toVerifiedTraceLocation() = with(traceLocation) { ) } +/** + * Converts time in seconds into [Instant] + */ private fun Int.instant() = - if (this == 0) null else Instant.ofEpochMilli(this.toLong()) + if (this == 0) null else Instant.ofEpochMilli(TimeUnit.SECONDS.toMillis(toLong())) From 5d783bc1f18222f69ed14a3cf4371b586839ed33 Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Tue, 9 Mar 2021 18:30:52 +0100 Subject: [PATCH 25/30] Delete redundants --- .../eventregistration/checkins/CheckInsRepository.kt | 10 ---------- .../eventregistration/checkins/TraceLocationCheckIn.kt | 10 ---------- .../checkins/download/CheckInsPackage.kt | 4 ++-- 3 files changed, 2 insertions(+), 22 deletions(-) delete mode 100644 Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/CheckInsRepository.kt delete mode 100644 Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/TraceLocationCheckIn.kt diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/CheckInsRepository.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/CheckInsRepository.kt deleted file mode 100644 index 143b2c34af7..00000000000 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/CheckInsRepository.kt +++ /dev/null @@ -1,10 +0,0 @@ -package de.rki.coronawarnapp.eventregistration.checkins - -import kotlinx.coroutines.flow.Flow - -interface CheckInsRepository { - - val allCheckIns: Flow> - - suspend fun addCheckIn(checkIn: TraceLocationCheckIn) -} diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/TraceLocationCheckIn.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/TraceLocationCheckIn.kt deleted file mode 100644 index 8453f61bda4..00000000000 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/TraceLocationCheckIn.kt +++ /dev/null @@ -1,10 +0,0 @@ -package de.rki.coronawarnapp.eventregistration.checkins - -import org.joda.time.Instant - -interface TraceLocationCheckIn { - val id: Long - val guid: String - val startTime: Instant - val endTime: Instant -} diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/download/CheckInsPackage.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/download/CheckInsPackage.kt index fe8a3a92892..97f513181b5 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/download/CheckInsPackage.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/download/CheckInsPackage.kt @@ -1,11 +1,11 @@ package de.rki.coronawarnapp.eventregistration.checkins.download -import de.rki.coronawarnapp.eventregistration.checkins.TraceLocationCheckIn +import de.rki.coronawarnapp.eventregistration.checkins.CheckIn interface CheckInsPackage { /** * Hides the file reading */ - suspend fun extractCheckIns(): List + suspend fun extractCheckIns(): List } From 94f5bb43ed2458fa50e7c60806c8e00e30496682 Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Wed, 10 Mar 2021 15:40:08 +0100 Subject: [PATCH 26/30] Remove destinations from main graph those destinations are part of attendee graph now --- .../src/main/res/navigation/nav_graph.xml | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/Corona-Warn-App/src/main/res/navigation/nav_graph.xml b/Corona-Warn-App/src/main/res/navigation/nav_graph.xml index 0354e3e8c1b..cc6efcc8ebf 100644 --- a/Corona-Warn-App/src/main/res/navigation/nav_graph.xml +++ b/Corona-Warn-App/src/main/res/navigation/nav_graph.xml @@ -596,7 +596,7 @@ android:id="@+id/debugLogUploadFragment" android:name="de.rki.coronawarnapp.bugreporting.debuglog.ui.upload.DebugLogUploadFragment" android:label="DebugLogUploadFragment" - tools:layout="@layout/bugreporting_debuglog_upload_fragment" > + tools:layout="@layout/bugreporting_debuglog_upload_fragment"> @@ -606,21 +606,4 @@ android:name="de.rki.coronawarnapp.bugreporting.debuglog.ui.legal.DebugLogLegalFragment" android:label="DebugLogLegalFragment" tools:layout="@layout/bugreporting_legal_fragment" /> - - - - - - - From 2e6fba130b5bb7848e8fd12de33f8d0502ca57ac Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Wed, 10 Mar 2021 18:05:27 +0100 Subject: [PATCH 27/30] Use hard coded string --- .../ui/qrcode/QrCodeCreationTestFragment.kt | 7 +++++++ .../res/layout/fragment_test_qrcode_creation.xml | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/test/eventregistration/ui/qrcode/QrCodeCreationTestFragment.kt b/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/test/eventregistration/ui/qrcode/QrCodeCreationTestFragment.kt index 4ee3871599a..2ae2fafd1af 100644 --- a/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/test/eventregistration/ui/qrcode/QrCodeCreationTestFragment.kt +++ b/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/test/eventregistration/ui/qrcode/QrCodeCreationTestFragment.kt @@ -1,5 +1,6 @@ package de.rki.coronawarnapp.test.eventregistration.ui.qrcode +import android.annotation.SuppressLint import android.os.Bundle import android.view.View import android.widget.Toast @@ -21,6 +22,7 @@ class QrCodeCreationTestFragment : Fragment(R.layout.fragment_test_qrcode_creati private val viewModel: QrCodeCreationTestViewModel by cwaViewModels { viewModelFactory } private val binding: FragmentTestQrcodeCreationBinding by viewBindingLazy() + @SuppressLint("SetTextI18n") override fun onViewCreated(view: View, savedInstanceState: Bundle?) { viewModel.sharingIntent.observe2(this) { @@ -36,6 +38,11 @@ class QrCodeCreationTestFragment : Fragment(R.layout.fragment_test_qrcode_creati Toast.makeText(requireContext(), it, Toast.LENGTH_LONG).show() } + binding.qrCodeText.setText( + "HTTPS://E.CORONAWARN.APP/C1/BIYAUEDBZY6EIWF7QX6JOKSRPAGEB3H7CIIEGV2BEBGGC5LOMNUCAUD" + + "BOJ2HSGGTQ6SACIHXQ6SACKA6CJEDARQCEEAPHGEZ5JI2K2T422L5U3SMZY5DGCPUZ2RQACAYEJ3HQYMAFF" + + "BU2SQCEEAJAUCJSQJ7WDM675MCMOD3L2UL7ECJU7TYERH23B746RQTABO3CTI=" + ) binding.generateQrCode.setOnClickListener { viewModel.createQrCode(binding.qrCodeText.text.toString()) } diff --git a/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_qrcode_creation.xml b/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_qrcode_creation.xml index 915142f41e4..e6ec6eebc8e 100644 --- a/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_qrcode_creation.xml +++ b/Corona-Warn-App/src/deviceForTesters/res/layout/fragment_test_qrcode_creation.xml @@ -47,7 +47,6 @@ android:id="@+id/qrCodeText" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="@string/qr_code_input" android:textSize="14sp" /> From 42f9625a0925a7fb38b95b1bdfdf9389b48c9a69 Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Wed, 10 Mar 2021 18:05:45 +0100 Subject: [PATCH 28/30] Verify uri --- .../attendee/checkin/CheckInsFragment.kt | 2 +- .../attendee/checkin/CheckInsViewModel.kt | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt index 4699b60bb67..b70081beac2 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt @@ -50,7 +50,7 @@ class CheckInsFragment : Fragment(R.layout.fragment_check_ins), AutoInject { } } - uri?.let { viewModel.verifyTraceLocation(it) } + uri?.let { viewModel.verifyUri(it) } viewModel.navigationRoutes.observe2(this) { doNavigate( CheckInsFragmentDirections diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt index b4a16d71f56..5ac860f689e 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt @@ -4,6 +4,7 @@ import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import de.rki.coronawarnapp.eventregistration.checkins.qrcode.QRCodeVerifier import de.rki.coronawarnapp.eventregistration.checkins.qrcode.TraceLocationQRCode +import de.rki.coronawarnapp.eventregistration.checkins.qrcode.isValidQRCodeUri import de.rki.coronawarnapp.exception.ExceptionCategory import de.rki.coronawarnapp.exception.reporting.report import de.rki.coronawarnapp.util.coroutine.DispatcherProvider @@ -19,12 +20,20 @@ class CheckInsViewModel @AssistedInject constructor( val navigationRoutes = SingleLiveEvent() - fun verifyTraceLocation(uri: String) = launch { + fun verifyUri(uri: String) = launch { try { Timber.i("uri: $uri") - val traceLocationQRCode = qrCodeVerifier.verify(uri) + if (!uri.isValidQRCodeUri()) + throw IllegalArgumentException("Invalid uri: $uri") + + val encodedEvent = uri.substringAfterLast("/") + val traceLocationQRCode = qrCodeVerifier.verify(encodedEvent) Timber.i("traceLocationQRCode: $traceLocationQRCode") - navigationRoutes.postValue(traceLocationQRCode) + navigationRoutes.postValue( + TraceLocationQRCode( + traceLocationQRCode.singedTraceLocation.event + ) + ) } catch (e: Exception) { Timber.d(e, "TraceLocation verification failed") e.report(ExceptionCategory.INTERNAL) From 8e388acfbd2e2e23781e4792f15ac1c82b48664d Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Wed, 10 Mar 2021 18:34:33 +0100 Subject: [PATCH 29/30] Pass QRCodeVerifyResult directly --- .../checkin/VerifiedTraceLocationKtTest.kt | 4 +-- .../checkins/qrcode/TraceLocationQRCode.kt | 7 ------ .../attendee/checkin/CheckInsFragment.kt | 2 +- .../attendee/checkin/CheckInsViewModel.kt | 18 ++++++------- .../attendee/checkin/VerifiedTraceLocation.kt | 25 +++++++++++-------- 5 files changed, 25 insertions(+), 31 deletions(-) delete mode 100644 Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/TraceLocationQRCode.kt diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocationKtTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocationKtTest.kt index a17aaaba973..9ae34bda665 100644 --- a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocationKtTest.kt +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocationKtTest.kt @@ -1,6 +1,6 @@ package de.rki.coronawarnapp.ui.eventregistration.attendee.checkin -import de.rki.coronawarnapp.eventregistration.checkins.qrcode.TraceLocationQRCode +import de.rki.coronawarnapp.eventregistration.checkins.qrcode.QRCodeVerifyResult import de.rki.coronawarnapp.eventregistration.common.decodeBase32 import de.rki.coronawarnapp.server.protocols.internal.evreg.SignedEventOuterClass import io.kotest.assertions.throwables.shouldNotThrowAny @@ -20,7 +20,7 @@ class VerifiedTraceLocationKtTest : BaseTestInstrumentation() { val signedTraceLocation = SignedEventOuterClass.SignedEvent.parseFrom(DECODED_TRACE_LOCATION.decodeBase32().toByteArray()) val verifiedTraceLocation = - TraceLocationQRCode(traceLocation = signedTraceLocation.event).toVerifiedTraceLocation() + QRCodeVerifyResult(singedTraceLocation = signedTraceLocation).toVerifiedTraceLocation() verifiedTraceLocation shouldBe VerifiedTraceLocation( guid = "Yc48RFi/hfyXKlF4DEDs/w==", start = Instant.parse("1970-02-01T02:39:15.000Z"), diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/TraceLocationQRCode.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/TraceLocationQRCode.kt deleted file mode 100644 index 8e6e87487b9..00000000000 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/qrcode/TraceLocationQRCode.kt +++ /dev/null @@ -1,7 +0,0 @@ -package de.rki.coronawarnapp.eventregistration.checkins.qrcode - -import de.rki.coronawarnapp.server.protocols.internal.evreg.EventOuterClass - -data class TraceLocationQRCode( - val traceLocation: EventOuterClass.Event -) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt index b70081beac2..2ab0eb9fa9a 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsFragment.kt @@ -51,7 +51,7 @@ class CheckInsFragment : Fragment(R.layout.fragment_check_ins), AutoInject { } uri?.let { viewModel.verifyUri(it) } - viewModel.navigationRoutes.observe2(this) { + viewModel.verifyResult.observe2(this) { doNavigate( CheckInsFragmentDirections .actionCheckInsFragmentToConfirmCheckInFragment(it.toVerifiedTraceLocation()) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt index 5ac860f689e..c72f034e320 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/CheckInsViewModel.kt @@ -1,14 +1,15 @@ package de.rki.coronawarnapp.ui.eventregistration.attendee.checkin +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import de.rki.coronawarnapp.eventregistration.checkins.qrcode.QRCodeVerifier -import de.rki.coronawarnapp.eventregistration.checkins.qrcode.TraceLocationQRCode +import de.rki.coronawarnapp.eventregistration.checkins.qrcode.QRCodeVerifyResult import de.rki.coronawarnapp.eventregistration.checkins.qrcode.isValidQRCodeUri import de.rki.coronawarnapp.exception.ExceptionCategory import de.rki.coronawarnapp.exception.reporting.report import de.rki.coronawarnapp.util.coroutine.DispatcherProvider -import de.rki.coronawarnapp.util.ui.SingleLiveEvent import de.rki.coronawarnapp.util.viewmodel.CWAViewModel import de.rki.coronawarnapp.util.viewmodel.SimpleCWAViewModelFactory import timber.log.Timber @@ -18,7 +19,8 @@ class CheckInsViewModel @AssistedInject constructor( private val qrCodeVerifier: QRCodeVerifier ) : CWAViewModel(dispatcherProvider) { - val navigationRoutes = SingleLiveEvent() + private val verifyResultData = MutableLiveData() + val verifyResult: LiveData = verifyResultData fun verifyUri(uri: String) = launch { try { @@ -27,13 +29,9 @@ class CheckInsViewModel @AssistedInject constructor( throw IllegalArgumentException("Invalid uri: $uri") val encodedEvent = uri.substringAfterLast("/") - val traceLocationQRCode = qrCodeVerifier.verify(encodedEvent) - Timber.i("traceLocationQRCode: $traceLocationQRCode") - navigationRoutes.postValue( - TraceLocationQRCode( - traceLocationQRCode.singedTraceLocation.event - ) - ) + val verifyResult = qrCodeVerifier.verify(encodedEvent) + Timber.i("verifyResult: $verifyResult") + verifyResultData.postValue(verifyResult) } catch (e: Exception) { Timber.d(e, "TraceLocation verification failed") e.report(ExceptionCategory.INTERNAL) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocation.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocation.kt index 464ecd9725b..c3c21ccc1f3 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocation.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocation.kt @@ -1,7 +1,8 @@ package de.rki.coronawarnapp.ui.eventregistration.attendee.checkin import android.os.Parcelable -import de.rki.coronawarnapp.eventregistration.checkins.qrcode.TraceLocationQRCode +import de.rki.coronawarnapp.eventregistration.checkins.CheckIn +import de.rki.coronawarnapp.eventregistration.checkins.qrcode.QRCodeVerifyResult import kotlinx.parcelize.Parcelize import okio.ByteString.Companion.toByteString import org.joda.time.Instant @@ -13,18 +14,20 @@ data class VerifiedTraceLocation( val description: String?, val start: Instant?, val end: Instant?, - val defaultCheckInLengthInMinutes: Int + val defaultCheckInLengthInMinutes: Int, + // TODO add required properties to confirm check-in ) : Parcelable -fun TraceLocationQRCode.toVerifiedTraceLocation() = with(traceLocation) { - VerifiedTraceLocation( - guid = guid.toByteArray().toByteString().base64(), - start = start.instant(), - end = end.instant(), - description = description, - defaultCheckInLengthInMinutes = defaultCheckInLengthInMinutes - ) -} +fun QRCodeVerifyResult.toVerifiedTraceLocation() = + with(singedTraceLocation.event) { + VerifiedTraceLocation( + guid = guid.toByteArray().toByteString().base64(), + start = start.instant(), + end = end.instant(), + description = description, + defaultCheckInLengthInMinutes = defaultCheckInLengthInMinutes + ) + } /** * Converts time in seconds into [Instant] From acda89f425f368a76acb523b607c0276736598a7 Mon Sep 17 00:00:00 2001 From: Mohamed Metwalli Date: Wed, 10 Mar 2021 18:38:41 +0100 Subject: [PATCH 30/30] lint --- .../eventregistration/attendee/checkin/VerifiedTraceLocation.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocation.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocation.kt index c3c21ccc1f3..b733005d9a7 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocation.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkin/VerifiedTraceLocation.kt @@ -1,7 +1,6 @@ package de.rki.coronawarnapp.ui.eventregistration.attendee.checkin import android.os.Parcelable -import de.rki.coronawarnapp.eventregistration.checkins.CheckIn import de.rki.coronawarnapp.eventregistration.checkins.qrcode.QRCodeVerifyResult import kotlinx.parcelize.Parcelize import okio.ByteString.Companion.toByteString