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

Add support for DialogFragment #14

Closed
fahimk opened this issue Apr 27, 2015 · 19 comments
Closed

Add support for DialogFragment #14

fahimk opened this issue Apr 27, 2015 · 19 comments
Milestone

Comments

@fahimk
Copy link
Contributor

fahimk commented Apr 27, 2015

It's almost exactly the same as regular Fragment, I'm not sure if there is an easy way to share the boilerplate code between them.

If anyone does try to add support for DialogFragments, this will keep the dialog on the screen for orientation changes.

    @Override
    public void onDestroyView() {
        if (getDialog() != null && getRetainInstance()) {
            getDialog().setDismissMessage(null);
        }
        ButterKnife.reset(this);
        super.onDestroyView();
    }```
@sockeqwe sockeqwe added this to the Backlog milestone Apr 27, 2015
@sockeqwe
Copy link
Owner

I will have a look at DialogFragment. I guess it's just a copy & paste from already existing MvpFragment implementation

@fahimk
Copy link
Contributor Author

fahimk commented Apr 27, 2015

Yes, that's what I've done in my current project.

@jenzz
Copy link
Contributor

jenzz commented Apr 27, 2015

I've been experimenting with this library a tiny bit this afternoon and was looking for a similiar PreferenceFragment implementation.

I think the best and most flexible solution for this is a delegate interface / abstraction similar to what we can find in the latest support library update. So I would expect this library to provide abstract MVP implementations for the most common base classes, but if I cannot find a particular implementation, I can still extend the support to any type of Activity, Fragment, etc that I'm looking for.

@sockeqwe
Copy link
Owner

Yep, actually, the ViewState implementation already works like that by using a delegate. Have a look at ViewStateManager and ViewStateSupport. Maybe I should rename ViewStateManager to something like ViewStateDelegate and rename methods to match activity / fragments lifecycle names to make it more clear how to use them.

@IgorGanapolsky
Copy link
Contributor

Yes, please rename to make them more clear with the design pattern.

Igor
On Apr 27, 2015 4:06 PM, "Hannes Dorfmann" [email protected] wrote:

Yep, actually, the ViewState implementation already works like that by
providing a delegate. Have a look at ViewStateManager and ViewStateSupport.
Maybe I should rename ViewStateManager to something like ViewStateDelegate
and rename methods to match activity / fragments lifecycle names to make it
more clear how to use them.


Reply to this email directly or view it on GitHub
#14 (comment).

@sockeqwe
Copy link
Owner

sockeqwe commented May 21, 2015

I have written a new blog post which describes how to use the delegate.
http://hannesdorfmann.com/android/mosby-playbook

See "Tip 22" (scroll down to the end of the page)

@siavashabdoli
Copy link

@sockeqwe your blog page show 404 error :D is there any example for dialogfragment in your project?

@sockeqwe
Copy link
Owner

sockeqwe commented Sep 5, 2016

@siavashabdoli I have updated the linke: http://hannesdorfmann.com/android/mosby-playbook
No there i no example project, but dialogfragments doesn't behave differently than any other fragment.

@siavashabdoli
Copy link

@sockeqwe Yes, I see but we can't extend your library class directly in this one. I have to implement MvpViewStateDelegateCallback and implement attaching detaching and all MVP logic, is it right?

@Thomas-Vos
Copy link
Contributor

@sockeqwe I read your blog post and understand how to use the delegate. However, your example code for a DialogFragment uses a custom view. Where should I call the delegate.onViewCreated(View, Bundle) method if I'm overriding onCreateDialog(Bundle) instead?

@liuzhen2008
Copy link

@sockeqwe I see that we use a MvpViewStateDelegateCallback in the document. Is this only available in mosby3?

@sockeqwe
Copy link
Owner

@SuperThomasLab
sorry, I have missed your comment / question, somehow I have accidentally muted this thread.
I think it works if you just use onCreateDialog(Bundle) for the dialog title etc. onCreateView(...) for your main custom view. I have never tried it.

@liuzhen2008 it might have been renamed in Mosby3 (or moved into another package, but it there is the same class also in Mosby 2 (and Mosby 1).

I have to update the docs #185

@liuzhen2008
Copy link

liuzhen2008 commented Jun 15, 2017

@sockeqwe Any idea what the name is in mosby2?

I see BaseMvpViewStateDelegateCallback and FragmentMvpDelegate. Where can I find the document to properly initialize a "ViewState"?

@sockeqwe
Copy link
Owner

I think it was MvpViewStateDelegateCallback (must be implemented by your Fragment or Activity) ActivityMvpViewStateDelegateImpl and FragmentMvpViewStateDelegateImpl where you have to forward (delegate) the lifecycle events to.

@mseroczynski
Copy link
Contributor

@sockeqwe Are you planning on adding base implementations for DialogFragment or should it be handled by developer by design?

@sockeqwe
Copy link
Owner

Not planned to add a DialogFragment base implementation for MVP, MVP ViewState and MVI (mainly because of time constraints) but if such a base implementation is that straight forward as it is with any other Fragment (just adding the corresponding delegate) then we can add it to this library.

Do you wanna send a pull request?

@mseroczynski
Copy link
Contributor

If I'll manage to implement it I'll surely make a PR, but currently (sadly) I just need a fast working solution for my specific MVP case for my work so please do not consider it 'incoming asap' :). Btw, big thanks(!) for your work with Mosby, awesome blog posts, The Context podcast and everything! 👍

@sockeqwe
Copy link
Owner

Thank you very much!

If you use traditional Fragment lifecycle callbacks and setup your Dialog's view in Fragment.onCreateView() I would expect that simply adding the delegate like I did here works.

@ltrojanowski
Copy link

I'm not sure if it is a good idea to even add this to mosby. It's yet another thing to maintain and I can't imagine how busy someone like @sockeqwe must be anyways. The suggested solution of adding the delegate worked with no problems. If anyone stumbles upon this and wants to copy paste an implementation for MVI check out this gist.

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

No branches or pull requests

9 participants