mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-01-27 09:31:20 +01:00
CreateRoomFragment: use argument instead of Activity ViewModel to pass the initial room name
This commit is contained in:
parent
af8b400bf4
commit
16b6678aa2
@ -26,18 +26,15 @@ import im.vector.app.core.di.ScreenComponent
|
||||
import im.vector.app.core.extensions.addFragment
|
||||
import im.vector.app.core.extensions.addFragmentToBackstack
|
||||
import im.vector.app.core.platform.VectorBaseActivity
|
||||
import im.vector.app.features.roomdirectory.createroom.CreateRoomAction
|
||||
import im.vector.app.features.roomdirectory.createroom.CreateRoomFragment
|
||||
import im.vector.app.features.roomdirectory.createroom.CreateRoomViewModel
|
||||
import im.vector.app.features.roomdirectory.createroom.CreateRoomArgs
|
||||
import im.vector.app.features.roomdirectory.picker.RoomDirectoryPickerFragment
|
||||
import javax.inject.Inject
|
||||
|
||||
class RoomDirectoryActivity : VectorBaseActivity() {
|
||||
|
||||
@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 sharedActionViewModel: RoomDirectorySharedActionViewModel
|
||||
|
||||
override fun getLayoutRes() = R.layout.activity_simple
|
||||
@ -60,10 +57,13 @@ class RoomDirectoryActivity : VectorBaseActivity() {
|
||||
when (sharedAction) {
|
||||
is RoomDirectorySharedAction.Back -> onBackPressed()
|
||||
is RoomDirectorySharedAction.CreateRoom -> {
|
||||
addFragmentToBackstack(R.id.simpleFragmentContainer, CreateRoomFragment::class.java)
|
||||
// Transmit the filter to the createRoomViewModel
|
||||
// Transmit the filter to the CreateRoomFragment
|
||||
withState(roomDirectoryViewModel) {
|
||||
createRoomViewModel.handle(CreateRoomAction.SetName(it.currentFilter))
|
||||
addFragmentToBackstack(
|
||||
R.id.simpleFragmentContainer,
|
||||
CreateRoomFragment::class.java,
|
||||
CreateRoomArgs(it.currentFilter)
|
||||
)
|
||||
}
|
||||
}
|
||||
is RoomDirectorySharedAction.ChangeProtocol ->
|
||||
|
@ -20,7 +20,6 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import com.airbnb.mvrx.viewModel
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.di.ScreenComponent
|
||||
import im.vector.app.core.extensions.addFragment
|
||||
@ -28,16 +27,12 @@ import im.vector.app.core.platform.ToolbarConfigurable
|
||||
import im.vector.app.core.platform.VectorBaseActivity
|
||||
import im.vector.app.features.roomdirectory.RoomDirectorySharedAction
|
||||
import im.vector.app.features.roomdirectory.RoomDirectorySharedActionViewModel
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Simple container for [CreateRoomFragment]
|
||||
*/
|
||||
class CreateRoomActivity : VectorBaseActivity(), ToolbarConfigurable {
|
||||
|
||||
@Inject lateinit var createRoomViewModelFactory: CreateRoomViewModel.Factory
|
||||
private val createRoomViewModel: CreateRoomViewModel by viewModel()
|
||||
|
||||
private lateinit var sharedActionViewModel: RoomDirectorySharedActionViewModel
|
||||
|
||||
override fun getLayoutRes() = R.layout.activity_simple
|
||||
@ -52,8 +47,11 @@ class CreateRoomActivity : VectorBaseActivity(), ToolbarConfigurable {
|
||||
|
||||
override fun initUiAndData() {
|
||||
if (isFirstCreation()) {
|
||||
addFragment(R.id.simpleFragmentContainer, CreateRoomFragment::class.java)
|
||||
createRoomViewModel.handle(CreateRoomAction.SetName(intent?.getStringExtra(INITIAL_NAME) ?: ""))
|
||||
addFragment(
|
||||
R.id.simpleFragmentContainer,
|
||||
CreateRoomFragment::class.java,
|
||||
CreateRoomArgs(intent?.getStringExtra(INITIAL_NAME) ?: "")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,10 +18,12 @@ package im.vector.app.features.roomdirectory.createroom
|
||||
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.Parcelable
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.airbnb.mvrx.Success
|
||||
import com.airbnb.mvrx.activityViewModel
|
||||
import com.airbnb.mvrx.args
|
||||
import com.airbnb.mvrx.fragmentViewModel
|
||||
import com.airbnb.mvrx.withState
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.dialogs.GalleryOrCameraDialogHelper
|
||||
@ -33,12 +35,19 @@ import im.vector.app.core.platform.VectorBaseFragment
|
||||
import im.vector.app.core.resources.ColorProvider
|
||||
import im.vector.app.features.roomdirectory.RoomDirectorySharedAction
|
||||
import im.vector.app.features.roomdirectory.RoomDirectorySharedActionViewModel
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
import kotlinx.android.synthetic.main.fragment_create_room.*
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
@Parcelize
|
||||
data class CreateRoomArgs(
|
||||
val initialName: String
|
||||
) : Parcelable
|
||||
|
||||
class CreateRoomFragment @Inject constructor(
|
||||
private val createRoomController: CreateRoomController,
|
||||
val createRoomViewModelFactory: CreateRoomViewModel.Factory,
|
||||
colorProvider: ColorProvider
|
||||
) : VectorBaseFragment(),
|
||||
CreateRoomController.Listener,
|
||||
@ -46,8 +55,8 @@ class CreateRoomFragment @Inject constructor(
|
||||
OnBackPressed {
|
||||
|
||||
private lateinit var sharedActionViewModel: RoomDirectorySharedActionViewModel
|
||||
// TODO BMA: use fragmentViewMode(). Else back does not reset the form. Use Fragment Argument to pass room name
|
||||
private val viewModel: CreateRoomViewModel by activityViewModel()
|
||||
private val viewModel: CreateRoomViewModel by fragmentViewModel()
|
||||
private val args: CreateRoomArgs by args()
|
||||
|
||||
private val galleryOrCameraDialogHelper = GalleryOrCameraDialogHelper(this, colorProvider)
|
||||
|
||||
|
@ -17,10 +17,9 @@
|
||||
package im.vector.app.features.roomdirectory.createroom
|
||||
|
||||
import androidx.core.net.toFile
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.airbnb.mvrx.ActivityViewModelContext
|
||||
import com.airbnb.mvrx.Fail
|
||||
import com.airbnb.mvrx.FragmentViewModelContext
|
||||
import com.airbnb.mvrx.Loading
|
||||
import com.airbnb.mvrx.MvRxViewModelFactory
|
||||
import com.airbnb.mvrx.Success
|
||||
@ -31,7 +30,6 @@ import im.vector.app.core.extensions.exhaustive
|
||||
import im.vector.app.core.platform.VectorViewModel
|
||||
import im.vector.app.features.raw.wellknown.getElementWellknown
|
||||
import im.vector.app.features.raw.wellknown.isE2EByDefault
|
||||
import im.vector.app.features.roomdirectory.RoomDirectoryActivity
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import org.matrix.android.sdk.api.MatrixCallback
|
||||
@ -88,13 +86,9 @@ class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: Cr
|
||||
|
||||
@JvmStatic
|
||||
override fun create(viewModelContext: ViewModelContext, state: CreateRoomViewState): CreateRoomViewModel? {
|
||||
val activity: FragmentActivity = (viewModelContext as ActivityViewModelContext).activity()
|
||||
val fragment: CreateRoomFragment = (viewModelContext as FragmentViewModelContext).fragment()
|
||||
|
||||
return when (activity) {
|
||||
is CreateRoomActivity -> activity.createRoomViewModelFactory.create(state)
|
||||
is RoomDirectoryActivity -> activity.createRoomViewModelFactory.create(state)
|
||||
else -> error("Wrong activity")
|
||||
}
|
||||
return fragment.createRoomViewModelFactory.create(state)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,10 @@ data class CreateRoomViewState(
|
||||
val asyncCreateRoomRequest: Async<String> = Uninitialized
|
||||
) : MvRxState {
|
||||
|
||||
constructor(args: CreateRoomArgs) : this(
|
||||
roomName = args.initialName
|
||||
)
|
||||
|
||||
/**
|
||||
* Return true if there is not important input from user
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user