2020-04-29 15:38:01 +03:00
|
|
|
package ${escapeKotlinIdentifiers(packageName)}
|
|
|
|
|
2020-04-29 18:58:54 +03:00
|
|
|
import com.airbnb.mvrx.ActivityViewModelContext
|
2020-04-29 15:38:01 +03:00
|
|
|
import com.airbnb.mvrx.FragmentViewModelContext
|
2021-10-01 18:11:53 +03:00
|
|
|
import com.airbnb.mvrx.MavericksViewModelFactory
|
2020-04-29 15:38:01 +03:00
|
|
|
import com.airbnb.mvrx.ViewModelContext
|
2021-01-15 16:40:26 +03:00
|
|
|
import dagger.assisted.Assisted
|
|
|
|
import dagger.assisted.AssistedInject
|
|
|
|
import dagger.assisted.AssistedFactory
|
2020-08-03 19:31:41 +03:00
|
|
|
import im.vector.app.core.platform.VectorViewModel
|
2020-04-29 15:38:01 +03:00
|
|
|
|
|
|
|
<#if createViewEvents>
|
|
|
|
<#else>
|
2020-08-03 19:31:41 +03:00
|
|
|
import im.vector.app.core.platform.EmptyViewEvents
|
2020-04-29 15:38:01 +03:00
|
|
|
</#if>
|
|
|
|
|
|
|
|
class ${viewModelClass} @AssistedInject constructor(@Assisted initialState: ${viewStateClass})
|
|
|
|
<#if createViewEvents>
|
|
|
|
: VectorViewModel<${viewStateClass}, ${actionClass}, ${viewEventsClass}>(initialState) {
|
|
|
|
<#else>
|
|
|
|
: VectorViewModel<${viewStateClass}, ${actionClass}, EmptyViewEvents>(initialState) {
|
|
|
|
</#if>
|
2020-04-29 18:58:54 +03:00
|
|
|
|
2021-01-15 16:40:26 +03:00
|
|
|
@AssistedFactory
|
2020-04-29 15:38:01 +03:00
|
|
|
interface Factory {
|
|
|
|
fun create(initialState: ${viewStateClass}): ${viewModelClass}
|
|
|
|
}
|
|
|
|
|
2021-10-01 18:11:53 +03:00
|
|
|
companion object : MavericksViewModelFactory<${viewModelClass}, ${viewStateClass}> {
|
2020-04-29 15:38:01 +03:00
|
|
|
|
|
|
|
@JvmStatic
|
|
|
|
override fun create(viewModelContext: ViewModelContext, state: ${viewStateClass}): ${viewModelClass}? {
|
2020-04-29 18:58:54 +03:00
|
|
|
val factory = when (viewModelContext) {
|
|
|
|
is FragmentViewModelContext -> viewModelContext.fragment as? Factory
|
|
|
|
is ActivityViewModelContext -> viewModelContext.activity as? Factory
|
|
|
|
}
|
|
|
|
return factory?.create(state) ?: error("You should let your activity/fragment implements Factory interface")
|
2020-04-29 15:38:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun handle(action: ${actionClass}) {
|
2020-05-14 02:31:15 +03:00
|
|
|
when (action) {
|
2020-04-29 15:38:01 +03:00
|
|
|
|
2022-03-22 17:56:06 +03:00
|
|
|
}
|
2020-05-14 02:31:15 +03:00
|
|
|
}
|
2020-04-29 15:38:01 +03:00
|
|
|
}
|