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

Migrated java PurchasesFlutterPlugin class to kotlin class. #686

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Arunshaik2001
Copy link

What does this pr do?

  1. Migrated Java plugin file to Kotlin file to use kotlin features.
  2. Moved method names and argument names in constant file

2. Moved method names and argument names in constant file
Copy link
Contributor

@tonidero tonidero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Arunshaik2001, really sorry for taking so long to answer.

We definitely would like to move this code to Kotlin! So this is a great contribution, thanks! I left a few comments here, let me know if you have any questions or anything I can help with!


internal object Constants {

object MethodNameConstants{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We believe extracting all these constants doesn't provide much value and can even decrease legibility. The exception to this would be when they are repeated. Could you move the constants back to the plugin class? It would be fine to leave any that are repeated.


override fun onDetachedFromEngine(binding: FlutterPluginBinding) {
if (channel != null) {
channel!!.setMethodCallHandler(null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be channel?.setMethodCallHandler(null)

}

private fun getActivity(): Activity? {
return if (registrar != null) registrar!!.activity() else activity
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be registrar?.activity() ?: activity I think?

store = Store.AMAZON
}
configure(
applicationContext!!, apiKey!!, appUserID, observerMode,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of crashing here, it would be better to try to handle this gracefully by calling result.error (I understand it would have crashes with the Java version as well, but we can improve that now)

type: String?,
result: MethodChannel.Result
) {
getProductInfo(productIDs, type!!, object : OnResultList {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here and other places we use !!. Ideally we handle it gracefully

private fun invokeChannelMethodOnUiThread(method: String, argumentsMap: Any) {
runOnUiThread {
if (channel != null) {
channel!!.invokeMethod(method, argumentsMap)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be channel?.invokeMethod(method, argumentsMap)

private const val CUSTOMER_INFO_UPDATED = "Purchases-CustomerInfoUpdated"
protected const val LOG_HANDLER_EVENT = "Purchases-LogHandlerEvent"
private const val PLATFORM_NAME = "flutter"
private const val PLUGIN_VERSION = "4.13.0-SNAPSHOT"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need to update to use the latest version of the plugin.

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

Successfully merging this pull request may close these issues.

2 participants