Create separate view model for poll detail.

This commit is contained in:
Onuray Sahin 2023-01-31 15:25:37 +03:00 committed by Maxime NATUREL
parent 9d43846b9b
commit 429a71964d
5 changed files with 93 additions and 8 deletions

View File

@ -0,0 +1,23 @@
/*
* 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.features.roomprofile.polls.detail
import im.vector.app.core.platform.VectorViewModelAction
sealed interface RoomPollDetailAction : VectorViewModelAction {
}

View File

@ -24,17 +24,18 @@ import javax.inject.Inject
class RoomPollDetailController @Inject constructor( class RoomPollDetailController @Inject constructor(
) : TypedEpoxyController<RoomPollsViewState>() { ) : TypedEpoxyController<RoomPollDetailViewState>() {
override fun buildModels(viewState: RoomPollsViewState?) { override fun buildModels(viewState: RoomPollDetailViewState?) {
viewState ?: return viewState ?: return
val pollSummary = viewState.getSelectedPoll() ?: return
PollItem_() PollItem_()
/*
.eventId(pollSummary.id) .eventId(pollSummary.id)
.pollQuestion(pollSummary.title.toEpoxyCharSequence()) .pollQuestion(pollSummary.title.toEpoxyCharSequence())
.canVote(viewState.canVoteSelectedPoll()) .canVote(viewState.canVoteSelectedPoll())
.optionViewStates(pollSummary.optionViewStates) .optionViewStates(pollSummary.optionViewStates)
.ended(viewState.canVoteSelectedPoll().not()) .ended(viewState.canVoteSelectedPoll().not())
*/
} }
} }

View File

@ -45,7 +45,7 @@ class RoomPollDetailFragment : VectorBaseFragment<FragmentRoomPollDetailBinding>
@Inject lateinit var roomPollDetailController: RoomPollDetailController @Inject lateinit var roomPollDetailController: RoomPollDetailController
private val viewModel: RoomPollsViewModel by fragmentViewModel() private val viewModel: RoomPollDetailViewModel by fragmentViewModel()
private val roomPollDetailArgs: RoomPollDetailArgs by args() private val roomPollDetailArgs: RoomPollDetailArgs by args()
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentRoomPollDetailBinding { override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentRoomPollDetailBinding {
@ -61,9 +61,9 @@ class RoomPollDetailFragment : VectorBaseFragment<FragmentRoomPollDetailBinding>
) )
} }
private fun setupToolbar(roomPollsType: RoomPollsType) { private fun setupToolbar(isEnded: Boolean) {
val title = if (roomPollsType == RoomPollsType.ACTIVE) getString(R.string.room_polls_active) val title = if (isEnded) getString(R.string.room_polls_ended)
else getString(R.string.room_polls_ended) else getString(R.string.room_polls_active)
setupToolbar(views.roomPollDetailToolbar) setupToolbar(views.roomPollDetailToolbar)
.setTitle(title) .setTitle(title)
@ -71,11 +71,15 @@ class RoomPollDetailFragment : VectorBaseFragment<FragmentRoomPollDetailBinding>
} }
override fun invalidate() = withState(viewModel) { state -> override fun invalidate() = withState(viewModel) { state ->
setupToolbar(state.selectedRoomPollsType) state.pollDetail ?: return@withState
setupToolbar(state.pollDetail.isEnded)
/*
state.getSelectedPoll()?.let { _ -> state.getSelectedPoll()?.let { _ ->
roomPollDetailController.setData(state) roomPollDetailController.setData(state)
} }
Unit Unit
*/
} }
} }

View File

@ -0,0 +1,23 @@
/*
* 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.features.roomprofile.polls.detail
import im.vector.app.core.platform.VectorViewEvents
sealed class RoomPollDetailViewEvent : VectorViewEvents {
}

View File

@ -0,0 +1,34 @@
/*
* 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.features.roomprofile.polls.detail
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import im.vector.app.core.platform.VectorViewModel
class RoomPollDetailViewModel @AssistedInject constructor(
@Assisted initialState: RoomPollDetailViewState,
) : VectorViewModel<RoomPollDetailViewState, RoomPollDetailAction, RoomPollDetailViewEvent>(initialState) {
init {
// Subscribe to the poll event and map it
}
override fun handle(action: RoomPollDetailAction) {
}
}