From 1f01836cb7da8101430508fe78dc9b2e98109df9 Mon Sep 17 00:00:00 2001 From: Juraj Kusnier <jurajkusnier@users.noreply.github.com> Date: Wed, 31 Mar 2021 16:28:13 +0200 Subject: [PATCH] Event duplication (EXPOSUREAPP-5985) (#2714) * TraceLocation duplication * Implement event duplication to list fragment * Update nav_graph Co-authored-by: harambasicluka <64483219+harambasicluka@users.noreply.github.com> Co-authored-by: Kolya Opahle <k.opahle@sap.com> --- .../res/navigation/test_nav_graph.xml | 24 +++++++++++++------ .../create/TraceLocationCreateFragment.kt | 22 ++++++++++++++--- .../organizer/list/TraceLocationEvent.kt | 2 ++ .../organizer/list/TraceLocationsFragment.kt | 20 ++++++++++++++++ .../organizer/list/TraceLocationsViewModel.kt | 2 +- .../trace_location_organizer_nav_graph.xml | 10 ++++++-- 6 files changed, 67 insertions(+), 13 deletions(-) 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 1f46f457a..fac7f7f82 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 @@ -178,25 +178,27 @@ android:id="@+id/traceLocationOrganizerCategoriesFragment" android:name="de.rki.coronawarnapp.ui.eventregistration.organizer.category.TraceLocationCategoryFragment" android:label="TraceLocationCategoryFragment" - tools:layout="@layout/trace_location_organizer_category_fragment" /> - <fragment - android:id="@+id/qrCodeDetailFragment" - android:name="de.rki.coronawarnapp.ui.eventregistration.organizer.details.QrCodeDetailFragment" - android:label="QrCodeDetailFragment" - tools:layout="@layout/trace_location_organizer_qr_code_detail_fragment" > + tools:layout="@layout/trace_location_organizer_category_fragment"> <action android:id="@+id/action_traceLocationOrganizerCategoriesFragment_to_traceLocationCreateFragment" app:destination="@id/traceLocationCreateFragment" /> </fragment> + <fragment + android:id="@+id/qrCodeDetailFragment" + android:name="de.rki.coronawarnapp.ui.eventregistration.organizer.details.QrCodeDetailFragment" + android:label="QrCodeDetailFragment" + tools:layout="@layout/trace_location_organizer_qr_code_detail_fragment" /> <fragment android:id="@+id/traceLocationOrganizerListFragment" android:name="de.rki.coronawarnapp.ui.eventregistration.organizer.list.TraceLocationsFragment" android:label="TraceLocationCategoryFragment" tools:layout="@layout/trace_location_organizer_trace_locations_list_fragment"> - <action android:id="@+id/action_traceLocationOrganizerListFragment_to_traceLocationOrganizerCategoriesFragment" app:destination="@id/traceLocationOrganizerCategoriesFragment" /> + <action + android:id="@+id/action_traceLocationOrganizerListFragment_to_traceLocationCreateFragment" + app:destination="@id/traceLocationCreateFragment" /> </fragment> <fragment android:id="@+id/traceLocationCreateFragment" @@ -206,6 +208,14 @@ <argument android:name="category" app:argType="de.rki.coronawarnapp.ui.eventregistration.organizer.category.adapter.category.TraceLocationCategory" /> + <argument + android:name="originalItem" + android:defaultValue="@null" + app:argType="de.rki.coronawarnapp.eventregistration.checkins.qrcode.TraceLocation" + app:nullable="true" /> + <action + android:id="@+id/action_traceLocationCreateFragment_to_traceLocationOrganizerListFragment" + app:destination="@id/traceLocationOrganizerListFragment" /> </fragment> </navigation> diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/organizer/create/TraceLocationCreateFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/organizer/create/TraceLocationCreateFragment.kt index 02e785df4..6d02e318f 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/organizer/create/TraceLocationCreateFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/organizer/create/TraceLocationCreateFragment.kt @@ -3,7 +3,6 @@ package de.rki.coronawarnapp.ui.eventregistration.organizer.create import android.os.Bundle import android.text.format.DateFormat.is24HourFormat import android.view.View -import android.widget.Toast import androidx.core.view.isVisible import androidx.core.widget.doOnTextChanged import androidx.fragment.app.Fragment @@ -25,6 +24,7 @@ import de.rki.coronawarnapp.ui.durationpicker.DurationPicker import de.rki.coronawarnapp.ui.durationpicker.toContactDiaryFormat import de.rki.coronawarnapp.util.DialogHelper import de.rki.coronawarnapp.util.di.AutoInject +import de.rki.coronawarnapp.util.ui.doNavigate import de.rki.coronawarnapp.util.ui.popBackStack import de.rki.coronawarnapp.util.ui.viewBindingLazy import de.rki.coronawarnapp.util.viewmodel.CWAViewModelFactoryProvider @@ -66,8 +66,10 @@ class TraceLocationCreateFragment : Fragment(R.layout.trace_location_create_frag DialogHelper.showDialog(getErrorDialogInstance(result.exception)) } is TraceLocationCreateViewModel.Result.Success -> { - // TODO: will be handled in another PR - Toast.makeText(context, "Done! TODO: redirect to another screen", Toast.LENGTH_SHORT).show() + doNavigate( + TraceLocationCreateFragmentDirections + .actionTraceLocationCreateFragmentToTraceLocationOrganizerListFragment() + ) } } } @@ -116,6 +118,20 @@ class TraceLocationCreateFragment : Fragment(R.layout.trace_location_create_frag it.hideKeyboard() viewModel.send() } + + if (savedInstanceState == null) { + navArgs.originalItem?.let { + binding.apply { + descriptionInputEdit.setText(it.description) + placeInputEdit.setText(it.address) + } + viewModel.apply { + begin = LocalDateTime(it.startDate) + end = LocalDateTime(it.endDate) + checkInLength = Duration.standardMinutes(it.defaultCheckInLengthInMinutes?.toLong() ?: 0L) + } + } + } } private fun getErrorDialogInstance(exception: Exception): DialogHelper.DialogInstance { diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/organizer/list/TraceLocationEvent.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/organizer/list/TraceLocationEvent.kt index f40e8d04b..38db76c07 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/organizer/list/TraceLocationEvent.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/organizer/list/TraceLocationEvent.kt @@ -4,6 +4,8 @@ import de.rki.coronawarnapp.eventregistration.checkins.qrcode.TraceLocation sealed class TraceLocationEvent { + data class DuplicateItem(val traceLocation: TraceLocation) : TraceLocationEvent() + data class ConfirmDeleteItem(val traceLocation: TraceLocation) : TraceLocationEvent() data class ConfirmSwipeItem(val traceLocation: TraceLocation, val position: Int) : TraceLocationEvent() diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/organizer/list/TraceLocationsFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/organizer/list/TraceLocationsFragment.kt index d72e35e21..14f6f3e68 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/organizer/list/TraceLocationsFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/organizer/list/TraceLocationsFragment.kt @@ -14,6 +14,7 @@ import com.google.android.material.transition.Hold import de.rki.coronawarnapp.R import de.rki.coronawarnapp.databinding.TraceLocationOrganizerTraceLocationsListFragmentBinding import de.rki.coronawarnapp.eventregistration.checkins.qrcode.TraceLocation +import de.rki.coronawarnapp.ui.eventregistration.organizer.category.adapter.category.traceLocationCategories import de.rki.coronawarnapp.util.DialogHelper import de.rki.coronawarnapp.util.di.AutoInject import de.rki.coronawarnapp.util.list.isSwipeable @@ -26,6 +27,7 @@ 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 TraceLocationsFragment : Fragment(R.layout.trace_location_organizer_trace_locations_list_fragment), AutoInject { @@ -78,6 +80,9 @@ class TraceLocationsFragment : Fragment(R.layout.trace_location_organizer_trace_ is TraceLocationEvent.ConfirmSwipeItem -> { showDeleteSingleDialog(it.traceLocation, it.position) } + is TraceLocationEvent.DuplicateItem -> { + openCreateEventFragment(it.traceLocation) + } } } @@ -129,6 +134,21 @@ class TraceLocationsFragment : Fragment(R.layout.trace_location_organizer_trace_ DialogHelper.showDialog(deleteAllDialog) } + private fun openCreateEventFragment(traceLocation: TraceLocation) { + val category = traceLocationCategories.find { it.type == traceLocation.type } + if (category == null) { + Timber.e("Category not found, traceLocation = $traceLocation") + } else { + findNavController().navigate( + TraceLocationsFragmentDirections + .actionTraceLocationOrganizerListFragmentToTraceLocationCreateFragment( + category, + traceLocation + ) + ) + } + } + private fun showDeleteSingleDialog(traceLocation: TraceLocation, position: Int?) { AlertDialog.Builder(requireContext()).apply { setTitle(R.string.trace_location_organiser_list_delete_single_popup_title) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/organizer/list/TraceLocationsViewModel.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/organizer/list/TraceLocationsViewModel.kt index d30d8ea3d..639de4e4a 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/organizer/list/TraceLocationsViewModel.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/eventregistration/organizer/list/TraceLocationsViewModel.kt @@ -34,7 +34,7 @@ class TraceLocationsViewModel @AssistedInject constructor( TraceLocationVH.Item( traceLocation = traceLocation, onCheckIn = { /* TODO */ }, - onDuplicate = { /* TODO */ }, + onDuplicate = { events.postValue(TraceLocationEvent.DuplicateItem(it)) }, onShowPrint = { /* TODO */ }, onClearItem = { events.postValue(TraceLocationEvent.ConfirmDeleteItem(it)) }, onSwipeItem = { traceLocation, position -> diff --git a/Corona-Warn-App/src/main/res/navigation/trace_location_organizer_nav_graph.xml b/Corona-Warn-App/src/main/res/navigation/trace_location_organizer_nav_graph.xml index 469c3064b..69035f13a 100644 --- a/Corona-Warn-App/src/main/res/navigation/trace_location_organizer_nav_graph.xml +++ b/Corona-Warn-App/src/main/res/navigation/trace_location_organizer_nav_graph.xml @@ -24,7 +24,6 @@ android:name="de.rki.coronawarnapp.ui.eventregistration.organizer.category.TraceLocationCategoryFragment" android:label="TraceLocationCategoryFragment" tools:layout="@layout/trace_location_organizer_category_fragment"> - <action android:id="@+id/action_traceLocationOrganizerCategoriesFragment_to_traceLocationCreateFragment" app:destination="@id/traceLocationCreateFragment" /> @@ -37,6 +36,11 @@ <argument android:name="category" app:argType="de.rki.coronawarnapp.ui.eventregistration.organizer.category.adapter.category.TraceLocationCategory" /> + <argument + android:name="originalItem" + android:defaultValue="@null" + app:argType="de.rki.coronawarnapp.eventregistration.checkins.qrcode.TraceLocation" + app:nullable="true" /> <action android:id="@+id/action_traceLocationCreateFragment_to_traceLocationOrganizerListFragment" app:destination="@id/traceLocationOrganizerListFragment" /> @@ -46,10 +50,12 @@ android:name="de.rki.coronawarnapp.ui.eventregistration.organizer.list.TraceLocationsFragment" android:label="TraceLocationCategoryFragment" tools:layout="@layout/trace_location_organizer_trace_locations_list_fragment"> - <action android:id="@+id/action_traceLocationOrganizerListFragment_to_traceLocationOrganizerCategoriesFragment" app:destination="@id/traceLocationOrganizerCategoriesFragment" /> + <action + android:id="@+id/action_traceLocationOrganizerListFragment_to_traceLocationCreateFragment" + app:destination="@id/traceLocationCreateFragment" /> </fragment> </navigation> \ No newline at end of file -- GitLab