mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 05:31:21 +03:00
Create poll event content.
This commit is contained in:
parent
6cee266a95
commit
dd58dd800c
11 changed files with 153 additions and 20 deletions
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021 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 org.matrix.android.sdk.api.session.room.model.message
|
||||||
|
|
||||||
|
import com.squareup.moshi.Json
|
||||||
|
import com.squareup.moshi.JsonClass
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
data class MessagePollContent(
|
||||||
|
@Json(name = "m.poll.start") val pollCreationInfo: PollCreationInfo? = null
|
||||||
|
)
|
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021 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 org.matrix.android.sdk.api.session.room.model.message
|
||||||
|
|
||||||
|
import com.squareup.moshi.Json
|
||||||
|
import com.squareup.moshi.JsonClass
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
data class PollAnswer(
|
||||||
|
@Json(name = "id") val id: String? = null,
|
||||||
|
@Json(name = "m.text") val answer: String? = null
|
||||||
|
)
|
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021 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 org.matrix.android.sdk.api.session.room.model.message
|
||||||
|
|
||||||
|
import com.squareup.moshi.Json
|
||||||
|
import com.squareup.moshi.JsonClass
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
data class PollCreationInfo(
|
||||||
|
@Json(name = "question") val question: PollQuestion? = null,
|
||||||
|
@Json(name = "kind") val kind: String? = "m.poll.disclosed",
|
||||||
|
@Json(name = "max_selections") val maxSelections: Int = 1,
|
||||||
|
@Json(name = "answers") val answers: List<PollAnswer>? = null
|
||||||
|
)
|
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021 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 org.matrix.android.sdk.api.session.room.model.message
|
||||||
|
|
||||||
|
import com.squareup.moshi.Json
|
||||||
|
import com.squareup.moshi.JsonClass
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
data class PollQuestion(
|
||||||
|
@Json(name = "m.text") val question: String? = null
|
||||||
|
)
|
|
@ -20,7 +20,6 @@ import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import com.airbnb.mvrx.viewModel
|
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.di.ScreenComponent
|
import im.vector.app.core.di.ScreenComponent
|
||||||
import im.vector.app.core.extensions.addFragment
|
import im.vector.app.core.extensions.addFragment
|
||||||
|
@ -29,32 +28,40 @@ import javax.inject.Inject
|
||||||
|
|
||||||
class CreatePollActivity : SimpleFragmentActivity(), CreatePollViewModel.Factory {
|
class CreatePollActivity : SimpleFragmentActivity(), CreatePollViewModel.Factory {
|
||||||
|
|
||||||
private val viewModel: CreatePollViewModel by viewModel()
|
var currentRoomId: String? = null
|
||||||
@Inject lateinit var viewModelFactory: CreatePollViewModel.Factory
|
@Inject lateinit var createPollViewModelFactory: CreatePollViewModel.Factory
|
||||||
|
|
||||||
override fun injectWith(injector: ScreenComponent) {
|
override fun injectWith(injector: ScreenComponent) {
|
||||||
super.injectWith(injector)
|
super.injectWith(injector)
|
||||||
injector.inject(this)
|
injector.inject(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun create(initialState: CreatePollViewState) = viewModelFactory.create(initialState)
|
override fun create(initialState: CreatePollViewState) = createPollViewModelFactory.create(initialState)
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
views.toolbar.visibility = View.GONE
|
views.toolbar.visibility = View.GONE
|
||||||
|
|
||||||
|
val createPollArgs: CreatePollArgs? = intent?.extras?.getParcelable(EXTRA_CREATE_POLL_ARGS)
|
||||||
|
currentRoomId = createPollArgs?.roomId
|
||||||
|
|
||||||
if (isFirstCreation()) {
|
if (isFirstCreation()) {
|
||||||
addFragment(
|
addFragment(
|
||||||
R.id.container,
|
R.id.container,
|
||||||
CreatePollFragment::class.java
|
CreatePollFragment::class.java,
|
||||||
|
createPollArgs
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun getIntent(context: Context): Intent {
|
private const val EXTRA_CREATE_POLL_ARGS = "EXTRA_CREATE_POLL_ARGS"
|
||||||
return Intent(context, CreatePollActivity::class.java)
|
|
||||||
|
fun getIntent(context: Context, createPollArgs: CreatePollArgs): Intent {
|
||||||
|
return Intent(context, CreatePollActivity::class.java).apply {
|
||||||
|
putExtra(EXTRA_CREATE_POLL_ARGS, createPollArgs)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,21 +17,31 @@
|
||||||
package im.vector.app.features.createpoll
|
package im.vector.app.features.createpoll
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.os.Parcelable
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import com.airbnb.mvrx.activityViewModel
|
import com.airbnb.mvrx.activityViewModel
|
||||||
|
import com.airbnb.mvrx.args
|
||||||
import com.airbnb.mvrx.withState
|
import com.airbnb.mvrx.withState
|
||||||
import im.vector.app.core.extensions.configureWith
|
import im.vector.app.core.extensions.configureWith
|
||||||
import im.vector.app.core.platform.VectorBaseFragment
|
import im.vector.app.core.platform.VectorBaseFragment
|
||||||
import im.vector.app.databinding.FragmentCreatePollBinding
|
import im.vector.app.databinding.FragmentCreatePollBinding
|
||||||
|
import kotlinx.parcelize.Parcelize
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
data class CreatePollArgs(
|
||||||
|
val roomId: String
|
||||||
|
) : Parcelable
|
||||||
|
|
||||||
class CreatePollFragment @Inject constructor(
|
class CreatePollFragment @Inject constructor(
|
||||||
private val controller: CreatePollController
|
private val controller: CreatePollController,
|
||||||
|
val createPollViewModelFactory: CreatePollViewModel.Factory
|
||||||
) : VectorBaseFragment<FragmentCreatePollBinding>(), CreatePollController.Callback {
|
) : VectorBaseFragment<FragmentCreatePollBinding>(), CreatePollController.Callback {
|
||||||
|
|
||||||
private val viewModel: CreatePollViewModel by activityViewModel()
|
private val viewModel: CreatePollViewModel by activityViewModel()
|
||||||
|
private val createPollArgs: CreatePollArgs by args()
|
||||||
|
|
||||||
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentCreatePollBinding {
|
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentCreatePollBinding {
|
||||||
return FragmentCreatePollBinding.inflate(inflater, container, false)
|
return FragmentCreatePollBinding.inflate(inflater, container, false)
|
||||||
|
|
|
@ -24,11 +24,15 @@ import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import im.vector.app.core.platform.VectorViewModel
|
import im.vector.app.core.platform.VectorViewModel
|
||||||
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
class CreatePollViewModel @AssistedInject constructor(@Assisted
|
class CreatePollViewModel @AssistedInject constructor(
|
||||||
initialState: CreatePollViewState) :
|
@Assisted private val initialState: CreatePollViewState,
|
||||||
VectorViewModel<CreatePollViewState, CreatePollAction, CreatePollViewEvents>(initialState) {
|
private val session: Session
|
||||||
|
) : VectorViewModel<CreatePollViewState, CreatePollAction, CreatePollViewEvents>(initialState) {
|
||||||
|
|
||||||
|
private val room = session.getRoom(initialState.roomId)!!
|
||||||
|
|
||||||
@AssistedFactory
|
@AssistedFactory
|
||||||
interface Factory {
|
interface Factory {
|
||||||
|
@ -40,7 +44,7 @@ class CreatePollViewModel @AssistedInject constructor(@Assisted
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
override fun create(viewModelContext: ViewModelContext, state: CreatePollViewState): CreatePollViewModel {
|
override fun create(viewModelContext: ViewModelContext, state: CreatePollViewState): CreatePollViewModel {
|
||||||
val factory = when (viewModelContext) {
|
val factory = when (viewModelContext) {
|
||||||
is FragmentViewModelContext -> viewModelContext.fragment as? Factory
|
is FragmentViewModelContext -> (viewModelContext.fragment as CreatePollFragment).createPollViewModelFactory
|
||||||
is ActivityViewModelContext -> viewModelContext.activity as? Factory
|
is ActivityViewModelContext -> viewModelContext.activity as? Factory
|
||||||
}
|
}
|
||||||
return factory?.create(state) ?: error("You should let your activity/fragment implements Factory interface")
|
return factory?.create(state) ?: error("You should let your activity/fragment implements Factory interface")
|
||||||
|
@ -68,7 +72,7 @@ class CreatePollViewModel @AssistedInject constructor(@Assisted
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleOnCreatePoll() = withState { state ->
|
private fun handleOnCreatePoll() = withState { state ->
|
||||||
Timber.d(state.toString())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleOnAddOption() {
|
private fun handleOnAddOption() {
|
||||||
|
|
|
@ -19,6 +19,13 @@ package im.vector.app.features.createpoll
|
||||||
import com.airbnb.mvrx.MavericksState
|
import com.airbnb.mvrx.MavericksState
|
||||||
|
|
||||||
data class CreatePollViewState(
|
data class CreatePollViewState(
|
||||||
|
val roomId: String,
|
||||||
val question: String = "",
|
val question: String = "",
|
||||||
val options: List<String> = emptyList()
|
val options: List<String> = emptyList()
|
||||||
) : MavericksState
|
) : MavericksState {
|
||||||
|
|
||||||
|
constructor(args: CreatePollArgs) : this(
|
||||||
|
roomId = args.roomId
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -2145,7 +2145,7 @@ class RoomDetailFragment @Inject constructor(
|
||||||
AttachmentTypeSelectorView.Type.AUDIO -> attachmentsHelper.selectAudio(attachmentAudioActivityResultLauncher)
|
AttachmentTypeSelectorView.Type.AUDIO -> attachmentsHelper.selectAudio(attachmentAudioActivityResultLauncher)
|
||||||
AttachmentTypeSelectorView.Type.CONTACT -> attachmentsHelper.selectContact(attachmentContactActivityResultLauncher)
|
AttachmentTypeSelectorView.Type.CONTACT -> attachmentsHelper.selectContact(attachmentContactActivityResultLauncher)
|
||||||
AttachmentTypeSelectorView.Type.STICKER -> roomDetailViewModel.handle(RoomDetailAction.SelectStickerAttachment)
|
AttachmentTypeSelectorView.Type.STICKER -> roomDetailViewModel.handle(RoomDetailAction.SelectStickerAttachment)
|
||||||
AttachmentTypeSelectorView.Type.POLL -> navigator.openCreatePoll(requireContext())
|
AttachmentTypeSelectorView.Type.POLL -> navigator.openCreatePoll(requireContext(), roomDetailArgs.roomId)
|
||||||
}.exhaustive
|
}.exhaustive
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ import im.vector.app.features.call.conference.VectorJitsiActivity
|
||||||
import im.vector.app.features.call.transfer.CallTransferActivity
|
import im.vector.app.features.call.transfer.CallTransferActivity
|
||||||
import im.vector.app.features.createdirect.CreateDirectRoomActivity
|
import im.vector.app.features.createdirect.CreateDirectRoomActivity
|
||||||
import im.vector.app.features.createpoll.CreatePollActivity
|
import im.vector.app.features.createpoll.CreatePollActivity
|
||||||
|
import im.vector.app.features.createpoll.CreatePollArgs
|
||||||
import im.vector.app.features.crypto.keysbackup.settings.KeysBackupManageActivity
|
import im.vector.app.features.crypto.keysbackup.settings.KeysBackupManageActivity
|
||||||
import im.vector.app.features.crypto.keysbackup.setup.KeysBackupSetupActivity
|
import im.vector.app.features.crypto.keysbackup.setup.KeysBackupSetupActivity
|
||||||
import im.vector.app.features.crypto.recover.BootstrapBottomSheet
|
import im.vector.app.features.crypto.recover.BootstrapBottomSheet
|
||||||
|
@ -499,8 +500,8 @@ class DefaultNavigator @Inject constructor(
|
||||||
context.startActivity(intent)
|
context.startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun openCreatePoll(context: Context) {
|
override fun openCreatePoll(context: Context, roomId: String) {
|
||||||
val intent = CreatePollActivity.getIntent(context)
|
val intent = CreatePollActivity.getIntent(context, CreatePollArgs(roomId = roomId))
|
||||||
context.startActivity(intent)
|
context.startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -141,5 +141,5 @@ interface Navigator {
|
||||||
|
|
||||||
fun openCallTransfer(context: Context, callId: String)
|
fun openCallTransfer(context: Context, callId: String)
|
||||||
|
|
||||||
fun openCreatePoll(context: Context)
|
fun openCreatePoll(context: Context, roomId: String)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue