Use existing ResultListener interface

This commit is contained in:
Maxime NATUREL 2022-03-30 17:35:19 +02:00
parent 265dd4a0c3
commit a6a494170e
2 changed files with 11 additions and 16 deletions

View File

@ -30,6 +30,7 @@ import com.airbnb.mvrx.withState
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.mapbox.mapboxsdk.maps.MapView import com.mapbox.mapboxsdk.maps.MapView
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.app.core.platform.VectorBaseFragment 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_BACKGROUND_LOCATION_SHARING
import im.vector.app.core.utils.PERMISSIONS_FOR_FOREGROUND_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, private val vectorFeatures: VectorFeatures,
) : VectorBaseFragment<FragmentLocationSharingBinding>(), ) : VectorBaseFragment<FragmentLocationSharingBinding>(),
LocationTargetChangeListener, LocationTargetChangeListener,
ChooseLiveDurationBottomSheet.DurationChoiceListener { VectorBaseBottomSheetDialogFragment.ResultListener {
private val viewModel: LocationSharingViewModel by fragmentViewModel() private val viewModel: LocationSharingViewModel by fragmentViewModel()
@ -242,8 +243,10 @@ class LocationSharingFragment @Inject constructor(
.show(requireActivity().supportFragmentManager, "DISPLAY_CHOOSE_DURATION_OPTIONS") .show(requireActivity().supportFragmentManager, "DISPLAY_CHOOSE_DURATION_OPTIONS")
} }
override fun onDurationChoice(durationMillis: Long) { override fun onBottomSheetResult(resultCode: Int, data: Any?) {
viewModel.handle(LocationSharingAction.StartLiveLocationSharing(durationMillis)) if (resultCode == VectorBaseBottomSheetDialogFragment.ResultListener.RESULT_OK) {
(data as? Long)?.let { viewModel.handle(LocationSharingAction.StartLiveLocationSharing(it)) }
}
} }
private fun updateMap(state: LocationSharingViewState) { private fun updateMap(state: LocationSharingViewState) {

View File

@ -23,6 +23,7 @@ import android.view.ViewGroup
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment.ResultListener.Companion.RESULT_OK
import im.vector.app.databinding.BottomSheetChooseLiveLocationShareDurationBinding 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 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 @AndroidEntryPoint
class ChooseLiveDurationBottomSheet : class ChooseLiveDurationBottomSheet :
VectorBaseBottomSheetDialogFragment<BottomSheetChooseLiveLocationShareDurationBinding>() { VectorBaseBottomSheetDialogFragment<BottomSheetChooseLiveLocationShareDurationBinding>() {
// TODO fix text color problem of button in dqrk mode
var durationChoiceListener: DurationChoiceListener? = null
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetChooseLiveLocationShareDurationBinding { override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetChooseLiveLocationShareDurationBinding {
return BottomSheetChooseLiveLocationShareDurationBinding.inflate(inflater, container, false) return BottomSheetChooseLiveLocationShareDurationBinding.inflate(inflater, container, false)
} }
@ -60,17 +57,12 @@ class ChooseLiveDurationBottomSheet :
initConfirmButton() 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() // we are not using state for this one as it's static, so no need to override invalidate()
private fun initConfirmButton() { private fun initConfirmButton() {
views.liveLocShareChooseDurationConfirm.setOnClickListener { views.liveLocShareChooseDurationConfirm.setOnClickListener {
val currentChoice = getCurrentChoice() val currentChoice = getCurrentChoice()
durationChoiceListener?.onDurationChoice(currentChoice) resultListener?.onBottomSheetResult(RESULT_OK, currentChoice)
dismiss() dismiss()
} }
} }
@ -85,9 +77,9 @@ class ChooseLiveDurationBottomSheet :
} }
companion object { companion object {
fun newInstance(durationChoiceListener: DurationChoiceListener): ChooseLiveDurationBottomSheet { fun newInstance(resultListener: ResultListener): ChooseLiveDurationBottomSheet {
val bottomSheet = ChooseLiveDurationBottomSheet() val bottomSheet = ChooseLiveDurationBottomSheet()
bottomSheet.durationChoiceListener = durationChoiceListener bottomSheet.resultListener = resultListener
return bottomSheet return bottomSheet
} }
} }