forked from GitHub-Mirror/riotX-android
Pre fill the room directory filter and and the room name with the already entered string from the user
This commit is contained in:
parent
3651ec4870
commit
c32ef02a12
@ -30,10 +30,13 @@ abstract class FilteredRoomFooterItem : VectorEpoxyModel<FilteredRoomFooterItem.
|
|||||||
@EpoxyAttribute
|
@EpoxyAttribute
|
||||||
var listener: FilteredRoomFooterItemListener? = null
|
var listener: FilteredRoomFooterItemListener? = null
|
||||||
|
|
||||||
|
@EpoxyAttribute
|
||||||
|
var currentFilter: String = ""
|
||||||
|
|
||||||
override fun bind(holder: Holder) {
|
override fun bind(holder: Holder) {
|
||||||
holder.createRoomButton.setOnClickListener { listener?.createRoom() }
|
holder.createRoomButton.setOnClickListener { listener?.createRoom(currentFilter) }
|
||||||
holder.createDirectChat.setOnClickListener { listener?.createDirectChat() }
|
holder.createDirectChat.setOnClickListener { listener?.createDirectChat() }
|
||||||
holder.openRoomDirectory.setOnClickListener { listener?.openRoomDirectory() }
|
holder.openRoomDirectory.setOnClickListener { listener?.openRoomDirectory(currentFilter) }
|
||||||
}
|
}
|
||||||
|
|
||||||
class Holder : VectorEpoxyHolder() {
|
class Holder : VectorEpoxyHolder() {
|
||||||
@ -43,7 +46,7 @@ abstract class FilteredRoomFooterItem : VectorEpoxyModel<FilteredRoomFooterItem.
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface FilteredRoomFooterItemListener : FabMenuView.Listener {
|
interface FilteredRoomFooterItemListener : FabMenuView.Listener {
|
||||||
fun createRoom()
|
fun createRoom(initialName: String)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,8 +139,8 @@ class RoomListFragment : VectorBaseFragment(), RoomSummaryController.Listener, O
|
|||||||
roomListViewModel.accept(RoomListActions.FilterWith(filter))
|
roomListViewModel.accept(RoomListActions.FilterWith(filter))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun openRoomDirectory() {
|
override fun openRoomDirectory(initialFilter: String) {
|
||||||
navigator.openRoomDirectory(requireActivity())
|
navigator.openRoomDirectory(requireActivity(), initialFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createDirectChat() {
|
override fun createDirectChat() {
|
||||||
@ -266,9 +266,8 @@ class RoomListFragment : VectorBaseFragment(), RoomSummaryController.Listener, O
|
|||||||
roomListViewModel.accept(RoomListActions.ToggleCategory(roomCategory))
|
roomListViewModel.accept(RoomListActions.ToggleCategory(roomCategory))
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Pass title
|
override fun createRoom(initialName: String) {
|
||||||
override fun createRoom() {
|
navigator.openCreateRoom(requireActivity(), initialName)
|
||||||
navigator.openCreateRoom(requireActivity())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -70,13 +70,14 @@ class RoomSummaryController @Inject constructor(private val stringProvider: Stri
|
|||||||
viewState.rejectingRoomsIds,
|
viewState.rejectingRoomsIds,
|
||||||
viewState.rejectingErrorRoomsIds)
|
viewState.rejectingErrorRoomsIds)
|
||||||
|
|
||||||
addFilterFooter()
|
addFilterFooter(viewState)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addFilterFooter() {
|
private fun addFilterFooter(viewState: RoomListViewState) {
|
||||||
filteredRoomFooterItem {
|
filteredRoomFooterItem {
|
||||||
id("filter_footer")
|
id("filter_footer")
|
||||||
listener(listener)
|
listener(listener)
|
||||||
|
currentFilter(viewState.roomFilter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ class FabMenuView @JvmOverloads constructor(context: Context, attrs: AttributeSe
|
|||||||
|
|
||||||
interface Listener {
|
interface Listener {
|
||||||
fun createDirectChat()
|
fun createDirectChat()
|
||||||
fun openRoomDirectory()
|
fun openRoomDirectory(initialFilter: String = "")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -58,13 +58,13 @@ class DefaultNavigator @Inject constructor() : Navigator {
|
|||||||
context.startActivity(intent)
|
context.startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun openRoomDirectory(context: Context) {
|
override fun openRoomDirectory(context: Context, initialFilter: String) {
|
||||||
val intent = Intent(context, RoomDirectoryActivity::class.java)
|
val intent = RoomDirectoryActivity.getIntent(context, initialFilter)
|
||||||
context.startActivity(intent)
|
context.startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun openCreateRoom(context: Context) {
|
override fun openCreateRoom(context: Context, initialName: String) {
|
||||||
val intent = CreateRoomActivity.getIntent(context)
|
val intent = CreateRoomActivity.getIntent(context, initialName)
|
||||||
context.startActivity(intent)
|
context.startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,9 +27,9 @@ interface Navigator {
|
|||||||
|
|
||||||
fun openRoomPreview(publicRoom: PublicRoom, context: Context)
|
fun openRoomPreview(publicRoom: PublicRoom, context: Context)
|
||||||
|
|
||||||
fun openCreateRoom(context: Context)
|
fun openCreateRoom(context: Context, initialName: String = "")
|
||||||
|
|
||||||
fun openRoomDirectory(context: Context)
|
fun openRoomDirectory(context: Context, initialFilter: String = "")
|
||||||
|
|
||||||
fun openRoomsFiltering(context: Context)
|
fun openRoomsFiltering(context: Context)
|
||||||
|
|
||||||
|
@ -147,6 +147,11 @@ class PublicRoomsFragment : VectorBaseFragment(), PublicRoomsController.Callback
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun invalidate() = withState(viewModel) { state ->
|
override fun invalidate() = withState(viewModel) { state ->
|
||||||
|
if (publicRoomsFilter.text.toString() != state.currentFilter) {
|
||||||
|
// For initial filter
|
||||||
|
publicRoomsFilter.setText(state.currentFilter)
|
||||||
|
}
|
||||||
|
|
||||||
// Populate list with Epoxy
|
// Populate list with Epoxy
|
||||||
publicRoomsController.setData(state)
|
publicRoomsController.setData(state)
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,8 @@ import com.airbnb.mvrx.Uninitialized
|
|||||||
import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoom
|
import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoom
|
||||||
|
|
||||||
data class PublicRoomsViewState(
|
data class PublicRoomsViewState(
|
||||||
|
// The current filter
|
||||||
|
val currentFilter: String = "",
|
||||||
// Store cumul of pagination result
|
// Store cumul of pagination result
|
||||||
val publicRooms: List<PublicRoom> = emptyList(),
|
val publicRooms: List<PublicRoom> = emptyList(),
|
||||||
// Current pagination request
|
// Current pagination request
|
||||||
|
@ -16,8 +16,11 @@
|
|||||||
|
|
||||||
package im.vector.riotx.features.roomdirectory
|
package im.vector.riotx.features.roomdirectory
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.lifecycle.ViewModelProviders
|
import androidx.lifecycle.ViewModelProviders
|
||||||
|
import com.airbnb.mvrx.viewModel
|
||||||
import im.vector.riotx.R
|
import im.vector.riotx.R
|
||||||
import im.vector.riotx.core.di.ScreenComponent
|
import im.vector.riotx.core.di.ScreenComponent
|
||||||
import im.vector.riotx.core.extensions.addFragment
|
import im.vector.riotx.core.extensions.addFragment
|
||||||
@ -25,6 +28,7 @@ import im.vector.riotx.core.extensions.addFragmentToBackstack
|
|||||||
import im.vector.riotx.core.extensions.observeEvent
|
import im.vector.riotx.core.extensions.observeEvent
|
||||||
import im.vector.riotx.core.platform.VectorBaseActivity
|
import im.vector.riotx.core.platform.VectorBaseActivity
|
||||||
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.picker.RoomDirectoryPickerFragment
|
import im.vector.riotx.features.roomdirectory.picker.RoomDirectoryPickerFragment
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@ -39,7 +43,10 @@ class RoomDirectoryActivity : VectorBaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Inject lateinit var createRoomViewModelFactory: CreateRoomViewModel.Factory
|
||||||
@Inject lateinit var roomDirectoryViewModelFactory: RoomDirectoryViewModel.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 navigationViewModel: RoomDirectoryNavigationViewModel
|
||||||
|
|
||||||
override fun getLayoutRes() = R.layout.activity_simple
|
override fun getLayoutRes() = R.layout.activity_simple
|
||||||
@ -51,6 +58,11 @@ class RoomDirectoryActivity : VectorBaseActivity() {
|
|||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
navigationViewModel = ViewModelProviders.of(this, viewModelFactory).get(RoomDirectoryNavigationViewModel::class.java)
|
navigationViewModel = ViewModelProviders.of(this, viewModelFactory).get(RoomDirectoryNavigationViewModel::class.java)
|
||||||
|
|
||||||
|
if (isFirstCreation()) {
|
||||||
|
roomDirectoryViewModel.filterWith(intent?.getStringExtra(INITIAL_FILTER) ?: "")
|
||||||
|
}
|
||||||
|
|
||||||
navigationViewModel.navigateTo.observeEvent(this) { navigation ->
|
navigationViewModel.navigateTo.observeEvent(this) { navigation ->
|
||||||
when (navigation) {
|
when (navigation) {
|
||||||
is Navigation.Back -> onBackPressed()
|
is Navigation.Back -> onBackPressed()
|
||||||
@ -59,6 +71,11 @@ class RoomDirectoryActivity : VectorBaseActivity() {
|
|||||||
is Navigation.Close -> finish()
|
is Navigation.Close -> finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
roomDirectoryViewModel.selectSubscribe(this, PublicRoomsViewState::currentFilter) { currentFilter ->
|
||||||
|
// Transmit the filter to the createRoomViewModel
|
||||||
|
createRoomViewModel.setName(currentFilter)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun initUiAndData() {
|
override fun initUiAndData() {
|
||||||
@ -67,4 +84,13 @@ class RoomDirectoryActivity : VectorBaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val INITIAL_FILTER = "INITIAL_FILTER"
|
||||||
|
|
||||||
|
fun getIntent(context: Context, initialFilter: String = ""): Intent {
|
||||||
|
val intent = Intent(context, RoomDirectoryActivity::class.java)
|
||||||
|
intent.putExtra(INITIAL_FILTER, initialFilter)
|
||||||
|
return intent
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -59,9 +59,6 @@ class RoomDirectoryViewModel @AssistedInject constructor(@Assisted initialState:
|
|||||||
get() = _joinRoomErrorLiveData
|
get() = _joinRoomErrorLiveData
|
||||||
|
|
||||||
|
|
||||||
// TODO Store in ViewState?
|
|
||||||
private var currentFilter: String = ""
|
|
||||||
|
|
||||||
private var since: String? = null
|
private var since: String? = null
|
||||||
|
|
||||||
private var currentTask: Cancelable? = null
|
private var currentTask: Cancelable? = null
|
||||||
@ -70,9 +67,6 @@ class RoomDirectoryViewModel @AssistedInject constructor(@Assisted initialState:
|
|||||||
private var roomDirectoryData = RoomDirectoryData()
|
private var roomDirectoryData = RoomDirectoryData()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
// Load with empty filter
|
|
||||||
load()
|
|
||||||
|
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
roomDirectoryDisplayName = roomDirectoryData.displayName
|
roomDirectoryDisplayName = roomDirectoryData.displayName
|
||||||
@ -115,24 +109,20 @@ class RoomDirectoryViewModel @AssistedInject constructor(@Assisted initialState:
|
|||||||
|
|
||||||
this.roomDirectoryData = roomDirectoryData
|
this.roomDirectoryData = roomDirectoryData
|
||||||
|
|
||||||
reset()
|
reset("")
|
||||||
load()
|
load("")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun filterWith(filter: String) {
|
fun filterWith(filter: String) = withState { state ->
|
||||||
if (currentFilter == filter) {
|
if (state.currentFilter != filter) {
|
||||||
return
|
currentTask?.cancel()
|
||||||
|
|
||||||
|
reset(filter)
|
||||||
|
load(filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
currentTask?.cancel()
|
|
||||||
|
|
||||||
currentFilter = filter
|
|
||||||
|
|
||||||
reset()
|
|
||||||
load()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun reset() {
|
private fun reset(newFilter: String) {
|
||||||
// Reset since token
|
// Reset since token
|
||||||
since = null
|
since = null
|
||||||
|
|
||||||
@ -141,12 +131,13 @@ class RoomDirectoryViewModel @AssistedInject constructor(@Assisted initialState:
|
|||||||
publicRooms = emptyList(),
|
publicRooms = emptyList(),
|
||||||
asyncPublicRoomsRequest = Loading(),
|
asyncPublicRoomsRequest = Loading(),
|
||||||
hasMore = false,
|
hasMore = false,
|
||||||
roomDirectoryDisplayName = roomDirectoryData.displayName
|
roomDirectoryDisplayName = roomDirectoryData.displayName,
|
||||||
|
currentFilter = newFilter
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadMore() {
|
fun loadMore() = withState { state ->
|
||||||
if (currentTask == null) {
|
if (currentTask == null) {
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
@ -154,15 +145,15 @@ class RoomDirectoryViewModel @AssistedInject constructor(@Assisted initialState:
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
load()
|
load(state.currentFilter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun load() {
|
private fun load(filter: String) {
|
||||||
currentTask = session.getPublicRooms(roomDirectoryData.homeServer,
|
currentTask = session.getPublicRooms(roomDirectoryData.homeServer,
|
||||||
PublicRoomsParams(
|
PublicRoomsParams(
|
||||||
limit = PUBLIC_ROOMS_LIMIT,
|
limit = PUBLIC_ROOMS_LIMIT,
|
||||||
filter = PublicRoomsFilter(searchTerm = currentFilter),
|
filter = PublicRoomsFilter(searchTerm = filter),
|
||||||
includeAllNetworks = roomDirectoryData.includeAllNetworks,
|
includeAllNetworks = roomDirectoryData.includeAllNetworks,
|
||||||
since = since,
|
since = since,
|
||||||
thirdPartyInstanceId = roomDirectoryData.thirdPartyInstanceId
|
thirdPartyInstanceId = roomDirectoryData.thirdPartyInstanceId
|
||||||
|
@ -21,6 +21,7 @@ import android.content.Intent
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
import androidx.lifecycle.ViewModelProviders
|
import androidx.lifecycle.ViewModelProviders
|
||||||
|
import com.airbnb.mvrx.viewModel
|
||||||
import im.vector.riotx.R
|
import im.vector.riotx.R
|
||||||
import im.vector.riotx.core.di.ScreenComponent
|
import im.vector.riotx.core.di.ScreenComponent
|
||||||
import im.vector.riotx.core.extensions.addFragment
|
import im.vector.riotx.core.extensions.addFragment
|
||||||
@ -29,12 +30,16 @@ import im.vector.riotx.core.platform.ToolbarConfigurable
|
|||||||
import im.vector.riotx.core.platform.VectorBaseActivity
|
import im.vector.riotx.core.platform.VectorBaseActivity
|
||||||
import im.vector.riotx.features.roomdirectory.RoomDirectoryActivity
|
import im.vector.riotx.features.roomdirectory.RoomDirectoryActivity
|
||||||
import im.vector.riotx.features.roomdirectory.RoomDirectoryNavigationViewModel
|
import im.vector.riotx.features.roomdirectory.RoomDirectoryNavigationViewModel
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple container for [CreateRoomFragment]
|
* Simple container for [CreateRoomFragment]
|
||||||
*/
|
*/
|
||||||
class CreateRoomActivity : VectorBaseActivity(), ToolbarConfigurable {
|
class CreateRoomActivity : VectorBaseActivity(), ToolbarConfigurable {
|
||||||
|
|
||||||
|
@Inject lateinit var createRoomViewModelFactory: CreateRoomViewModel.Factory
|
||||||
|
private val createRoomViewModel: CreateRoomViewModel by viewModel()
|
||||||
|
|
||||||
private lateinit var navigationViewModel: RoomDirectoryNavigationViewModel
|
private lateinit var navigationViewModel: RoomDirectoryNavigationViewModel
|
||||||
|
|
||||||
override fun getLayoutRes() = R.layout.activity_simple
|
override fun getLayoutRes() = R.layout.activity_simple
|
||||||
@ -46,6 +51,8 @@ class CreateRoomActivity : VectorBaseActivity(), ToolbarConfigurable {
|
|||||||
override fun initUiAndData() {
|
override fun initUiAndData() {
|
||||||
if (isFirstCreation()) {
|
if (isFirstCreation()) {
|
||||||
addFragment(CreateRoomFragment(), R.id.simpleFragmentContainer)
|
addFragment(CreateRoomFragment(), R.id.simpleFragmentContainer)
|
||||||
|
|
||||||
|
createRoomViewModel.setName(intent?.getStringExtra(INITIAL_NAME) ?: "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,8 +71,12 @@ class CreateRoomActivity : VectorBaseActivity(), ToolbarConfigurable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun getIntent(context: Context): Intent {
|
private const val INITIAL_NAME = "INITIAL_NAME"
|
||||||
return Intent(context, CreateRoomActivity::class.java)
|
|
||||||
|
fun getIntent(context: Context, initialName: String = ""): Intent {
|
||||||
|
return Intent(context, CreateRoomActivity::class.java).apply {
|
||||||
|
putExtra(INITIAL_NAME, initialName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ import android.view.MenuItem
|
|||||||
import androidx.lifecycle.ViewModelProviders
|
import androidx.lifecycle.ViewModelProviders
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.airbnb.mvrx.Success
|
import com.airbnb.mvrx.Success
|
||||||
import com.airbnb.mvrx.fragmentViewModel
|
import com.airbnb.mvrx.activityViewModel
|
||||||
import com.airbnb.mvrx.withState
|
import com.airbnb.mvrx.withState
|
||||||
import im.vector.riotx.R
|
import im.vector.riotx.R
|
||||||
import im.vector.riotx.core.di.ScreenComponent
|
import im.vector.riotx.core.di.ScreenComponent
|
||||||
@ -35,9 +35,8 @@ import javax.inject.Inject
|
|||||||
class CreateRoomFragment : VectorBaseFragment(), CreateRoomController.Listener {
|
class CreateRoomFragment : VectorBaseFragment(), CreateRoomController.Listener {
|
||||||
|
|
||||||
private lateinit var navigationViewModel: RoomDirectoryNavigationViewModel
|
private lateinit var navigationViewModel: RoomDirectoryNavigationViewModel
|
||||||
private val viewModel: CreateRoomViewModel by fragmentViewModel()
|
private val viewModel: CreateRoomViewModel by activityViewModel()
|
||||||
@Inject lateinit var createRoomController: CreateRoomController
|
@Inject lateinit var createRoomController: CreateRoomController
|
||||||
@Inject lateinit var createRoomViewModelFactory: CreateRoomViewModel.Factory
|
|
||||||
|
|
||||||
override fun getLayoutResId() = R.layout.fragment_create_room
|
override fun getLayoutResId() = R.layout.fragment_create_room
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package im.vector.riotx.features.roomdirectory.createroom
|
package im.vector.riotx.features.roomdirectory.createroom
|
||||||
|
|
||||||
|
import androidx.fragment.app.FragmentActivity
|
||||||
import com.airbnb.mvrx.*
|
import com.airbnb.mvrx.*
|
||||||
import com.squareup.inject.assisted.Assisted
|
import com.squareup.inject.assisted.Assisted
|
||||||
import com.squareup.inject.assisted.AssistedInject
|
import com.squareup.inject.assisted.AssistedInject
|
||||||
@ -25,6 +26,7 @@ import im.vector.matrix.android.api.session.room.model.RoomDirectoryVisibility
|
|||||||
import im.vector.matrix.android.api.session.room.model.create.CreateRoomParams
|
import im.vector.matrix.android.api.session.room.model.create.CreateRoomParams
|
||||||
import im.vector.matrix.android.api.session.room.model.create.CreateRoomPreset
|
import im.vector.matrix.android.api.session.room.model.create.CreateRoomPreset
|
||||||
import im.vector.riotx.core.platform.VectorViewModel
|
import im.vector.riotx.core.platform.VectorViewModel
|
||||||
|
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
|
||||||
@ -39,8 +41,13 @@ class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: Cr
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
override fun create(viewModelContext: ViewModelContext, state: CreateRoomViewState): CreateRoomViewModel? {
|
override fun create(viewModelContext: ViewModelContext, state: CreateRoomViewState): CreateRoomViewModel? {
|
||||||
val fragment: CreateRoomFragment = (viewModelContext as FragmentViewModelContext).fragment()
|
val activity: FragmentActivity = (viewModelContext as ActivityViewModelContext).activity()
|
||||||
return fragment.createRoomViewModelFactory.create(state)
|
|
||||||
|
return when (activity) {
|
||||||
|
is CreateRoomActivity -> activity.createRoomViewModelFactory.create(state)
|
||||||
|
is RoomDirectoryActivity -> activity.createRoomViewModelFactory.create(state)
|
||||||
|
else -> throw IllegalStateException("Wrong activity")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user