mikepenz/Android-Iconics

Need help with migration

mehmetgunacti opened this issue · 11 comments

About this issue

I have code from around 2017 (pre-Kotlin) that I want to migrate using the latest version of Android-Iconics.

This instantiated an IconicsDrawable object:

                new IconicsDrawable(
                        context,
                        GoogleMaterial.Icon.gmd_keyboard_arrow_right
                )
                .sizeDp(size)
                .paddingDp(padding)
                .color(colorWidgetTitle)
                .toBitmap()

This is what I have so far:


        IconicsSize dp = IconicsSizeDp.dp(size); // size = int
        IconicsColor color = IconicsColor.colorInt(color); // color = int

        new IconicsDrawable(
                        context,
                        GoogleMaterial.Icon.gmd_keyboard_arrow_right.getCharacter()
        ).toBitmap();

How can I add padding, IconicsSize, and IconicsColor to IconicsDrawable?

The migration guide says "IconcisDrawable now depends on the resources and theme, and tries to eliminate dependency on the Context". Since I'm still using context in the constructor, what would be the proper way of instantiating an IconicsDrawable?

Checklist

@msegmx the new version is mainly targeted for kotlin users, it looks like you are trying to use it from a java project still though.

All those functions to set the above values are extension functions and won't be available from java.

Ah ok, it seems they have to be called via static methods in Java. Will give it try or simply go back to a previous version. Thanks!

@mehmetgunacti Did you find a solution to call this from Java? I am now in the same situation.

@chrisonline I didn't look for an alternative, the old (Java) version is still good enough for my app.

@msegmx the new version is mainly targeted for kotlin users, it looks like you are trying to use it from a java project still though.

All those functions to set the above values are extension functions and won't be available from java.

@mikepenz Does this mean I can't use the newest version with Java anymore?

The newest version is only created for (and tested with) Kotlin.

Very sad, but thanks for the info.

Depending on your usecase, you probably could achieve a thing Kotlin based wrapper class which does the respective API adjustments to allow Java classes to use it.

I need only to set the icon size, padding and color. So the extension functions.
You mean I write a Kotlin wrapper class, so I can call this Kotlin wrapper from Java?

Indeed. A Kotlin class which is able to access the respective functions of the library, but created so it's compatible with Java.

One note on this. the IconicsDrawable has functions which should be available from Java:

https://github.com/mikepenz/Android-Iconics/blob/develop/iconics-core/src/main/java/com/mikepenz/iconics/IconicsDrawable.kt#L200 -> setSizeXPx
https://github.com/mikepenz/Android-Iconics/blob/develop/iconics-core/src/main/java/com/mikepenz/iconics/IconicsDrawable.kt#L249 -> setPaddingPx
https://github.com/mikepenz/Android-Iconics/blob/develop/iconics-core/src/main/java/com/mikepenz/iconics/IconicsDrawable.kt#L66 -> setColorList

(the extension functions in Kotlin also call these in the end)

Thank you very much for your input and help.
So I will try to use the "set methods". I have thought that this set methods are not available anymore because of the Kotlin functions.
Great, this would fit my needs.