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

Weird problem when creating a drawable with kotlin #27

Closed
wspl opened this issue May 17, 2016 · 2 comments
Closed

Weird problem when creating a drawable with kotlin #27

wspl opened this issue May 17, 2016 · 2 comments

Comments

@wspl
Copy link

wspl commented May 17, 2016

When I was trying to create a drawable icon in a kotlin project:
image

val test1 = MaterialDrawableBuilder.with(applicationContext)
        .setIcon(MaterialDrawableBuilder.IconValue.WEATHER_RAINY)
        .setColor(Color.WHITE)

val test2 = test1.build()

Then Android Studio show a error:
Type net.steamcrafted.materialiconlib.MaterialDrawableBuilder.MaterialDrawable! is inaccessible in this context due to: net.steamcrafted.materialiconlib.MaterialDrawableBuilder.MaterialDrawable!

I was only import net.steamcrafted.materialiconlib.MaterialDrawableBuilder

Is this a bug or my mistake?
Hope someone can solve this problem, very thanks!

@wspl
Copy link
Author

wspl commented May 17, 2016

I has found out a temporary solution to solve this problem.

Firstly, create a util class with Java:

package moe.impl.v2exnext.utils;

import android.graphics.drawable.Drawable;
import net.steamcrafted.materialiconlib.MaterialDrawableBuilder;

public class MaterialDrawableBuilderFix {
    public static Drawable build(MaterialDrawableBuilder materialDrawableBuilder){
        return materialDrawableBuilder.build();
    }
}

Then create a drawable with kotlin:

val icon = MaterialDrawableBuilderFix.build(MaterialDrawableBuilder
                .with(applicationContext)
                .setIcon(MaterialDrawableBuilder.IconValue.WEATHER_RAINY)
                .setColor(Color.WHITE))

This seems like a bug of kotlin.

@wspl wspl closed this as completed May 17, 2016
@code-mc
Copy link
Owner

code-mc commented May 17, 2016

You also need to chain the build method, you can't save the intermediate builder, the intermediate representation class was made private to prevent anyone from doing that.

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