Rename class

This commit is contained in:
Benoit Marty 2019-11-08 15:20:46 +01:00
parent f17564d743
commit 12376368c7
46 changed files with 332 additions and 312 deletions

View File

@ -23,10 +23,6 @@ import im.vector.riotx.core.utils.LiveEvent
import io.reactivex.Observable import io.reactivex.Observable
import io.reactivex.Single import io.reactivex.Single
interface VectorViewModelAction
object EmptyAction : VectorViewModelAction
abstract class VectorViewModel<S : MvRxState, A : VectorViewModelAction>(initialState: S) abstract class VectorViewModel<S : MvRxState, A : VectorViewModelAction>(initialState: S)
: BaseMvRxViewModel<S>(initialState, false) { : BaseMvRxViewModel<S>(initialState, false) {

View File

@ -0,0 +1,24 @@
/*
* Copyright 2019 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.riotx.core.platform
interface VectorViewModelAction
/**
* To use when no action is associated to the ViewModel
*/
object EmptyAction : VectorViewModelAction

View File

@ -18,8 +18,8 @@ package im.vector.riotx.features.crypto.keysbackup.settings
import im.vector.riotx.core.platform.VectorViewModelAction import im.vector.riotx.core.platform.VectorViewModelAction
sealed class KeyBackupSettingsActions : VectorViewModelAction { sealed class KeyBackupSettingsAction : VectorViewModelAction {
object Init : KeyBackupSettingsActions() object Init : KeyBackupSettingsAction()
object GetKeyBackupTrust : KeyBackupSettingsActions() object GetKeyBackupTrust : KeyBackupSettingsAction()
object DeleteKeyBackup : KeyBackupSettingsActions() object DeleteKeyBackup : KeyBackupSettingsAction()
} }

View File

@ -51,7 +51,7 @@ class KeysBackupManageActivity : SimpleFragmentActivity() {
super.initUiAndData() super.initUiAndData()
if (supportFragmentManager.fragments.isEmpty()) { if (supportFragmentManager.fragments.isEmpty()) {
replaceFragment(R.id.container, KeysBackupSettingsFragment::class.java) replaceFragment(R.id.container, KeysBackupSettingsFragment::class.java)
viewModel.handle(KeyBackupSettingsActions.Init) viewModel.handle(KeyBackupSettingsAction.Init)
} }
// Observe the deletion of keys backup // Observe the deletion of keys backup

View File

@ -66,7 +66,7 @@ class KeysBackupSettingsFragment @Inject constructor(private val keysBackupSetti
.setMessage(R.string.keys_backup_settings_delete_confirm_message) .setMessage(R.string.keys_backup_settings_delete_confirm_message)
.setCancelable(false) .setCancelable(false)
.setPositiveButton(R.string.keys_backup_settings_delete_confirm_title) { _, _ -> .setPositiveButton(R.string.keys_backup_settings_delete_confirm_title) { _, _ ->
viewModel.handle(KeyBackupSettingsActions.DeleteKeyBackup) viewModel.handle(KeyBackupSettingsAction.DeleteKeyBackup)
} }
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.setCancelable(true) .setCancelable(true)
@ -75,10 +75,10 @@ class KeysBackupSettingsFragment @Inject constructor(private val keysBackupSetti
} }
override fun loadTrustData() { override fun loadTrustData() {
viewModel.handle(KeyBackupSettingsActions.GetKeyBackupTrust) viewModel.handle(KeyBackupSettingsAction.GetKeyBackupTrust)
} }
override fun loadKeysBackupState() { override fun loadKeysBackupState() {
viewModel.handle(KeyBackupSettingsActions.Init) viewModel.handle(KeyBackupSettingsAction.Init)
} }
} }

View File

@ -28,7 +28,7 @@ import im.vector.riotx.core.platform.VectorViewModel
class KeysBackupSettingsViewModel @AssistedInject constructor(@Assisted initialState: KeysBackupSettingViewState, class KeysBackupSettingsViewModel @AssistedInject constructor(@Assisted initialState: KeysBackupSettingViewState,
session: Session session: Session
) : VectorViewModel<KeysBackupSettingViewState, KeyBackupSettingsActions>(initialState), ) : VectorViewModel<KeysBackupSettingViewState, KeyBackupSettingsAction>(initialState),
KeysBackupStateListener { KeysBackupStateListener {
@AssistedInject.Factory @AssistedInject.Factory
@ -58,11 +58,11 @@ class KeysBackupSettingsViewModel @AssistedInject constructor(@Assisted initialS
getKeysBackupTrust() getKeysBackupTrust()
} }
override fun handle(action: KeyBackupSettingsActions) { override fun handle(action: KeyBackupSettingsAction) {
when (action) { when (action) {
KeyBackupSettingsActions.Init -> init() KeyBackupSettingsAction.Init -> init()
KeyBackupSettingsActions.GetKeyBackupTrust -> getKeysBackupTrust() KeyBackupSettingsAction.GetKeyBackupTrust -> getKeysBackupTrust()
KeyBackupSettingsActions.DeleteKeyBackup -> deleteCurrentBackup() KeyBackupSettingsAction.DeleteKeyBackup -> deleteCurrentBackup()
} }
} }

View File

@ -19,11 +19,11 @@ package im.vector.riotx.features.home.createdirect
import im.vector.matrix.android.api.session.user.model.User import im.vector.matrix.android.api.session.user.model.User
import im.vector.riotx.core.platform.VectorViewModelAction import im.vector.riotx.core.platform.VectorViewModelAction
sealed class CreateDirectRoomActions : VectorViewModelAction { sealed class CreateDirectRoomAction : VectorViewModelAction {
object CreateRoomAndInviteSelectedUsers : CreateDirectRoomActions() object CreateRoomAndInviteSelectedUsers : CreateDirectRoomAction()
data class FilterKnownUsers(val value: String) : CreateDirectRoomActions() data class FilterKnownUsers(val value: String) : CreateDirectRoomAction()
data class SearchDirectoryUsers(val value: String) : CreateDirectRoomActions() data class SearchDirectoryUsers(val value: String) : CreateDirectRoomAction()
object ClearFilterKnownUsers : CreateDirectRoomActions() object ClearFilterKnownUsers : CreateDirectRoomAction()
data class SelectUser(val user: User) : CreateDirectRoomActions() data class SelectUser(val user: User) : CreateDirectRoomAction()
data class RemoveSelectedUser(val user: User) : CreateDirectRoomActions() data class RemoveSelectedUser(val user: User) : CreateDirectRoomAction()
} }

View File

@ -60,7 +60,7 @@ class CreateDirectRoomDirectoryUsersFragment @Inject constructor(
createDirectRoomSearchById createDirectRoomSearchById
.textChanges() .textChanges()
.subscribe { .subscribe {
viewModel.handle(CreateDirectRoomActions.SearchDirectoryUsers(it.toString())) viewModel.handle(CreateDirectRoomAction.SearchDirectoryUsers(it.toString()))
} }
.disposeOnDestroy() .disposeOnDestroy()
createDirectRoomSearchById.requestFocus() createDirectRoomSearchById.requestFocus()
@ -80,12 +80,12 @@ class CreateDirectRoomDirectoryUsersFragment @Inject constructor(
override fun onItemClick(user: User) { override fun onItemClick(user: User) {
view?.hideKeyboard() view?.hideKeyboard()
viewModel.handle(CreateDirectRoomActions.SelectUser(user)) viewModel.handle(CreateDirectRoomAction.SelectUser(user))
actionViewModel.post(CreateDirectRoomSharedAction.GoBack) actionViewModel.post(CreateDirectRoomSharedAction.GoBack)
} }
override fun retryDirectoryUsersRequest() { override fun retryDirectoryUsersRequest() {
val currentSearch = createDirectRoomSearchById.text.toString() val currentSearch = createDirectRoomSearchById.text.toString()
viewModel.handle(CreateDirectRoomActions.SearchDirectoryUsers(currentSearch)) viewModel.handle(CreateDirectRoomAction.SearchDirectoryUsers(currentSearch))
} }
} }

View File

@ -79,7 +79,7 @@ class CreateDirectRoomKnownUsersFragment @Inject constructor(
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) { return when (item.itemId) {
R.id.action_create_direct_room -> { R.id.action_create_direct_room -> {
viewModel.handle(CreateDirectRoomActions.CreateRoomAndInviteSelectedUsers) viewModel.handle(CreateDirectRoomAction.CreateRoomAndInviteSelectedUsers)
true true
} }
else -> else ->
@ -108,9 +108,9 @@ class CreateDirectRoomKnownUsersFragment @Inject constructor(
.subscribe { text -> .subscribe { text ->
val filterValue = text.trim() val filterValue = text.trim()
val action = if (filterValue.isBlank()) { val action = if (filterValue.isBlank()) {
CreateDirectRoomActions.ClearFilterKnownUsers CreateDirectRoomAction.ClearFilterKnownUsers
} else { } else {
CreateDirectRoomActions.FilterKnownUsers(filterValue.toString()) CreateDirectRoomAction.FilterKnownUsers(filterValue.toString())
} }
viewModel.handle(action) viewModel.handle(action)
} }
@ -157,7 +157,7 @@ class CreateDirectRoomKnownUsersFragment @Inject constructor(
chip.isCloseIconVisible = true chip.isCloseIconVisible = true
chipGroup.addView(chip) chipGroup.addView(chip)
chip.setOnCloseIconClickListener { chip.setOnCloseIconClickListener {
viewModel.handle(CreateDirectRoomActions.RemoveSelectedUser(user)) viewModel.handle(CreateDirectRoomAction.RemoveSelectedUser(user))
} }
chipGroupScrollView.post { chipGroupScrollView.post {
chipGroupScrollView.fullScroll(ScrollView.FOCUS_DOWN) chipGroupScrollView.fullScroll(ScrollView.FOCUS_DOWN)
@ -166,6 +166,6 @@ class CreateDirectRoomKnownUsersFragment @Inject constructor(
override fun onItemClick(user: User) { override fun onItemClick(user: User) {
view?.hideKeyboard() view?.hideKeyboard()
viewModel.handle(CreateDirectRoomActions.SelectUser(user)) viewModel.handle(CreateDirectRoomAction.SelectUser(user))
} }
} }

View File

@ -51,7 +51,7 @@ data class SelectUserAction(
class CreateDirectRoomViewModel @AssistedInject constructor(@Assisted class CreateDirectRoomViewModel @AssistedInject constructor(@Assisted
initialState: CreateDirectRoomViewState, initialState: CreateDirectRoomViewState,
private val session: Session) private val session: Session)
: VectorViewModel<CreateDirectRoomViewState, CreateDirectRoomActions>(initialState) { : VectorViewModel<CreateDirectRoomViewState, CreateDirectRoomAction>(initialState) {
@AssistedInject.Factory @AssistedInject.Factory
interface Factory { interface Factory {
@ -79,14 +79,14 @@ class CreateDirectRoomViewModel @AssistedInject constructor(@Assisted
observeDirectoryUsers() observeDirectoryUsers()
} }
override fun handle(action: CreateDirectRoomActions) { override fun handle(action: CreateDirectRoomAction) {
when (action) { when (action) {
is CreateDirectRoomActions.CreateRoomAndInviteSelectedUsers -> createRoomAndInviteSelectedUsers() is CreateDirectRoomAction.CreateRoomAndInviteSelectedUsers -> createRoomAndInviteSelectedUsers()
is CreateDirectRoomActions.FilterKnownUsers -> knownUsersFilter.accept(Option.just(action.value)) is CreateDirectRoomAction.FilterKnownUsers -> knownUsersFilter.accept(Option.just(action.value))
is CreateDirectRoomActions.ClearFilterKnownUsers -> knownUsersFilter.accept(Option.empty()) is CreateDirectRoomAction.ClearFilterKnownUsers -> knownUsersFilter.accept(Option.empty())
is CreateDirectRoomActions.SearchDirectoryUsers -> directoryUsersSearch.accept(action.value) is CreateDirectRoomAction.SearchDirectoryUsers -> directoryUsersSearch.accept(action.value)
is CreateDirectRoomActions.SelectUser -> handleSelectUser(action) is CreateDirectRoomAction.SelectUser -> handleSelectUser(action)
is CreateDirectRoomActions.RemoveSelectedUser -> handleRemoveSelectedUser(action) is CreateDirectRoomAction.RemoveSelectedUser -> handleRemoveSelectedUser(action)
} }
} }
@ -105,14 +105,14 @@ class CreateDirectRoomViewModel @AssistedInject constructor(@Assisted
} }
} }
private fun handleRemoveSelectedUser(action: CreateDirectRoomActions.RemoveSelectedUser) = withState { state -> private fun handleRemoveSelectedUser(action: CreateDirectRoomAction.RemoveSelectedUser) = withState { state ->
val index = state.selectedUsers.indexOfFirst { it.userId == action.user.userId } val index = state.selectedUsers.indexOfFirst { it.userId == action.user.userId }
val selectedUsers = state.selectedUsers.minus(action.user) val selectedUsers = state.selectedUsers.minus(action.user)
setState { copy(selectedUsers = selectedUsers) } setState { copy(selectedUsers = selectedUsers) }
_selectUserEvent.postLiveEvent(SelectUserAction(action.user, false, index)) _selectUserEvent.postLiveEvent(SelectUserAction(action.user, false, index))
} }
private fun handleSelectUser(action: CreateDirectRoomActions.SelectUser) = withState { state -> private fun handleSelectUser(action: CreateDirectRoomAction.SelectUser) = withState { state ->
// Reset the filter asap // Reset the filter asap
directoryUsersSearch.accept("") directoryUsersSearch.accept("")
val isAddOperation: Boolean val isAddOperation: Boolean

View File

@ -19,6 +19,6 @@ package im.vector.riotx.features.home.group
import im.vector.matrix.android.api.session.group.model.GroupSummary import im.vector.matrix.android.api.session.group.model.GroupSummary
import im.vector.riotx.core.platform.VectorViewModelAction import im.vector.riotx.core.platform.VectorViewModelAction
sealed class GroupListActions : VectorViewModelAction { sealed class GroupListAction : VectorViewModelAction {
data class SelectGroup(val groupSummary: GroupSummary) : GroupListActions() data class SelectGroup(val groupSummary: GroupSummary) : GroupListAction()
} }

View File

@ -62,6 +62,6 @@ class GroupListFragment @Inject constructor(
} }
override fun onGroupSelected(groupSummary: GroupSummary) { override fun onGroupSelected(groupSummary: GroupSummary) {
viewModel.handle(GroupListActions.SelectGroup(groupSummary)) viewModel.handle(GroupListAction.SelectGroup(groupSummary))
} }
} }

View File

@ -42,7 +42,7 @@ class GroupListViewModel @AssistedInject constructor(@Assisted initialState: Gro
private val selectedGroupStore: SelectedGroupDataSource, private val selectedGroupStore: SelectedGroupDataSource,
private val session: Session, private val session: Session,
private val stringProvider: StringProvider private val stringProvider: StringProvider
) : VectorViewModel<GroupListViewState, GroupListActions>(initialState) { ) : VectorViewModel<GroupListViewState, GroupListAction>(initialState) {
@AssistedInject.Factory @AssistedInject.Factory
interface Factory { interface Factory {
@ -81,15 +81,15 @@ class GroupListViewModel @AssistedInject constructor(@Assisted initialState: Gro
} }
} }
override fun handle(action: GroupListActions) { override fun handle(action: GroupListAction) {
when (action) { when (action) {
is GroupListActions.SelectGroup -> handleSelectGroup(action) is GroupListAction.SelectGroup -> handleSelectGroup(action)
} }
} }
// PRIVATE METHODS ***************************************************************************** // PRIVATE METHODS *****************************************************************************
private fun handleSelectGroup(action: GroupListActions.SelectGroup) = withState { state -> private fun handleSelectGroup(action: GroupListAction.SelectGroup) = withState { state ->
if (state.selectedGroup?.groupId != action.groupSummary.groupId) { if (state.selectedGroup?.groupId != action.groupSummary.groupId) {
setState { copy(selectedGroup = action.groupSummary) } setState { copy(selectedGroup = action.groupSummary) }
} }

View File

@ -23,42 +23,42 @@ import im.vector.matrix.android.api.session.room.timeline.Timeline
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
import im.vector.riotx.core.platform.VectorViewModelAction import im.vector.riotx.core.platform.VectorViewModelAction
sealed class RoomDetailActions : VectorViewModelAction { sealed class RoomDetailAction : VectorViewModelAction {
data class SaveDraft(val draft: String) : RoomDetailActions() data class SaveDraft(val draft: String) : RoomDetailAction()
data class SendMessage(val text: String, val autoMarkdown: Boolean) : RoomDetailActions() data class SendMessage(val text: String, val autoMarkdown: Boolean) : RoomDetailAction()
data class SendMedia(val attachments: List<ContentAttachmentData>) : RoomDetailActions() data class SendMedia(val attachments: List<ContentAttachmentData>) : RoomDetailAction()
data class TimelineEventTurnsVisible(val event: TimelineEvent) : RoomDetailActions() data class TimelineEventTurnsVisible(val event: TimelineEvent) : RoomDetailAction()
data class TimelineEventTurnsInvisible(val event: TimelineEvent) : RoomDetailActions() data class TimelineEventTurnsInvisible(val event: TimelineEvent) : RoomDetailAction()
data class LoadMoreTimelineEvents(val direction: Timeline.Direction) : RoomDetailActions() data class LoadMoreTimelineEvents(val direction: Timeline.Direction) : RoomDetailAction()
data class SendReaction(val targetEventId: String, val reaction: String) : RoomDetailActions() data class SendReaction(val targetEventId: String, val reaction: String) : RoomDetailAction()
data class UndoReaction(val targetEventId: String, val reaction: String, val reason: String? = "") : RoomDetailActions() data class UndoReaction(val targetEventId: String, val reaction: String, val reason: String? = "") : RoomDetailAction()
data class RedactAction(val targetEventId: String, val reason: String? = "") : RoomDetailActions() data class RedactAction(val targetEventId: String, val reason: String? = "") : RoomDetailAction()
data class UpdateQuickReactAction(val targetEventId: String, val selectedReaction: String, val add: Boolean) : RoomDetailActions() data class UpdateQuickReactAction(val targetEventId: String, val selectedReaction: String, val add: Boolean) : RoomDetailAction()
data class NavigateToEvent(val eventId: String, val highlight: Boolean) : RoomDetailActions() data class NavigateToEvent(val eventId: String, val highlight: Boolean) : RoomDetailAction()
data class SetReadMarkerAction(val eventId: String) : RoomDetailActions() data class SetReadMarkerAction(val eventId: String) : RoomDetailAction()
object MarkAllAsRead : RoomDetailActions() object MarkAllAsRead : RoomDetailAction()
data class DownloadFile(val eventId: String, val messageFileContent: MessageFileContent) : RoomDetailActions() data class DownloadFile(val eventId: String, val messageFileContent: MessageFileContent) : RoomDetailAction()
data class HandleTombstoneEvent(val event: Event) : RoomDetailActions() data class HandleTombstoneEvent(val event: Event) : RoomDetailAction()
object AcceptInvite : RoomDetailActions() object AcceptInvite : RoomDetailAction()
object RejectInvite : RoomDetailActions() object RejectInvite : RoomDetailAction()
data class EnterEditMode(val eventId: String, val draft: String) : RoomDetailActions() data class EnterEditMode(val eventId: String, val draft: String) : RoomDetailAction()
data class EnterQuoteMode(val eventId: String, val draft: String) : RoomDetailActions() data class EnterQuoteMode(val eventId: String, val draft: String) : RoomDetailAction()
data class EnterReplyMode(val eventId: String, val draft: String) : RoomDetailActions() data class EnterReplyMode(val eventId: String, val draft: String) : RoomDetailAction()
data class ExitSpecialMode(val draft: String) : RoomDetailActions() data class ExitSpecialMode(val draft: String) : RoomDetailAction()
data class ResendMessage(val eventId: String) : RoomDetailActions() data class ResendMessage(val eventId: String) : RoomDetailAction()
data class RemoveFailedEcho(val eventId: String) : RoomDetailActions() data class RemoveFailedEcho(val eventId: String) : RoomDetailAction()
data class ReportContent( data class ReportContent(
val eventId: String, val eventId: String,
val senderId: String?, val senderId: String?,
val reason: String, val reason: String,
val spam: Boolean = false, val spam: Boolean = false,
val inappropriate: Boolean = false) : RoomDetailActions() val inappropriate: Boolean = false) : RoomDetailAction()
data class IgnoreUser(val userId: String?) : RoomDetailActions() data class IgnoreUser(val userId: String?) : RoomDetailAction()
object ClearSendQueue : RoomDetailActions() object ClearSendQueue : RoomDetailAction()
object ResendAll : RoomDetailActions() object ResendAll : RoomDetailAction()
} }

View File

@ -91,7 +91,7 @@ import im.vector.riotx.features.home.AvatarRenderer
import im.vector.riotx.features.home.NavigateToRoomInterceptor import im.vector.riotx.features.home.NavigateToRoomInterceptor
import im.vector.riotx.features.home.PermalinkHandler import im.vector.riotx.features.home.PermalinkHandler
import im.vector.riotx.features.home.getColorFromUserId import im.vector.riotx.features.home.getColorFromUserId
import im.vector.riotx.features.home.room.detail.composer.TextComposerActions import im.vector.riotx.features.home.room.detail.composer.TextComposerAction
import im.vector.riotx.features.home.room.detail.composer.TextComposerView import im.vector.riotx.features.home.room.detail.composer.TextComposerView
import im.vector.riotx.features.home.room.detail.composer.TextComposerViewModel import im.vector.riotx.features.home.room.detail.composer.TextComposerViewModel
import im.vector.riotx.features.home.room.detail.composer.TextComposerViewState import im.vector.riotx.features.home.room.detail.composer.TextComposerViewState
@ -278,8 +278,8 @@ class RoomDetailFragment @Inject constructor(
if (savedInstanceState == null) { if (savedInstanceState == null) {
when (val sharedData = roomDetailArgs.sharedData) { when (val sharedData = roomDetailArgs.sharedData) {
is SharedData.Text -> roomDetailViewModel.handle(RoomDetailActions.SendMessage(sharedData.text, false)) is SharedData.Text -> roomDetailViewModel.handle(RoomDetailAction.SendMessage(sharedData.text, false))
is SharedData.Attachments -> roomDetailViewModel.handle(RoomDetailActions.SendMedia(sharedData.attachmentData)) is SharedData.Attachments -> roomDetailViewModel.handle(RoomDetailAction.SendMedia(sharedData.attachmentData))
null -> Timber.v("No share data to process") null -> Timber.v("No share data to process")
} }
} }
@ -323,7 +323,7 @@ class RoomDetailFragment @Inject constructor(
private fun setupNotificationView() { private fun setupNotificationView() {
notificationAreaView.delegate = object : NotificationAreaView.Delegate { notificationAreaView.delegate = object : NotificationAreaView.Delegate {
override fun onTombstoneEventClicked(tombstoneEvent: Event) { override fun onTombstoneEventClicked(tombstoneEvent: Event) {
roomDetailViewModel.handle(RoomDetailActions.HandleTombstoneEvent(tombstoneEvent)) roomDetailViewModel.handle(RoomDetailAction.HandleTombstoneEvent(tombstoneEvent))
} }
override fun resendUnsentEvents() { override fun resendUnsentEvents() {
@ -355,11 +355,11 @@ class RoomDetailFragment @Inject constructor(
// This a temporary option during dev as it is not super stable // This a temporary option during dev as it is not super stable
// Cancel all pending actions in room queue and post a dummy // Cancel all pending actions in room queue and post a dummy
// Then mark all sending events as undelivered // Then mark all sending events as undelivered
roomDetailViewModel.handle(RoomDetailActions.ClearSendQueue) roomDetailViewModel.handle(RoomDetailAction.ClearSendQueue)
return true return true
} }
if (item.itemId == R.id.resend_all) { if (item.itemId == R.id.resend_all) {
roomDetailViewModel.handle(RoomDetailActions.ResendAll) roomDetailViewModel.handle(RoomDetailAction.ResendAll)
return true return true
} }
return super.onOptionsItemSelected(item) return super.onOptionsItemSelected(item)
@ -427,7 +427,7 @@ class RoomDetailFragment @Inject constructor(
notificationDrawerManager.setCurrentRoom(null) notificationDrawerManager.setCurrentRoom(null)
roomDetailViewModel.handle(RoomDetailActions.SaveDraft(composerLayout.composerEditText.text.toString())) roomDetailViewModel.handle(RoomDetailAction.SaveDraft(composerLayout.composerEditText.text.toString()))
} }
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
@ -440,7 +440,7 @@ class RoomDetailFragment @Inject constructor(
val reaction = data.getStringExtra(EmojiReactionPickerActivity.EXTRA_REACTION_RESULT) val reaction = data.getStringExtra(EmojiReactionPickerActivity.EXTRA_REACTION_RESULT)
?: return ?: return
// TODO check if already reacted with that? // TODO check if already reacted with that?
roomDetailViewModel.handle(RoomDetailActions.SendReaction(eventId, reaction)) roomDetailViewModel.handle(RoomDetailAction.SendReaction(eventId, reaction))
} }
} }
} }
@ -498,7 +498,7 @@ class RoomDetailFragment @Inject constructor(
override fun performQuickReplyOnHolder(model: EpoxyModel<*>) { override fun performQuickReplyOnHolder(model: EpoxyModel<*>) {
(model as? AbsMessageItem)?.attributes?.informationData?.let { (model as? AbsMessageItem)?.attributes?.informationData?.let {
val eventId = it.eventId val eventId = it.eventId
roomDetailViewModel.handle(RoomDetailActions.EnterReplyMode(eventId, composerLayout.composerEditText.text.toString())) roomDetailViewModel.handle(RoomDetailAction.EnterReplyMode(eventId, composerLayout.composerEditText.text.toString()))
} }
} }
@ -601,11 +601,11 @@ class RoomDetailFragment @Inject constructor(
val textMessage = composerLayout.composerEditText.text.toString() val textMessage = composerLayout.composerEditText.text.toString()
if (textMessage.isNotBlank()) { if (textMessage.isNotBlank()) {
lockSendButton = true lockSendButton = true
roomDetailViewModel.handle(RoomDetailActions.SendMessage(textMessage, vectorPreferences.isMarkdownEnabled())) roomDetailViewModel.handle(RoomDetailAction.SendMessage(textMessage, vectorPreferences.isMarkdownEnabled()))
} }
} }
composerLayout.composerRelatedMessageCloseButton.setOnClickListener { composerLayout.composerRelatedMessageCloseButton.setOnClickListener {
roomDetailViewModel.handle(RoomDetailActions.ExitSpecialMode(composerLayout.composerEditText.text.toString())) roomDetailViewModel.handle(RoomDetailAction.ExitSpecialMode(composerLayout.composerEditText.text.toString()))
} }
composerLayout.callback = object : TextComposerView.Callback { composerLayout.callback = object : TextComposerView.Callback {
override fun onRichContentSelected(contentUri: Uri): Boolean { override fun onRichContentSelected(contentUri: Uri): Boolean {
@ -760,13 +760,13 @@ class RoomDetailFragment @Inject constructor(
.setView(layout) .setView(layout)
.setPositiveButton(R.string.report_content_custom_submit) { _, _ -> .setPositiveButton(R.string.report_content_custom_submit) { _, _ ->
val reason = input.text.toString() val reason = input.text.toString()
roomDetailViewModel.handle(RoomDetailActions.ReportContent(action.eventId, action.senderId, reason)) roomDetailViewModel.handle(RoomDetailAction.ReportContent(action.eventId, action.senderId, reason))
} }
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.show() .show()
} }
private fun displayRoomDetailActionResult(result: Async<RoomDetailActions>) { private fun displayRoomDetailActionResult(result: Async<RoomDetailAction>) {
when (result) { when (result) {
is Fail -> { is Fail -> {
AlertDialog.Builder(requireActivity()) AlertDialog.Builder(requireActivity())
@ -777,7 +777,7 @@ class RoomDetailFragment @Inject constructor(
} }
is Success -> { is Success -> {
when (val data = result.invoke()) { when (val data = result.invoke()) {
is RoomDetailActions.ReportContent -> { is RoomDetailAction.ReportContent -> {
when { when {
data.spam -> { data.spam -> {
AlertDialog.Builder(requireActivity()) AlertDialog.Builder(requireActivity())
@ -785,7 +785,7 @@ class RoomDetailFragment @Inject constructor(
.setMessage(R.string.content_reported_as_spam_content) .setMessage(R.string.content_reported_as_spam_content)
.setPositiveButton(R.string.ok, null) .setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.block_user) { _, _ -> .setNegativeButton(R.string.block_user) { _, _ ->
roomDetailViewModel.handle(RoomDetailActions.IgnoreUser(data.senderId)) roomDetailViewModel.handle(RoomDetailAction.IgnoreUser(data.senderId))
} }
.show() .show()
.withColoredButton(DialogInterface.BUTTON_NEGATIVE) .withColoredButton(DialogInterface.BUTTON_NEGATIVE)
@ -796,7 +796,7 @@ class RoomDetailFragment @Inject constructor(
.setMessage(R.string.content_reported_as_inappropriate_content) .setMessage(R.string.content_reported_as_inappropriate_content)
.setPositiveButton(R.string.ok, null) .setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.block_user) { _, _ -> .setNegativeButton(R.string.block_user) { _, _ ->
roomDetailViewModel.handle(RoomDetailActions.IgnoreUser(data.senderId)) roomDetailViewModel.handle(RoomDetailAction.IgnoreUser(data.senderId))
} }
.show() .show()
.withColoredButton(DialogInterface.BUTTON_NEGATIVE) .withColoredButton(DialogInterface.BUTTON_NEGATIVE)
@ -807,7 +807,7 @@ class RoomDetailFragment @Inject constructor(
.setMessage(R.string.content_reported_content) .setMessage(R.string.content_reported_content)
.setPositiveButton(R.string.ok, null) .setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.block_user) { _, _ -> .setNegativeButton(R.string.block_user) { _, _ ->
roomDetailViewModel.handle(RoomDetailActions.IgnoreUser(data.senderId)) roomDetailViewModel.handle(RoomDetailAction.IgnoreUser(data.senderId))
} }
.show() .show()
.withColoredButton(DialogInterface.BUTTON_NEGATIVE) .withColoredButton(DialogInterface.BUTTON_NEGATIVE)
@ -831,7 +831,7 @@ class RoomDetailFragment @Inject constructor(
showSnackWithMessage(getString(R.string.navigate_to_room_when_already_in_the_room)) showSnackWithMessage(getString(R.string.navigate_to_room_when_already_in_the_room))
} else { } else {
// Highlight and scroll to this event // Highlight and scroll to this event
roomDetailViewModel.handle(RoomDetailActions.NavigateToEvent(eventId, true)) roomDetailViewModel.handle(RoomDetailAction.NavigateToEvent(eventId, true))
} }
return true return true
} }
@ -859,11 +859,11 @@ class RoomDetailFragment @Inject constructor(
} }
override fun onEventVisible(event: TimelineEvent) { override fun onEventVisible(event: TimelineEvent) {
roomDetailViewModel.handle(RoomDetailActions.TimelineEventTurnsVisible(event)) roomDetailViewModel.handle(RoomDetailAction.TimelineEventTurnsVisible(event))
} }
override fun onEventInvisible(event: TimelineEvent) { override fun onEventInvisible(event: TimelineEvent) {
roomDetailViewModel.handle(RoomDetailActions.TimelineEventTurnsInvisible(event)) roomDetailViewModel.handle(RoomDetailAction.TimelineEventTurnsInvisible(event))
} }
override fun onEncryptedMessageClicked(informationData: MessageInformationData, view: View) { override fun onEncryptedMessageClicked(informationData: MessageInformationData, view: View) {
@ -899,7 +899,7 @@ class RoomDetailFragment @Inject constructor(
} }
override fun onFileMessageClicked(eventId: String, messageFileContent: MessageFileContent) { override fun onFileMessageClicked(eventId: String, messageFileContent: MessageFileContent) {
val action = RoomDetailActions.DownloadFile(eventId, messageFileContent) val action = RoomDetailAction.DownloadFile(eventId, messageFileContent)
// We need WRITE_EXTERNAL permission // We need WRITE_EXTERNAL permission
if (checkPermissions(PERMISSIONS_FOR_WRITING_FILES, this, PERMISSION_REQUEST_CODE_DOWNLOAD_FILE)) { if (checkPermissions(PERMISSIONS_FOR_WRITING_FILES, this, PERMISSION_REQUEST_CODE_DOWNLOAD_FILE)) {
roomDetailViewModel.handle(action) roomDetailViewModel.handle(action)
@ -946,7 +946,7 @@ class RoomDetailFragment @Inject constructor(
} }
override fun onLoadMore(direction: Timeline.Direction) { override fun onLoadMore(direction: Timeline.Direction) {
roomDetailViewModel.handle(RoomDetailActions.LoadMoreTimelineEvents(direction)) roomDetailViewModel.handle(RoomDetailAction.LoadMoreTimelineEvents(direction))
} }
override fun onEventCellClicked(informationData: MessageInformationData, messageContent: MessageContent?, view: View) { override fun onEventCellClicked(informationData: MessageInformationData, messageContent: MessageContent?, view: View) {
@ -976,10 +976,10 @@ class RoomDetailFragment @Inject constructor(
override fun onClickOnReactionPill(informationData: MessageInformationData, reaction: String, on: Boolean) { override fun onClickOnReactionPill(informationData: MessageInformationData, reaction: String, on: Boolean) {
if (on) { if (on) {
// we should test the current real state of reaction on this event // we should test the current real state of reaction on this event
roomDetailViewModel.handle(RoomDetailActions.SendReaction(informationData.eventId, reaction)) roomDetailViewModel.handle(RoomDetailAction.SendReaction(informationData.eventId, reaction))
} else { } else {
// I need to redact a reaction // I need to redact a reaction
roomDetailViewModel.handle(RoomDetailActions.UndoReaction(informationData.eventId, reaction)) roomDetailViewModel.handle(RoomDetailAction.UndoReaction(informationData.eventId, reaction))
} }
} }
@ -1027,14 +1027,14 @@ class RoomDetailFragment @Inject constructor(
} }
} }
if (nextReadMarkerId != null) { if (nextReadMarkerId != null) {
roomDetailViewModel.handle(RoomDetailActions.SetReadMarkerAction(nextReadMarkerId)) roomDetailViewModel.handle(RoomDetailAction.SetReadMarkerAction(nextReadMarkerId))
} }
} }
// AutocompleteUserPresenter.Callback // AutocompleteUserPresenter.Callback
override fun onQueryUsers(query: CharSequence?) { override fun onQueryUsers(query: CharSequence?) {
textComposerViewModel.handle(TextComposerActions.QueryUsers(query)) textComposerViewModel.handle(TextComposerAction.QueryUsers(query))
} }
private fun handleActions(action: EventSharedAction) { private fun handleActions(action: EventSharedAction) {
@ -1053,7 +1053,7 @@ class RoomDetailFragment @Inject constructor(
showSnackWithMessage(msg, Snackbar.LENGTH_SHORT) showSnackWithMessage(msg, Snackbar.LENGTH_SHORT)
} }
is EventSharedAction.Delete -> { is EventSharedAction.Delete -> {
roomDetailViewModel.handle(RoomDetailActions.RedactAction(action.eventId, context?.getString(R.string.event_redacted_by_user_reason))) roomDetailViewModel.handle(RoomDetailAction.RedactAction(action.eventId, context?.getString(R.string.event_redacted_by_user_reason)))
} }
is EventSharedAction.Share -> { is EventSharedAction.Share -> {
// TODO current data communication is too limited // TODO current data communication is too limited
@ -1110,16 +1110,16 @@ class RoomDetailFragment @Inject constructor(
} }
is EventSharedAction.QuickReact -> { is EventSharedAction.QuickReact -> {
// eventId,ClickedOn,Add // eventId,ClickedOn,Add
roomDetailViewModel.handle(RoomDetailActions.UpdateQuickReactAction(action.eventId, action.clickedOn, action.add)) roomDetailViewModel.handle(RoomDetailAction.UpdateQuickReactAction(action.eventId, action.clickedOn, action.add))
} }
is EventSharedAction.Edit -> { is EventSharedAction.Edit -> {
roomDetailViewModel.handle(RoomDetailActions.EnterEditMode(action.eventId, composerLayout.composerEditText.text.toString())) roomDetailViewModel.handle(RoomDetailAction.EnterEditMode(action.eventId, composerLayout.composerEditText.text.toString()))
} }
is EventSharedAction.Quote -> { is EventSharedAction.Quote -> {
roomDetailViewModel.handle(RoomDetailActions.EnterQuoteMode(action.eventId, composerLayout.composerEditText.text.toString())) roomDetailViewModel.handle(RoomDetailAction.EnterQuoteMode(action.eventId, composerLayout.composerEditText.text.toString()))
} }
is EventSharedAction.Reply -> { is EventSharedAction.Reply -> {
roomDetailViewModel.handle(RoomDetailActions.EnterReplyMode(action.eventId, composerLayout.composerEditText.text.toString())) roomDetailViewModel.handle(RoomDetailAction.EnterReplyMode(action.eventId, composerLayout.composerEditText.text.toString()))
} }
is EventSharedAction.CopyPermalink -> { is EventSharedAction.CopyPermalink -> {
val permalink = PermalinkFactory.createPermalink(roomDetailArgs.roomId, action.eventId) val permalink = PermalinkFactory.createPermalink(roomDetailArgs.roomId, action.eventId)
@ -1127,17 +1127,17 @@ class RoomDetailFragment @Inject constructor(
showSnackWithMessage(requireContext().getString(R.string.copied_to_clipboard), Snackbar.LENGTH_SHORT) showSnackWithMessage(requireContext().getString(R.string.copied_to_clipboard), Snackbar.LENGTH_SHORT)
} }
is EventSharedAction.Resend -> { is EventSharedAction.Resend -> {
roomDetailViewModel.handle(RoomDetailActions.ResendMessage(action.eventId)) roomDetailViewModel.handle(RoomDetailAction.ResendMessage(action.eventId))
} }
is EventSharedAction.Remove -> { is EventSharedAction.Remove -> {
roomDetailViewModel.handle(RoomDetailActions.RemoveFailedEcho(action.eventId)) roomDetailViewModel.handle(RoomDetailAction.RemoveFailedEcho(action.eventId))
} }
is EventSharedAction.ReportContentSpam -> { is EventSharedAction.ReportContentSpam -> {
roomDetailViewModel.handle(RoomDetailActions.ReportContent( roomDetailViewModel.handle(RoomDetailAction.ReportContent(
action.eventId, action.senderId, "This message is spam", spam = true)) action.eventId, action.senderId, "This message is spam", spam = true))
} }
is EventSharedAction.ReportContentInappropriate -> { is EventSharedAction.ReportContentInappropriate -> {
roomDetailViewModel.handle(RoomDetailActions.ReportContent( roomDetailViewModel.handle(RoomDetailAction.ReportContent(
action.eventId, action.senderId, "This message is inappropriate", inappropriate = true)) action.eventId, action.senderId, "This message is inappropriate", inappropriate = true))
} }
is EventSharedAction.ReportContentCustom -> { is EventSharedAction.ReportContentCustom -> {
@ -1210,22 +1210,22 @@ class RoomDetailFragment @Inject constructor(
override fun onAcceptInvite() { override fun onAcceptInvite() {
notificationDrawerManager.clearMemberShipNotificationForRoom(roomDetailArgs.roomId) notificationDrawerManager.clearMemberShipNotificationForRoom(roomDetailArgs.roomId)
roomDetailViewModel.handle(RoomDetailActions.AcceptInvite) roomDetailViewModel.handle(RoomDetailAction.AcceptInvite)
} }
override fun onRejectInvite() { override fun onRejectInvite() {
notificationDrawerManager.clearMemberShipNotificationForRoom(roomDetailArgs.roomId) notificationDrawerManager.clearMemberShipNotificationForRoom(roomDetailArgs.roomId)
roomDetailViewModel.handle(RoomDetailActions.RejectInvite) roomDetailViewModel.handle(RoomDetailAction.RejectInvite)
} }
// JumpToReadMarkerView.Callback // JumpToReadMarkerView.Callback
override fun onJumpToReadMarkerClicked(readMarkerId: String) { override fun onJumpToReadMarkerClicked(readMarkerId: String) {
roomDetailViewModel.handle(RoomDetailActions.NavigateToEvent(readMarkerId, false)) roomDetailViewModel.handle(RoomDetailAction.NavigateToEvent(readMarkerId, false))
} }
override fun onClearReadMarkerClicked() { override fun onClearReadMarkerClicked() {
roomDetailViewModel.handle(RoomDetailActions.MarkAllAsRead) roomDetailViewModel.handle(RoomDetailAction.MarkAllAsRead)
} }
// AttachmentTypeSelectorView.Callback // AttachmentTypeSelectorView.Callback
@ -1252,7 +1252,7 @@ class RoomDetailFragment @Inject constructor(
// AttachmentsHelper.Callback // AttachmentsHelper.Callback
override fun onContentAttachmentsReady(attachments: List<ContentAttachmentData>) { override fun onContentAttachmentsReady(attachments: List<ContentAttachmentData>) {
roomDetailViewModel.handle(RoomDetailActions.SendMedia(attachments)) roomDetailViewModel.handle(RoomDetailAction.SendMedia(attachments))
} }
override fun onAttachmentsProcessFailed() { override fun onAttachmentsProcessFailed() {
@ -1262,6 +1262,6 @@ class RoomDetailFragment @Inject constructor(
override fun onContactAttachmentReady(contactAttachment: ContactAttachment) { override fun onContactAttachmentReady(contactAttachment: ContactAttachment) {
super.onContactAttachmentReady(contactAttachment) super.onContactAttachmentReady(contactAttachment)
val formattedContact = contactAttachment.toHumanReadable() val formattedContact = contactAttachment.toHumanReadable()
roomDetailViewModel.handle(RoomDetailActions.SendMessage(formattedContact, false)) roomDetailViewModel.handle(RoomDetailAction.SendMessage(formattedContact, false))
} }
} }

View File

@ -69,12 +69,12 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
private val vectorPreferences: VectorPreferences, private val vectorPreferences: VectorPreferences,
private val stringProvider: StringProvider, private val stringProvider: StringProvider,
private val session: Session private val session: Session
) : VectorViewModel<RoomDetailViewState, RoomDetailActions>(initialState) { ) : VectorViewModel<RoomDetailViewState, RoomDetailAction>(initialState) {
private val room = session.getRoom(initialState.roomId)!! private val room = session.getRoom(initialState.roomId)!!
private val eventId = initialState.eventId private val eventId = initialState.eventId
private val invisibleEventsObservable = BehaviorRelay.create<RoomDetailActions.TimelineEventTurnsInvisible>() private val invisibleEventsObservable = BehaviorRelay.create<RoomDetailAction.TimelineEventTurnsInvisible>()
private val visibleEventsObservable = BehaviorRelay.create<RoomDetailActions.TimelineEventTurnsVisible>() private val visibleEventsObservable = BehaviorRelay.create<RoomDetailAction.TimelineEventTurnsVisible>()
private val timelineSettings = if (userPreferencesProvider.shouldShowHiddenEvents()) { private val timelineSettings = if (userPreferencesProvider.shouldShowHiddenEvents()) {
TimelineSettings(30, TimelineSettings(30,
filterEdits = false, filterEdits = false,
@ -92,12 +92,12 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
private var timeline = room.createTimeline(eventId, timelineSettings) private var timeline = room.createTimeline(eventId, timelineSettings)
// Can be used for several actions, for a one shot result // Can be used for several actions, for a one shot result
private val _requestLiveData = MutableLiveData<LiveEvent<Async<RoomDetailActions>>>() private val _requestLiveData = MutableLiveData<LiveEvent<Async<RoomDetailAction>>>()
val requestLiveData: LiveData<LiveEvent<Async<RoomDetailActions>>> val requestLiveData: LiveData<LiveEvent<Async<RoomDetailAction>>>
get() = _requestLiveData get() = _requestLiveData
// Slot to keep a pending action during permission request // Slot to keep a pending action during permission request
var pendingAction: RoomDetailActions? = null var pendingAction: RoomDetailAction? = null
// Slot to keep a pending uri during permission request // Slot to keep a pending uri during permission request
var pendingUri: Uri? = null var pendingUri: Uri? = null
@ -129,46 +129,46 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
setState { copy(timeline = this@RoomDetailViewModel.timeline) } setState { copy(timeline = this@RoomDetailViewModel.timeline) }
} }
override fun handle(action: RoomDetailActions) { override fun handle(action: RoomDetailAction) {
when (action) { when (action) {
is RoomDetailActions.SaveDraft -> handleSaveDraft(action) is RoomDetailAction.SaveDraft -> handleSaveDraft(action)
is RoomDetailActions.SendMessage -> handleSendMessage(action) is RoomDetailAction.SendMessage -> handleSendMessage(action)
is RoomDetailActions.SendMedia -> handleSendMedia(action) is RoomDetailAction.SendMedia -> handleSendMedia(action)
is RoomDetailActions.TimelineEventTurnsVisible -> handleEventVisible(action) is RoomDetailAction.TimelineEventTurnsVisible -> handleEventVisible(action)
is RoomDetailActions.TimelineEventTurnsInvisible -> handleEventInvisible(action) is RoomDetailAction.TimelineEventTurnsInvisible -> handleEventInvisible(action)
is RoomDetailActions.LoadMoreTimelineEvents -> handleLoadMore(action) is RoomDetailAction.LoadMoreTimelineEvents -> handleLoadMore(action)
is RoomDetailActions.SendReaction -> handleSendReaction(action) is RoomDetailAction.SendReaction -> handleSendReaction(action)
is RoomDetailActions.AcceptInvite -> handleAcceptInvite() is RoomDetailAction.AcceptInvite -> handleAcceptInvite()
is RoomDetailActions.RejectInvite -> handleRejectInvite() is RoomDetailAction.RejectInvite -> handleRejectInvite()
is RoomDetailActions.RedactAction -> handleRedactEvent(action) is RoomDetailAction.RedactAction -> handleRedactEvent(action)
is RoomDetailActions.UndoReaction -> handleUndoReact(action) is RoomDetailAction.UndoReaction -> handleUndoReact(action)
is RoomDetailActions.UpdateQuickReactAction -> handleUpdateQuickReaction(action) is RoomDetailAction.UpdateQuickReactAction -> handleUpdateQuickReaction(action)
is RoomDetailActions.ExitSpecialMode -> handleExitSpecialMode(action) is RoomDetailAction.ExitSpecialMode -> handleExitSpecialMode(action)
is RoomDetailActions.EnterEditMode -> handleEditAction(action) is RoomDetailAction.EnterEditMode -> handleEditAction(action)
is RoomDetailActions.EnterQuoteMode -> handleQuoteAction(action) is RoomDetailAction.EnterQuoteMode -> handleQuoteAction(action)
is RoomDetailActions.EnterReplyMode -> handleReplyAction(action) is RoomDetailAction.EnterReplyMode -> handleReplyAction(action)
is RoomDetailActions.DownloadFile -> handleDownloadFile(action) is RoomDetailAction.DownloadFile -> handleDownloadFile(action)
is RoomDetailActions.NavigateToEvent -> handleNavigateToEvent(action) is RoomDetailAction.NavigateToEvent -> handleNavigateToEvent(action)
is RoomDetailActions.HandleTombstoneEvent -> handleTombstoneEvent(action) is RoomDetailAction.HandleTombstoneEvent -> handleTombstoneEvent(action)
is RoomDetailActions.ResendMessage -> handleResendEvent(action) is RoomDetailAction.ResendMessage -> handleResendEvent(action)
is RoomDetailActions.RemoveFailedEcho -> handleRemove(action) is RoomDetailAction.RemoveFailedEcho -> handleRemove(action)
is RoomDetailActions.ClearSendQueue -> handleClearSendQueue() is RoomDetailAction.ClearSendQueue -> handleClearSendQueue()
is RoomDetailActions.ResendAll -> handleResendAll() is RoomDetailAction.ResendAll -> handleResendAll()
is RoomDetailActions.SetReadMarkerAction -> handleSetReadMarkerAction(action) is RoomDetailAction.SetReadMarkerAction -> handleSetReadMarkerAction(action)
is RoomDetailActions.MarkAllAsRead -> handleMarkAllAsRead() is RoomDetailAction.MarkAllAsRead -> handleMarkAllAsRead()
is RoomDetailActions.ReportContent -> handleReportContent(action) is RoomDetailAction.ReportContent -> handleReportContent(action)
is RoomDetailActions.IgnoreUser -> handleIgnoreUser(action) is RoomDetailAction.IgnoreUser -> handleIgnoreUser(action)
} }
} }
private fun handleEventInvisible(action: RoomDetailActions.TimelineEventTurnsInvisible) { private fun handleEventInvisible(action: RoomDetailAction.TimelineEventTurnsInvisible) {
invisibleEventsObservable.accept(action) invisibleEventsObservable.accept(action)
} }
/** /**
* Convert a send mode to a draft and save the draft * Convert a send mode to a draft and save the draft
*/ */
private fun handleSaveDraft(action: RoomDetailActions.SaveDraft) { private fun handleSaveDraft(action: RoomDetailAction.SaveDraft) {
withState { withState {
when (it.sendMode) { when (it.sendMode) {
is SendMode.REGULAR -> room.saveDraft(UserDraft.REGULAR(action.draft)) is SendMode.REGULAR -> room.saveDraft(UserDraft.REGULAR(action.draft))
@ -211,7 +211,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
.disposeOnClear() .disposeOnClear()
} }
private fun handleTombstoneEvent(action: RoomDetailActions.HandleTombstoneEvent) { private fun handleTombstoneEvent(action: RoomDetailAction.HandleTombstoneEvent) {
val tombstoneContent = action.event.getClearContent().toModel<RoomTombstoneContent>() val tombstoneContent = action.event.getClearContent().toModel<RoomTombstoneContent>()
?: return ?: return
@ -267,7 +267,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
// PRIVATE METHODS ***************************************************************************** // PRIVATE METHODS *****************************************************************************
private fun handleSendMessage(action: RoomDetailActions.SendMessage) { private fun handleSendMessage(action: RoomDetailAction.SendMessage) {
withState { state -> withState { state ->
when (state.sendMode) { when (state.sendMode) {
is SendMode.REGULAR -> { is SendMode.REGULAR -> {
@ -458,20 +458,20 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
}) })
} }
private fun handleSendReaction(action: RoomDetailActions.SendReaction) { private fun handleSendReaction(action: RoomDetailAction.SendReaction) {
room.sendReaction(action.targetEventId, action.reaction) room.sendReaction(action.targetEventId, action.reaction)
} }
private fun handleRedactEvent(action: RoomDetailActions.RedactAction) { private fun handleRedactEvent(action: RoomDetailAction.RedactAction) {
val event = room.getTimeLineEvent(action.targetEventId) ?: return val event = room.getTimeLineEvent(action.targetEventId) ?: return
room.redactEvent(event.root, action.reason) room.redactEvent(event.root, action.reason)
} }
private fun handleUndoReact(action: RoomDetailActions.UndoReaction) { private fun handleUndoReact(action: RoomDetailAction.UndoReaction) {
room.undoReaction(action.targetEventId, action.reaction) room.undoReaction(action.targetEventId, action.reaction)
} }
private fun handleUpdateQuickReaction(action: RoomDetailActions.UpdateQuickReactAction) { private fun handleUpdateQuickReaction(action: RoomDetailAction.UpdateQuickReactAction) {
if (action.add) { if (action.add) {
room.sendReaction(action.targetEventId, action.selectedReaction) room.sendReaction(action.targetEventId, action.selectedReaction)
} else { } else {
@ -479,7 +479,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
} }
} }
private fun handleSendMedia(action: RoomDetailActions.SendMedia) { private fun handleSendMedia(action: RoomDetailAction.SendMedia) {
val attachments = action.attachments val attachments = action.attachments
val homeServerCapabilities = session.getHomeServerCapabilities() val homeServerCapabilities = session.getHomeServerCapabilities()
val maxUploadFileSize = homeServerCapabilities.maxUploadFileSize val maxUploadFileSize = homeServerCapabilities.maxUploadFileSize
@ -496,19 +496,19 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
} }
} }
private fun handleEventVisible(action: RoomDetailActions.TimelineEventTurnsVisible) { private fun handleEventVisible(action: RoomDetailAction.TimelineEventTurnsVisible) {
if (action.event.root.sendState.isSent()) { // ignore pending/local events if (action.event.root.sendState.isSent()) { // ignore pending/local events
visibleEventsObservable.accept(action) visibleEventsObservable.accept(action)
} }
// We need to update this with the related m.replace also (to move read receipt) // We need to update this with the related m.replace also (to move read receipt)
action.event.annotations?.editSummary?.sourceEvents?.forEach { action.event.annotations?.editSummary?.sourceEvents?.forEach {
room.getTimeLineEvent(it)?.let { event -> room.getTimeLineEvent(it)?.let { event ->
visibleEventsObservable.accept(RoomDetailActions.TimelineEventTurnsVisible(event)) visibleEventsObservable.accept(RoomDetailAction.TimelineEventTurnsVisible(event))
} }
} }
} }
private fun handleLoadMore(action: RoomDetailActions.LoadMoreTimelineEvents) { private fun handleLoadMore(action: RoomDetailAction.LoadMoreTimelineEvents) {
timeline.paginate(action.direction, PAGINATION_COUNT) timeline.paginate(action.direction, PAGINATION_COUNT)
} }
@ -520,7 +520,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
room.join(callback = object : MatrixCallback<Unit> {}) room.join(callback = object : MatrixCallback<Unit> {})
} }
private fun handleEditAction(action: RoomDetailActions.EnterEditMode) { private fun handleEditAction(action: RoomDetailAction.EnterEditMode) {
saveCurrentDraft(action.draft) saveCurrentDraft(action.draft)
room.getTimeLineEvent(action.eventId)?.let { timelineEvent -> room.getTimeLineEvent(action.eventId)?.let { timelineEvent ->
@ -530,7 +530,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
} }
} }
private fun handleQuoteAction(action: RoomDetailActions.EnterQuoteMode) { private fun handleQuoteAction(action: RoomDetailAction.EnterQuoteMode) {
saveCurrentDraft(action.draft) saveCurrentDraft(action.draft)
room.getTimeLineEvent(action.eventId)?.let { timelineEvent -> room.getTimeLineEvent(action.eventId)?.let { timelineEvent ->
@ -547,7 +547,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
} }
} }
private fun handleReplyAction(action: RoomDetailActions.EnterReplyMode) { private fun handleReplyAction(action: RoomDetailAction.EnterReplyMode) {
saveCurrentDraft(action.draft) saveCurrentDraft(action.draft)
room.getTimeLineEvent(action.eventId)?.let { timelineEvent -> room.getTimeLineEvent(action.eventId)?.let { timelineEvent ->
@ -578,7 +578,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
} }
} }
private fun handleExitSpecialMode(action: RoomDetailActions.ExitSpecialMode) { private fun handleExitSpecialMode(action: RoomDetailAction.ExitSpecialMode) {
withState { state -> withState { state ->
// For edit, just delete the current draft // For edit, just delete the current draft
if (state.sendMode is SendMode.EDIT) { if (state.sendMode is SendMode.EDIT) {
@ -590,7 +590,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
} }
} }
private fun handleDownloadFile(action: RoomDetailActions.DownloadFile) { private fun handleDownloadFile(action: RoomDetailAction.DownloadFile) {
session.downloadFile( session.downloadFile(
FileService.DownloadMode.TO_EXPORT, FileService.DownloadMode.TO_EXPORT,
action.eventId, action.eventId,
@ -616,7 +616,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
}) })
} }
private fun handleNavigateToEvent(action: RoomDetailActions.NavigateToEvent) { private fun handleNavigateToEvent(action: RoomDetailAction.NavigateToEvent) {
val targetEventId: String = action.eventId val targetEventId: String = action.eventId
val correctedEventId = timeline.getFirstDisplayableEventId(targetEventId) ?: targetEventId val correctedEventId = timeline.getFirstDisplayableEventId(targetEventId) ?: targetEventId
val indexOfEvent = timeline.getIndexOfEvent(correctedEventId) val indexOfEvent = timeline.getIndexOfEvent(correctedEventId)
@ -630,7 +630,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
_navigateToEvent.postLiveEvent(correctedEventId) _navigateToEvent.postLiveEvent(correctedEventId)
} }
private fun handleResendEvent(action: RoomDetailActions.ResendMessage) { private fun handleResendEvent(action: RoomDetailAction.ResendMessage) {
val targetEventId = action.eventId val targetEventId = action.eventId
room.getTimeLineEvent(targetEventId)?.let { room.getTimeLineEvent(targetEventId)?.let {
// State must be UNDELIVERED or Failed // State must be UNDELIVERED or Failed
@ -648,7 +648,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
} }
} }
private fun handleRemove(action: RoomDetailActions.RemoveFailedEcho) { private fun handleRemove(action: RoomDetailAction.RemoveFailedEcho) {
val targetEventId = action.eventId val targetEventId = action.eventId
room.getTimeLineEvent(targetEventId)?.let { room.getTimeLineEvent(targetEventId)?.let {
// State must be UNDELIVERED or Failed // State must be UNDELIVERED or Failed
@ -683,7 +683,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
.disposeOnClear() .disposeOnClear()
} }
private fun handleSetReadMarkerAction(action: RoomDetailActions.SetReadMarkerAction) = withState { private fun handleSetReadMarkerAction(action: RoomDetailAction.SetReadMarkerAction) = withState {
var readMarkerId = action.eventId var readMarkerId = action.eventId
val indexOfEvent = timeline.getIndexOfEvent(readMarkerId) val indexOfEvent = timeline.getIndexOfEvent(readMarkerId)
// force to set the read marker on the next event // force to set the read marker on the next event
@ -699,7 +699,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
room.markAllAsRead(object : MatrixCallback<Any> {}) room.markAllAsRead(object : MatrixCallback<Any> {})
} }
private fun handleReportContent(action: RoomDetailActions.ReportContent) { private fun handleReportContent(action: RoomDetailAction.ReportContent) {
room.reportContent(action.eventId, -100, action.reason, object : MatrixCallback<Unit> { room.reportContent(action.eventId, -100, action.reason, object : MatrixCallback<Unit> {
override fun onSuccess(data: Unit) { override fun onSuccess(data: Unit) {
_requestLiveData.postValue(LiveEvent(Success(action))) _requestLiveData.postValue(LiveEvent(Success(action)))
@ -711,7 +711,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
}) })
} }
private fun handleIgnoreUser(action: RoomDetailActions.IgnoreUser) { private fun handleIgnoreUser(action: RoomDetailAction.IgnoreUser) {
if (action.userId.isNullOrEmpty()) { if (action.userId.isNullOrEmpty()) {
return return
} }

View File

@ -18,6 +18,6 @@ package im.vector.riotx.features.home.room.detail.composer
import im.vector.riotx.core.platform.VectorViewModelAction import im.vector.riotx.core.platform.VectorViewModelAction
sealed class TextComposerActions : VectorViewModelAction { sealed class TextComposerAction : VectorViewModelAction {
data class QueryUsers(val query: CharSequence?) : TextComposerActions() data class QueryUsers(val query: CharSequence?) : TextComposerAction()
} }

View File

@ -36,7 +36,7 @@ typealias AutocompleteUserQuery = CharSequence
class TextComposerViewModel @AssistedInject constructor(@Assisted initialState: TextComposerViewState, class TextComposerViewModel @AssistedInject constructor(@Assisted initialState: TextComposerViewState,
private val session: Session private val session: Session
) : VectorViewModel<TextComposerViewState, TextComposerActions>(initialState) { ) : VectorViewModel<TextComposerViewState, TextComposerAction>(initialState) {
private val room = session.getRoom(initialState.roomId)!! private val room = session.getRoom(initialState.roomId)!!
private val roomId = initialState.roomId private val roomId = initialState.roomId
@ -61,13 +61,13 @@ class TextComposerViewModel @AssistedInject constructor(@Assisted initialState:
observeUsersQuery() observeUsersQuery()
} }
override fun handle(action: TextComposerActions) { override fun handle(action: TextComposerAction) {
when (action) { when (action) {
is TextComposerActions.QueryUsers -> handleQueryUsers(action) is TextComposerAction.QueryUsers -> handleQueryUsers(action)
} }
} }
private fun handleQueryUsers(action: TextComposerActions.QueryUsers) { private fun handleQueryUsers(action: TextComposerAction.QueryUsers) {
val query = Option.fromNullable(action.query) val query = Option.fromNullable(action.query)
usersQueryObservable.accept(query) usersQueryObservable.accept(query)
} }

View File

@ -18,6 +18,6 @@ package im.vector.riotx.features.home.room.detail.timeline.action
import im.vector.riotx.core.platform.VectorViewModelAction import im.vector.riotx.core.platform.VectorViewModelAction
sealed class MessageActionsActions : VectorViewModelAction { sealed class MessageActionsAction : VectorViewModelAction {
object ToggleReportMenu : MessageActionsActions() object ToggleReportMenu : MessageActionsAction()
} }

View File

@ -72,7 +72,7 @@ class MessageActionsBottomSheet : VectorBaseBottomSheetDialogFragment(), Message
override fun didSelectMenuAction(eventAction: EventSharedAction) { override fun didSelectMenuAction(eventAction: EventSharedAction) {
if (eventAction is EventSharedAction.ReportContent) { if (eventAction is EventSharedAction.ReportContent) {
// Toggle report menu // Toggle report menu
viewModel.handle(MessageActionsActions.ToggleReportMenu) viewModel.handle(MessageActionsAction.ToggleReportMenu)
} else { } else {
messageActionsStore.post(eventAction) messageActionsStore.post(eventAction)
dismiss() dismiss()

View File

@ -85,7 +85,7 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted
private val session: Session, private val session: Session,
private val noticeEventFormatter: NoticeEventFormatter, private val noticeEventFormatter: NoticeEventFormatter,
private val stringProvider: StringProvider private val stringProvider: StringProvider
) : VectorViewModel<MessageActionState, MessageActionsActions>(initialState) { ) : VectorViewModel<MessageActionState, MessageActionsAction>(initialState) {
private val eventId = initialState.eventId private val eventId = initialState.eventId
private val informationData = initialState.informationData private val informationData = initialState.informationData
@ -112,9 +112,9 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted
observeEventAction() observeEventAction()
} }
override fun handle(action: MessageActionsActions) { override fun handle(action: MessageActionsAction) {
when (action) { when (action) {
MessageActionsActions.ToggleReportMenu -> toggleReportMenu() MessageActionsAction.ToggleReportMenu -> toggleReportMenu()
} }
} }

View File

@ -20,13 +20,13 @@ import im.vector.matrix.android.api.session.room.model.RoomSummary
import im.vector.matrix.android.api.session.room.notification.RoomNotificationState import im.vector.matrix.android.api.session.room.notification.RoomNotificationState
import im.vector.riotx.core.platform.VectorViewModelAction import im.vector.riotx.core.platform.VectorViewModelAction
sealed class RoomListActions : VectorViewModelAction { sealed class RoomListAction : VectorViewModelAction {
data class SelectRoom(val roomSummary: RoomSummary) : RoomListActions() data class SelectRoom(val roomSummary: RoomSummary) : RoomListAction()
data class ToggleCategory(val category: RoomCategory) : RoomListActions() data class ToggleCategory(val category: RoomCategory) : RoomListAction()
data class AcceptInvitation(val roomSummary: RoomSummary) : RoomListActions() data class AcceptInvitation(val roomSummary: RoomSummary) : RoomListAction()
data class RejectInvitation(val roomSummary: RoomSummary) : RoomListActions() data class RejectInvitation(val roomSummary: RoomSummary) : RoomListAction()
data class FilterWith(val filter: String) : RoomListActions() data class FilterWith(val filter: String) : RoomListAction()
data class ChangeRoomNotificationState(val roomId: String, val notificationState: RoomNotificationState) : RoomListActions() data class ChangeRoomNotificationState(val roomId: String, val notificationState: RoomNotificationState) : RoomListAction()
data class LeaveRoom(val roomId: String) : RoomListActions() data class LeaveRoom(val roomId: String) : RoomListAction()
object MarkAllRoomsRead : RoomListActions() object MarkAllRoomsRead : RoomListAction()
} }

View File

@ -85,7 +85,7 @@ class RoomListFragment @Inject constructor(
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.menu_home_mark_all_as_read -> { R.id.menu_home_mark_all_as_read -> {
roomListViewModel.handle(RoomListActions.MarkAllRoomsRead) roomListViewModel.handle(RoomListAction.MarkAllRoomsRead)
return true return true
} }
} }
@ -183,7 +183,7 @@ class RoomListFragment @Inject constructor(
// Scroll the list to top // Scroll the list to top
roomListEpoxyRecyclerView.scrollToPosition(0) roomListEpoxyRecyclerView.scrollToPosition(0)
roomListViewModel.handle(RoomListActions.FilterWith(filter)) roomListViewModel.handle(RoomListAction.FilterWith(filter))
} }
override fun openRoomDirectory(initialFilter: String) { override fun openRoomDirectory(initialFilter: String) {
@ -219,16 +219,16 @@ class RoomListFragment @Inject constructor(
private fun handleQuickActions(quickAction: RoomListQuickActionsSharedAction) { private fun handleQuickActions(quickAction: RoomListQuickActionsSharedAction) {
when (quickAction) { when (quickAction) {
is RoomListQuickActionsSharedAction.NotificationsAllNoisy -> { is RoomListQuickActionsSharedAction.NotificationsAllNoisy -> {
roomListViewModel.handle(RoomListActions.ChangeRoomNotificationState(quickAction.roomId, RoomNotificationState.ALL_MESSAGES_NOISY)) roomListViewModel.handle(RoomListAction.ChangeRoomNotificationState(quickAction.roomId, RoomNotificationState.ALL_MESSAGES_NOISY))
} }
is RoomListQuickActionsSharedAction.NotificationsAll -> { is RoomListQuickActionsSharedAction.NotificationsAll -> {
roomListViewModel.handle(RoomListActions.ChangeRoomNotificationState(quickAction.roomId, RoomNotificationState.ALL_MESSAGES)) roomListViewModel.handle(RoomListAction.ChangeRoomNotificationState(quickAction.roomId, RoomNotificationState.ALL_MESSAGES))
} }
is RoomListQuickActionsSharedAction.NotificationsMentionsOnly -> { is RoomListQuickActionsSharedAction.NotificationsMentionsOnly -> {
roomListViewModel.handle(RoomListActions.ChangeRoomNotificationState(quickAction.roomId, RoomNotificationState.MENTIONS_ONLY)) roomListViewModel.handle(RoomListAction.ChangeRoomNotificationState(quickAction.roomId, RoomNotificationState.MENTIONS_ONLY))
} }
is RoomListQuickActionsSharedAction.NotificationsMute -> { is RoomListQuickActionsSharedAction.NotificationsMute -> {
roomListViewModel.handle(RoomListActions.ChangeRoomNotificationState(quickAction.roomId, RoomNotificationState.MUTE)) roomListViewModel.handle(RoomListAction.ChangeRoomNotificationState(quickAction.roomId, RoomNotificationState.MUTE))
} }
is RoomListQuickActionsSharedAction.Settings -> { is RoomListQuickActionsSharedAction.Settings -> {
vectorBaseActivity.notImplemented("Opening room settings") vectorBaseActivity.notImplemented("Opening room settings")
@ -238,7 +238,7 @@ class RoomListFragment @Inject constructor(
.setTitle(R.string.room_participants_leave_prompt_title) .setTitle(R.string.room_participants_leave_prompt_title)
.setMessage(R.string.room_participants_leave_prompt_msg) .setMessage(R.string.room_participants_leave_prompt_msg)
.setPositiveButton(R.string.leave) { _, _ -> .setPositiveButton(R.string.leave) { _, _ ->
roomListViewModel.handle(RoomListActions.LeaveRoom(quickAction.roomId)) roomListViewModel.handle(RoomListAction.LeaveRoom(quickAction.roomId))
} }
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.show() .show()
@ -342,7 +342,7 @@ class RoomListFragment @Inject constructor(
// RoomSummaryController.Callback ************************************************************** // RoomSummaryController.Callback **************************************************************
override fun onRoomClicked(room: RoomSummary) { override fun onRoomClicked(room: RoomSummary) {
roomListViewModel.handle(RoomListActions.SelectRoom(room)) roomListViewModel.handle(RoomListAction.SelectRoom(room))
} }
override fun onRoomLongClicked(room: RoomSummary): Boolean { override fun onRoomLongClicked(room: RoomSummary): Boolean {
@ -354,16 +354,16 @@ class RoomListFragment @Inject constructor(
override fun onAcceptRoomInvitation(room: RoomSummary) { override fun onAcceptRoomInvitation(room: RoomSummary) {
notificationDrawerManager.clearMemberShipNotificationForRoom(room.roomId) notificationDrawerManager.clearMemberShipNotificationForRoom(room.roomId)
roomListViewModel.handle(RoomListActions.AcceptInvitation(room)) roomListViewModel.handle(RoomListAction.AcceptInvitation(room))
} }
override fun onRejectRoomInvitation(room: RoomSummary) { override fun onRejectRoomInvitation(room: RoomSummary) {
notificationDrawerManager.clearMemberShipNotificationForRoom(room.roomId) notificationDrawerManager.clearMemberShipNotificationForRoom(room.roomId)
roomListViewModel.handle(RoomListActions.RejectInvitation(room)) roomListViewModel.handle(RoomListAction.RejectInvitation(room))
} }
override fun onToggleRoomCategory(roomCategory: RoomCategory) { override fun onToggleRoomCategory(roomCategory: RoomCategory) {
roomListViewModel.handle(RoomListActions.ToggleCategory(roomCategory)) roomListViewModel.handle(RoomListAction.ToggleCategory(roomCategory))
} }
override fun createRoom(initialName: String) { override fun createRoom(initialName: String) {

View File

@ -36,7 +36,7 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
private val roomSummariesSource: DataSource<List<RoomSummary>>, private val roomSummariesSource: DataSource<List<RoomSummary>>,
private val alphabeticalRoomComparator: AlphabeticalRoomComparator, private val alphabeticalRoomComparator: AlphabeticalRoomComparator,
private val chronologicalRoomComparator: ChronologicalRoomComparator) private val chronologicalRoomComparator: ChronologicalRoomComparator)
: VectorViewModel<RoomListViewState, RoomListActions>(initialState) { : VectorViewModel<RoomListViewState, RoomListAction>(initialState) {
interface Factory { interface Factory {
fun create(initialState: RoomListViewState): RoomListViewModel fun create(initialState: RoomListViewState): RoomListViewModel
@ -61,30 +61,30 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
observeRoomSummaries() observeRoomSummaries()
} }
override fun handle(action: RoomListActions) { override fun handle(action: RoomListAction) {
when (action) { when (action) {
is RoomListActions.SelectRoom -> handleSelectRoom(action) is RoomListAction.SelectRoom -> handleSelectRoom(action)
is RoomListActions.ToggleCategory -> handleToggleCategory(action) is RoomListAction.ToggleCategory -> handleToggleCategory(action)
is RoomListActions.AcceptInvitation -> handleAcceptInvitation(action) is RoomListAction.AcceptInvitation -> handleAcceptInvitation(action)
is RoomListActions.RejectInvitation -> handleRejectInvitation(action) is RoomListAction.RejectInvitation -> handleRejectInvitation(action)
is RoomListActions.FilterWith -> handleFilter(action) is RoomListAction.FilterWith -> handleFilter(action)
is RoomListActions.MarkAllRoomsRead -> handleMarkAllRoomsRead() is RoomListAction.MarkAllRoomsRead -> handleMarkAllRoomsRead()
is RoomListActions.LeaveRoom -> handleLeaveRoom(action) is RoomListAction.LeaveRoom -> handleLeaveRoom(action)
is RoomListActions.ChangeRoomNotificationState -> handleChangeNotificationMode(action) is RoomListAction.ChangeRoomNotificationState -> handleChangeNotificationMode(action)
} }
} }
// PRIVATE METHODS ***************************************************************************** // PRIVATE METHODS *****************************************************************************
private fun handleSelectRoom(action: RoomListActions.SelectRoom) { private fun handleSelectRoom(action: RoomListAction.SelectRoom) {
_viewEvents.post(RoomListViewEvents.SelectRoom(action.roomSummary.roomId)) _viewEvents.post(RoomListViewEvents.SelectRoom(action.roomSummary.roomId))
} }
private fun handleToggleCategory(action: RoomListActions.ToggleCategory) = setState { private fun handleToggleCategory(action: RoomListAction.ToggleCategory) = setState {
this.toggle(action.category) this.toggle(action.category)
} }
private fun handleFilter(action: RoomListActions.FilterWith) { private fun handleFilter(action: RoomListAction.FilterWith) {
setState { setState {
copy( copy(
roomFilter = action.filter roomFilter = action.filter
@ -112,7 +112,7 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
} }
} }
private fun handleAcceptInvitation(action: RoomListActions.AcceptInvitation) = withState { state -> private fun handleAcceptInvitation(action: RoomListAction.AcceptInvitation) = withState { state ->
val roomId = action.roomSummary.roomId val roomId = action.roomSummary.roomId
if (state.joiningRoomsIds.contains(roomId) || state.rejectingRoomsIds.contains(roomId)) { if (state.joiningRoomsIds.contains(roomId) || state.rejectingRoomsIds.contains(roomId)) {
@ -147,7 +147,7 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
}) })
} }
private fun handleRejectInvitation(action: RoomListActions.RejectInvitation) = withState { state -> private fun handleRejectInvitation(action: RoomListAction.RejectInvitation) = withState { state ->
val roomId = action.roomSummary.roomId val roomId = action.roomSummary.roomId
if (state.joiningRoomsIds.contains(roomId) || state.rejectingRoomsIds.contains(roomId)) { if (state.joiningRoomsIds.contains(roomId) || state.rejectingRoomsIds.contains(roomId)) {
@ -193,7 +193,7 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
?.let { session.markAllAsRead(it, object : MatrixCallback<Unit> {}) } ?.let { session.markAllAsRead(it, object : MatrixCallback<Unit> {}) }
} }
private fun handleChangeNotificationMode(action: RoomListActions.ChangeRoomNotificationState) { private fun handleChangeNotificationMode(action: RoomListAction.ChangeRoomNotificationState) {
session.getRoom(action.roomId)?.setRoomNotificationState(action.notificationState, object : MatrixCallback<Unit> { session.getRoom(action.roomId)?.setRoomNotificationState(action.notificationState, object : MatrixCallback<Unit> {
override fun onFailure(failure: Throwable) { override fun onFailure(failure: Throwable) {
_viewEvents.post(RoomListViewEvents.Failure(failure)) _viewEvents.post(RoomListViewEvents.Failure(failure))
@ -201,7 +201,7 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
}) })
} }
private fun handleLeaveRoom(action: RoomListActions.LeaveRoom) { private fun handleLeaveRoom(action: RoomListAction.LeaveRoom) {
session.getRoom(action.roomId)?.leave(object : MatrixCallback<Unit> { session.getRoom(action.roomId)?.leave(object : MatrixCallback<Unit> {
override fun onFailure(failure: Throwable) { override fun onFailure(failure: Throwable) {
_viewEvents.post(RoomListViewEvents.Failure(failure)) _viewEvents.post(RoomListViewEvents.Failure(failure))

View File

@ -19,10 +19,10 @@ package im.vector.riotx.features.login
import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.auth.data.Credentials
import im.vector.riotx.core.platform.VectorViewModelAction import im.vector.riotx.core.platform.VectorViewModelAction
sealed class LoginActions : VectorViewModelAction { sealed class LoginAction : VectorViewModelAction {
data class UpdateHomeServer(val homeServerUrl: String) : LoginActions() data class UpdateHomeServer(val homeServerUrl: String) : LoginAction()
data class Login(val login: String, val password: String) : LoginActions() data class Login(val login: String, val password: String) : LoginAction()
data class SsoLoginSuccess(val credentials: Credentials) : LoginActions() data class SsoLoginSuccess(val credentials: Credentials) : LoginAction()
data class NavigateTo(val target: LoginActivity.Navigation) : LoginActions() data class NavigateTo(val target: LoginActivity.Navigation) : LoginAction()
data class InitWith(val loginConfig: LoginConfig) : LoginActions() data class InitWith(val loginConfig: LoginConfig) : LoginAction()
} }

View File

@ -57,7 +57,7 @@ class LoginActivity : VectorBaseActivity() {
// Get config extra // Get config extra
val loginConfig = intent.getParcelableExtra<LoginConfig?>(EXTRA_CONFIG) val loginConfig = intent.getParcelableExtra<LoginConfig?>(EXTRA_CONFIG)
if (loginConfig != null && isFirstCreation()) { if (loginConfig != null && isFirstCreation()) {
loginViewModel.handle(LoginActions.InitWith(loginConfig)) loginViewModel.handle(LoginAction.InitWith(loginConfig))
} }
loginViewModel.navigationLiveData.observeEvent(this) { loginViewModel.navigationLiveData.observeEvent(this) {

View File

@ -59,14 +59,14 @@ class LoginFragment @Inject constructor() : VectorBaseFragment() {
homeServerField.focusChanges() homeServerField.focusChanges()
.subscribe { .subscribe {
if (!it) { if (!it) {
viewModel.handle(LoginActions.UpdateHomeServer(homeServerField.text.toString())) viewModel.handle(LoginAction.UpdateHomeServer(homeServerField.text.toString()))
} }
} }
.disposeOnDestroy() .disposeOnDestroy()
homeServerField.setOnEditorActionListener { _, actionId, _ -> homeServerField.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_DONE) { if (actionId == EditorInfo.IME_ACTION_DONE) {
viewModel.handle(LoginActions.UpdateHomeServer(homeServerField.text.toString())) viewModel.handle(LoginAction.UpdateHomeServer(homeServerField.text.toString()))
return@setOnEditorActionListener true return@setOnEditorActionListener true
} }
return@setOnEditorActionListener false return@setOnEditorActionListener false
@ -78,7 +78,7 @@ class LoginFragment @Inject constructor() : VectorBaseFragment() {
} else { } else {
homeServerField.setText(ServerUrlsRepository.getDefaultHomeServerUrl(requireContext())) homeServerField.setText(ServerUrlsRepository.getDefaultHomeServerUrl(requireContext()))
} }
viewModel.handle(LoginActions.UpdateHomeServer(homeServerField.text.toString())) viewModel.handle(LoginAction.UpdateHomeServer(homeServerField.text.toString()))
} }
private fun setupNotice() { private fun setupNotice() {
@ -93,7 +93,7 @@ class LoginFragment @Inject constructor() : VectorBaseFragment() {
val login = loginField.text?.trim().toString() val login = loginField.text?.trim().toString()
val password = passwordField.text?.trim().toString() val password = passwordField.text?.trim().toString()
viewModel.handle(LoginActions.Login(login, password)) viewModel.handle(LoginAction.Login(login, password))
} }
private fun setupAuthButton() { private fun setupAuthButton() {
@ -114,7 +114,7 @@ class LoginFragment @Inject constructor() : VectorBaseFragment() {
} }
private fun openSso() { private fun openSso() {
viewModel.handle(LoginActions.NavigateTo(LoginActivity.Navigation.OpenSsoLoginFallback)) viewModel.handle(LoginAction.NavigateTo(LoginActivity.Navigation.OpenSsoLoginFallback))
} }
private fun setupPasswordReveal() { private fun setupPasswordReveal() {

View File

@ -143,7 +143,7 @@ class LoginSsoFallbackFragment @Inject constructor() : VectorBaseFragment(), OnB
super.onReceivedError(view, errorCode, description, failingUrl) super.onReceivedError(view, errorCode, description, failingUrl)
// on error case, close this fragment // on error case, close this fragment
viewModel.handle(LoginActions.NavigateTo(LoginActivity.Navigation.GoBack)) viewModel.handle(LoginAction.NavigateTo(LoginActivity.Navigation.GoBack))
} }
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) { override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
@ -253,7 +253,7 @@ class LoginSsoFallbackFragment @Inject constructor() : VectorBaseFragment(), OnB
refreshToken = null refreshToken = null
) )
viewModel.handle(LoginActions.SsoLoginSuccess(safeCredentials)) viewModel.handle(LoginAction.SsoLoginSuccess(safeCredentials))
} }
} }
} catch (e: Exception) { } catch (e: Exception) {
@ -278,7 +278,7 @@ class LoginSsoFallbackFragment @Inject constructor() : VectorBaseFragment(), OnB
refreshToken = null refreshToken = null
) )
viewModel.handle(LoginActions.SsoLoginSuccess(credentials)) viewModel.handle(LoginAction.SsoLoginSuccess(credentials))
} }
} }
} }

View File

@ -42,7 +42,7 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
private val activeSessionHolder: ActiveSessionHolder, private val activeSessionHolder: ActiveSessionHolder,
private val pushRuleTriggerListener: PushRuleTriggerListener, private val pushRuleTriggerListener: PushRuleTriggerListener,
private val sessionListener: SessionListener) private val sessionListener: SessionListener)
: VectorViewModel<LoginViewState, LoginActions>(initialState) { : VectorViewModel<LoginViewState, LoginAction>(initialState) {
@AssistedInject.Factory @AssistedInject.Factory
interface Factory { interface Factory {
@ -67,21 +67,21 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
private var homeServerConnectionConfig: HomeServerConnectionConfig? = null private var homeServerConnectionConfig: HomeServerConnectionConfig? = null
private var currentTask: Cancelable? = null private var currentTask: Cancelable? = null
override fun handle(action: LoginActions) { override fun handle(action: LoginAction) {
when (action) { when (action) {
is LoginActions.InitWith -> handleInitWith(action) is LoginAction.InitWith -> handleInitWith(action)
is LoginActions.UpdateHomeServer -> handleUpdateHomeserver(action) is LoginAction.UpdateHomeServer -> handleUpdateHomeserver(action)
is LoginActions.Login -> handleLogin(action) is LoginAction.Login -> handleLogin(action)
is LoginActions.SsoLoginSuccess -> handleSsoLoginSuccess(action) is LoginAction.SsoLoginSuccess -> handleSsoLoginSuccess(action)
is LoginActions.NavigateTo -> handleNavigation(action) is LoginAction.NavigateTo -> handleNavigation(action)
} }
} }
private fun handleInitWith(action: LoginActions.InitWith) { private fun handleInitWith(action: LoginAction.InitWith) {
loginConfig = action.loginConfig loginConfig = action.loginConfig
} }
private fun handleLogin(action: LoginActions.Login) { private fun handleLogin(action: LoginAction.Login) {
val homeServerConnectionConfigFinal = homeServerConnectionConfig val homeServerConnectionConfigFinal = homeServerConnectionConfig
if (homeServerConnectionConfigFinal == null) { if (homeServerConnectionConfigFinal == null) {
@ -124,7 +124,7 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
} }
} }
private fun handleSsoLoginSuccess(action: LoginActions.SsoLoginSuccess) { private fun handleSsoLoginSuccess(action: LoginAction.SsoLoginSuccess) {
val homeServerConnectionConfigFinal = homeServerConnectionConfig val homeServerConnectionConfigFinal = homeServerConnectionConfig
if (homeServerConnectionConfigFinal == null) { if (homeServerConnectionConfigFinal == null) {
@ -137,7 +137,7 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
} }
} }
private fun handleUpdateHomeserver(action: LoginActions.UpdateHomeServer) = withState { state -> private fun handleUpdateHomeserver(action: LoginAction.UpdateHomeServer) = withState { state ->
var newConfig: HomeServerConnectionConfig? = null var newConfig: HomeServerConnectionConfig? = null
Try { Try {
@ -197,7 +197,7 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
} }
} }
private fun handleNavigation(action: LoginActions.NavigateTo) { private fun handleNavigation(action: LoginAction.NavigateTo) {
_navigationLiveData.postValue(LiveEvent(action.target)) _navigationLiveData.postValue(LiveEvent(action.target))
} }

View File

@ -201,7 +201,7 @@ class EmojiReactionPickerActivity : VectorBaseActivity(),
tabLayout.isVisible = false tabLayout.isVisible = false
emojiPickerWholeListFragmentContainer.isVisible = false emojiPickerWholeListFragmentContainer.isVisible = false
emojiPickerFilteredListFragmentContainer.isVisible = true emojiPickerFilteredListFragmentContainer.isVisible = true
searchResultViewModel.handle(EmojiSearchActions.UpdateQuery(query)) searchResultViewModel.handle(EmojiSearchAction.UpdateQuery(query))
} }
} }

View File

@ -18,6 +18,6 @@ package im.vector.riotx.features.reactions
import im.vector.riotx.core.platform.VectorViewModelAction import im.vector.riotx.core.platform.VectorViewModelAction
sealed class EmojiSearchActions : VectorViewModelAction { sealed class EmojiSearchAction : VectorViewModelAction {
data class UpdateQuery(val queryString: String) : EmojiSearchActions() data class UpdateQuery(val queryString: String) : EmojiSearchAction()
} }

View File

@ -26,15 +26,15 @@ data class EmojiSearchResultViewState(
) : MvRxState ) : MvRxState
class EmojiSearchResultViewModel(val dataSource: EmojiDataSource, initialState: EmojiSearchResultViewState) class EmojiSearchResultViewModel(val dataSource: EmojiDataSource, initialState: EmojiSearchResultViewState)
: VectorViewModel<EmojiSearchResultViewState, EmojiSearchActions>(initialState) { : VectorViewModel<EmojiSearchResultViewState, EmojiSearchAction>(initialState) {
override fun handle(action: EmojiSearchActions) { override fun handle(action: EmojiSearchAction) {
when (action) { when (action) {
is EmojiSearchActions.UpdateQuery -> updateQuery(action) is EmojiSearchAction.UpdateQuery -> updateQuery(action)
} }
} }
private fun updateQuery(action: EmojiSearchActions.UpdateQuery) { private fun updateQuery(action: EmojiSearchAction.UpdateQuery) {
setState { setState {
copy( copy(
query = action.queryString, query = action.queryString,

View File

@ -66,7 +66,7 @@ class PublicRoomsFragment @Inject constructor(
publicRoomsFilter.queryTextChanges() publicRoomsFilter.queryTextChanges()
.debounce(500, TimeUnit.MILLISECONDS) .debounce(500, TimeUnit.MILLISECONDS)
.subscribeBy { .subscribeBy {
viewModel.handle(RoomDirectoryActions.FilterWith(it.toString())) viewModel.handle(RoomDirectoryAction.FilterWith(it.toString()))
} }
.disposeOnDestroy() .disposeOnDestroy()
@ -130,11 +130,11 @@ class PublicRoomsFragment @Inject constructor(
override fun onPublicRoomJoin(publicRoom: PublicRoom) { override fun onPublicRoomJoin(publicRoom: PublicRoom) {
Timber.v("PublicRoomJoinClicked: $publicRoom") Timber.v("PublicRoomJoinClicked: $publicRoom")
viewModel.handle(RoomDirectoryActions.JoinRoom(publicRoom.roomId)) viewModel.handle(RoomDirectoryAction.JoinRoom(publicRoom.roomId))
} }
override fun loadMore() { override fun loadMore() {
viewModel.handle(RoomDirectoryActions.LoadMore) viewModel.handle(RoomDirectoryAction.LoadMore)
} }
private var initialValueSet = false private var initialValueSet = false

View File

@ -19,9 +19,9 @@ package im.vector.riotx.features.roomdirectory
import im.vector.matrix.android.api.session.room.model.thirdparty.RoomDirectoryData import im.vector.matrix.android.api.session.room.model.thirdparty.RoomDirectoryData
import im.vector.riotx.core.platform.VectorViewModelAction import im.vector.riotx.core.platform.VectorViewModelAction
sealed class RoomDirectoryActions : VectorViewModelAction { sealed class RoomDirectoryAction : VectorViewModelAction {
data class SetRoomDirectoryData(val roomDirectoryData: RoomDirectoryData) : RoomDirectoryActions() data class SetRoomDirectoryData(val roomDirectoryData: RoomDirectoryData) : RoomDirectoryAction()
data class FilterWith(val filter: String) : RoomDirectoryActions() data class FilterWith(val filter: String) : RoomDirectoryAction()
object LoadMore : RoomDirectoryActions() object LoadMore : RoomDirectoryAction()
data class JoinRoom(val roomId: String) : RoomDirectoryActions() data class JoinRoom(val roomId: String) : RoomDirectoryAction()
} }

View File

@ -26,7 +26,7 @@ import im.vector.riotx.core.di.ScreenComponent
import im.vector.riotx.core.extensions.addFragment import im.vector.riotx.core.extensions.addFragment
import im.vector.riotx.core.extensions.addFragmentToBackstack import im.vector.riotx.core.extensions.addFragmentToBackstack
import im.vector.riotx.core.platform.VectorBaseActivity import im.vector.riotx.core.platform.VectorBaseActivity
import im.vector.riotx.features.roomdirectory.createroom.CreateRoomActions import im.vector.riotx.features.roomdirectory.createroom.CreateRoomAction
import im.vector.riotx.features.roomdirectory.createroom.CreateRoomFragment import im.vector.riotx.features.roomdirectory.createroom.CreateRoomFragment
import im.vector.riotx.features.roomdirectory.createroom.CreateRoomViewModel import im.vector.riotx.features.roomdirectory.createroom.CreateRoomViewModel
import im.vector.riotx.features.roomdirectory.picker.RoomDirectoryPickerFragment import im.vector.riotx.features.roomdirectory.picker.RoomDirectoryPickerFragment
@ -51,7 +51,7 @@ class RoomDirectoryActivity : VectorBaseActivity() {
actionViewModel = ViewModelProviders.of(this, viewModelFactory).get(RoomDirectorySharedActionViewModel::class.java) actionViewModel = ViewModelProviders.of(this, viewModelFactory).get(RoomDirectorySharedActionViewModel::class.java)
if (isFirstCreation()) { if (isFirstCreation()) {
roomDirectoryViewModel.handle(RoomDirectoryActions.FilterWith(intent?.getStringExtra(INITIAL_FILTER) ?: "")) roomDirectoryViewModel.handle(RoomDirectoryAction.FilterWith(intent?.getStringExtra(INITIAL_FILTER) ?: ""))
} }
actionViewModel.observe() actionViewModel.observe()
@ -67,7 +67,7 @@ class RoomDirectoryActivity : VectorBaseActivity() {
roomDirectoryViewModel.selectSubscribe(this, PublicRoomsViewState::currentFilter) { currentFilter -> roomDirectoryViewModel.selectSubscribe(this, PublicRoomsViewState::currentFilter) { currentFilter ->
// Transmit the filter to the createRoomViewModel // Transmit the filter to the createRoomViewModel
createRoomViewModel.handle(CreateRoomActions.SetName(currentFilter)) createRoomViewModel.handle(CreateRoomAction.SetName(currentFilter))
} }
} }

View File

@ -40,7 +40,7 @@ private const val PUBLIC_ROOMS_LIMIT = 20
class RoomDirectoryViewModel @AssistedInject constructor(@Assisted initialState: PublicRoomsViewState, class RoomDirectoryViewModel @AssistedInject constructor(@Assisted initialState: PublicRoomsViewState,
private val session: Session) private val session: Session)
: VectorViewModel<PublicRoomsViewState, RoomDirectoryActions>(initialState) { : VectorViewModel<PublicRoomsViewState, RoomDirectoryAction>(initialState) {
@AssistedInject.Factory @AssistedInject.Factory
interface Factory { interface Factory {
@ -103,16 +103,16 @@ class RoomDirectoryViewModel @AssistedInject constructor(@Assisted initialState:
.disposeOnClear() .disposeOnClear()
} }
override fun handle(action: RoomDirectoryActions) { override fun handle(action: RoomDirectoryAction) {
when (action) { when (action) {
is RoomDirectoryActions.SetRoomDirectoryData -> setRoomDirectoryData(action) is RoomDirectoryAction.SetRoomDirectoryData -> setRoomDirectoryData(action)
is RoomDirectoryActions.FilterWith -> filterWith(action) is RoomDirectoryAction.FilterWith -> filterWith(action)
RoomDirectoryActions.LoadMore -> loadMore() RoomDirectoryAction.LoadMore -> loadMore()
is RoomDirectoryActions.JoinRoom -> joinRoom(action) is RoomDirectoryAction.JoinRoom -> joinRoom(action)
} }
} }
private fun setRoomDirectoryData(action: RoomDirectoryActions.SetRoomDirectoryData) { private fun setRoomDirectoryData(action: RoomDirectoryAction.SetRoomDirectoryData) {
if (this.roomDirectoryData == action.roomDirectoryData) { if (this.roomDirectoryData == action.roomDirectoryData) {
return return
} }
@ -123,7 +123,7 @@ class RoomDirectoryViewModel @AssistedInject constructor(@Assisted initialState:
load("") load("")
} }
private fun filterWith(action: RoomDirectoryActions.FilterWith) = withState { state -> private fun filterWith(action: RoomDirectoryAction.FilterWith) = withState { state ->
if (state.currentFilter != action.filter) { if (state.currentFilter != action.filter) {
currentTask?.cancel() currentTask?.cancel()
@ -201,7 +201,7 @@ class RoomDirectoryViewModel @AssistedInject constructor(@Assisted initialState:
}) })
} }
private fun joinRoom(action: RoomDirectoryActions.JoinRoom) = withState { state -> private fun joinRoom(action: RoomDirectoryAction.JoinRoom) = withState { state ->
if (state.joiningRoomsIds.contains(action.roomId)) { if (state.joiningRoomsIds.contains(action.roomId)) {
// Request already sent, should not happen // Request already sent, should not happen
Timber.w("Try to join an already joining room. Should not happen") Timber.w("Try to join an already joining room. Should not happen")

View File

@ -18,9 +18,9 @@ package im.vector.riotx.features.roomdirectory.createroom
import im.vector.riotx.core.platform.VectorViewModelAction import im.vector.riotx.core.platform.VectorViewModelAction
sealed class CreateRoomActions : VectorViewModelAction { sealed class CreateRoomAction : VectorViewModelAction {
data class SetName(val name: String) : CreateRoomActions() data class SetName(val name: String) : CreateRoomAction()
data class SetIsPublic(val isPublic: Boolean) : CreateRoomActions() data class SetIsPublic(val isPublic: Boolean) : CreateRoomAction()
data class SetIsInRoomDirectory(val isInRoomDirectory: Boolean) : CreateRoomActions() data class SetIsInRoomDirectory(val isInRoomDirectory: Boolean) : CreateRoomAction()
object Create : CreateRoomActions() object Create : CreateRoomAction()
} }

View File

@ -49,7 +49,7 @@ class CreateRoomActivity : VectorBaseActivity(), ToolbarConfigurable {
override fun initUiAndData() { override fun initUiAndData() {
if (isFirstCreation()) { if (isFirstCreation()) {
addFragment(R.id.simpleFragmentContainer, CreateRoomFragment::class.java) addFragment(R.id.simpleFragmentContainer, CreateRoomFragment::class.java)
createRoomViewModel.handle(CreateRoomActions.SetName(intent?.getStringExtra(INITIAL_NAME) ?: "")) createRoomViewModel.handle(CreateRoomAction.SetName(intent?.getStringExtra(INITIAL_NAME) ?: ""))
} }
} }

View File

@ -53,7 +53,7 @@ class CreateRoomFragment @Inject constructor(private val createRoomController: C
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) { return when (item.itemId) {
R.id.action_create_room -> { R.id.action_create_room -> {
viewModel.handle(CreateRoomActions.Create) viewModel.handle(CreateRoomAction.Create)
true true
} }
else -> else ->
@ -71,20 +71,20 @@ class CreateRoomFragment @Inject constructor(private val createRoomController: C
} }
override fun onNameChange(newName: String) { override fun onNameChange(newName: String) {
viewModel.handle(CreateRoomActions.SetName(newName)) viewModel.handle(CreateRoomAction.SetName(newName))
} }
override fun setIsPublic(isPublic: Boolean) { override fun setIsPublic(isPublic: Boolean) {
viewModel.handle(CreateRoomActions.SetIsPublic(isPublic)) viewModel.handle(CreateRoomAction.SetIsPublic(isPublic))
} }
override fun setIsInRoomDirectory(isInRoomDirectory: Boolean) { override fun setIsInRoomDirectory(isInRoomDirectory: Boolean) {
viewModel.handle(CreateRoomActions.SetIsInRoomDirectory(isInRoomDirectory)) viewModel.handle(CreateRoomAction.SetIsInRoomDirectory(isInRoomDirectory))
} }
override fun retry() { override fun retry() {
Timber.v("Retry") Timber.v("Retry")
viewModel.handle(CreateRoomActions.Create) viewModel.handle(CreateRoomAction.Create)
} }
override fun invalidate() = withState(viewModel) { state -> override fun invalidate() = withState(viewModel) { state ->

View File

@ -30,7 +30,7 @@ import im.vector.riotx.features.roomdirectory.RoomDirectoryActivity
class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: CreateRoomViewState, class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: CreateRoomViewState,
private val session: Session private val session: Session
) : VectorViewModel<CreateRoomViewState, CreateRoomActions>(initialState) { ) : VectorViewModel<CreateRoomViewState, CreateRoomAction>(initialState) {
@AssistedInject.Factory @AssistedInject.Factory
interface Factory { interface Factory {
@ -51,20 +51,20 @@ class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: Cr
} }
} }
override fun handle(action: CreateRoomActions) { override fun handle(action: CreateRoomAction) {
when (action) { when (action) {
is CreateRoomActions.SetName -> setName(action) is CreateRoomAction.SetName -> setName(action)
is CreateRoomActions.SetIsPublic -> setIsPublic(action) is CreateRoomAction.SetIsPublic -> setIsPublic(action)
is CreateRoomActions.SetIsInRoomDirectory -> setIsInRoomDirectory(action) is CreateRoomAction.SetIsInRoomDirectory -> setIsInRoomDirectory(action)
is CreateRoomActions.Create -> doCreateRoom() is CreateRoomAction.Create -> doCreateRoom()
} }
} }
private fun setName(action: CreateRoomActions.SetName) = setState { copy(roomName = action.name) } private fun setName(action: CreateRoomAction.SetName) = setState { copy(roomName = action.name) }
private fun setIsPublic(action: CreateRoomActions.SetIsPublic) = setState { copy(isPublic = action.isPublic) } private fun setIsPublic(action: CreateRoomAction.SetIsPublic) = setState { copy(isPublic = action.isPublic) }
private fun setIsInRoomDirectory(action: CreateRoomActions.SetIsInRoomDirectory) = setState { copy(isInRoomDirectory = action.isInRoomDirectory) } private fun setIsInRoomDirectory(action: CreateRoomAction.SetIsInRoomDirectory) = setState { copy(isInRoomDirectory = action.isInRoomDirectory) }
private fun doCreateRoom() = withState { state -> private fun doCreateRoom() = withState { state ->
if (state.asyncCreateRoomRequest is Loading || state.asyncCreateRoomRequest is Success) { if (state.asyncCreateRoomRequest is Loading || state.asyncCreateRoomRequest is Success) {

View File

@ -18,6 +18,6 @@ package im.vector.riotx.features.roomdirectory.picker
import im.vector.riotx.core.platform.VectorViewModelAction import im.vector.riotx.core.platform.VectorViewModelAction
sealed class RoomDirectoryPickerActions : VectorViewModelAction { sealed class RoomDirectoryPickerAction : VectorViewModelAction {
object Retry : RoomDirectoryPickerActions() object Retry : RoomDirectoryPickerAction()
} }

View File

@ -27,7 +27,7 @@ import com.airbnb.mvrx.withState
import im.vector.matrix.android.api.session.room.model.thirdparty.RoomDirectoryData import im.vector.matrix.android.api.session.room.model.thirdparty.RoomDirectoryData
import im.vector.riotx.R import im.vector.riotx.R
import im.vector.riotx.core.platform.VectorBaseFragment import im.vector.riotx.core.platform.VectorBaseFragment
import im.vector.riotx.features.roomdirectory.RoomDirectoryActions import im.vector.riotx.features.roomdirectory.RoomDirectoryAction
import im.vector.riotx.features.roomdirectory.RoomDirectorySharedAction import im.vector.riotx.features.roomdirectory.RoomDirectorySharedAction
import im.vector.riotx.features.roomdirectory.RoomDirectorySharedActionViewModel import im.vector.riotx.features.roomdirectory.RoomDirectorySharedActionViewModel
import im.vector.riotx.features.roomdirectory.RoomDirectoryViewModel import im.vector.riotx.features.roomdirectory.RoomDirectoryViewModel
@ -87,14 +87,14 @@ class RoomDirectoryPickerFragment @Inject constructor(val roomDirectoryPickerVie
override fun onRoomDirectoryClicked(roomDirectoryData: RoomDirectoryData) { override fun onRoomDirectoryClicked(roomDirectoryData: RoomDirectoryData) {
Timber.v("onRoomDirectoryClicked: $roomDirectoryData") Timber.v("onRoomDirectoryClicked: $roomDirectoryData")
viewModel.handle(RoomDirectoryActions.SetRoomDirectoryData(roomDirectoryData)) viewModel.handle(RoomDirectoryAction.SetRoomDirectoryData(roomDirectoryData))
actionViewModel.post(RoomDirectorySharedAction.Back) actionViewModel.post(RoomDirectorySharedAction.Back)
} }
override fun retry() { override fun retry() {
Timber.v("Retry") Timber.v("Retry")
pickerViewModel.handle(RoomDirectoryPickerActions.Retry) pickerViewModel.handle(RoomDirectoryPickerAction.Retry)
} }
override fun invalidate() = withState(pickerViewModel) { state -> override fun invalidate() = withState(pickerViewModel) { state ->

View File

@ -26,7 +26,7 @@ import im.vector.riotx.core.platform.VectorViewModel
class RoomDirectoryPickerViewModel @AssistedInject constructor(@Assisted initialState: RoomDirectoryPickerViewState, class RoomDirectoryPickerViewModel @AssistedInject constructor(@Assisted initialState: RoomDirectoryPickerViewState,
private val session: Session) private val session: Session)
: VectorViewModel<RoomDirectoryPickerViewState, RoomDirectoryPickerActions>(initialState) { : VectorViewModel<RoomDirectoryPickerViewState, RoomDirectoryPickerAction>(initialState) {
@AssistedInject.Factory @AssistedInject.Factory
interface Factory { interface Factory {
@ -62,9 +62,9 @@ class RoomDirectoryPickerViewModel @AssistedInject constructor(@Assisted initial
}) })
} }
override fun handle(action: RoomDirectoryPickerActions) { override fun handle(action: RoomDirectoryPickerAction) {
when (action) { when (action) {
RoomDirectoryPickerActions.Retry -> load() RoomDirectoryPickerAction.Retry -> load()
} }
} }
} }

View File

@ -18,6 +18,6 @@ package im.vector.riotx.features.roomdirectory.roompreview
import im.vector.riotx.core.platform.VectorViewModelAction import im.vector.riotx.core.platform.VectorViewModelAction
sealed class RoomPreviewActions : VectorViewModelAction { sealed class RoomPreviewAction : VectorViewModelAction {
object Join : RoomPreviewActions() object Join : RoomPreviewAction()
} }

View File

@ -72,7 +72,7 @@ class RoomPreviewNoPreviewFragment @Inject constructor(
roomPreviewNoPreviewJoin.callback = object : ButtonStateView.Callback { roomPreviewNoPreviewJoin.callback = object : ButtonStateView.Callback {
override fun onButtonClicked() { override fun onButtonClicked() {
roomPreviewViewModel.handle(RoomPreviewActions.Join) roomPreviewViewModel.handle(RoomPreviewAction.Join)
} }
override fun onRetryClicked() { override fun onRetryClicked() {

View File

@ -31,7 +31,7 @@ import timber.log.Timber
class RoomPreviewViewModel @AssistedInject constructor(@Assisted initialState: RoomPreviewViewState, class RoomPreviewViewModel @AssistedInject constructor(@Assisted initialState: RoomPreviewViewState,
private val session: Session) private val session: Session)
: VectorViewModel<RoomPreviewViewState, RoomPreviewActions>(initialState) { : VectorViewModel<RoomPreviewViewState, RoomPreviewAction>(initialState) {
@AssistedInject.Factory @AssistedInject.Factory
interface Factory { interface Factory {
@ -77,9 +77,9 @@ class RoomPreviewViewModel @AssistedInject constructor(@Assisted initialState: R
.disposeOnClear() .disposeOnClear()
} }
override fun handle(action: RoomPreviewActions) { override fun handle(action: RoomPreviewAction) {
when (action) { when (action) {
RoomPreviewActions.Join -> joinRoom() RoomPreviewAction.Join -> joinRoom()
} }
} }