AppIntro / AppIntro

Make a cool intro for your Android app.
Apache License 2.0
10.52k stars 1.77k forks source link

Did you forget about old good Java? #936

Closed Massi-X closed 3 years ago

Massi-X commented 3 years ago

AppIntro Version: 6.1.0

Device/Android Version: Not related

Issue details / Repro steps / Use case background: Try to set any Kotlin variable like isSkipButtonEnabled, isWizardMode... Java doesn't know about this!

I have created a small helper function to set this variables, but obviously it doesn't work for all functions (without other tweaks) and it really doesn't need to because this is something that need to be backed inside the lib itself.

Am I doing something wrong? Totally possible I don't know a lot about Kotlin.

Here is the code to access fields via reflection:

try {
    Field a = AppIntroBase.class.getDeclaredField("isSkipButtonEnabled");
    a.setAccessible(true);
    a.set(this, false);
    Method c = AppIntroBase.class.getDeclaredMethod("updateButtonsVisibility");
    c.setAccessible(true);
    c.invoke(this);
} catch (NoSuchFieldException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
    e.printStackTrace();
}
Massi-X commented 3 years ago

Also unrelated but in the wiki Slide transformers is all about Kotlin, you should add an explanation that on Java you need to call for example setTransformer(AppIntroPageTransformerType.Fade.INSTANCE);. I think this is valid also for the other sections

cortinico commented 3 years ago

Did you forget about old good Java?

Not really. There is a Java example specifically for Java users: JavaIntro inside the sample app:

https://github.com/AppIntro/AppIntro/blob/85350b289644c3d4bb2dfbf884044e83d5ad6103/example/src/main/java/com/github/appintro/example/ui/java/JavaIntro.java#L41-L42

you should add an explanation that on Java you need to call for example setTransformer(AppIntroPageTransformerType.Fade.INSTANCE);. I think this is valid also for the other sections

The JavaIntro class serves exactly for this. If you wish, you can update the JavaIntro class with more examples :) I'll be more than happy to review.

Here is the code to access fields via reflection:

You should not do that. You can just call:

setSkipButtonEnabled(true);

from Java.

Hope I was helpful. feel free to reopen if you have more questions.

Massi-X commented 3 years ago

Wow I totally missed that! I saw the JavaIntro class before but setSkipButtonEnabled and all the others methods weren't there so I created the issue sorry!

I will make a PR to update this class and the readme so no one will fall again into this issues. Thank you

Massi-X commented 3 years ago

Pull here !