mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-18 20:29:10 +03:00
Observe timeline event of the selected poll
This commit is contained in:
parent
60d3ae6cc5
commit
afe036dd9d
7 changed files with 83 additions and 15 deletions
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (c) 2023 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.core.event
|
||||
|
||||
import androidx.lifecycle.asFlow
|
||||
import im.vector.app.core.di.ActiveSessionHolder
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.emptyFlow
|
||||
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
|
||||
import org.matrix.android.sdk.flow.unwrap
|
||||
import javax.inject.Inject
|
||||
|
||||
// TODO add unit tests
|
||||
class GetTimelineEventUseCase @Inject constructor(
|
||||
private val activeSessionHolder: ActiveSessionHolder,
|
||||
) {
|
||||
|
||||
fun execute(roomId: String, eventId: String): Flow<TimelineEvent> {
|
||||
return activeSessionHolder
|
||||
.getActiveSession()
|
||||
.roomService()
|
||||
.getRoom(roomId)
|
||||
?.timelineService()
|
||||
?.getTimelineEventLive(eventId)
|
||||
?.asFlow()
|
||||
?.unwrap()
|
||||
?: emptyFlow()
|
||||
}
|
||||
}
|
|
@ -47,9 +47,13 @@ class RoomPollDetailActivity : VectorBaseActivity<ActivitySimpleBinding>() {
|
|||
}
|
||||
|
||||
companion object {
|
||||
fun newIntent(context: Context, pollId: String): Intent {
|
||||
fun newIntent(context: Context, pollId: String, roomId: String): Intent {
|
||||
return Intent(context, RoomPollDetailActivity::class.java).apply {
|
||||
putExtra(Mavericks.KEY_ARG, RoomPollDetailArgs(pollId))
|
||||
val args = RoomPollDetailArgs(
|
||||
pollId = pollId,
|
||||
roomId = roomId,
|
||||
)
|
||||
putExtra(Mavericks.KEY_ARG, args)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ import javax.inject.Inject
|
|||
@Parcelize
|
||||
data class RoomPollDetailArgs(
|
||||
val pollId: String,
|
||||
val roomId: String,
|
||||
) : Parcelable
|
||||
|
||||
@AndroidEntryPoint
|
||||
|
@ -80,13 +81,9 @@ class RoomPollDetailFragment : VectorBaseFragment<FragmentRoomPollDetailBinding>
|
|||
override fun invalidate() = withState(viewModel) { state ->
|
||||
state.pollDetail ?: return@withState
|
||||
|
||||
// TODO should we update the title when the poll status changes?
|
||||
setupToolbar(state.pollDetail.isEnded)
|
||||
|
||||
/*
|
||||
state.getSelectedPoll()?.let { _ ->
|
||||
roomPollDetailController.setData(state)
|
||||
}
|
||||
Unit
|
||||
*/
|
||||
// TODO update data of the controller
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,15 +18,25 @@ package im.vector.app.features.roomprofile.polls.detail.ui
|
|||
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedInject
|
||||
import im.vector.app.core.event.GetTimelineEventUseCase
|
||||
import im.vector.app.core.platform.VectorViewModel
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
|
||||
class RoomPollDetailViewModel @AssistedInject constructor(
|
||||
@Assisted initialState: RoomPollDetailViewState,
|
||||
private val getTimelineEventUseCase: GetTimelineEventUseCase,
|
||||
) : VectorViewModel<RoomPollDetailViewState, RoomPollDetailAction, RoomPollDetailViewEvent>(initialState) {
|
||||
|
||||
init {
|
||||
// TODO observe poll using TimelineService.getTimelineEventLive
|
||||
// TODO create a dedicated useCase and mapper
|
||||
observePollDetails(
|
||||
pollId = initialState.pollId,
|
||||
roomId = initialState.roomId,
|
||||
)
|
||||
}
|
||||
|
||||
private fun observePollDetails(pollId: String, roomId: String) {
|
||||
getTimelineEventUseCase.execute(roomId = roomId, eventId = pollId)
|
||||
.launchIn(viewModelScope)
|
||||
}
|
||||
|
||||
override fun handle(action: RoomPollDetailAction) {
|
||||
|
|
|
@ -20,8 +20,12 @@ import com.airbnb.mvrx.MavericksState
|
|||
|
||||
data class RoomPollDetailViewState(
|
||||
val pollId: String,
|
||||
val roomId: String,
|
||||
val pollDetail: RoomPollDetail? = null,
|
||||
) : MavericksState {
|
||||
|
||||
constructor(roomPollDetailArgs: RoomPollDetailArgs) : this(pollId = roomPollDetailArgs.pollId)
|
||||
constructor(roomPollDetailArgs: RoomPollDetailArgs) : this(
|
||||
pollId = roomPollDetailArgs.pollId,
|
||||
roomId = roomPollDetailArgs.roomId,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -127,8 +127,12 @@ abstract class RoomPollsListFragment :
|
|||
views.roomPollsLoadMoreWhenEmptyProgress.isVisible = viewState.hasNoPollsAndCanLoadMore() && viewState.isLoadingMore
|
||||
}
|
||||
|
||||
override fun onPollClicked(pollId: String) {
|
||||
viewNavigator.goToPollDetails(requireContext(), pollId)
|
||||
override fun onPollClicked(pollId: String) = withState(viewModel) {
|
||||
viewNavigator.goToPollDetails(
|
||||
context = requireContext(),
|
||||
pollId = pollId,
|
||||
roomId = it.roomId,
|
||||
)
|
||||
}
|
||||
|
||||
override fun onLoadMoreClicked() {
|
||||
|
|
|
@ -23,7 +23,13 @@ import javax.inject.Inject
|
|||
// TODO add unit tests
|
||||
class RoomPollsListNavigator @Inject constructor() {
|
||||
|
||||
fun goToPollDetails(context: Context, pollId: String) {
|
||||
context.startActivity(RoomPollDetailActivity.newIntent(context, pollId))
|
||||
fun goToPollDetails(context: Context, pollId: String, roomId: String) {
|
||||
context.startActivity(
|
||||
RoomPollDetailActivity.newIntent(
|
||||
context = context,
|
||||
pollId = pollId,
|
||||
roomId = roomId,
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue