Mavericks 2: clean after PR review

This commit is contained in:
ganfra 2021-10-11 17:31:27 +02:00
parent bde129ddce
commit a26e43e90c
11 changed files with 30 additions and 20 deletions

1
changelog.d/3890.misc Normal file
View file

@ -0,0 +1 @@
Migrate to MvRx2 (Mavericks)

View file

@ -0,0 +1,11 @@
Useful links:
- https://airbnb.io/mavericks/#/new-2x
Mavericks 2 is replacing MvRx, by removing usage of Rx by Flow, both internally and in the API.
See the link ^ to have more intel, but basically, the changes are:
session.rx() => session.flow()
room.rx() => room.flow()
subscribe { }.disposeOnClear() => onEach { }.launchIn(viewModelScope)
Only using manually onEach requires to add launchIn,any other methods provided by Mavericks on viewModel and activity/fragment are already taking care of lifecycle.

View file

@ -22,8 +22,7 @@ import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.withContext
internal fun <T> Flow<T>.startWith(supplier: suspend () -> T): Flow<T> {
return this
.onStart {
return onStart {
val value = withContext(Dispatchers.IO) {
supplier()
}

View file

@ -42,7 +42,7 @@ import org.matrix.android.sdk.internal.crypto.model.CryptoDeviceInfo
import org.matrix.android.sdk.internal.crypto.model.rest.DeviceInfo
import org.matrix.android.sdk.internal.crypto.store.PrivateKeysInfo
class RxFlow(private val session: Session) {
class FlowSession(private val session: Session) {
fun liveRoomSummaries(queryParams: RoomSummaryQueryParams): Flow<List<RoomSummary>> {
return session.getRoomSummariesLive(queryParams).asFlow()
@ -175,6 +175,6 @@ class RxFlow(private val session: Session) {
}
}
fun Session.flow(): RxFlow {
return RxFlow(this)
fun Session.flow(): FlowSession {
return FlowSession(this)
}

View file

@ -40,7 +40,7 @@ import androidx.fragment.app.FragmentFactory
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.ViewModelProvider
import androidx.viewbinding.ViewBinding
import com.airbnb.mvrx.MvRxView
import com.airbnb.mvrx.MavericksView
import com.bumptech.glide.util.Util
import com.google.android.material.appbar.MaterialToolbar
import com.google.android.material.snackbar.Snackbar
@ -89,7 +89,7 @@ import timber.log.Timber
import java.util.concurrent.TimeUnit
import kotlin.system.measureTimeMillis
abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), HasScreenInjector, MvRxView {
abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), HasScreenInjector, MavericksView {
/* ==========================================================================================
* View
* ========================================================================================== */

View file

@ -30,7 +30,7 @@ import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.viewbinding.ViewBinding
import com.airbnb.mvrx.MvRxView
import com.airbnb.mvrx.MavericksView
import com.bumptech.glide.util.Util.assertMainThread
import com.google.android.material.appbar.MaterialToolbar
import com.google.android.material.dialog.MaterialAlertDialogBuilder
@ -50,7 +50,7 @@ import io.reactivex.disposables.Disposable
import timber.log.Timber
import java.util.concurrent.TimeUnit
abstract class VectorBaseFragment<VB : ViewBinding> : Fragment(), MvRxView, HasScreenInjector {
abstract class VectorBaseFragment<VB : ViewBinding> : Fragment(), MavericksView, HasScreenInjector {
protected val vectorBaseActivity: VectorBaseActivity<*> by lazy {
activity as VectorBaseActivity<*>

View file

@ -16,7 +16,6 @@
package im.vector.app.features.crypto.quads
import androidx.lifecycle.viewModelScope
import com.airbnb.mvrx.Async
import com.airbnb.mvrx.Fail
import com.airbnb.mvrx.Loading

View file

@ -161,7 +161,7 @@ class HomeDetailFragment @Inject constructor(
}
}
unknownDeviceDetectorSharedViewModel.subscribe { state ->
unknownDeviceDetectorSharedViewModel.onEach { state ->
state.unknownSessions.invoke()?.let { unknownDevices ->
// Timber.v("## Detector Triggerred in fragment - ${unknownDevices.firstOrNull()}")
if (unknownDevices.firstOrNull()?.currentSessionTrust == true) {
@ -179,7 +179,7 @@ class HomeDetailFragment @Inject constructor(
}
}
unreadMessagesSharedViewModel.subscribe { state ->
unreadMessagesSharedViewModel.onEach { state ->
views.drawerUnreadCounterBadgeView.render(
UnreadCounterBadgeView.State(
count = state.otherSpacesUnread.totalCount,

View file

@ -72,7 +72,7 @@ class AccountCreatedFragment @Inject constructor(
setupSubmitButton()
observeViewEvents()
viewModel.subscribe { invalidateState(it) }
viewModel.onEach { invalidateState(it) }
views.loginAccountCreatedTime.text = dateFormatter.format(System.currentTimeMillis(), DateFormatKind.MESSAGE_SIMPLE)
}

View file

@ -49,7 +49,7 @@ class ChoosePrivateSpaceTypeFragment @Inject constructor(
sharedViewModel.handle(CreateSpaceAction.SetSpaceTopology(SpaceTopology.MeAndTeammates))
}
sharedViewModel.subscribe { state ->
sharedViewModel.onEach { state ->
views.accessInfoHelpText.text = stringProvider.getString(R.string.create_spaces_make_sure_access, state.name ?: "")
}
}

View file

@ -81,7 +81,7 @@ class UserListFragment @Inject constructor(
setupRecyclerView()
setupSearchView()
homeServerCapabilitiesViewModel.subscribe {
homeServerCapabilitiesViewModel.onEach {
views.userListE2EbyDefaultDisabled.isVisible = !it.isE2EByDefault
}