mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-04 04:57:39 +01:00
Use existing ResultListener interface
This commit is contained in:
parent
265dd4a0c3
commit
a6a494170e
@ -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<FragmentLocationSharingBinding>(),
|
||||
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) {
|
||||
|
@ -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<BottomSheetChooseLiveLocationShareDurationBinding>() {
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user