Home android moxy. Android. MVP. Implementation in BasePresenter

moxy. Android. MVP. Implementation in BasePresenter




disassembled how the Moxy is arranged. And a certain problem arose. Any presenter is inherited from BasePresenter (also with View, there is also a BaseView). In the example, MainPresenter is inherited from BasePresenter, so it’s impossible to inherit from MVPPResentter (there is already one Super Type). The option remains with BasePresenter, but there it gives an error (the error is presented below). An error is also error and with view. How to better go in this case. Get rid of BasePresenter and BaseView? But it will have to copy the code every time (not everything was inserted into these classes, inserted only what he considered it necessary). Yes, and in the MainActivity there is @injectPresenter, but not in it.

class MainActivity: BaseActive & LT; MainPresenter & gt; (), mainview {
Override Fun OnCreate (SavedInstanceState: Bundle?) {
  super.oncreate (SavedInstanceState)
  SetContentView (R.Layout.Activity_Main)
  If (SavedInstanceState == NULL) {
    presenter.pushfragments (
      EntranceApp (),
Override Fun InstantiatePresenter (): MainPresenter {
  Return MainPresenter (MainView = This)


Abstract Class BaseActivity & lt; presenter & gt; : BaseView, MVPappCompatactivity () {
   Protected Val Presenter: Presenter by Lazy {InstantiatePresenter ()}
   Override Fun GetContext (): Activity = This}


class MainPresenter (mainview: mainview): basepresenter & lt; mainview & gt; (mainview) {}


@ injectViewState
ABSTRACT Class BasePresenter & LT; V: BaseView & GT; (Protected Val View: V): MVPPResentter & LT; V & GT; () {
Private Val Injector: PresenterInjector = Daggerpresenterinjector
  .builder ()
  .BaseView (View)
  .contextModule (ContextModule)
  .NetworkModule (NetworkModule)
  .databaseModule (view.getContext (View.GetContext ()))
  .build ()
init {
  Inject ()
Private Fun Inject () {

mainview.kt and baseview.kt

Interface BaseView: MVPVIEW {
  Fun GetContext (): Context
Interface MainView: BaseView

BasePresenter error

Moxy Compiling Failed; See The Compiler Error Output for Details (Java.lang.illegAlargumentException: View "" for com.viground.ui.Base.BasePresenter Cannot Be Found)

Answer 1, Authority 100%

Annotation @injectViewState allows you to generate for your presenter-A object ViewState . MVPPResentter Creates an instance of this ViewState , and puts it as a field and will use it everywhere. You will simply stay to work with the Public View GetViewState () from MVPPResentter .

From this it follows that it is possible to apply annotation only to specific classes PRESENTER-A . In your own case, you are trying to apply it to an abstract class.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions