mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-26 03:16:02 +03:00
Ganfra's review: use simple ViewModel
This commit is contained in:
parent
c0be04f46c
commit
b48c920292
6 changed files with 19 additions and 17 deletions
|
@ -18,14 +18,10 @@ package im.vector.riotredesign.core.mvrx
|
|||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.airbnb.mvrx.MvRxState
|
||||
import im.vector.riotredesign.core.platform.VectorViewModel
|
||||
import androidx.lifecycle.ViewModel
|
||||
import im.vector.riotredesign.core.utils.LiveEvent
|
||||
|
||||
// MvRx require a state with at least one attribute
|
||||
data class NavigationState(val dummy: Boolean = false) : MvRxState
|
||||
|
||||
abstract class NavigationViewModel<NavigationClass>(initialState: NavigationState) : VectorViewModel<NavigationState>(initialState) {
|
||||
abstract class NavigationViewModel<NavigationClass> : ViewModel() {
|
||||
|
||||
private val _navigateTo = MutableLiveData<LiveEvent<NavigationClass>>()
|
||||
val navigateTo: LiveData<LiveEvent<NavigationClass>>
|
||||
|
|
|
@ -20,6 +20,7 @@ import android.os.Bundle
|
|||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.airbnb.epoxy.EpoxyVisibilityTracker
|
||||
import com.airbnb.mvrx.activityViewModel
|
||||
|
@ -29,9 +30,7 @@ import com.jakewharton.rxbinding2.widget.RxTextView
|
|||
import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoom
|
||||
import im.vector.riotredesign.R
|
||||
import im.vector.riotredesign.core.error.ErrorFormatter
|
||||
import im.vector.riotredesign.core.extensions.addFragmentToBackstack
|
||||
import im.vector.riotredesign.core.platform.VectorBaseFragment
|
||||
import im.vector.riotredesign.features.roomdirectory.picker.RoomDirectoryPickerFragment
|
||||
import im.vector.riotredesign.features.themes.ThemeUtils
|
||||
import io.reactivex.rxkotlin.subscribeBy
|
||||
import kotlinx.android.synthetic.main.fragment_public_rooms.*
|
||||
|
@ -49,7 +48,7 @@ import java.util.concurrent.TimeUnit
|
|||
class PublicRoomsFragment : VectorBaseFragment(), PublicRoomsController.Callback {
|
||||
|
||||
private val viewModel: RoomDirectoryViewModel by activityViewModel()
|
||||
private val navigationViewModel: RoomDirectoryNavigationViewModel by activityViewModel()
|
||||
private lateinit var navigationViewModel: RoomDirectoryNavigationViewModel
|
||||
private val publicRoomsController: PublicRoomsController by inject()
|
||||
private val errorFormatter: ErrorFormatter by inject()
|
||||
|
||||
|
@ -103,6 +102,8 @@ class PublicRoomsFragment : VectorBaseFragment(), PublicRoomsController.Callback
|
|||
super.onActivityCreated(savedInstanceState)
|
||||
bindScope(getOrCreateScope(RoomDirectoryModule.ROOM_DIRECTORY_SCOPE))
|
||||
|
||||
navigationViewModel = ViewModelProviders.of(requireActivity()).get(RoomDirectoryNavigationViewModel::class.java)
|
||||
|
||||
setupRecyclerView()
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package im.vector.riotredesign.features.roomdirectory
|
||||
|
||||
import android.os.Bundle
|
||||
import com.airbnb.mvrx.viewModel
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
import im.vector.riotredesign.R
|
||||
import im.vector.riotredesign.core.extensions.addFragment
|
||||
import im.vector.riotredesign.core.extensions.addFragmentToBackstack
|
||||
|
@ -39,7 +39,7 @@ class RoomDirectoryActivity : VectorBaseActivity() {
|
|||
}
|
||||
|
||||
|
||||
private val navigationViewModel: RoomDirectoryNavigationViewModel by viewModel()
|
||||
private lateinit var navigationViewModel: RoomDirectoryNavigationViewModel
|
||||
|
||||
override fun getLayoutRes() = R.layout.activity_simple
|
||||
|
||||
|
@ -48,6 +48,8 @@ class RoomDirectoryActivity : VectorBaseActivity() {
|
|||
|
||||
bindScope(getOrCreateScope(RoomDirectoryModule.ROOM_DIRECTORY_SCOPE))
|
||||
|
||||
navigationViewModel = ViewModelProviders.of(this).get(RoomDirectoryNavigationViewModel::class.java)
|
||||
|
||||
navigationViewModel.navigateTo.observeEvent(this) { navigation ->
|
||||
when (navigation) {
|
||||
is Navigation.Back -> onBackPressed()
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
|
||||
package im.vector.riotredesign.features.roomdirectory
|
||||
|
||||
import im.vector.riotredesign.core.mvrx.NavigationState
|
||||
import im.vector.riotredesign.core.mvrx.NavigationViewModel
|
||||
|
||||
class RoomDirectoryNavigationViewModel(initialState: NavigationState)
|
||||
: NavigationViewModel<RoomDirectoryActivity.Navigation>(initialState)
|
||||
class RoomDirectoryNavigationViewModel : NavigationViewModel<RoomDirectoryActivity.Navigation>()
|
|
@ -18,9 +18,9 @@ package im.vector.riotredesign.features.roomdirectory.createroom
|
|||
|
||||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.airbnb.mvrx.Success
|
||||
import com.airbnb.mvrx.activityViewModel
|
||||
import com.airbnb.mvrx.fragmentViewModel
|
||||
import com.airbnb.mvrx.withState
|
||||
import im.vector.riotredesign.R
|
||||
|
@ -36,7 +36,7 @@ import timber.log.Timber
|
|||
|
||||
class CreateRoomFragment : VectorBaseFragment(), CreateRoomController.Listener {
|
||||
|
||||
private val navigationViewModel: RoomDirectoryNavigationViewModel by activityViewModel()
|
||||
private lateinit var navigationViewModel: RoomDirectoryNavigationViewModel
|
||||
private val viewModel: CreateRoomViewModel by fragmentViewModel()
|
||||
private val createRoomController: CreateRoomController by inject()
|
||||
|
||||
|
@ -50,6 +50,8 @@ class CreateRoomFragment : VectorBaseFragment(), CreateRoomController.Listener {
|
|||
|
||||
vectorBaseActivity.setSupportActionBar(createRoomToolbar)
|
||||
|
||||
navigationViewModel = ViewModelProviders.of(requireActivity()).get(RoomDirectoryNavigationViewModel::class.java)
|
||||
|
||||
setupRecyclerView()
|
||||
|
||||
createRoomClose.setOnClickListener {
|
||||
|
|
|
@ -19,6 +19,7 @@ package im.vector.riotredesign.features.roomdirectory.picker
|
|||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.airbnb.mvrx.activityViewModel
|
||||
import com.airbnb.mvrx.fragmentViewModel
|
||||
|
@ -41,7 +42,7 @@ import timber.log.Timber
|
|||
class RoomDirectoryPickerFragment : VectorBaseFragment(), RoomDirectoryPickerController.Callback {
|
||||
|
||||
private val viewModel: RoomDirectoryViewModel by activityViewModel()
|
||||
private val navigationViewModel: RoomDirectoryNavigationViewModel by activityViewModel()
|
||||
private lateinit var navigationViewModel: RoomDirectoryNavigationViewModel
|
||||
private val pickerViewModel: RoomDirectoryPickerViewModel by fragmentViewModel()
|
||||
private val roomDirectoryPickerController: RoomDirectoryPickerController by inject()
|
||||
|
||||
|
@ -74,6 +75,8 @@ class RoomDirectoryPickerFragment : VectorBaseFragment(), RoomDirectoryPickerCon
|
|||
super.onActivityCreated(savedInstanceState)
|
||||
bindScope(getOrCreateScope(RoomDirectoryModule.ROOM_DIRECTORY_SCOPE))
|
||||
|
||||
navigationViewModel = ViewModelProviders.of(requireActivity()).get(RoomDirectoryNavigationViewModel::class.java)
|
||||
|
||||
setupRecyclerView()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue