Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using MVP #35

Closed
jkochcode opened this issue Apr 26, 2016 · 13 comments
Closed

Using MVP #35

jkochcode opened this issue Apr 26, 2016 · 13 comments

Comments

@jkochcode
Copy link

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)

@kboyarshinov
Copy link

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.

@jkochcode
Copy link
Author

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?

@burntcookie90
Copy link
Contributor

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.

@kboyarshinov
Copy link

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.

@sockeqwe
Copy link
Contributor

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 notifications@github.com 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
#35 (comment)

@sockeqwe
Copy link
Contributor

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

@leon8zhang
Copy link

The Mosby + Conductor is best.

@dimsuz
Copy link
Contributor

dimsuz commented Jul 2, 2016

Shouldn't this issue be closed then?..

@chris-horner
Copy link
Contributor

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()
  }
}

@sdrygalski
Copy link

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

@sockeqwe
Copy link
Contributor

sockeqwe commented Jul 6, 2016

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 sockeqwe/mosby-conductor#2

@EricKuck
Copy link
Member

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.

@bangarharshit
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants