Update MxRx library from 0.7.0 to 1.0.1

This commit is contained in:
Benoit Marty 2019-05-22 16:36:31 +02:00
parent 99087019d2
commit 5da29e8063
4 changed files with 16 additions and 3 deletions

View File

@ -156,7 +156,7 @@ dependencies {

implementation("com.airbnb.android:epoxy:$epoxy_version")
kapt "com.airbnb.android:epoxy-processor:$epoxy_version"
implementation 'com.airbnb.android:mvrx:0.7.0'
implementation 'com.airbnb.android:mvrx:1.0.1'

// Work
implementation "android.arch.work:work-runtime-ktx:1.0.0"

View File

@ -27,6 +27,7 @@ import kotlinx.android.synthetic.main.view_state.view.*
class StateView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0)
: FrameLayout(context, attrs, defStyle) {

// TODO Use Async from MvRx?
sealed class State {
object Content : State()
object Loading : State()

View File

@ -100,6 +100,7 @@ abstract class VectorBaseFragment : BaseMvRxFragment(), OnBackPressed {

override fun invalidate() {
//no-ops by default
// TODO Remove default implementation?
}

protected fun setArguments(args: Parcelable? = null) {

View File

@ -19,21 +19,30 @@ import android.os.Bundle
import com.airbnb.mvrx.MvRxView
import com.airbnb.mvrx.MvRxViewModelStore
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import java.util.*

/**
* Add MvRx capabilities to bottomsheetdialog (like BaseMvRxFragment)
*/
abstract class BaseMvRxBottomSheetDialog() : BottomSheetDialogFragment(), MvRxView {
abstract class BaseMvRxBottomSheetDialog : BottomSheetDialogFragment(), MvRxView {

override val mvrxViewModelStore by lazy { MvRxViewModelStore(viewModelStore) }
private lateinit var mvrxPersistedViewId: String

final override val mvrxViewId: String by lazy { mvrxPersistedViewId }

override fun onCreate(savedInstanceState: Bundle?) {
mvrxViewModelStore.restoreViewModels(this, savedInstanceState)
mvrxPersistedViewId = savedInstanceState?.getString(PERSISTED_VIEW_ID_KEY)
?: this::class.java.simpleName + "_" + UUID.randomUUID().toString()

super.onCreate(savedInstanceState)
}

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
mvrxViewModelStore.saveViewModels(outState)
outState.putString(PERSISTED_VIEW_ID_KEY, mvrxViewId)
}

override fun onStart() {
@ -42,4 +51,6 @@ abstract class BaseMvRxBottomSheetDialog() : BottomSheetDialogFragment(), MvRxVi
// subscribe to a ViewModel.
postInvalidate()
}
}
}

private const val PERSISTED_VIEW_ID_KEY = "mvrx:bottomsheet_persisted_view_id"