Implement stop sharing function from bottom sheet.

This commit is contained in:
Onuray Sahin 2022-05-27 16:52:20 +03:00
parent 83e79207c1
commit 2eaf843031
4 changed files with 37 additions and 2 deletions

View File

@ -26,6 +26,7 @@ import im.vector.app.core.resources.StringProvider
import im.vector.app.core.resources.toTimestamp
import im.vector.app.core.time.Clock
import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.location.live.map.bottomsheet.LiveLocationUserItem
import im.vector.app.features.location.live.map.bottomsheet.liveLocationUserItem
import javax.inject.Inject
@ -54,10 +55,17 @@ class LiveLocationBottomSheetController @Inject constructor(
val currentUserLocations = userLocations ?: return
val host = this
val userItemCallback = object : LiveLocationUserItem.Callback {
override fun onStopSharingClicked() {
host.callback?.onStopLocationClicked()
}
}
currentUserLocations.forEach { liveLocationViewState ->
val remainingTime = getFormattedLocalTimeEndOfLive(liveLocationViewState.endOfLiveTimestampMillis)
liveLocationUserItem {
id(liveLocationViewState.matrixItem.id)
callback(userItemCallback)
matrixItem(liveLocationViewState.matrixItem)
stringProvider(host.stringProvider)
clock(host.clock)

View File

@ -21,4 +21,5 @@ import im.vector.app.core.platform.VectorViewModelAction
sealed class LocationLiveMapAction : VectorViewModelAction {
data class AddMapSymbol(val key: String, val value: Long) : LocationLiveMapAction()
data class RemoveMapSymbol(val key: String) : LocationLiveMapAction()
object StopSharing : LocationLiveMapAction()
}

View File

@ -71,6 +71,16 @@ class LocationLiveMapViewFragment @Inject constructor(
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
views.bottomSheetRecyclerView.configureWith(bottomSheetController, hasFixedSize = false, disableItemAnimation = true)
bottomSheetController.callback = object : LiveLocationBottomSheetController.Callback {
override fun onUserSelected(userId: String) {
}
override fun onStopLocationClicked() {
viewModel.handle(LocationLiveMapAction.StopSharing)
}
}
}
override fun onResume() {

View File

@ -23,13 +23,15 @@ import dagger.assisted.AssistedInject
import im.vector.app.core.di.MavericksAssistedViewModelFactory
import im.vector.app.core.di.hiltMavericksViewModelFactory
import im.vector.app.core.platform.VectorViewModel
import im.vector.app.features.location.LocationSharingServiceConnection
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
class LocationLiveMapViewModel @AssistedInject constructor(
@Assisted private val initialState: LocationLiveMapViewState,
getListOfUserLiveLocationUseCase: GetListOfUserLiveLocationUseCase
) : VectorViewModel<LocationLiveMapViewState, LocationLiveMapAction, LocationLiveMapViewEvents>(initialState) {
getListOfUserLiveLocationUseCase: GetListOfUserLiveLocationUseCase,
private val locationSharingServiceConnection: LocationSharingServiceConnection,
) : VectorViewModel<LocationLiveMapViewState, LocationLiveMapAction, LocationLiveMapViewEvents>(initialState), LocationSharingServiceConnection.Callback {
@AssistedFactory
interface Factory : MavericksAssistedViewModelFactory<LocationLiveMapViewModel, LocationLiveMapViewState> {
@ -42,12 +44,14 @@ class LocationLiveMapViewModel @AssistedInject constructor(
getListOfUserLiveLocationUseCase.execute(initialState.roomId)
.onEach { setState { copy(userLocations = it) } }
.launchIn(viewModelScope)
locationSharingServiceConnection.bind(this)
}
override fun handle(action: LocationLiveMapAction) {
when (action) {
is LocationLiveMapAction.AddMapSymbol -> handleAddMapSymbol(action)
is LocationLiveMapAction.RemoveMapSymbol -> handleRemoveMapSymbol(action)
LocationLiveMapAction.StopSharing -> handleStopSharing()
}
}
@ -64,4 +68,16 @@ class LocationLiveMapViewModel @AssistedInject constructor(
copy(mapSymbolIds = newMapSymbolIds)
}
}
private fun handleStopSharing() {
locationSharingServiceConnection.stopLiveLocationSharing(initialState.roomId)
}
override fun onLocationServiceRunning() {
// NOOP
}
override fun onLocationServiceStopped() {
// NOOP
}
}