From 9d43846b9bbbe39233434e33d8dab374be4c08d2 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Tue, 31 Jan 2023 15:01:07 +0300 Subject: [PATCH] Implement new view state. --- .../roomprofile/RoomProfileFragment.kt | 1 - .../polls/detail/RoomPollDetail.kt | 29 +++++++++++++++++++ .../polls/detail/RoomPollDetailFragment.kt | 14 ++++++--- .../polls/detail/RoomPollDetailViewState.kt | 29 +++++++++++++++++++ 4 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/RoomPollDetail.kt create mode 100644 vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/RoomPollDetailViewState.kt diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt index f90dd76d29..9436bafc03 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt @@ -65,7 +65,6 @@ import javax.inject.Inject @Parcelize data class RoomProfileArgs( val roomId: String, - val selectedPollId: String? = null, ) : Parcelable @AndroidEntryPoint diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/RoomPollDetail.kt b/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/RoomPollDetail.kt new file mode 100644 index 0000000000..c149daaef2 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/RoomPollDetail.kt @@ -0,0 +1,29 @@ +/* + * 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.features.home.room.detail.timeline.item.PollOptionViewState + +data class RoomPollDetail( + val eventId: String, + val question: String, + val canVote: Boolean, + val votesStatusSummary: String, + val optionViewStates: List, + val hasBeenEdited: Boolean, + val isEnded: Boolean, +) diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/RoomPollDetailFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/RoomPollDetailFragment.kt index ec8e8ea004..96eea5bdd8 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/RoomPollDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/RoomPollDetailFragment.kt @@ -17,10 +17,10 @@ package im.vector.app.features.roomprofile.polls.detail import android.os.Bundle +import android.os.Parcelable import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import com.airbnb.mvrx.activityViewModel import com.airbnb.mvrx.args import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState @@ -29,18 +29,24 @@ import im.vector.app.R import im.vector.app.core.extensions.configureWith import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.databinding.FragmentRoomPollDetailBinding -import im.vector.app.features.roomprofile.RoomProfileArgs import im.vector.app.features.roomprofile.polls.RoomPollsType import im.vector.app.features.roomprofile.polls.RoomPollsViewModel +import kotlinx.parcelize.Parcelize import javax.inject.Inject +@Parcelize +data class RoomPollDetailArgs( + val roomId: String, + val pollId: String, +) : Parcelable + @AndroidEntryPoint class RoomPollDetailFragment : VectorBaseFragment() { @Inject lateinit var roomPollDetailController: RoomPollDetailController - private val viewModel: RoomPollsViewModel by activityViewModel() - private val roomProfileArgs: RoomProfileArgs by args() + private val viewModel: RoomPollsViewModel by fragmentViewModel() + private val roomPollDetailArgs: RoomPollDetailArgs by args() override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentRoomPollDetailBinding { return FragmentRoomPollDetailBinding.inflate(inflater, container, false) diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/RoomPollDetailViewState.kt b/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/RoomPollDetailViewState.kt new file mode 100644 index 0000000000..d7e31a0424 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/RoomPollDetailViewState.kt @@ -0,0 +1,29 @@ +/* + * 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 com.airbnb.mvrx.MavericksState + +data class RoomPollDetailViewState( + val roomId: String, + val pollId: String, + val pollDetail: RoomPollDetail? = null, +) : MavericksState { + + constructor(roomPollDetailArgs: RoomPollDetailArgs) + : this(roomId = roomPollDetailArgs.roomId, pollId = roomPollDetailArgs.pollId) +}