From 6463f3439f90c234047ff3536b5c2d864a6221fb Mon Sep 17 00:00:00 2001 From: ganfra Date: Tue, 12 Nov 2019 15:11:52 +0100 Subject: [PATCH] Update Mvrx to 1.3 --- vector/build.gradle | 2 +- .../riotx/core/platform/VectorBaseActivity.kt | 4 ++-- .../VectorBaseBottomSheetDialogFragment.kt | 18 +++++------------- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/vector/build.gradle b/vector/build.gradle index d0a757d4e0..e425d53a62 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -268,7 +268,7 @@ dependencies { implementation("com.airbnb.android:epoxy:$epoxy_version") kapt "com.airbnb.android:epoxy-processor:$epoxy_version" implementation "com.airbnb.android:epoxy-paging:$epoxy_version" - implementation 'com.airbnb.android:mvrx:1.1.0' + implementation 'com.airbnb.android:mvrx:1.3.0' // Work implementation "androidx.work:work-runtime-ktx:2.3.0-alpha01" diff --git a/vector/src/main/java/im/vector/riotx/core/platform/VectorBaseActivity.kt b/vector/src/main/java/im/vector/riotx/core/platform/VectorBaseActivity.kt index f0f6eea91d..4a3056657f 100644 --- a/vector/src/main/java/im/vector/riotx/core/platform/VectorBaseActivity.kt +++ b/vector/src/main/java/im/vector/riotx/core/platform/VectorBaseActivity.kt @@ -24,6 +24,7 @@ import android.view.Menu import android.view.MenuItem import android.view.View import androidx.annotation.* +import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.Toolbar import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.core.view.isVisible @@ -34,7 +35,6 @@ import androidx.lifecycle.ViewModelProviders import butterknife.BindView import butterknife.ButterKnife import butterknife.Unbinder -import com.airbnb.mvrx.BaseMvRxActivity import com.airbnb.mvrx.MvRx import com.bumptech.glide.util.Util import com.google.android.material.snackbar.Snackbar @@ -59,7 +59,7 @@ import io.reactivex.disposables.Disposable import timber.log.Timber import kotlin.system.measureTimeMillis -abstract class VectorBaseActivity : BaseMvRxActivity(), HasScreenInjector { +abstract class VectorBaseActivity : AppCompatActivity(), HasScreenInjector { /* ========================================================================================== * UI * ========================================================================================== */ diff --git a/vector/src/main/java/im/vector/riotx/core/platform/VectorBaseBottomSheetDialogFragment.kt b/vector/src/main/java/im/vector/riotx/core/platform/VectorBaseBottomSheetDialogFragment.kt index 2c8f840a41..5727580653 100644 --- a/vector/src/main/java/im/vector/riotx/core/platform/VectorBaseBottomSheetDialogFragment.kt +++ b/vector/src/main/java/im/vector/riotx/core/platform/VectorBaseBottomSheetDialogFragment.kt @@ -25,24 +25,22 @@ import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProviders import com.airbnb.mvrx.MvRx import com.airbnb.mvrx.MvRxView -import com.airbnb.mvrx.MvRxViewModelStore +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 import im.vector.riotx.core.di.DaggerScreenComponent import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.utils.DimensionConverter -import java.util.* /** * Add MvRx capabilities to bottomsheetdialog (like BaseMvRxFragment) */ abstract class VectorBaseBottomSheetDialogFragment : BottomSheetDialogFragment(), MvRxView { - override val mvrxViewModelStore by lazy { MvRxViewModelStore(viewModelStore) } - private lateinit var mvrxPersistedViewId: String + private val mvrxViewIdProperty = MvRxViewId() + final override val mvrxViewId: String by mvrxViewIdProperty private lateinit var screenComponent: ScreenComponent - final override val mvrxViewId: String by lazy { mvrxPersistedViewId } /* ========================================================================================== * View model @@ -78,10 +76,7 @@ abstract class VectorBaseBottomSheetDialogFragment : BottomSheetDialogFragment() protected open fun injectWith(screenComponent: ScreenComponent) = Unit override fun onCreate(savedInstanceState: Bundle?) { - mvrxViewModelStore.restoreViewModels(this, savedInstanceState) - mvrxPersistedViewId = savedInstanceState?.getString(PERSISTED_VIEW_ID_KEY) - ?: this::class.java.simpleName + "_" + UUID.randomUUID().toString() - + mvrxViewIdProperty.restoreFrom(savedInstanceState) super.onCreate(savedInstanceState) } @@ -98,8 +93,7 @@ abstract class VectorBaseBottomSheetDialogFragment : BottomSheetDialogFragment() override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mvrxViewModelStore.saveViewModels(outState) - outState.putString(PERSISTED_VIEW_ID_KEY, mvrxViewId) + mvrxViewIdProperty.saveTo(outState) } override fun onStart() { @@ -121,5 +115,3 @@ abstract class VectorBaseBottomSheetDialogFragment : BottomSheetDialogFragment() arguments = args?.let { Bundle().apply { putParcelable(MvRx.KEY_ARG, it) } } } } - -private const val PERSISTED_VIEW_ID_KEY = "mvrx:bottomsheet_persisted_view_id"