Adding use case to get live location of users

This commit is contained in:
Maxime NATUREL 2022-05-11 16:15:45 +02:00
parent 44ca82bbef
commit d6029210d0
2 changed files with 56 additions and 6 deletions

View File

@ -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<List<UserLiveLocationViewState>> {
// 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))
}
}
}

View File

@ -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<LocationLiveMapViewState, LocationLiveMapAction, LocationLiveMapViewEvents>(initialState) {
// TODO create useCase to get Flow of user live location in room => Mock data for now
@AssistedFactory
interface Factory : MavericksAssistedViewModelFactory<LocationLiveMapViewModel, LocationLiveMapViewState> {
override fun create(initialState: LocationLiveMapViewState): LocationLiveMapViewModel
@ -41,7 +40,9 @@ class LocationLiveMapViewModel @AssistedInject constructor(
companion object : MavericksViewModelFactory<LocationLiveMapViewModel, LocationLiveMapViewState> 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) {