Update Mvrx to 1.3

This commit is contained in:
ganfra 2019-11-12 15:11:52 +01:00
parent b6199b1f27
commit 6463f3439f
3 changed files with 8 additions and 16 deletions

View File

@ -268,7 +268,7 @@ dependencies {
implementation("com.airbnb.android:epoxy:$epoxy_version") implementation("com.airbnb.android:epoxy:$epoxy_version")
kapt "com.airbnb.android:epoxy-processor:$epoxy_version" kapt "com.airbnb.android:epoxy-processor:$epoxy_version"
implementation "com.airbnb.android:epoxy-paging:$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 // Work
implementation "androidx.work:work-runtime-ktx:2.3.0-alpha01" implementation "androidx.work:work-runtime-ktx:2.3.0-alpha01"

View File

@ -24,6 +24,7 @@ import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import androidx.annotation.* import androidx.annotation.*
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.view.isVisible import androidx.core.view.isVisible
@ -34,7 +35,6 @@ import androidx.lifecycle.ViewModelProviders
import butterknife.BindView import butterknife.BindView
import butterknife.ButterKnife import butterknife.ButterKnife
import butterknife.Unbinder import butterknife.Unbinder
import com.airbnb.mvrx.BaseMvRxActivity
import com.airbnb.mvrx.MvRx import com.airbnb.mvrx.MvRx
import com.bumptech.glide.util.Util import com.bumptech.glide.util.Util
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
@ -59,7 +59,7 @@ import io.reactivex.disposables.Disposable
import timber.log.Timber import timber.log.Timber
import kotlin.system.measureTimeMillis import kotlin.system.measureTimeMillis
abstract class VectorBaseActivity : BaseMvRxActivity(), HasScreenInjector { abstract class VectorBaseActivity : AppCompatActivity(), HasScreenInjector {
/* ========================================================================================== /* ==========================================================================================
* UI * UI
* ========================================================================================== */ * ========================================================================================== */

View File

@ -25,24 +25,22 @@ import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelProviders import androidx.lifecycle.ViewModelProviders
import com.airbnb.mvrx.MvRx import com.airbnb.mvrx.MvRx
import com.airbnb.mvrx.MvRxView 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.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import im.vector.riotx.core.di.DaggerScreenComponent import im.vector.riotx.core.di.DaggerScreenComponent
import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.di.ScreenComponent
import im.vector.riotx.core.utils.DimensionConverter import im.vector.riotx.core.utils.DimensionConverter
import java.util.*
/** /**
* Add MvRx capabilities to bottomsheetdialog (like BaseMvRxFragment) * Add MvRx capabilities to bottomsheetdialog (like BaseMvRxFragment)
*/ */
abstract class VectorBaseBottomSheetDialogFragment : BottomSheetDialogFragment(), MvRxView { abstract class VectorBaseBottomSheetDialogFragment : BottomSheetDialogFragment(), MvRxView {
override val mvrxViewModelStore by lazy { MvRxViewModelStore(viewModelStore) } private val mvrxViewIdProperty = MvRxViewId()
private lateinit var mvrxPersistedViewId: String final override val mvrxViewId: String by mvrxViewIdProperty
private lateinit var screenComponent: ScreenComponent private lateinit var screenComponent: ScreenComponent
final override val mvrxViewId: String by lazy { mvrxPersistedViewId }
/* ========================================================================================== /* ==========================================================================================
* View model * View model
@ -78,10 +76,7 @@ abstract class VectorBaseBottomSheetDialogFragment : BottomSheetDialogFragment()
protected open fun injectWith(screenComponent: ScreenComponent) = Unit protected open fun injectWith(screenComponent: ScreenComponent) = Unit
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
mvrxViewModelStore.restoreViewModels(this, savedInstanceState) mvrxViewIdProperty.restoreFrom(savedInstanceState)
mvrxPersistedViewId = savedInstanceState?.getString(PERSISTED_VIEW_ID_KEY)
?: this::class.java.simpleName + "_" + UUID.randomUUID().toString()
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
} }
@ -98,8 +93,7 @@ abstract class VectorBaseBottomSheetDialogFragment : BottomSheetDialogFragment()
override fun onSaveInstanceState(outState: Bundle) { override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState) super.onSaveInstanceState(outState)
mvrxViewModelStore.saveViewModels(outState) mvrxViewIdProperty.saveTo(outState)
outState.putString(PERSISTED_VIEW_ID_KEY, mvrxViewId)
} }
override fun onStart() { override fun onStart() {
@ -121,5 +115,3 @@ abstract class VectorBaseBottomSheetDialogFragment : BottomSheetDialogFragment()
arguments = args?.let { Bundle().apply { putParcelable(MvRx.KEY_ARG, it) } } arguments = args?.let { Bundle().apply { putParcelable(MvRx.KEY_ARG, it) } }
} }
} }
private const val PERSISTED_VIEW_ID_KEY = "mvrx:bottomsheet_persisted_view_id"