Skip to content

Commit

Permalink
Upgrade to mavericks
Browse files Browse the repository at this point in the history
  • Loading branch information
BillCarsonFr committed Oct 21, 2021
1 parent fc197ce commit a8fa35d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ dependencies {
implementation("com.airbnb.android:epoxy:$epoxy_version")
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
kapt "com.airbnb.android:epoxy-processor:$epoxy_version"
implementation 'com.airbnb.android:mvrx:1.5.1'
implementation 'com.airbnb.android:mavericks:2.4.0'
// ============

testImplementation 'junit:junit:4.13.2'
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.billcarsonfr.jsonviewerexample

import android.app.Application
import com.airbnb.mvrx.Mavericks

class MyApplication : Application() {

override fun onCreate() {
super.onCreate()
Mavericks.initialize(false)
}

}
2 changes: 1 addition & 1 deletion jsonviewer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dependencies {
// Epoxy dependency
implementation "com.airbnb.android:epoxy:$epoxy_version"
kapt "com.airbnb.android:epoxy-processor:$epoxy_version"
implementation 'com.airbnb.android:mvrx:1.5.1'
implementation 'com.airbnb.android:mavericks:2.4.0'
// Span utils
implementation 'me.gujun.android:span:1.7'
implementation 'com.google.android.material:material:1.4.0-alpha01'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import androidx.fragment.app.DialogFragment
import com.airbnb.mvrx.MvRx
import com.airbnb.mvrx.Mavericks


class JSonViewerDialog : DialogFragment() {
Expand All @@ -22,7 +22,7 @@ class JSonViewerDialog : DialogFragment() {

override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
val args: JSonViewerFragmentArgs = arguments?.getParcelable(MvRx.KEY_ARG) ?: return
val args: JSonViewerFragmentArgs = arguments?.getParcelable(Mavericks.KEY_ARG) ?: return
if (savedInstanceState == null) {
childFragmentManager.beginTransaction()
.replace(
Expand Down Expand Up @@ -56,7 +56,7 @@ class JSonViewerDialog : DialogFragment() {
val args = Bundle()
val parcelableArgs =
JSonViewerFragmentArgs(jsonString, initialOpenDepth, false, styleProvider)
args.putParcelable(MvRx.KEY_ARG, parcelableArgs)
args.putParcelable(Mavericks.KEY_ARG, parcelableArgs)
return JSonViewerDialog().apply { arguments = args }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import android.os.Parcelable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.airbnb.epoxy.EpoxyRecyclerView
import com.airbnb.mvrx.BaseMvRxFragment
import com.airbnb.mvrx.MvRx
import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import com.airbnb.mvrx.*
import kotlinx.parcelize.Parcelize

@Parcelize
Expand All @@ -22,9 +20,9 @@ data class JSonViewerFragmentArgs(
) : Parcelable


class JSonViewerFragment : BaseMvRxFragment() {
class JSonViewerFragment : Fragment(), MavericksView {

private val viewModel: JSonViewerViewModel by fragmentViewModel(JSonViewerViewModel::class)
private val viewModel: JSonViewerViewModel by fragmentViewModel()

private val epoxyController by lazy {
JSonViewerEpoxyController(requireContext())
Expand All @@ -37,7 +35,7 @@ class JSonViewerFragment : BaseMvRxFragment() {
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val args: JSonViewerFragmentArgs? = arguments?.getParcelable(MvRx.KEY_ARG)
val args: JSonViewerFragmentArgs? = arguments?.getParcelable(Mavericks.KEY_ARG)
val inflate =
if (args?.wrap == true) {
inflater.inflate(R.layout.fragment_jv_recycler_view_wrap, container, false)
Expand Down Expand Up @@ -71,7 +69,7 @@ class JSonViewerFragment : BaseMvRxFragment() {
return JSonViewerFragment().apply {
arguments = Bundle().apply {
putParcelable(
MvRx.KEY_ARG,
Mavericks.KEY_ARG,
JSonViewerFragmentArgs(
jsonString,
initialOpenDepth,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import kotlinx.coroutines.launch

data class JSonViewerState(
val root: Async<JSonViewerObject> = Uninitialized
) : MvRxState
) : MavericksState

class JSonViewerViewModel(initialState: JSonViewerState) :
BaseMvRxViewModel<JSonViewerState>(initialState, false) {
MavericksViewModel<JSonViewerState>(initialState) {


fun setJsonSource(json: String, initialOpenDepth: Int) {
Expand All @@ -36,7 +36,7 @@ class JSonViewerViewModel(initialState: JSonViewerState) :
}
}

companion object : MvRxViewModelFactory<JSonViewerViewModel, JSonViewerState> {
companion object : MavericksViewModelFactory<JSonViewerViewModel, JSonViewerState> {

@JvmStatic
override fun initialState(viewModelContext: ViewModelContext): JSonViewerState? {
Expand Down

0 comments on commit a8fa35d

Please sign in to comment.