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

initDefaults broken #54

Closed
MFlisar opened this issue May 24, 2018 · 8 comments
Closed

initDefaults broken #54

MFlisar opened this issue May 24, 2018 · 8 comments
Labels

Comments

@MFlisar
Copy link

MFlisar commented May 24, 2018

In v2.2.0, initDefaults is generated, in v2.6.0 or v2.7.0 it is empty...

@dkunzler
Copy link
Owner

I will have a look!

@dkunzler dkunzler added the bug label May 24, 2018
@MFlisar
Copy link
Author

MFlisar commented May 24, 2018

Thanks. Just take your time, I don't need the new features in the project where I need the initDefaults... I can simply continue using v2.2.0 for now

@dkunzler
Copy link
Owner

Hi, I looked into it and guess it is a user error 😁
(And a lack of documentation from my side)

Initidefaults uses (at least in the newer versions, I can't remember the old ones) the getter and setter methods since the getters already contain the complete logic to generate the correct defaults.
If setter or getter is missing no default initialization is generated for this specific preference. I even can't decide how to init them, so it wouldn't make sense to generate them.

Can you check and confirm for your examples that this is the case for the different files you use?

@MFlisar
Copy link
Author

MFlisar commented May 25, 2018

In this very old app of mine I use it like following:

@SharedPreferences(name = Preferences.PREF_NAME, mode = SharedPreferenceMode.PRIVATE)
public interface Preferences extends SharedPreferenceActions
{
    String PREF_NAME = "APP_PREFERENCES";
    
    public static final String userKnowsNavigationDrawer = "userKnowsNavigationDrawer";
    @Default(ofBoolean = false)
    boolean userKnowsNavigationDrawer();
    boolean userKnowsNavigationDrawer(boolean userKnowsNavigationDrawer);
    
    public static final String language = "language";
    @Default(ofString = "0")
    String language();
    boolean language(String language);
}

Should work, shouldn't it?

@dkunzler
Copy link
Owner

Yeah, that's the bug I found after writing my comment 👍
If you had a commit setter (boolean return type) it also didn't work. This is fixed locally. I will also remove the need for a setter and use the normal SharedPreference object for writing, and then push a new version.

@MFlisar
Copy link
Author

MFlisar commented May 25, 2018

great, thanks a lot

@dkunzler
Copy link
Owner

I just pushed 2.7.1 to maven central. initDefaults should no show better results.

@MFlisar
Copy link
Author

MFlisar commented May 28, 2018

Great, works. Thank you

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

No branches or pull requests

2 participants