maxkeppeler / sheets

⭐ ‎‎‎‏‏‎ ‎Offers a range of beautiful sheets (dialogs & bottom sheets) for quick use in your project. Includes many ways to customize sheets.
https://maxkeppeler.github.io/sheets/
Apache License 2.0
921 stars 77 forks source link

Make Lottie animation setup code more Java friendly #81

Closed GraxCode closed 3 years ago

GraxCode commented 3 years ago
                new InfoSheet().show(context, null, infoSheet -> {
                  infoSheet.title(R.string.send_item);
                  infoSheet.content(R.string.connect_bluetooth);
                  LottieAnimationView coverAnimationView = new LottieAnimationView(context);
                  coverAnimationView.setAnimation(R.raw.bluetooth);
                  infoSheet.setCoverAnimationView(coverAnimationView);
                  infoSheet.onPositive(() -> {
                    return null;
                  });
                  return null;
                });

This does not seem to work. infoSheet.withCoverLottieAnimation does not seem to exist for me.

GraxCode commented 3 years ago

I found a very ugly way to do it.

     new InfoSheet().show(context, null, infoSheet -> {
                  infoSheet.title(R.string.send_item);
                  infoSheet.content(R.string.connect_bluetooth);
                  com.maxkeppeler.sheets.lottie.LottieAnimationExtKt.withCoverLottieAnimation(infoSheet, new LottieAnimation(lottieAnimation -> {
                    lottieAnimation.setupAnimation(lottieAnimationRequest -> {
                      lottieAnimationRequest.setAnimation(R.raw.bluetooth);
                      return null;
                    });
                    return null;
                  }));
                  return null;
                });

There should be a better solution for java users.

ghost commented 3 years ago

().show(context, null, infoSheet -> { infoSheet.title(R.string.send_item); infoSheet.content(R.string.connect_bluetooth); com.maxkeppeler.sheets.Maxe.MaxeAnimationExtKt.withCoverMaxeAnimation(infoSheet, new MaxeAnimation(MaxeAnimation -> { MaxeAnimation.setupAnimation(MaxeAnimationRequest -> { MaxeAnimationRequest.setAnimation(R.raw.bluetooth); return 0.01 }); return 0.01 })); return 0.01 });

maxkeppeler commented 3 years ago

That's very ugly. Any tips on how to improve it for Java? Since it was meant to be for Kotlin, I never thought of using it in Java and therefore also never thought about the usage looks there.

GraxCode commented 3 years ago

Don't really know. There is not much you can do probably, as the design of the Kotlin language is here the problem.

  1. Option Make an Util class which does it. It's not much different than LottieAnimationExtKt#withCoverLottieAnimation though, only the name.

  2. Option Make some abstract "Builder" or "Setup" or whatever name you'd like class in the core module. Create the following instance method: Sheet#withBuilder(Builder b). Builder then has an abstract method called Builder#buildFor(Sheet s), which is called in Sheet#withBuilder(Builder b). Then make a LottieAnimationBuilder class in the lottie module which then does all the ugly LottieAnimationExtKt.withCoverLottieAnimation stuff for me (which will not be ugly anymore in Kotlin). All I would have to do would then look probably look like that infoSheet.withBuilder(new LottieAnimationBuilder(R.raw.my_anim)).

maxkeppeler commented 3 years ago

What's the reason that you are still using Kotlin? From what I have seen and noticed, everything is about Kotlin, alongside a lot of Kotlin-first libraries.

GraxCode commented 3 years ago

I don't like the syntax of Kotlin, and honestly I am too lazy to learn all the Kotlin specific classes / methods. Java works fine for me, and I really like it as it feels closer to C.

maxkeppeler commented 3 years ago

I feel like it's not worth it to make it nicer on Java, as it is meant to be a Kotlin library and as it would affect the existing Kotlin users of the library. Sorry!