diff --git a/vector/src/main/java/im/vector/app/features/location/live/map/GetCurrentUserLiveLocationUseCase.kt b/vector/src/main/java/im/vector/app/features/location/live/map/GetCurrentUserLiveLocationUseCase.kt new file mode 100644 index 0000000000..3f12fb9181 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/location/live/map/GetCurrentUserLiveLocationUseCase.kt @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2022 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.location.live.map + +import im.vector.app.features.location.LocationData +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flow +import javax.inject.Inject + +class GetCurrentUserLiveLocationUseCase @Inject constructor() { + + // TODO add unit tests + fun execute(): Flow> { + // TODO get room and call SDK to get the correct flow + return flow { + val user1 = UserLiveLocationViewState( + userId = "user1", + locationData = LocationData( + latitude = 48.863447, + longitude = 2.328608, + uncertainty = null + ) + ) + val user2 = UserLiveLocationViewState( + userId = "user2", + locationData = LocationData( + latitude = 48.843816, + longitude = 2.359235, + uncertainty = null + ) + ) + emit(listOf(user1, user2)) + } + } +} diff --git a/vector/src/main/java/im/vector/app/features/location/live/map/LocationLiveMapViewModel.kt b/vector/src/main/java/im/vector/app/features/location/live/map/LocationLiveMapViewModel.kt index e9b9cc8259..c33e708d6b 100644 --- a/vector/src/main/java/im/vector/app/features/location/live/map/LocationLiveMapViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/location/live/map/LocationLiveMapViewModel.kt @@ -23,16 +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.home.room.detail.timeline.helper.LocationPinProvider -import org.matrix.android.sdk.api.session.Session -import org.matrix.android.sdk.api.session.getRoom +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach +// TODO add unit tests class LocationLiveMapViewModel @AssistedInject constructor( @Assisted private val initialState: LocationLiveMapViewState, + getCurrentUserLiveLocationUseCase: GetCurrentUserLiveLocationUseCase ) : VectorViewModel(initialState) { - // TODO create useCase to get Flow of user live location in room => Mock data for now - @AssistedFactory interface Factory : MavericksAssistedViewModelFactory { override fun create(initialState: LocationLiveMapViewState): LocationLiveMapViewModel @@ -41,7 +40,9 @@ class LocationLiveMapViewModel @AssistedInject constructor( companion object : MavericksViewModelFactory by hiltMavericksViewModelFactory() init { - // TODO call use case to collect flow of user live location + getCurrentUserLiveLocationUseCase.execute() + .onEach { setState { copy(userLocations = it) } } + .launchIn(viewModelScope) } override fun handle(action: LocationLiveMapAction) {