Skip to content

Commit 9352d8a

Browse files
committed
Add parameter PresenterType to providePresenter
1 parent f346caa commit 9352d8a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

moxy/compiler/src/main/java/com/omegar/mvp/compiler/processors/ViewStateGenerator.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.omegar.mvp.compiler.entities.View.Method.Type.Function
1111
import com.omegar.mvp.compiler.entities.View.Method.Type.Property
1212
import com.omegar.mvp.compiler.extensions.safeParameterizedBy
1313
import com.omegar.mvp.compiler.extensions.toFileSpecBuilder
14+
import com.omegar.mvp.presenter.PresenterType
1415
import com.omegar.mvp.viewstate.MvpViewState
1516
import com.omegar.mvp.viewstate.ViewCommand
1617
import com.omegar.mvp.viewstate.strategy.AddToEndSingleStrategy
@@ -285,11 +286,15 @@ class ViewStateGenerator : Processor<View, FileSpec> {
285286
return FunSpec.builder("provide${ if (generalName) "Presenter" else presenterType.simpleName}")
286287
.receiver(receiver)
287288
.addTypeVariables(typeParams)
289+
.addParameter(ParameterSpec.builder("presenterType", PresenterType::class)
290+
.defaultValue("%T.%L", PresenterType::class.asTypeName(), PresenterType.LOCAL)
291+
.build()
292+
)
288293
.addParameter("factoryBlock", lambda)
289294
.returns(presenterFactoryTypeName)
290295
.addCode(viewStateClassName.simpleName + ".Companion\n")
291296
.addStatement("@Suppress(\"UNCHECKED_CAST\")")
292-
.addCode("return %T(%T::class as %T<%T>, factoryBlock).also { mvpDelegate.addCustomPresenterFields(it) }", presenterFactoryTypeName, presenterType, KClass::class.asClassName(), parameterizedPresenterType)
297+
.addCode("return %T(%T::class as %T<%T>, presenterType, factoryBlock).also { mvpDelegate.addCustomPresenterFields(it) }", presenterFactoryTypeName, presenterType, KClass::class.asClassName(), parameterizedPresenterType)
293298
.build()
294299
}
295300

moxy/src/main/java/com/omegar/mvp/CustomPresenterFactory.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import kotlin.reflect.KProperty
99
* Created by Anton Knyazev on 25.11.2020.
1010
*/
1111

12-
class CustomPresenterFactory<P : MvpPresenter<*>, D>(presenterClass: KClass<P>, private val factoryBlock: () -> P) :
13-
PresenterField<D, P>(PresenterType.LOCAL, presenterClass) {
12+
class CustomPresenterFactory<P : MvpPresenter<*>, D>(presenterClass: KClass<P>, presenterType: PresenterType = PresenterType.LOCAL, private val factoryBlock: () -> P) :
13+
PresenterField<D, P>(presenterType, presenterClass) {
1414

1515
private var presenter: P? = null
1616

0 commit comments

Comments
 (0)