Feature/java projects support - #38
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds Java interoperability support for the Prince of Versions library on Android and JVM platforms. It introduces callback-based APIs and non-suspend interfaces to make the library more accessible to Java developers while maintaining the existing Kotlin-based architecture.
Changes:
- Added Java-friendly extension functions and callback interfaces for Android and JVM platforms
- Created
JavaLoaderinterface andUpdaterCallbackas alternatives to suspend-based APIs - Added Java usage examples to both Android and JVM sample applications
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| princeofversions/src/androidMain/kotlin/com/infinum/princeofversions/java/JavaLoader.kt | Defines JavaLoader interface for Android platform |
| princeofversions/src/androidMain/kotlin/com/infinum/princeofversions/java/PrinceOfVersions.kt | Android-specific extension functions for Java interop |
| princeofversions/src/androidMain/kotlin/com/infinum/princeofversions/java/UpdaterCallback.kt | Callback interface for Android platform |
| princeofversions/src/jvmMain/kotlin/com/infinum/princeofversions/java/JavaLoader.kt | Defines JavaLoader interface for JVM platform |
| princeofversions/src/jvmMain/kotlin/com/infinum/princeofversions/java/PrinceOfVersions.kt | JVM-specific extension functions for Java interop |
| princeofversions/src/jvmMain/kotlin/com/infinum/princeofversions/java/UpdaterCallback.kt | Callback interface for JVM platform |
| princeofversions/src/commonMain/kotlin/com/infinum/princeofversions/BasePrinceOfVersionsCall.kt | Removed unused interface |
| princeofversions/src/commonMain/kotlin/com/infinum/princeofversions/Cancelable.kt | Removed unused interface |
| princeofversions/src/commonMain/kotlin/com/infinum/princeofversions/UpdateCallback.kt | Removed unused interface |
| sampleApp/src/main/java/com/infinum/princeofversions/sample/JavaUsageExample.java | Android Java usage example implementation |
| sampleApp/src/androidMain/kotlin/com/infinum/princeofversions/sample/ComposeJavaBridge.kt | Bridge to set up Compose content from Java on Android |
| sampleApp/src/androidMain/kotlin/com/infinum/princeofversions/sample/MainActivity.kt | Added navigation to Java usage example |
| sampleApp/src/androidMain/AndroidManifest.xml | Registered JavaUsageExample activity |
| sampleApp/src/desktopMain/java/com/infinum/princeofversions/sample/JavaUsageExample.java | JVM Java usage example implementation |
| sampleApp/src/desktopMain/kotlin/com/infinum/princeofversions/sample/ComposeJavaBridge.kt | Bridge to set up Compose content from Java on JVM |
| sampleApp/src/desktopMain/kotlin/com/infinum/princeofversions/sample/main.kt | Added navigation and exception handling improvements |
| sampleApp/src/commonMain/kotlin/com/infinum/princeofversions/sample/App.kt | Added Java usage button to main menu |
Comments suppressed due to low confidence (2)
princeofversions/src/androidMain/kotlin/com/infinum/princeofversions/java/JavaLoader.kt:1
- The documentation states 'This class' but JavaLoader is an interface, not a class. Change 'This class' to 'This interface'.
princeofversions/src/androidMain/kotlin/com/infinum/princeofversions/java/UpdaterCallback.kt:1 - The documentation comment is misleading. The onSuccess method is called when the update check completes successfully, regardless of whether an update is available. The actual update status is determined by checking result.status. Update the documentation to accurately reflect this behavior.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
KCeh
left a comment
There was a problem hiding this comment.
I guess solution in this PR is fine.
I don't know how much we really need Java support in Android 🤷
Only note from my side:
Current code organisation is acceptable since Java support is not "heavy"
In case we need to do more for Java support (eg, introduce new dependencies, different APIs), then I think it would be better to extract support to separate module/artefact. But for now it is ok 👍
Summary
This PR adds convenience methods which should make the usage of this library easier in Java projects on the Android and Jvm platforms. It also adjusts requirements not satisfied exception handling in the jvm sample app.
Related issue:
Changes
Type
Additional information
Checklist
Additional notes
Note One more point of friction remains for java projects, and that is the storage interface which declares suspend functions. This simply means that java projects will have a bit more of an issue if they decide to implement custom storage solutions. Given that covering this means even more code duplication, and the use case appears to be rare, I decided that we currently don't need to cover this but I'm open to feedback.
Note Due to the fact that Kotlin typealiases don't work in Java (this was an oversight), the base interfaces with generics have to be used. This is a bit less convenient but does not seem like a major issue.