Conductor: Using MVP

Created on 26 Apr 2016  Â·  13Comments  Â·  Source: bluelinelabs/Conductor

I am wanting to switch from Flow to Conductor, but I cannot seem to grasp my head around when to create my presenter in the controller. After looking at the source, I would imagine that creating the presenter in preAttach then attaching the view to the presenter and detaching the view in postDetach would be a good route to go, but I am struggling on actually doing that. Any help/advice would be greatly appreciated!

(If this isn't the right place for this, let me know and I'll remove it)

Most helpful comment

Here is the official Mosby plugin for conductor:
https://github.com/sockeqwe/mosby-conductor

All 13 comments

Attach presenter in onAttach and detach in onDetach. These are called from onAttachedToWindow and onDetachFromWindow respectively. So it will work the same as with Flow.

So I am using Mosby(probably should have stated that in the initial comment) and my presenter is shown below.

  class PostPresenter @Inject constructor(val nm: NetworkManager): MvpBasePresenter<PostView>() {

    ...        

    fun loadPosts(pullToRefresh: Boolean) {...}

    override fun attachView(view: PostView?) {
        super.attachView(view)
    }

    override fun detachView(retainInstance: Boolean) {
        super.detachView(retainInstance)
        if (!retainInstance) {
            subscription?.unsubscribe()
        }
    }
}

How would I go about making this usable within a controller? Or should I wait until @sockeqwe has added offical "support" to Mosby?

I don't know much about Mosby, but shouldn't you be interacting with the view via an interface? In that case, have the Controller implement the PostView interface and then you should be fine.

For Mosby you need to write your own MvpController that implements MvpDelegateCallback and has MvpControllerDelegate that does basic attaching/detaching thing. See how this done for Activity and Fragment in sources.

Official Mosby support is around the corner (works as described by Kirill
except the fact that it is a Confuctor lifecycle listener)... I can release
a snapshot today

Kirill Boyarshinov [email protected] schrieb am Mi., 27. Apr.
2016, 07:44:

For Mosby you need to write your own MvpController that implements
MvpDelegateCallback and has MvpControllerDelegate that does basic
attaching/detaching thing. See how this done for Activity and Fragment in
sources
https://github.com/sockeqwe/mosby/tree/master/mvp/src/main/java/com/hannesdorfmann/mosby/mvp/
.

—
You are receiving this because you were mentioned.

Reply to this email directly or view it on GitHub
https://github.com/bluelinelabs/Conductor/issues/35#issuecomment-214977282

Here is the official Mosby plugin for conductor:
https://github.com/sockeqwe/mosby-conductor

The Mosby + Conductor is best.

Shouldn't this issue be closed then?..

I agree, this should be closed. It's also trivial to implement this yourself.

class SomeController : Controller() {
  private val presenter = SomePresenter()

  override fun onCreateView(inflater: LayoutInflater, container: ViewGroup)
      = inflater.inflate(R.layout.something, container, false)

  override fun onAttach(view: View) {
    presenter.takeView(view as SomePresenter.View)
  }

  override fun onDetach(view: View) {
    presenter.dropView()
  }
}

class SomePresenter {
  fun takeView(view: View) {
    // Do whatever with view.
  }

  fun dropView() {
    // Clear whatever was using the view.
  }

  interface View {
    fun doSomething()
  }
}

Is mosby-conductor supported with Conductor 2.0? @sockeqwe doesn't respond to issues

Sorry, I have accidentally unwatched my own repository and didn't get notifications about Conductor 2.0 issues. Right now mosby-conductor doesn't work with Conductor 2.0 because of imho a bug in Conductor 2.0, see #85 and https://github.com/sockeqwe/mosby-conductor/issues/2

It sounds like people are pretty satisfied with Mosby's support and/or rolling their own solution, so I'll close this. Feel free to re-open if anything new emerges.

Another small MVP library - https://github.com/bangarharshit/ConductorMVP. You are encouraged to read the code (it is just 2 class) and modify it based on your need.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ZakTaccardi picture ZakTaccardi  Â·  8Comments

dmarcato picture dmarcato  Â·  4Comments

lenguyenthanh picture lenguyenthanh  Â·  5Comments

moezbhatti picture moezbhatti  Â·  7Comments

EricKuck picture EricKuck  Â·  5Comments