Create common parent for Action view model, to handle navigation, action, or other type of event

This commit is contained in:
Benoit Marty 2019-11-08 11:53:58 +01:00
parent cbdbe5033f
commit fa5d44af65
26 changed files with 216 additions and 198 deletions

View file

@ -14,11 +14,17 @@
* limitations under the License.
*/
package im.vector.riotx.features.home
package im.vector.riotx.core.platform
import androidx.lifecycle.ViewModel
import im.vector.riotx.core.utils.PublishDataSource
import im.vector.riotx.core.utils.MutableDataSource
import im.vector.riotx.core.utils.PublishDataSource
class HomeNavigationViewModel(private val source: MutableDataSource<HomeActivity.Navigation> = PublishDataSource())
: ViewModel(), MutableDataSource<HomeActivity.Navigation> by source
interface VectorAction
/**
* Parent class to handle navigation events, action events, or other any events
*/
open class VectorActionViewModel<T : VectorAction>(private val store: MutableDataSource<T> = PublishDataSource())
: ViewModel(), MutableDataSource<T> by store

View file

@ -0,0 +1,21 @@
/*
* 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.features.home
import im.vector.riotx.core.platform.VectorActionViewModel
class HomeActionViewModel : VectorActionViewModel<HomeActivity.HomeActivityAction>()

View file

@ -33,6 +33,7 @@ import im.vector.riotx.core.di.ScreenComponent
import im.vector.riotx.core.extensions.hideKeyboard
import im.vector.riotx.core.extensions.replaceFragment
import im.vector.riotx.core.platform.ToolbarConfigurable
import im.vector.riotx.core.platform.VectorAction
import im.vector.riotx.core.platform.VectorBaseActivity
import im.vector.riotx.core.pushers.PushersManager
import im.vector.riotx.features.disclaimer.showDisclaimerDialog
@ -48,12 +49,12 @@ import javax.inject.Inject
class HomeActivity : VectorBaseActivity(), ToolbarConfigurable {
// Supported navigation actions for this Activity
sealed class Navigation {
object OpenDrawer : Navigation()
object OpenGroup : Navigation()
sealed class HomeActivityAction : VectorAction {
object OpenDrawer : HomeActivityAction()
object OpenGroup : HomeActivityAction()
}
private lateinit var navigationViewModel: HomeNavigationViewModel
private lateinit var actionViewModel: HomeActionViewModel
@Inject lateinit var activeSessionHolder: ActiveSessionHolder
@Inject lateinit var vectorUncaughtExceptionHandler: VectorUncaughtExceptionHandler
@ -75,18 +76,18 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
FcmHelper.ensureFcmTokenIsRetrieved(this, pushManager)
navigationViewModel = ViewModelProviders.of(this).get(HomeNavigationViewModel::class.java)
actionViewModel = ViewModelProviders.of(this).get(HomeActionViewModel::class.java)
drawerLayout.addDrawerListener(drawerListener)
if (isFirstCreation()) {
replaceFragment(R.id.homeDetailFragmentContainer, LoadingFragment::class.java)
replaceFragment(R.id.homeDrawerFragmentContainer, HomeDrawerFragment::class.java)
}
navigationViewModel.observe()
actionViewModel.observe()
.subscribe { navigation ->
when (navigation) {
is Navigation.OpenDrawer -> drawerLayout.openDrawer(GravityCompat.START)
is Navigation.OpenGroup -> {
is HomeActivityAction.OpenDrawer -> drawerLayout.openDrawer(GravityCompat.START)
is HomeActivityAction.OpenGroup -> {
drawerLayout.closeDrawer(GravityCompat.START)
replaceFragment(R.id.homeDetailFragmentContainer, HomeDetailFragment::class.java)
}

View file

@ -54,7 +54,7 @@ class HomeDetailFragment @Inject constructor(
private val unreadCounterBadgeViews = arrayListOf<UnreadCounterBadgeView>()
private val viewModel: HomeDetailViewModel by fragmentViewModel()
private lateinit var navigationViewModel: HomeNavigationViewModel
private lateinit var actionViewModel: HomeActionViewModel
override fun getLayoutResId(): Int {
return R.layout.fragment_home_detail
@ -63,7 +63,7 @@ class HomeDetailFragment @Inject constructor(
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
navigationViewModel = ViewModelProviders.of(requireActivity()).get(HomeNavigationViewModel::class.java)
actionViewModel = ViewModelProviders.of(requireActivity()).get(HomeActionViewModel::class.java)
setupBottomNavigationView()
setupToolbar()
@ -129,7 +129,7 @@ class HomeDetailFragment @Inject constructor(
}
groupToolbar.title = ""
groupToolbarAvatarImageView.setOnClickListener {
navigationViewModel.post(HomeActivity.Navigation.OpenDrawer)
actionViewModel.post(HomeActivity.HomeActivityAction.OpenDrawer)
}
}

View file

@ -16,9 +16,6 @@
package im.vector.riotx.features.home.createdirect
import androidx.lifecycle.ViewModel
import im.vector.riotx.core.utils.PublishDataSource
import im.vector.riotx.core.utils.MutableDataSource
import im.vector.riotx.core.platform.VectorActionViewModel
class CreateDirectRoomNavigationViewModel(private val dataSource: MutableDataSource<CreateDirectRoomActivity.Navigation> = PublishDataSource())
: ViewModel(), MutableDataSource<CreateDirectRoomActivity.Navigation> by dataSource
class CreateDirectRoomActionViewModel : VectorActionViewModel<CreateDirectRoomActivity.CreateDirectRoomAction>()

View file

@ -32,20 +32,21 @@ import im.vector.riotx.core.error.ErrorFormatter
import im.vector.riotx.core.extensions.addFragment
import im.vector.riotx.core.extensions.addFragmentToBackstack
import im.vector.riotx.core.platform.SimpleFragmentActivity
import im.vector.riotx.core.platform.VectorAction
import im.vector.riotx.core.platform.WaitingViewData
import kotlinx.android.synthetic.main.activity.*
import javax.inject.Inject
class CreateDirectRoomActivity : SimpleFragmentActivity() {
sealed class Navigation {
object UsersDirectory : Navigation()
object Close : Navigation()
object Previous : Navigation()
sealed class CreateDirectRoomAction : VectorAction {
object OpenUsersDirectory : CreateDirectRoomAction()
object Close : CreateDirectRoomAction()
object GoBack : CreateDirectRoomAction()
}
private val viewModel: CreateDirectRoomViewModel by viewModel()
lateinit var navigationViewModel: CreateDirectRoomNavigationViewModel
private lateinit var actionViewModel: CreateDirectRoomActionViewModel
@Inject lateinit var createDirectRoomViewModelFactory: CreateDirectRoomViewModel.Factory
@Inject lateinit var errorFormatter: ErrorFormatter
@ -57,13 +58,13 @@ class CreateDirectRoomActivity : SimpleFragmentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
toolbar.visibility = View.GONE
navigationViewModel = ViewModelProviders.of(this, viewModelFactory).get(CreateDirectRoomNavigationViewModel::class.java)
navigationViewModel.observe()
actionViewModel = ViewModelProviders.of(this, viewModelFactory).get(CreateDirectRoomActionViewModel::class.java)
actionViewModel.observe()
.subscribe { navigation ->
when (navigation) {
is Navigation.UsersDirectory -> addFragmentToBackstack(R.id.container, CreateDirectRoomDirectoryUsersFragment::class.java)
Navigation.Close -> finish()
Navigation.Previous -> onBackPressed()
CreateDirectRoomAction.OpenUsersDirectory -> addFragmentToBackstack(R.id.container, CreateDirectRoomDirectoryUsersFragment::class.java)
CreateDirectRoomAction.Close -> finish()
CreateDirectRoomAction.GoBack -> onBackPressed()
}
}
.disposeOnDestroy()

View file

@ -39,11 +39,11 @@ class CreateDirectRoomDirectoryUsersFragment @Inject constructor(
private val viewModel: CreateDirectRoomViewModel by activityViewModel()
private lateinit var navigationViewModel: CreateDirectRoomNavigationViewModel
private lateinit var actionViewModel: CreateDirectRoomActionViewModel
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
navigationViewModel = ViewModelProviders.of(requireActivity(), viewModelFactory).get(CreateDirectRoomNavigationViewModel::class.java)
actionViewModel = ViewModelProviders.of(requireActivity(), viewModelFactory).get(CreateDirectRoomActionViewModel::class.java)
setupRecyclerView()
setupSearchByMatrixIdView()
setupCloseView()
@ -70,7 +70,7 @@ class CreateDirectRoomDirectoryUsersFragment @Inject constructor(
private fun setupCloseView() {
createDirectRoomClose.setOnClickListener {
navigationViewModel.post(CreateDirectRoomActivity.Navigation.Previous)
actionViewModel.post(CreateDirectRoomActivity.CreateDirectRoomAction.GoBack)
}
}
@ -81,7 +81,7 @@ class CreateDirectRoomDirectoryUsersFragment @Inject constructor(
override fun onItemClick(user: User) {
view?.hideKeyboard()
viewModel.handle(CreateDirectRoomActions.SelectUser(user))
navigationViewModel.post(CreateDirectRoomActivity.Navigation.Previous)
actionViewModel.post(CreateDirectRoomActivity.CreateDirectRoomAction.GoBack)
}
override fun retryDirectoryUsersRequest() {

View file

@ -49,11 +49,11 @@ class CreateDirectRoomKnownUsersFragment @Inject constructor(
override fun getMenuRes() = R.menu.vector_create_direct_room
private val viewModel: CreateDirectRoomViewModel by activityViewModel()
private lateinit var navigationViewModel: CreateDirectRoomNavigationViewModel
private lateinit var actionViewModel: CreateDirectRoomActionViewModel
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
navigationViewModel = ViewModelProviders.of(requireActivity(), viewModelFactory).get(CreateDirectRoomNavigationViewModel::class.java)
actionViewModel = ViewModelProviders.of(requireActivity(), viewModelFactory).get(CreateDirectRoomActionViewModel::class.java)
vectorBaseActivity.setSupportActionBar(createDirectRoomToolbar)
setupRecyclerView()
setupFilterView()
@ -89,7 +89,7 @@ class CreateDirectRoomKnownUsersFragment @Inject constructor(
private fun setupAddByMatrixIdView() {
addByMatrixId.setOnClickListener {
navigationViewModel.post(CreateDirectRoomActivity.Navigation.UsersDirectory)
actionViewModel.post(CreateDirectRoomActivity.CreateDirectRoomAction.OpenUsersDirectory)
}
}

View file

@ -26,8 +26,8 @@ import im.vector.riotx.R
import im.vector.riotx.core.extensions.observeEvent
import im.vector.riotx.core.platform.StateView
import im.vector.riotx.core.platform.VectorBaseFragment
import im.vector.riotx.features.home.HomeActionViewModel
import im.vector.riotx.features.home.HomeActivity
import im.vector.riotx.features.home.HomeNavigationViewModel
import kotlinx.android.synthetic.main.fragment_group_list.*
import javax.inject.Inject
@ -36,20 +36,20 @@ class GroupListFragment @Inject constructor(
private val groupController: GroupSummaryController
) : VectorBaseFragment(), GroupSummaryController.Callback {
private lateinit var navigationViewModel: HomeNavigationViewModel
private lateinit var actionViewModel: HomeActionViewModel
private val viewModel: GroupListViewModel by fragmentViewModel()
override fun getLayoutResId() = R.layout.fragment_group_list
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
navigationViewModel = ViewModelProviders.of(requireActivity()).get(HomeNavigationViewModel::class.java)
actionViewModel = ViewModelProviders.of(requireActivity()).get(HomeActionViewModel::class.java)
groupController.callback = this
stateView.contentView = groupListEpoxyRecyclerView
groupListEpoxyRecyclerView.setController(groupController)
viewModel.subscribe { renderState(it) }
viewModel.openGroupLiveData.observeEvent(this) {
navigationViewModel.post(HomeActivity.Navigation.OpenGroup)
actionViewModel.post(HomeActivity.HomeActivityAction.OpenGroup)
}
}

View file

@ -99,7 +99,7 @@ import im.vector.riotx.features.home.room.detail.readreceipts.DisplayReadReceipt
import im.vector.riotx.features.home.room.detail.timeline.TimelineEventController
import im.vector.riotx.features.home.room.detail.timeline.action.MessageActionsBottomSheet
import im.vector.riotx.features.home.room.detail.timeline.action.MessageActionsDispatcher
import im.vector.riotx.features.home.room.detail.timeline.action.SimpleAction
import im.vector.riotx.features.home.room.detail.timeline.action.EventAction
import im.vector.riotx.features.home.room.detail.timeline.edithistory.ViewEditHistoryBottomSheet
import im.vector.riotx.features.home.room.detail.timeline.item.*
import im.vector.riotx.features.home.room.detail.timeline.reactions.ViewReactionsBottomSheet
@ -749,7 +749,7 @@ class RoomDetailFragment @Inject constructor(
.show()
}
private fun promptReasonToReportContent(action: SimpleAction.ReportContentCustom) {
private fun promptReasonToReportContent(action: EventAction.ReportContentCustom) {
val inflater = requireActivity().layoutInflater
val layout = inflater.inflate(R.layout.dialog_report_content, null)
@ -1037,25 +1037,25 @@ class RoomDetailFragment @Inject constructor(
textComposerViewModel.process(TextComposerActions.QueryUsers(query))
}
private fun handleActions(action: SimpleAction) {
private fun handleActions(action: EventAction) {
when (action) {
is SimpleAction.AddReaction -> {
is EventAction.AddReaction -> {
startActivityForResult(EmojiReactionPickerActivity.intent(requireContext(), action.eventId), REACTION_SELECT_REQUEST_CODE)
}
is SimpleAction.ViewReactions -> {
is EventAction.ViewReactions -> {
ViewReactionsBottomSheet.newInstance(roomDetailArgs.roomId, action.messageInformationData)
.show(requireActivity().supportFragmentManager, "DISPLAY_REACTIONS")
}
is SimpleAction.Copy -> {
is EventAction.Copy -> {
// I need info about the current selected message :/
copyToClipboard(requireContext(), action.content, false)
val msg = requireContext().getString(R.string.copied_to_clipboard)
showSnackWithMessage(msg, Snackbar.LENGTH_SHORT)
}
is SimpleAction.Delete -> {
is EventAction.Delete -> {
roomDetailViewModel.process(RoomDetailActions.RedactAction(action.eventId, context?.getString(R.string.event_redacted_by_user_reason)))
}
is SimpleAction.Share -> {
is EventAction.Share -> {
// TODO current data communication is too limited
// Need to now the media type
// TODO bad, just POC
@ -1083,10 +1083,10 @@ class RoomDetailFragment @Inject constructor(
}
)
}
is SimpleAction.ViewEditHistory -> {
is EventAction.ViewEditHistory -> {
onEditedDecorationClicked(action.messageInformationData)
}
is SimpleAction.ViewSource -> {
is EventAction.ViewSource -> {
val view = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_event_content, null)
view.findViewById<TextView>(R.id.event_content_text_view)?.let {
it.text = action.content
@ -1097,7 +1097,7 @@ class RoomDetailFragment @Inject constructor(
.setPositiveButton(R.string.ok, null)
.show()
}
is SimpleAction.ViewDecryptedSource -> {
is EventAction.ViewDecryptedSource -> {
val view = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_event_content, null)
view.findViewById<TextView>(R.id.event_content_text_view)?.let {
it.text = action.content
@ -1108,42 +1108,42 @@ class RoomDetailFragment @Inject constructor(
.setPositiveButton(R.string.ok, null)
.show()
}
is SimpleAction.QuickReact -> {
is EventAction.QuickReact -> {
// eventId,ClickedOn,Add
roomDetailViewModel.process(RoomDetailActions.UpdateQuickReactAction(action.eventId, action.clickedOn, action.add))
}
is SimpleAction.Edit -> {
is EventAction.Edit -> {
roomDetailViewModel.process(RoomDetailActions.EnterEditMode(action.eventId, composerLayout.composerEditText.text.toString()))
}
is SimpleAction.Quote -> {
is EventAction.Quote -> {
roomDetailViewModel.process(RoomDetailActions.EnterQuoteMode(action.eventId, composerLayout.composerEditText.text.toString()))
}
is SimpleAction.Reply -> {
is EventAction.Reply -> {
roomDetailViewModel.process(RoomDetailActions.EnterReplyMode(action.eventId, composerLayout.composerEditText.text.toString()))
}
is SimpleAction.CopyPermalink -> {
is EventAction.CopyPermalink -> {
val permalink = PermalinkFactory.createPermalink(roomDetailArgs.roomId, action.eventId)
copyToClipboard(requireContext(), permalink, false)
showSnackWithMessage(requireContext().getString(R.string.copied_to_clipboard), Snackbar.LENGTH_SHORT)
}
is SimpleAction.Resend -> {
is EventAction.Resend -> {
roomDetailViewModel.process(RoomDetailActions.ResendMessage(action.eventId))
}
is SimpleAction.Remove -> {
is EventAction.Remove -> {
roomDetailViewModel.process(RoomDetailActions.RemoveFailedEcho(action.eventId))
}
is SimpleAction.ReportContentSpam -> {
is EventAction.ReportContentSpam -> {
roomDetailViewModel.process(RoomDetailActions.ReportContent(
action.eventId, action.senderId, "This message is spam", spam = true))
}
is SimpleAction.ReportContentInappropriate -> {
is EventAction.ReportContentInappropriate -> {
roomDetailViewModel.process(RoomDetailActions.ReportContent(
action.eventId, action.senderId, "This message is inappropriate", inappropriate = true))
}
is SimpleAction.ReportContentCustom -> {
is EventAction.ReportContentCustom -> {
promptReasonToReportContent(action)
}
else -> {
else -> {
Toast.makeText(context, "Action $action is not implemented yet", Toast.LENGTH_LONG).show()
}
}

View file

@ -19,66 +19,67 @@ package im.vector.riotx.features.home.room.detail.timeline.action
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import im.vector.riotx.R
import im.vector.riotx.core.platform.VectorAction
import im.vector.riotx.features.home.room.detail.timeline.item.MessageInformationData
sealed class SimpleAction(@StringRes val titleRes: Int, @DrawableRes val iconResId: Int) {
sealed class EventAction(@StringRes val titleRes: Int, @DrawableRes val iconResId: Int) : VectorAction {
data class AddReaction(val eventId: String) :
SimpleAction(R.string.message_add_reaction, R.drawable.ic_add_reaction)
EventAction(R.string.message_add_reaction, R.drawable.ic_add_reaction)
data class Copy(val content: String) :
SimpleAction(R.string.copy, R.drawable.ic_copy)
EventAction(R.string.copy, R.drawable.ic_copy)
data class Edit(val eventId: String) :
SimpleAction(R.string.edit, R.drawable.ic_edit)
EventAction(R.string.edit, R.drawable.ic_edit)
data class Quote(val eventId: String) :
SimpleAction(R.string.quote, R.drawable.ic_quote)
EventAction(R.string.quote, R.drawable.ic_quote)
data class Reply(val eventId: String) :
SimpleAction(R.string.reply, R.drawable.ic_reply)
EventAction(R.string.reply, R.drawable.ic_reply)
data class Share(val imageUrl: String) :
SimpleAction(R.string.share, R.drawable.ic_share)
EventAction(R.string.share, R.drawable.ic_share)
data class Resend(val eventId: String) :
SimpleAction(R.string.global_retry, R.drawable.ic_refresh_cw)
EventAction(R.string.global_retry, R.drawable.ic_refresh_cw)
data class Remove(val eventId: String) :
SimpleAction(R.string.remove, R.drawable.ic_trash)
EventAction(R.string.remove, R.drawable.ic_trash)
data class Delete(val eventId: String) :
SimpleAction(R.string.delete, R.drawable.ic_delete)
EventAction(R.string.delete, R.drawable.ic_delete)
data class Cancel(val eventId: String) :
SimpleAction(R.string.cancel, R.drawable.ic_close_round)
EventAction(R.string.cancel, R.drawable.ic_close_round)
data class ViewSource(val content: String) :
SimpleAction(R.string.view_source, R.drawable.ic_view_source)
EventAction(R.string.view_source, R.drawable.ic_view_source)
data class ViewDecryptedSource(val content: String) :
SimpleAction(R.string.view_decrypted_source, R.drawable.ic_view_source)
EventAction(R.string.view_decrypted_source, R.drawable.ic_view_source)
data class CopyPermalink(val eventId: String) :
SimpleAction(R.string.permalink, R.drawable.ic_permalink)
EventAction(R.string.permalink, R.drawable.ic_permalink)
data class ReportContent(val eventId: String, val senderId: String?) :
SimpleAction(R.string.report_content, R.drawable.ic_flag)
EventAction(R.string.report_content, R.drawable.ic_flag)
data class ReportContentSpam(val eventId: String, val senderId: String?) :
SimpleAction(R.string.report_content_spam, R.drawable.ic_report_spam)
EventAction(R.string.report_content_spam, R.drawable.ic_report_spam)
data class ReportContentInappropriate(val eventId: String, val senderId: String?) :
SimpleAction(R.string.report_content_inappropriate, R.drawable.ic_report_inappropriate)
EventAction(R.string.report_content_inappropriate, R.drawable.ic_report_inappropriate)
data class ReportContentCustom(val eventId: String, val senderId: String?) :
SimpleAction(R.string.report_content_custom, R.drawable.ic_report_custom)
EventAction(R.string.report_content_custom, R.drawable.ic_report_custom)
data class QuickReact(val eventId: String, val clickedOn: String, val add: Boolean) :
SimpleAction(0, 0)
EventAction(0, 0)
data class ViewReactions(val messageInformationData: MessageInformationData) :
SimpleAction(R.string.message_view_reaction, R.drawable.ic_view_reactions)
EventAction(R.string.message_view_reaction, R.drawable.ic_view_reactions)
data class ViewEditHistory(val messageInformationData: MessageInformationData) :
SimpleAction(R.string.message_view_edit_history, R.drawable.ic_view_edit_history)
EventAction(R.string.message_view_edit_history, R.drawable.ic_view_edit_history)
}

View file

@ -69,12 +69,12 @@ class MessageActionsBottomSheet : VectorBaseBottomSheetDialogFragment(), Message
messageActionsEpoxyController.listener = this
}
override fun didSelectMenuAction(simpleAction: SimpleAction) {
if (simpleAction is SimpleAction.ReportContent) {
override fun didSelectMenuAction(eventAction: EventAction) {
if (eventAction is EventAction.ReportContent) {
// Toggle report menu
viewModel.toggleReportMenu()
} else {
messageActionsStore.post(simpleAction)
messageActionsStore.post(eventAction)
dismiss()
}
}

View file

@ -15,13 +15,9 @@
*/
package im.vector.riotx.features.home.room.detail.timeline.action
import androidx.lifecycle.ViewModel
import im.vector.riotx.core.utils.PublishDataSource
import im.vector.riotx.core.utils.MutableDataSource
import im.vector.riotx.core.platform.VectorActionViewModel
/**
* Activity shared view model to handle message actions
*/
class MessageActionsDispatcher constructor(
private val dataSource: MutableDataSource<SimpleAction> = PublishDataSource()
) : ViewModel(), MutableDataSource<SimpleAction> by dataSource
class MessageActionsDispatcher : VectorActionViewModel<EventAction>()

View file

@ -84,7 +84,7 @@ class MessageActionsEpoxyController @Inject constructor(private val stringProvid
selecteds(state.quickStates.invoke().map { it.isSelected })
listener(object : BottomSheetItemQuickReactions.Listener {
override fun didSelect(emoji: String, selected: Boolean) {
listener?.didSelectMenuAction(SimpleAction.QuickReact(state.eventId, emoji, selected))
listener?.didSelectMenuAction(EventAction.QuickReact(state.eventId, emoji, selected))
}
})
}
@ -101,17 +101,17 @@ class MessageActionsEpoxyController @Inject constructor(private val stringProvid
id("action_$index")
iconRes(action.iconResId)
textRes(action.titleRes)
showExpand(action is SimpleAction.ReportContent)
showExpand(action is EventAction.ReportContent)
expanded(state.expendedReportContentMenu)
listener(View.OnClickListener { listener?.didSelectMenuAction(action) })
}
if (action is SimpleAction.ReportContent && state.expendedReportContentMenu) {
if (action is EventAction.ReportContent && state.expendedReportContentMenu) {
// Special case for report content menu: add the submenu
listOf(
SimpleAction.ReportContentSpam(action.eventId, action.senderId),
SimpleAction.ReportContentInappropriate(action.eventId, action.senderId),
SimpleAction.ReportContentCustom(action.eventId, action.senderId)
EventAction.ReportContentSpam(action.eventId, action.senderId),
EventAction.ReportContentInappropriate(action.eventId, action.senderId),
EventAction.ReportContentCustom(action.eventId, action.senderId)
).forEachIndexed { indexReport, actionReport ->
bottomSheetItemAction {
id("actionReport_$indexReport")
@ -126,6 +126,6 @@ class MessageActionsEpoxyController @Inject constructor(private val stringProvid
}
interface MessageActionsEpoxyControllerListener {
fun didSelectMenuAction(simpleAction: SimpleAction)
fun didSelectMenuAction(eventAction: EventAction)
}
}

View file

@ -62,7 +62,7 @@ data class MessageActionState(
// For quick reactions
val quickStates: Async<List<ToggleState>> = Uninitialized,
// For actions
val actions: Async<List<SimpleAction>> = Uninitialized,
val actions: Async<List<EventAction>> = Uninitialized,
val expendedReportContentMenu: Boolean = false
) : MvRxState {
@ -184,63 +184,63 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted
}
}
private fun actionsForEvent(optionalEvent: Optional<TimelineEvent>): List<SimpleAction> {
private fun actionsForEvent(optionalEvent: Optional<TimelineEvent>): List<EventAction> {
val event = optionalEvent.getOrNull() ?: return emptyList()
val messageContent: MessageContent? = event.annotations?.editSummary?.aggregatedContent.toModel()
?: event.root.getClearContent().toModel()
val type = messageContent?.type
return arrayListOf<SimpleAction>().apply {
return arrayListOf<EventAction>().apply {
if (event.root.sendState.hasFailed()) {
if (canRetry(event)) {
add(SimpleAction.Resend(eventId))
add(EventAction.Resend(eventId))
}
add(SimpleAction.Remove(eventId))
add(EventAction.Remove(eventId))
} else if (event.root.sendState.isSending()) {
// TODO is uploading attachment?
if (canCancel(event)) {
add(SimpleAction.Cancel(eventId))
add(EventAction.Cancel(eventId))
}
} else if (event.root.sendState == SendState.SYNCED) {
if (!event.root.isRedacted()) {
if (canReply(event, messageContent)) {
add(SimpleAction.Reply(eventId))
add(EventAction.Reply(eventId))
}
if (canEdit(event, session.myUserId)) {
add(SimpleAction.Edit(eventId))
add(EventAction.Edit(eventId))
}
if (canRedact(event, session.myUserId)) {
add(SimpleAction.Delete(eventId))
add(EventAction.Delete(eventId))
}
if (canCopy(type)) {
// TODO copy images? html? see ClipBoard
add(SimpleAction.Copy(messageContent!!.body))
add(EventAction.Copy(messageContent!!.body))
}
if (event.canReact()) {
add(SimpleAction.AddReaction(eventId))
add(EventAction.AddReaction(eventId))
}
if (canQuote(event, messageContent)) {
add(SimpleAction.Quote(eventId))
add(EventAction.Quote(eventId))
}
if (canViewReactions(event)) {
add(SimpleAction.ViewReactions(informationData))
add(EventAction.ViewReactions(informationData))
}
if (event.hasBeenEdited()) {
add(SimpleAction.ViewEditHistory(informationData))
add(EventAction.ViewEditHistory(informationData))
}
if (canShare(type)) {
if (messageContent is MessageImageContent) {
session.contentUrlResolver().resolveFullSize(messageContent.url)?.let { url ->
add(SimpleAction.Share(url))
add(EventAction.Share(url))
}
}
// TODO
@ -253,17 +253,17 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted
}
}
add(SimpleAction.ViewSource(event.root.toContentStringWithIndent()))
add(EventAction.ViewSource(event.root.toContentStringWithIndent()))
if (event.isEncrypted()) {
val decryptedContent = event.root.toClearContentStringWithIndent()
?: stringProvider.getString(R.string.encryption_information_decryption_error)
add(SimpleAction.ViewDecryptedSource(decryptedContent))
add(EventAction.ViewDecryptedSource(decryptedContent))
}
add(SimpleAction.CopyPermalink(eventId))
add(EventAction.CopyPermalink(eventId))
if (session.myUserId != event.root.senderId && event.root.getClearType() == EventType.MESSAGE) {
// not sent by me
add(SimpleAction.ReportContent(eventId, event.root.senderId))
add(EventAction.ReportContent(eventId, event.root.senderId))
}
}
}

View file

@ -39,7 +39,7 @@ import im.vector.riotx.core.error.ErrorFormatter
import im.vector.riotx.core.platform.OnBackPressed
import im.vector.riotx.core.platform.StateView
import im.vector.riotx.core.platform.VectorBaseFragment
import im.vector.riotx.features.home.room.list.actions.RoomListQuickActions
import im.vector.riotx.features.home.room.list.actions.RoomListQuickAction
import im.vector.riotx.features.home.room.list.actions.RoomListQuickActionsBottomSheet
import im.vector.riotx.features.home.room.list.actions.RoomListQuickActionsStore
import im.vector.riotx.features.home.room.list.widget.FabMenuView
@ -216,29 +216,29 @@ class RoomListFragment @Inject constructor(
}
}
private fun handleQuickActions(quickActions: RoomListQuickActions) {
when (quickActions) {
is RoomListQuickActions.NotificationsAllNoisy -> {
roomListViewModel.accept(RoomListActions.ChangeRoomNotificationState(quickActions.roomId, RoomNotificationState.ALL_MESSAGES_NOISY))
private fun handleQuickActions(quickAction: RoomListQuickAction) {
when (quickAction) {
is RoomListQuickAction.NotificationsAllNoisy -> {
roomListViewModel.accept(RoomListActions.ChangeRoomNotificationState(quickAction.roomId, RoomNotificationState.ALL_MESSAGES_NOISY))
}
is RoomListQuickActions.NotificationsAll -> {
roomListViewModel.accept(RoomListActions.ChangeRoomNotificationState(quickActions.roomId, RoomNotificationState.ALL_MESSAGES))
is RoomListQuickAction.NotificationsAll -> {
roomListViewModel.accept(RoomListActions.ChangeRoomNotificationState(quickAction.roomId, RoomNotificationState.ALL_MESSAGES))
}
is RoomListQuickActions.NotificationsMentionsOnly -> {
roomListViewModel.accept(RoomListActions.ChangeRoomNotificationState(quickActions.roomId, RoomNotificationState.MENTIONS_ONLY))
is RoomListQuickAction.NotificationsMentionsOnly -> {
roomListViewModel.accept(RoomListActions.ChangeRoomNotificationState(quickAction.roomId, RoomNotificationState.MENTIONS_ONLY))
}
is RoomListQuickActions.NotificationsMute -> {
roomListViewModel.accept(RoomListActions.ChangeRoomNotificationState(quickActions.roomId, RoomNotificationState.MUTE))
is RoomListQuickAction.NotificationsMute -> {
roomListViewModel.accept(RoomListActions.ChangeRoomNotificationState(quickAction.roomId, RoomNotificationState.MUTE))
}
is RoomListQuickActions.Settings -> {
is RoomListQuickAction.Settings -> {
vectorBaseActivity.notImplemented("Opening room settings")
}
is RoomListQuickActions.Leave -> {
is RoomListQuickAction.Leave -> {
AlertDialog.Builder(requireContext())
.setTitle(R.string.room_participants_leave_prompt_title)
.setMessage(R.string.room_participants_leave_prompt_msg)
.setPositiveButton(R.string.leave) { _, _ ->
roomListViewModel.accept(RoomListActions.LeaveRoom(quickActions.roomId))
roomListViewModel.accept(RoomListActions.LeaveRoom(quickAction.roomId))
}
.setNegativeButton(R.string.cancel, null)
.show()

View file

@ -19,35 +19,36 @@ package im.vector.riotx.features.home.room.list.actions
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import im.vector.riotx.R
import im.vector.riotx.core.platform.VectorAction
sealed class RoomListQuickActions(@StringRes val titleRes: Int, @DrawableRes val iconResId: Int, val destructive: Boolean = false) {
sealed class RoomListQuickAction(@StringRes val titleRes: Int, @DrawableRes val iconResId: Int, val destructive: Boolean = false) : VectorAction {
data class NotificationsAllNoisy(val roomId: String) : RoomListQuickActions(
data class NotificationsAllNoisy(val roomId: String) : RoomListQuickAction(
R.string.room_list_quick_actions_notifications_all_noisy,
R.drawable.ic_room_actions_notifications_all_noisy
)
data class NotificationsAll(val roomId: String) : RoomListQuickActions(
data class NotificationsAll(val roomId: String) : RoomListQuickAction(
R.string.room_list_quick_actions_notifications_all,
R.drawable.ic_room_actions_notifications_all
)
data class NotificationsMentionsOnly(val roomId: String) : RoomListQuickActions(
data class NotificationsMentionsOnly(val roomId: String) : RoomListQuickAction(
R.string.room_list_quick_actions_notifications_mentions,
R.drawable.ic_room_actions_notifications_mentions
)
data class NotificationsMute(val roomId: String) : RoomListQuickActions(
data class NotificationsMute(val roomId: String) : RoomListQuickAction(
R.string.room_list_quick_actions_notifications_mute,
R.drawable.ic_room_actions_notifications_mutes
)
data class Settings(val roomId: String) : RoomListQuickActions(
data class Settings(val roomId: String) : RoomListQuickAction(
R.string.room_list_quick_actions_settings,
R.drawable.ic_room_actions_settings
)
data class Leave(val roomId: String) : RoomListQuickActions(
data class Leave(val roomId: String) : RoomListQuickAction(
R.string.room_list_quick_actions_leave,
R.drawable.ic_room_actions_leave,
true

View file

@ -82,8 +82,8 @@ class RoomListQuickActionsBottomSheet : VectorBaseBottomSheetDialogFragment(), R
super.invalidate()
}
override fun didSelectMenuAction(quickActions: RoomListQuickActions) {
actionsDispatcher.post(quickActions)
override fun didSelectMenuAction(quickAction: RoomListQuickAction) {
actionsDispatcher.post(quickAction)
dismiss()
}

View file

@ -42,7 +42,7 @@ class RoomListQuickActionsEpoxyController @Inject constructor(private val avatar
roomName(roomSummary.displayName)
avatarUrl(roomSummary.avatarUrl)
roomId(roomSummary.roomId)
settingsClickListener(View.OnClickListener { listener?.didSelectMenuAction(RoomListQuickActions.Settings(roomSummary.roomId)) })
settingsClickListener(View.OnClickListener { listener?.didSelectMenuAction(RoomListQuickAction.Settings(roomSummary.roomId)) })
}
// Notifications
@ -51,26 +51,26 @@ class RoomListQuickActionsEpoxyController @Inject constructor(private val avatar
}
val selectedRoomState = state.roomNotificationState()
RoomListQuickActions.NotificationsAllNoisy(roomSummary.roomId).toBottomSheetItem(0, selectedRoomState)
RoomListQuickActions.NotificationsAll(roomSummary.roomId).toBottomSheetItem(1, selectedRoomState)
RoomListQuickActions.NotificationsMentionsOnly(roomSummary.roomId).toBottomSheetItem(2, selectedRoomState)
RoomListQuickActions.NotificationsMute(roomSummary.roomId).toBottomSheetItem(3, selectedRoomState)
RoomListQuickAction.NotificationsAllNoisy(roomSummary.roomId).toBottomSheetItem(0, selectedRoomState)
RoomListQuickAction.NotificationsAll(roomSummary.roomId).toBottomSheetItem(1, selectedRoomState)
RoomListQuickAction.NotificationsMentionsOnly(roomSummary.roomId).toBottomSheetItem(2, selectedRoomState)
RoomListQuickAction.NotificationsMute(roomSummary.roomId).toBottomSheetItem(3, selectedRoomState)
// Leave
bottomSheetItemSeparator {
id("leave_separator")
}
RoomListQuickActions.Leave(roomSummary.roomId).toBottomSheetItem(5)
RoomListQuickAction.Leave(roomSummary.roomId).toBottomSheetItem(5)
}
private fun RoomListQuickActions.toBottomSheetItem(index: Int, roomNotificationState: RoomNotificationState? = null) {
private fun RoomListQuickAction.toBottomSheetItem(index: Int, roomNotificationState: RoomNotificationState? = null) {
val selected = when (this) {
is RoomListQuickActions.NotificationsAllNoisy -> roomNotificationState == RoomNotificationState.ALL_MESSAGES_NOISY
is RoomListQuickActions.NotificationsAll -> roomNotificationState == RoomNotificationState.ALL_MESSAGES
is RoomListQuickActions.NotificationsMentionsOnly -> roomNotificationState == RoomNotificationState.MENTIONS_ONLY
is RoomListQuickActions.NotificationsMute -> roomNotificationState == RoomNotificationState.MUTE
is RoomListQuickActions.Settings,
is RoomListQuickActions.Leave -> false
is RoomListQuickAction.NotificationsAllNoisy -> roomNotificationState == RoomNotificationState.ALL_MESSAGES_NOISY
is RoomListQuickAction.NotificationsAll -> roomNotificationState == RoomNotificationState.ALL_MESSAGES
is RoomListQuickAction.NotificationsMentionsOnly -> roomNotificationState == RoomNotificationState.MENTIONS_ONLY
is RoomListQuickAction.NotificationsMute -> roomNotificationState == RoomNotificationState.MUTE
is RoomListQuickAction.Settings,
is RoomListQuickAction.Leave -> false
}
return bottomSheetItemAction {
id("action_$index")
@ -83,6 +83,6 @@ class RoomListQuickActionsEpoxyController @Inject constructor(private val avatar
}
interface Listener {
fun didSelectMenuAction(quickActions: RoomListQuickActions)
fun didSelectMenuAction(quickAction: RoomListQuickAction)
}
}

View file

@ -16,13 +16,9 @@
*/
package im.vector.riotx.features.home.room.list.actions
import androidx.lifecycle.ViewModel
import im.vector.riotx.core.utils.PublishDataSource
import im.vector.riotx.core.utils.MutableDataSource
import im.vector.riotx.core.platform.VectorActionViewModel
/**
* Activity shared view model to handle room list quick actions
*/
class RoomListQuickActionsStore constructor(
private val store: MutableDataSource<RoomListQuickActions> = PublishDataSource()
) : ViewModel(), MutableDataSource<RoomListQuickActions> by store
class RoomListQuickActionsStore : VectorActionViewModel<RoomListQuickAction>()

View file

@ -47,7 +47,7 @@ class PublicRoomsFragment @Inject constructor(
) : VectorBaseFragment(), PublicRoomsController.Callback {
private val viewModel: RoomDirectoryViewModel by activityViewModel()
private lateinit var navigationViewModel: RoomDirectoryNavigationViewModel
private lateinit var actionViewModel: RoomDirectoryActionViewModel
override fun getLayoutResId() = R.layout.fragment_public_rooms
@ -71,7 +71,7 @@ class PublicRoomsFragment @Inject constructor(
.disposeOnDestroy()
publicRoomsCreateNewRoom.setOnClickListener {
navigationViewModel.post(RoomDirectoryActivity.Navigation.CreateRoom)
actionViewModel.post(RoomDirectoryActivity.RoomDirectoryAction.CreateRoom)
}
viewModel.joinRoomErrorLiveData.observeEvent(this) { throwable ->
@ -83,7 +83,7 @@ class PublicRoomsFragment @Inject constructor(
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.menu_room_directory_change_protocol -> {
navigationViewModel.post(RoomDirectoryActivity.Navigation.ChangeProtocol)
actionViewModel.post(RoomDirectoryActivity.RoomDirectoryAction.ChangeProtocol)
true
}
else ->
@ -93,7 +93,7 @@ class PublicRoomsFragment @Inject constructor(
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
navigationViewModel = ViewModelProviders.of(requireActivity()).get(RoomDirectoryNavigationViewModel::class.java)
actionViewModel = ViewModelProviders.of(requireActivity()).get(RoomDirectoryActionViewModel::class.java)
setupRecyclerView()
}

View file

@ -16,9 +16,6 @@
package im.vector.riotx.features.roomdirectory
import androidx.lifecycle.ViewModel
import im.vector.riotx.core.utils.PublishDataSource
import im.vector.riotx.core.utils.MutableDataSource
import im.vector.riotx.core.platform.VectorActionViewModel
class RoomDirectoryNavigationViewModel(private val source: MutableDataSource<RoomDirectoryActivity.Navigation> = PublishDataSource())
: ViewModel(), MutableDataSource<RoomDirectoryActivity.Navigation> by source
class RoomDirectoryActionViewModel : VectorActionViewModel<RoomDirectoryActivity.RoomDirectoryAction>()

View file

@ -25,6 +25,7 @@ import im.vector.riotx.R
import im.vector.riotx.core.di.ScreenComponent
import im.vector.riotx.core.extensions.addFragment
import im.vector.riotx.core.extensions.addFragmentToBackstack
import im.vector.riotx.core.platform.VectorAction
import im.vector.riotx.core.platform.VectorBaseActivity
import im.vector.riotx.features.roomdirectory.createroom.CreateRoomFragment
import im.vector.riotx.features.roomdirectory.createroom.CreateRoomViewModel
@ -34,18 +35,18 @@ import javax.inject.Inject
class RoomDirectoryActivity : VectorBaseActivity() {
// Supported navigation actions for this Activity
sealed class Navigation {
object Back : Navigation()
object CreateRoom : Navigation()
object Close : Navigation()
object ChangeProtocol : Navigation()
sealed class RoomDirectoryAction : VectorAction {
object Back : RoomDirectoryAction()
object CreateRoom : RoomDirectoryAction()
object Close : RoomDirectoryAction()
object ChangeProtocol : RoomDirectoryAction()
}
@Inject lateinit var createRoomViewModelFactory: CreateRoomViewModel.Factory
@Inject lateinit var roomDirectoryViewModelFactory: RoomDirectoryViewModel.Factory
private val roomDirectoryViewModel: RoomDirectoryViewModel by viewModel()
private val createRoomViewModel: CreateRoomViewModel by viewModel()
private lateinit var navigationViewModel: RoomDirectoryNavigationViewModel
private lateinit var actionViewModel: RoomDirectoryActionViewModel
override fun getLayoutRes() = R.layout.activity_simple
@ -55,19 +56,19 @@ class RoomDirectoryActivity : VectorBaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
navigationViewModel = ViewModelProviders.of(this, viewModelFactory).get(RoomDirectoryNavigationViewModel::class.java)
actionViewModel = ViewModelProviders.of(this, viewModelFactory).get(RoomDirectoryActionViewModel::class.java)
if (isFirstCreation()) {
roomDirectoryViewModel.filterWith(intent?.getStringExtra(INITIAL_FILTER) ?: "")
}
navigationViewModel.observe()
actionViewModel.observe()
.subscribe { navigation ->
when (navigation) {
is Navigation.Back -> onBackPressed()
is Navigation.CreateRoom -> addFragmentToBackstack(R.id.simpleFragmentContainer, CreateRoomFragment::class.java)
is Navigation.ChangeProtocol -> addFragmentToBackstack(R.id.simpleFragmentContainer, RoomDirectoryPickerFragment::class.java)
is Navigation.Close -> finish()
is RoomDirectoryAction.Back -> onBackPressed()
is RoomDirectoryAction.CreateRoom -> addFragmentToBackstack(R.id.simpleFragmentContainer, CreateRoomFragment::class.java)
is RoomDirectoryAction.ChangeProtocol -> addFragmentToBackstack(R.id.simpleFragmentContainer, RoomDirectoryPickerFragment::class.java)
is RoomDirectoryAction.Close -> finish()
}
}
.disposeOnDestroy()

View file

@ -27,7 +27,7 @@ import im.vector.riotx.core.extensions.addFragment
import im.vector.riotx.core.platform.ToolbarConfigurable
import im.vector.riotx.core.platform.VectorBaseActivity
import im.vector.riotx.features.roomdirectory.RoomDirectoryActivity
import im.vector.riotx.features.roomdirectory.RoomDirectoryNavigationViewModel
import im.vector.riotx.features.roomdirectory.RoomDirectoryActionViewModel
import javax.inject.Inject
/**
@ -38,7 +38,7 @@ class CreateRoomActivity : VectorBaseActivity(), ToolbarConfigurable {
@Inject lateinit var createRoomViewModelFactory: CreateRoomViewModel.Factory
private val createRoomViewModel: CreateRoomViewModel by viewModel()
private lateinit var navigationViewModel: RoomDirectoryNavigationViewModel
private lateinit var actionViewModel: RoomDirectoryActionViewModel
override fun getLayoutRes() = R.layout.activity_simple
@ -55,12 +55,12 @@ class CreateRoomActivity : VectorBaseActivity(), ToolbarConfigurable {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
navigationViewModel = ViewModelProviders.of(this, viewModelFactory).get(RoomDirectoryNavigationViewModel::class.java)
navigationViewModel.observe()
actionViewModel = ViewModelProviders.of(this, viewModelFactory).get(RoomDirectoryActionViewModel::class.java)
actionViewModel.observe()
.subscribe { navigation ->
when (navigation) {
is RoomDirectoryActivity.Navigation.Back,
is RoomDirectoryActivity.Navigation.Close -> finish()
is RoomDirectoryActivity.RoomDirectoryAction.Back,
is RoomDirectoryActivity.RoomDirectoryAction.Close -> finish()
}
}
.disposeOnDestroy()

View file

@ -26,14 +26,14 @@ import com.airbnb.mvrx.withState
import im.vector.riotx.R
import im.vector.riotx.core.platform.VectorBaseFragment
import im.vector.riotx.features.roomdirectory.RoomDirectoryActivity
import im.vector.riotx.features.roomdirectory.RoomDirectoryNavigationViewModel
import im.vector.riotx.features.roomdirectory.RoomDirectoryActionViewModel
import kotlinx.android.synthetic.main.fragment_create_room.*
import timber.log.Timber
import javax.inject.Inject
class CreateRoomFragment @Inject constructor(private val createRoomController: CreateRoomController): VectorBaseFragment(), CreateRoomController.Listener {
private lateinit var navigationViewModel: RoomDirectoryNavigationViewModel
private lateinit var actionViewModel: RoomDirectoryActionViewModel
private val viewModel: CreateRoomViewModel by activityViewModel()
override fun getLayoutResId() = R.layout.fragment_create_room
@ -43,10 +43,10 @@ class CreateRoomFragment @Inject constructor(private val createRoomController: C
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
vectorBaseActivity.setSupportActionBar(createRoomToolbar)
navigationViewModel = ViewModelProviders.of(requireActivity()).get(RoomDirectoryNavigationViewModel::class.java)
actionViewModel = ViewModelProviders.of(requireActivity()).get(RoomDirectoryActionViewModel::class.java)
setupRecyclerView()
createRoomClose.setOnClickListener {
navigationViewModel.post(RoomDirectoryActivity.Navigation.Back)
actionViewModel.post(RoomDirectoryActivity.RoomDirectoryAction.Back)
}
}
@ -93,7 +93,7 @@ class CreateRoomFragment @Inject constructor(private val createRoomController: C
// Navigate to freshly created room
navigator.openRoom(requireActivity(), async())
navigationViewModel.post(RoomDirectoryActivity.Navigation.Close)
actionViewModel.post(RoomDirectoryActivity.RoomDirectoryAction.Close)
} else {
// Populate list with Epoxy
createRoomController.setData(state)

View file

@ -27,8 +27,8 @@ import com.airbnb.mvrx.withState
import im.vector.matrix.android.api.session.room.model.thirdparty.RoomDirectoryData
import im.vector.riotx.R
import im.vector.riotx.core.platform.VectorBaseFragment
import im.vector.riotx.features.roomdirectory.RoomDirectoryActionViewModel
import im.vector.riotx.features.roomdirectory.RoomDirectoryActivity
import im.vector.riotx.features.roomdirectory.RoomDirectoryNavigationViewModel
import im.vector.riotx.features.roomdirectory.RoomDirectoryViewModel
import kotlinx.android.synthetic.main.fragment_room_directory_picker.*
import timber.log.Timber
@ -41,7 +41,7 @@ class RoomDirectoryPickerFragment @Inject constructor(val roomDirectoryPickerVie
) : VectorBaseFragment(), RoomDirectoryPickerController.Callback {
private val viewModel: RoomDirectoryViewModel by activityViewModel()
private lateinit var navigationViewModel: RoomDirectoryNavigationViewModel
private lateinit var actionViewModel: RoomDirectoryActionViewModel
private val pickerViewModel: RoomDirectoryPickerViewModel by fragmentViewModel()
override fun getLayoutResId() = R.layout.fragment_room_directory_picker
@ -71,7 +71,7 @@ class RoomDirectoryPickerFragment @Inject constructor(val roomDirectoryPickerVie
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
navigationViewModel = ViewModelProviders.of(requireActivity()).get(RoomDirectoryNavigationViewModel::class.java)
actionViewModel = ViewModelProviders.of(requireActivity()).get(RoomDirectoryActionViewModel::class.java)
setupRecyclerView()
}
@ -88,7 +88,7 @@ class RoomDirectoryPickerFragment @Inject constructor(val roomDirectoryPickerVie
Timber.v("onRoomDirectoryClicked: $roomDirectoryData")
viewModel.setRoomDirectoryData(roomDirectoryData)
navigationViewModel.post(RoomDirectoryActivity.Navigation.Back)
actionViewModel.post(RoomDirectoryActivity.RoomDirectoryAction.Back)
}
override fun retry() {