Room creation: add topic (#2078)

This commit is contained in:
Benoit Marty 2020-10-20 10:40:44 +02:00 committed by Benoit Marty
parent 0667c0ce49
commit 99e8f9c6cd
6 changed files with 44 additions and 3 deletions

View file

@ -20,6 +20,7 @@ import im.vector.app.core.platform.VectorViewModelAction
sealed class CreateRoomAction : VectorViewModelAction {
data class SetName(val name: String) : CreateRoomAction()
data class SetTopic(val topic: String) : CreateRoomAction()
data class SetIsPublic(val isPublic: Boolean) : CreateRoomAction()
data class SetIsInRoomDirectory(val isInRoomDirectory: Boolean) : CreateRoomAction()
data class SetIsEncrypted(val isEncrypted: Boolean) : CreateRoomAction()

View file

@ -26,6 +26,7 @@ import im.vector.app.core.epoxy.errorWithRetryItem
import im.vector.app.core.epoxy.loadingItem
import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.resources.StringProvider
import im.vector.app.features.discovery.settingsSectionTitleItem
import im.vector.app.features.form.formEditTextItem
import im.vector.app.features.form.formSwitchItem
import javax.inject.Inject
@ -67,6 +68,10 @@ class CreateRoomController @Inject constructor(private val stringProvider: Strin
}
private fun buildForm(viewState: CreateRoomViewState, enableFormElement: Boolean) {
settingsSectionTitleItem {
id("nameSection")
titleResId(R.string.create_room_name_section)
}
formEditTextItem {
id("name")
enabled(enableFormElement)
@ -77,6 +82,24 @@ class CreateRoomController @Inject constructor(private val stringProvider: Strin
listener?.onNameChange(text)
}
}
settingsSectionTitleItem {
id("topicSection")
titleResId(R.string.create_room_topic_section)
}
formEditTextItem {
id("topic")
enabled(enableFormElement)
value(viewState.roomTopic)
hint(stringProvider.getString(R.string.create_room_topic_hint))
onTextChange { text ->
listener?.onTopicChange(text)
}
}
settingsSectionTitleItem {
id("settingsSection")
titleResId(R.string.create_room_settings_section)
}
formSwitchItem {
id("public")
enabled(enableFormElement)
@ -120,6 +143,7 @@ class CreateRoomController @Inject constructor(private val stringProvider: Strin
interface Listener {
fun onNameChange(newName: String)
fun onTopicChange(newTopic: String)
fun setIsPublic(isPublic: Boolean)
fun setIsInRoomDirectory(isInRoomDirectory: Boolean)
fun setIsEncrypted(isEncrypted: Boolean)

View file

@ -32,7 +32,9 @@ import kotlinx.android.synthetic.main.fragment_create_room.*
import timber.log.Timber
import javax.inject.Inject
class CreateRoomFragment @Inject constructor(private val createRoomController: CreateRoomController) : VectorBaseFragment(), CreateRoomController.Listener {
class CreateRoomFragment @Inject constructor(
private val createRoomController: CreateRoomController
) : VectorBaseFragment(), CreateRoomController.Listener {
private lateinit var sharedActionViewModel: RoomDirectorySharedActionViewModel
private val viewModel: CreateRoomViewModel by activityViewModel()
@ -77,6 +79,10 @@ class CreateRoomFragment @Inject constructor(private val createRoomController: C
viewModel.handle(CreateRoomAction.SetName(newName))
}
override fun onTopicChange(newTopic: String) {
viewModel.handle(CreateRoomAction.SetTopic(newTopic))
}
override fun setIsPublic(isPublic: Boolean) {
viewModel.handle(CreateRoomAction.SetIsPublic(isPublic))
}

View file

@ -26,6 +26,7 @@ import com.airbnb.mvrx.Success
import com.airbnb.mvrx.ViewModelContext
import com.squareup.inject.assisted.Assisted
import com.squareup.inject.assisted.AssistedInject
import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.platform.EmptyViewEvents
import im.vector.app.core.platform.VectorViewModel
import im.vector.app.features.raw.wellknown.getElementWellknown
@ -91,15 +92,18 @@ class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: Cr
override fun handle(action: CreateRoomAction) {
when (action) {
is CreateRoomAction.SetName -> setName(action)
is CreateRoomAction.SetTopic -> setTopic(action)
is CreateRoomAction.SetIsPublic -> setIsPublic(action)
is CreateRoomAction.SetIsInRoomDirectory -> setIsInRoomDirectory(action)
is CreateRoomAction.SetIsEncrypted -> setIsEncrypted(action)
is CreateRoomAction.Create -> doCreateRoom()
}
}.exhaustive
}
private fun setName(action: CreateRoomAction.SetName) = setState { copy(roomName = action.name) }
private fun setTopic(action: CreateRoomAction.SetTopic) = setState { copy(roomTopic = action.topic) }
private fun setIsPublic(action: CreateRoomAction.SetIsPublic) = setState {
copy(
isPublic = action.isPublic,
@ -123,6 +127,7 @@ class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: Cr
val createRoomParams = CreateRoomParams()
.apply {
name = state.roomName.takeIf { it.isNotBlank() }
topic = state.roomTopic.takeIf { it.isNotBlank() }
// Directory visibility
visibility = if (state.isInRoomDirectory) RoomDirectoryVisibility.PUBLIC else RoomDirectoryVisibility.PRIVATE
// Public room

View file

@ -22,6 +22,7 @@ import com.airbnb.mvrx.Uninitialized
data class CreateRoomViewState(
val roomName: String = "",
val roomTopic: String = "",
val isPublic: Boolean = false,
val isInRoomDirectory: Boolean = false,
val isEncrypted: Boolean = false,

View file

@ -1675,7 +1675,11 @@
<!-- Create room screen -->
<string name="create_room_title">"New Room"</string>
<string name="create_room_action_create">"CREATE"</string>
<string name="create_room_name_hint">"Room name"</string>
<string name="create_room_name_section">"Room name"</string>
<string name="create_room_name_hint">"Name"</string>
<string name="create_room_topic_section">"Room topic (optional)"</string>
<string name="create_room_topic_hint">"Topic"</string>
<string name="create_room_settings_section">"Room settings"</string>
<string name="create_room_public_title">"Public"</string>
<string name="create_room_public_description">"Anyone will be able to join this room"</string>
<string name="create_room_directory_title">"Room Directory"</string>