Closed AviranAbady closed 6 years ago
@Diolor @dmitry-zaitsev can you assist?
@AviranAbady you can use Kotlin version with your Java code, no problem!
Providing a code example, for everyone not familiar with Kotlin. Basicly Kotlin code can be integrated directly in the Java code, the callbacks should be defined as lambdas and return Unit.INSTANCE.
build.gradle
android {
...
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
fotoApparat.takePicture().
toPendingResult().
whenAvailable(photo -> {
/* handle photo */
return Unit.INSTANCE;
});
fotoApparat.focus().whenAvailable(focusResult -> {
return Unit.INSTANCE;
});
Still using Fotoapparat 1.x Exploring the idea of upgrading to 2.x, getting some issues with upgrading the code (while remaining in Java)
Not sure how the following legacy code should be handled in 2.x:
Focus listener:
Pending result seem to have changed, not sure how to apply the current Kotlin callback machanism while still writing in
Java
.FocusResult
enum is now an object type, shouldinstanceof
be used instead as a compare operator?Taking a picture
What's the proper way to handle the async operation / supplying the callback?
Please provide code examples.