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 MvpPreferenceActivity and MvpPreferenceFragment #206

Open
ProtopopovIgorAlidi opened this issue Jun 29, 2018 · 6 comments
Open

Add MvpPreferenceActivity and MvpPreferenceFragment #206

ProtopopovIgorAlidi opened this issue Jun 29, 2018 · 6 comments

Comments

@ProtopopovIgorAlidi
Copy link

ProtopopovIgorAlidi commented Jun 29, 2018

A lot of applications have preference screen. Google recommends to use PreferenceActivity and PreferenceFragment. Need support of Preference mechanics in Moxy.

@senneco
Copy link
Collaborator

senneco commented Jul 25, 2018

You able to create your own MvpPreferenceActivity =) Just make it same as MvpActivity, but extends from PreferenceActivity instead of just Activity.

Currently I don't see more same requests and I don't plane to do this.

@senneco senneco closed this as completed Jul 25, 2018
@ProtopopovIgorAlidi
Copy link
Author

Thank You, I create my own MvpPreferenceActivity.
But I couldn't make it complete MVP.
For example I have some ListPreference and set OnPreferenceChangeListener into it. It works well but without presenter. And if I open this preference and rotate screen before choose someting, dialog hides. Could be added someting to moxy library to support this? Or I can resolve task itself?

@senneco
Copy link
Collaborator

senneco commented Jul 26, 2018

I never used PreferenceActivity and ListReference before =) Could you explain your question?)

@senneco senneco reopened this Jul 26, 2018
@ProtopopovIgorAlidi
Copy link
Author

Yes.
To show preference screen I use
https://developer.android.com/reference/android/preference/PreferenceFragment

There is no setContentView(R.layout...), but have addPreferencesFromResource(R.xml...)

There defined preferences showed on the screen
<PreferenceScreen ...
<PreferenceCategory...
<Preference...
<ListPreference....

On click on ListPreference Android automatically show dialog with list of values. So I couldn't call some presenter function on this action. When screen rotates, activity recreates and dialog hides. I need some mechanics to override this classes (some moxy classes) and have able to call presenter function on show dialog window. To have able to re-show it on re-create activity, using some strategy.

@senneco
Copy link
Collaborator

senneco commented Jul 26, 2018

I think you can do something like this:

  1. Add listener ListPreference.onCreateDialogView() (by extends ListPreference)

  2. When this methods was called, send this action to Presenter

  3. From presenter send some command to the PrefView, like PrefView.showDialog()

  4. Implements this method in your PreferenceFragment like this:

public void showDialog() {
    if (presenter.isInRestoreState()) {
        listPreference.showDialog(...);
    }
}

Then listPreference.showDialog(...); will be called only after activity recreate.

  1. When dialog was closed, do similar work. And! PrefView.hideDialog() should be with SingleStateStrategy. Otherwise showDialog will be called after each activity recreation.

@ProtopopovIgorAlidi
Copy link
Author

ProtopopovIgorAlidi commented Aug 1, 2018

Thank You, catch the idea.
I am implementing this.
In addition, required to override onClick of listpreference to avoid automatic open list, and call presenter here.

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

2 participants