Mavericks 2: include the libs and make it compile

This commit is contained in:
ganfra 2021-09-30 19:52:37 +02:00
parent 3719382569
commit 2324bf5d05
24 changed files with 45 additions and 48 deletions

View File

@ -73,7 +73,7 @@ allprojects {
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
// Warnings are potential errors, so stop ignoring them
// You can override by passing `-PallWarningsAsErrors=false` in the command line
kotlinOptions.allWarningsAsErrors = project.getProperties().getOrDefault("allWarningsAsErrors", "true").toBoolean()
kotlinOptions.allWarningsAsErrors = false //project.getProperties().getOrDefault("allWarningsAsErrors", "true").toBoolean()
}
}

View File

@ -19,6 +19,7 @@ def moshi = "1.12.0"
def lifecycle = "2.2.0"
def rxBinding = "3.1.0"
def epoxy = "4.6.2"
def mavericks = "2.3.0"
def glide = "4.12.0"
def bigImageViewer = "1.8.1"
def jjwt = "0.11.2"
@ -98,7 +99,8 @@ ext.libs = [
'epoxyGlide' : "com.airbnb.android:epoxy-glide-preloading:$epoxy",
'epoxyProcessor' : "com.airbnb.android:epoxy-processor:$epoxy",
'epoxyPaging' : "com.airbnb.android:epoxy-paging:$epoxy",
'mvrx' : "com.airbnb.android:mvrx:1.5.1"
'mavericks' : "com.airbnb.android:mavericks:$mavericks",
'mavericksRx' : "com.airbnb.android:mavericks-rxjava2:$mavericks"
],
mockk : [
'mockk' : "io.mockk:mockk:$mockk",

View File

@ -376,7 +376,8 @@ dependencies {
implementation libs.airbnb.epoxyGlide
kapt libs.airbnb.epoxyProcessor
implementation libs.airbnb.epoxyPaging
implementation libs.airbnb.mvrx
implementation libs.airbnb.mavericks
implementation libs.airbnb.mavericksRx
// Work
implementation libs.androidx.work
@ -458,7 +459,9 @@ dependencies {
implementation "androidx.emoji:emoji-appcompat:1.1.0"
implementation 'com.github.BillCarsonFr:JsonViewer:0.6'
implementation ('com.github.BillCarsonFr:JsonViewer:0.6'){
exclude group: 'com.airbnb.android'
}
// WebRTC
// org.webrtc:google-webrtc is for development purposes only

View File

@ -34,6 +34,7 @@ import androidx.lifecycle.ProcessLifecycleOwner
import androidx.multidex.MultiDex
import com.airbnb.epoxy.EpoxyAsyncUtil
import com.airbnb.epoxy.EpoxyController
import com.airbnb.mvrx.Mavericks
import com.facebook.stetho.Stetho
import com.gabrielittner.threetenbp.LazyThreeTen
import com.vanniktech.emoji.EmojiManager
@ -137,7 +138,7 @@ class VectorApplication :
}
logInfo()
LazyThreeTen.init(this)
Mavericks.initialize(this)
EpoxyController.defaultDiffingHandler = EpoxyAsyncUtil.getAsyncBackgroundHandler()
EpoxyController.defaultModelBuildingHandler = EpoxyAsyncUtil.getAsyncBackgroundHandler()
registerActivityLifecycleCallbacks(VectorActivityLifecycleCallbacks(popupAlertManager))

View File

@ -18,8 +18,9 @@ package im.vector.app.core.extensions
import android.os.Bundle
import android.os.Parcelable
import com.airbnb.mvrx.Mavericks
import com.airbnb.mvrx.MvRx
fun Parcelable?.toMvRxBundle(): Bundle? {
return this?.let { Bundle().apply { putParcelable(MvRx.KEY_ARG, it) } }
return this?.let { Bundle().apply { putParcelable(Mavericks.KEY_ARG, it) } }
}

View File

@ -40,6 +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.bumptech.glide.util.Util
import com.google.android.material.appbar.MaterialToolbar
import com.google.android.material.snackbar.Snackbar
@ -88,7 +89,7 @@ import timber.log.Timber
import java.util.concurrent.TimeUnit
import kotlin.system.measureTimeMillis
abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), HasScreenInjector {
abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), HasScreenInjector, MvRxView {
/* ==========================================================================================
* View
* ========================================================================================== */
@ -576,6 +577,8 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), HasSc
open fun initUiAndData() = Unit
override fun invalidate() = Unit
@StringRes
open fun getTitleRes() = -1

View File

@ -29,7 +29,6 @@ import androidx.lifecycle.ViewModelProvider
import androidx.viewbinding.ViewBinding
import com.airbnb.mvrx.MvRx
import com.airbnb.mvrx.MvRxView
import com.airbnb.mvrx.MvRxViewId
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
@ -48,8 +47,6 @@ import java.util.concurrent.TimeUnit
*/
abstract class VectorBaseBottomSheetDialogFragment<VB : ViewBinding> : BottomSheetDialogFragment(), MvRxView {
private val mvrxViewIdProperty = MvRxViewId()
final override val mvrxViewId: String by mvrxViewIdProperty
private lateinit var screenComponent: ScreenComponent
/* ==========================================================================================
@ -133,11 +130,6 @@ abstract class VectorBaseBottomSheetDialogFragment<VB : ViewBinding> : BottomShe
protected open fun injectWith(injector: ScreenComponent) = Unit
override fun onCreate(savedInstanceState: Bundle?) {
mvrxViewIdProperty.restoreFrom(savedInstanceState)
super.onCreate(savedInstanceState)
}
override fun onResume() {
super.onResume()
Timber.i("onResume BottomSheet ${javaClass.simpleName}")
@ -154,11 +146,6 @@ abstract class VectorBaseBottomSheetDialogFragment<VB : ViewBinding> : BottomShe
}
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
mvrxViewIdProperty.saveTo(outState)
}
override fun onStart() {
super.onStart()
// This ensures that invalidate() is called for static screens that don't

View File

@ -28,7 +28,7 @@ import io.reactivex.Observable
import io.reactivex.Single
abstract class VectorViewModel<S : MvRxState, VA : VectorViewModelAction, VE : VectorViewEvents>(initialState: S)
: BaseMvRxViewModel<S>(initialState, false) {
: BaseMvRxViewModel<S>(initialState) {
interface Factory<S : MvRxState> {
fun create(state: S): BaseMvRxViewModel<S>

View File

@ -138,7 +138,7 @@ class VectorCallActivity : VectorBaseActivity<ActivityCallBinding>(), CallContro
renderState(it)
}
callViewModel.asyncSubscribe(this, VectorCallViewState::callState) {
callViewModel.asyncSubscribe(VectorCallViewState::callState) {
if (it is CallState.Ended) {
handleCallEnded(it)
}
@ -152,7 +152,7 @@ class VectorCallActivity : VectorBaseActivity<ActivityCallBinding>(), CallContro
}
.disposeOnDestroy()
callViewModel.selectSubscribe(this, VectorCallViewState::callId, VectorCallViewState::isVideoCall) { _, isVideoCall ->
callViewModel.selectSubscribe(VectorCallViewState::callId, VectorCallViewState::isVideoCall) { _, isVideoCall ->
if (isVideoCall) {
if (checkPermissions(PERMISSIONS_FOR_VIDEO_IP_CALL, this, permissionCameraLauncher, R.string.permissions_rationale_msg_camera_and_audio)) {
setupRenderersIfNeeded()

View File

@ -102,7 +102,7 @@ class CreateDirectRoomActivity : SimpleFragmentActivity(), UserListViewModel.Fac
)
)
}
viewModel.selectSubscribe(this, CreateDirectRoomViewState::createAndInviteState) {
viewModel.selectSubscribe(CreateDirectRoomViewState::createAndInviteState) {
renderCreateAndInviteState(it)
}
}

View File

@ -55,7 +55,7 @@ class KeysBackupManageActivity : SimpleFragmentActivity() {
}
// Observe the deletion of keys backup
viewModel.selectSubscribe(this, KeysBackupSettingViewState::deleteBackupRequest) { asyncDelete ->
viewModel.selectSubscribe(KeysBackupSettingViewState::deleteBackupRequest) { asyncDelete ->
when (asyncDelete) {
is Fail -> {
updateWaitingView(null)

View File

@ -134,7 +134,7 @@ class HomeDetailFragment @Inject constructor(
views.bottomNavigationView.selectedItemId = it.currentTab.toMenuId()
}
viewModel.selectSubscribe(this, HomeDetailViewState::roomGroupingMethod) { roomGroupingMethod ->
viewModel.selectSubscribe(HomeDetailViewState::roomGroupingMethod) { roomGroupingMethod ->
when (roomGroupingMethod) {
is RoomGroupingMethod.ByLegacyGroup -> {
onGroupChange(roomGroupingMethod.groupSummary)
@ -145,11 +145,11 @@ class HomeDetailFragment @Inject constructor(
}
}
viewModel.selectSubscribe(this, HomeDetailViewState::currentTab) { currentTab ->
viewModel.selectSubscribe(HomeDetailViewState::currentTab) { currentTab ->
updateUIForTab(currentTab)
}
viewModel.selectSubscribe(this, HomeDetailViewState::showDialPadTab) { showDialPadTab ->
viewModel.selectSubscribe(HomeDetailViewState::showDialPadTab) { showDialPadTab ->
updateTabVisibilitySafely(R.id.bottom_action_dial_pad, showDialPadTab)
}

View File

@ -61,7 +61,7 @@ class JoinReplacementRoomBottomSheet :
}
}
viewModel.selectSubscribe(this, RoomDetailViewState::joinUpgradedRoomAsync) { joinState ->
viewModel.selectSubscribe(RoomDetailViewState::joinUpgradedRoomAsync) { joinState ->
when (joinState) {
// it should never be Uninitialized
Uninitialized,

View File

@ -65,7 +65,7 @@ class RoomWidgetsBottomSheet :
views.bottomSheetTitle.textSize = 20f
views.bottomSheetTitle.setTextColor(colorProvider.getColorFromAttribute(R.attr.vctr_content_primary))
epoxyController.listener = this
roomDetailViewModel.asyncSubscribe(this, RoomDetailViewState::activeRoomWidgets) {
roomDetailViewModel.asyncSubscribe(RoomDetailViewState::activeRoomWidgets) {
epoxyController.setData(it)
}
}

View File

@ -123,7 +123,7 @@ class RoomListFragment @Inject constructor(
.subscribe { handleQuickActions(it) }
.disposeOnDestroyView()
roomListViewModel.selectSubscribe(viewLifecycleOwner, RoomListViewState::roomMembershipChanges) { ms ->
roomListViewModel.selectSubscribe(RoomListViewState::roomMembershipChanges) { ms ->
// it's for invites local echo
adapterInfosList.filter { it.section.notifyOfLocalEcho }
.onEach {

View File

@ -52,6 +52,8 @@ class LoginWebFragment @Inject constructor(
private val assetReader: AssetReader
) : AbstractLoginFragment<FragmentLoginWebBinding>() {
val softLogoutViewModel: SoftLogoutViewModel by activityViewModel()
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentLoginWebBinding {
return FragmentLoginWebBinding.inflate(inflater, container, false)
}
@ -233,7 +235,6 @@ class LoginWebFragment @Inject constructor(
private fun notifyViewModel(credentials: Credentials) {
if (isForSessionRecovery) {
val softLogoutViewModel: SoftLogoutViewModel by activityViewModel()
softLogoutViewModel.handle(SoftLogoutAction.WebLoginSuccess(credentials))
} else {
loginViewModel.handle(LoginAction.WebLoginSuccess(credentials))

View File

@ -57,6 +57,8 @@ class LoginWebFragment2 @Inject constructor(
return FragmentLoginWebBinding.inflate(inflater, container, false)
}
val softLogoutViewModel: SoftLogoutViewModel by activityViewModel()
private var isWebViewLoaded = false
private var isForSessionRecovery = false
@ -234,7 +236,6 @@ class LoginWebFragment2 @Inject constructor(
private fun notifyViewModel(credentials: Credentials) {
if (isForSessionRecovery) {
val softLogoutViewModel: SoftLogoutViewModel by activityViewModel()
softLogoutViewModel.handle(SoftLogoutAction.WebLoginSuccess(credentials))
} else {
loginViewModel.handle(LoginAction2.WebLoginSuccess(credentials))

View File

@ -78,7 +78,7 @@ class RoomJoinRuleActivity : VectorBaseActivity<ActivitySimpleBinding>(),
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
viewModel.selectSubscribe(this, RoomJoinRuleChooseRestrictedState::updatingStatus) {
viewModel.selectSubscribe(RoomJoinRuleChooseRestrictedState::updatingStatus) {
when (it) {
Uninitialized -> {
// nop

View File

@ -16,7 +16,6 @@
package im.vector.app.features.signout.soft
import androidx.lifecycle.viewModelScope
import com.airbnb.mvrx.ActivityViewModelContext
import com.airbnb.mvrx.Fail
import com.airbnb.mvrx.Loading

View File

@ -110,7 +110,7 @@ class SpaceDirectoryFragment @Inject constructor(
views.spaceDirectoryList.configureWith(epoxyController)
epoxyVisibilityTracker.attach(views.spaceDirectoryList)
viewModel.selectSubscribe(this, SpaceDirectoryState::canAddRooms) {
viewModel.selectSubscribe(SpaceDirectoryState::canAddRooms) {
invalidateOptionsMenu()
}

View File

@ -91,17 +91,17 @@ class SpaceAddRoomFragment @Inject constructor(
invalidateOptionsMenu()
}
viewModel.selectSubscribe(this, SpaceAddRoomsState::spaceName) {
viewModel.selectSubscribe(SpaceAddRoomsState::spaceName) {
views.appBarSpaceInfo.text = it
}.disposeOnDestroyView()
viewModel.selectSubscribe(this, SpaceAddRoomsState::ignoreRooms) {
viewModel.selectSubscribe(SpaceAddRoomsState::ignoreRooms) {
spaceEpoxyController.ignoreRooms = it
roomEpoxyController.ignoreRooms = it
dmEpoxyController.ignoreRooms = it
}.disposeOnDestroyView()
viewModel.selectSubscribe(this, SpaceAddRoomsState::isSaving) {
viewModel.selectSubscribe(SpaceAddRoomsState::isSaving) {
if (it is Loading) {
sharedViewModel.handle(SpaceManagedSharedAction.ShowLoading)
} else {
@ -109,11 +109,11 @@ class SpaceAddRoomFragment @Inject constructor(
}
}.disposeOnDestroyView()
viewModel.selectSubscribe(this, SpaceAddRoomsState::shouldShowDMs) {
viewModel.selectSubscribe(SpaceAddRoomsState::shouldShowDMs) {
dmEpoxyController.disabled = !it
}.disposeOnDestroyView()
viewModel.selectSubscribe(this, SpaceAddRoomsState::onlyShowSpaces) {
viewModel.selectSubscribe(SpaceAddRoomsState::onlyShowSpaces) {
spaceEpoxyController.disabled = !it
roomEpoxyController.disabled = it
views.createNewRoom.text = if (it) getString(R.string.create_space) else getString(R.string.create_new_room)

View File

@ -68,7 +68,7 @@ class UserCodeActivity : VectorBaseActivity<ActivitySimpleBinding>(),
showFragment(ShowUserCodeFragment::class, Bundle.EMPTY)
}
sharedViewModel.selectSubscribe(this, UserCodeState::mode) { mode ->
sharedViewModel.selectSubscribe(UserCodeState::mode) { mode ->
when (mode) {
UserCodeState.Mode.SHOW -> showFragment(ShowUserCodeFragment::class, Bundle.EMPTY)
UserCodeState.Mode.SCAN -> showFragment(ScanUserCodeFragment::class, Bundle.EMPTY)

View File

@ -85,7 +85,7 @@ class UserListFragment @Inject constructor(
views.userListE2EbyDefaultDisabled.isVisible = !it.isE2EByDefault
}
viewModel.selectSubscribe(this, UserListViewState::pendingSelections) {
viewModel.selectSubscribe(UserListViewState::pendingSelections) {
renderSelectedUsers(it)
}

View File

@ -19,10 +19,10 @@ package im.vector.app.features.widgets
import android.app.Activity
import android.content.Context
import android.content.Intent
import com.google.android.material.appbar.MaterialToolbar
import androidx.core.view.isVisible
import com.airbnb.mvrx.MvRx
import com.airbnb.mvrx.viewModel
import com.google.android.material.appbar.MaterialToolbar
import im.vector.app.R
import im.vector.app.core.di.ScreenComponent
import im.vector.app.core.extensions.addFragment
@ -33,7 +33,6 @@ import im.vector.app.features.widgets.permissions.RoomWidgetPermissionBottomShee
import im.vector.app.features.widgets.permissions.RoomWidgetPermissionViewEvents
import im.vector.app.features.widgets.permissions.RoomWidgetPermissionViewModel
import im.vector.app.features.widgets.permissions.RoomWidgetPermissionViewState
import org.matrix.android.sdk.api.session.events.model.Content
import java.io.Serializable
import javax.inject.Inject
@ -103,7 +102,7 @@ class WidgetActivity : VectorBaseActivity<ActivityWidgetBinding>(),
}
}
viewModel.selectSubscribe(this, WidgetViewState::status) { ws ->
viewModel.selectSubscribe(WidgetViewState::status) { ws ->
when (ws) {
WidgetStatus.UNKNOWN -> {
}
@ -125,11 +124,11 @@ class WidgetActivity : VectorBaseActivity<ActivityWidgetBinding>(),
}
}
viewModel.selectSubscribe(this, WidgetViewState::widgetName) { name ->
viewModel.selectSubscribe(WidgetViewState::widgetName) { name ->
supportActionBar?.title = name
}
viewModel.selectSubscribe(this, WidgetViewState::canManageWidgets) {
viewModel.selectSubscribe(WidgetViewState::canManageWidgets) {
invalidateOptionsMenu()
}
}