Skip to content

Commit

Permalink
Merge pull request #11 from stevenosse/use-kotlin
Browse files Browse the repository at this point in the history
Use kotlin for generated bindings
  • Loading branch information
Tiska authored Jun 19, 2023
2 parents 66bdafb + eb03070 commit 28795ca
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 164 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ migrate_working_dir/
.dart_tool/
.packages
build/

.fvm/
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## 2023-06-06

### Changes

---

- Use kotlin as output language for generated Pigeon bindings
- Use gradle 7.5

## 2023-05-23

### Changes
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,27 @@ package sncf.connect.tech.flutter_google_wallet
import android.app.Activity
import android.content.Context
import android.content.Intent
import androidx.annotation.NonNull
import com.google.android.gms.pay.Pay
import com.google.android.gms.pay.PayApiAvailabilityStatus
import com.google.android.gms.pay.PayClient
import com.google.android.gms.tasks.Tasks
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.PluginRegistry

class FlutterGoogleWalletPlugin: FlutterPlugin, Messages.GoogleWalletApi, ActivityAware, PluginRegistry.ActivityResultListener {
class FlutterGoogleWalletPlugin: FlutterPlugin, GoogleWalletApi, ActivityAware, PluginRegistry.ActivityResultListener {
private lateinit var context: Context
var activity: Activity? = null
private var activity: Activity? = null
private lateinit var walletClient: PayClient

override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
Messages.GoogleWalletApi.setup(flutterPluginBinding.binaryMessenger, this)
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
GoogleWalletApi.setUp(flutterPluginBinding.binaryMessenger, this)
context = flutterPluginBinding.applicationContext
}

override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
Messages.GoogleWalletApi.setup(binding.binaryMessenger, null)
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
GoogleWalletApi.setUp(binding.binaryMessenger, null)
}

override fun initWalletClient() {
Expand All @@ -47,14 +45,14 @@ class FlutterGoogleWalletPlugin: FlutterPlugin, Messages.GoogleWalletApi, Activi
}

override fun onAttachedToActivity(binding: ActivityPluginBinding) {
activity = binding.activity;
activity = binding.activity
binding.addActivityResultListener(this)
}

override fun onDetachedFromActivityForConfigChanges() {}

override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
activity = binding.activity;
activity = binding.activity
binding.addActivityResultListener(this)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Autogenerated from Pigeon (v10.0.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon

package sncf.connect.tech.flutter_google_wallet

import android.util.Log
import io.flutter.plugin.common.BasicMessageChannel
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.MessageCodec
import io.flutter.plugin.common.StandardMessageCodec
import java.io.ByteArrayOutputStream
import java.nio.ByteBuffer

private fun wrapResult(result: Any?): List<Any?> {
return listOf(result)
}

private fun wrapError(exception: Throwable): List<Any?> {
if (exception is FlutterError) {
return listOf(
exception.code,
exception.message,
exception.details
)
} else {
return listOf(
exception.javaClass.simpleName,
exception.toString(),
"Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception)
)
}
}

/**
* Error class for passing custom error details to Flutter via a thrown PlatformException.
* @property code The error code.
* @property message The error message.
* @property details The error details. Must be a datatype supported by the api codec.
*/
class FlutterError (
val code: String,
override val message: String? = null,
val details: Any? = null
) : Throwable()
/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
interface GoogleWalletApi {
fun initWalletClient()
fun getWalletApiAvailabilityStatus(): Boolean
fun savePasses(jsonPass: String, addToGoogleWalletRequestCode: Long)

companion object {
/** The codec used by GoogleWalletApi. */
val codec: MessageCodec<Any?> by lazy {
StandardMessageCodec()
}
/** Sets up an instance of `GoogleWalletApi` to handle messages through the `binaryMessenger`. */
@Suppress("UNCHECKED_CAST")
fun setUp(binaryMessenger: BinaryMessenger, api: GoogleWalletApi?) {
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.GoogleWalletApi.initWalletClient", codec)
if (api != null) {
channel.setMessageHandler { _, reply ->
var wrapped: List<Any?>
try {
api.initWalletClient()
wrapped = listOf<Any?>(null)
} catch (exception: Throwable) {
wrapped = wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
run {
val taskQueue = binaryMessenger.makeBackgroundTaskQueue()
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.GoogleWalletApi.getWalletApiAvailabilityStatus", codec, taskQueue)
if (api != null) {
channel.setMessageHandler { _, reply ->
var wrapped: List<Any?>
try {
wrapped = listOf<Any?>(api.getWalletApiAvailabilityStatus())
} catch (exception: Throwable) {
wrapped = wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.GoogleWalletApi.savePasses", codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val jsonPassArg = args[0] as String
val addToGoogleWalletRequestCodeArg = args[1].let { if (it is Int) it.toLong() else it as Long }
var wrapped: List<Any?>
try {
api.savePasses(jsonPassArg, addToGoogleWalletRequestCodeArg)
wrapped = listOf<Any?>(null)
} catch (exception: Throwable) {
wrapped = wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
}
}
}
4 changes: 2 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = '1.6.21'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
8 changes: 4 additions & 4 deletions run_pigeon.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dart pub run pigeon \
--input pigeons/messages.dart \
--dart_out lib/messages.dart \
--java_out android/src/main/java/sncf/connect/tech/flutter_google_wallet/Messages.java \
--java_package "sncf.connect.tech.flutter_google_wallet"
--input pigeons/messages.dart \
--dart_out lib/messages.dart \
--kotlin_out android/src/main/kotlin/sncf/connect/tech/flutter_google_wallet/Messages.kt \
--kotlin_package "sncf.connect.tech.flutter_google_wallet"

0 comments on commit 28795ca

Please sign in to comment.