diff --git a/vector/src/main/java/im/vector/app/features/location/LocationSharingFragment.kt b/vector/src/main/java/im/vector/app/features/location/LocationSharingFragment.kt index 3fdae43312..c0672bc3bb 100644 --- a/vector/src/main/java/im/vector/app/features/location/LocationSharingFragment.kt +++ b/vector/src/main/java/im/vector/app/features/location/LocationSharingFragment.kt @@ -30,6 +30,7 @@ import com.airbnb.mvrx.withState import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.mapbox.mapboxsdk.maps.MapView import im.vector.app.R +import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.core.utils.PERMISSIONS_FOR_BACKGROUND_LOCATION_SHARING import im.vector.app.core.utils.PERMISSIONS_FOR_FOREGROUND_LOCATION_SHARING @@ -55,7 +56,7 @@ class LocationSharingFragment @Inject constructor( private val vectorFeatures: VectorFeatures, ) : VectorBaseFragment(), LocationTargetChangeListener, - ChooseLiveDurationBottomSheet.DurationChoiceListener { + VectorBaseBottomSheetDialogFragment.ResultListener { private val viewModel: LocationSharingViewModel by fragmentViewModel() @@ -242,8 +243,10 @@ class LocationSharingFragment @Inject constructor( .show(requireActivity().supportFragmentManager, "DISPLAY_CHOOSE_DURATION_OPTIONS") } - override fun onDurationChoice(durationMillis: Long) { - viewModel.handle(LocationSharingAction.StartLiveLocationSharing(durationMillis)) + override fun onBottomSheetResult(resultCode: Int, data: Any?) { + if (resultCode == VectorBaseBottomSheetDialogFragment.ResultListener.RESULT_OK) { + (data as? Long)?.let { viewModel.handle(LocationSharingAction.StartLiveLocationSharing(it)) } + } } private fun updateMap(state: LocationSharingViewState) { diff --git a/vector/src/main/java/im/vector/app/features/location/live/duration/ChooseLiveDurationBottomSheet.kt b/vector/src/main/java/im/vector/app/features/location/live/duration/ChooseLiveDurationBottomSheet.kt index f0bee558cc..851dfa9d0b 100644 --- a/vector/src/main/java/im/vector/app/features/location/live/duration/ChooseLiveDurationBottomSheet.kt +++ b/vector/src/main/java/im/vector/app/features/location/live/duration/ChooseLiveDurationBottomSheet.kt @@ -23,6 +23,7 @@ import android.view.ViewGroup import dagger.hilt.android.AndroidEntryPoint import im.vector.app.R import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment +import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment.ResultListener.Companion.RESULT_OK import im.vector.app.databinding.BottomSheetChooseLiveLocationShareDurationBinding /** @@ -41,16 +42,12 @@ private const val DURATION_IN_MS_OPTION_2 = 60 * 60_000L private const val DURATION_IN_MS_OPTION_3 = 8 * 60 * 60_000L /** - * Bottom sheet displaying list of options to choose the duration of the live sharing. + * Bottom sheet displaying list of options to choose the duration of the location live sharing. */ @AndroidEntryPoint class ChooseLiveDurationBottomSheet : VectorBaseBottomSheetDialogFragment() { - // TODO fix text color problem of button in dqrk mode - - var durationChoiceListener: DurationChoiceListener? = null - override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetChooseLiveLocationShareDurationBinding { return BottomSheetChooseLiveLocationShareDurationBinding.inflate(inflater, container, false) } @@ -60,17 +57,12 @@ class ChooseLiveDurationBottomSheet : initConfirmButton() } - override fun onDestroyView() { - durationChoiceListener = null - super.onDestroyView() - } - // we are not using state for this one as it's static, so no need to override invalidate() private fun initConfirmButton() { views.liveLocShareChooseDurationConfirm.setOnClickListener { val currentChoice = getCurrentChoice() - durationChoiceListener?.onDurationChoice(currentChoice) + resultListener?.onBottomSheetResult(RESULT_OK, currentChoice) dismiss() } } @@ -85,9 +77,9 @@ class ChooseLiveDurationBottomSheet : } companion object { - fun newInstance(durationChoiceListener: DurationChoiceListener): ChooseLiveDurationBottomSheet { + fun newInstance(resultListener: ResultListener): ChooseLiveDurationBottomSheet { val bottomSheet = ChooseLiveDurationBottomSheet() - bottomSheet.durationChoiceListener = durationChoiceListener + bottomSheet.resultListener = resultListener return bottomSheet } }