|
| 1 | +// Autogenerated from Pigeon (v20.0.2), do not edit directly. |
| 2 | +// See also: https://pub.dev/packages/pigeon |
| 3 | +@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass") |
| 4 | + |
| 5 | +package com.zulip.flutter |
| 6 | + |
| 7 | +import android.util.Log |
| 8 | +import io.flutter.plugin.common.BasicMessageChannel |
| 9 | +import io.flutter.plugin.common.BinaryMessenger |
| 10 | +import io.flutter.plugin.common.MessageCodec |
| 11 | +import io.flutter.plugin.common.StandardMessageCodec |
| 12 | +import java.io.ByteArrayOutputStream |
| 13 | +import java.nio.ByteBuffer |
| 14 | + |
| 15 | +private fun wrapResult(result: Any?): List<Any?> { |
| 16 | + return listOf(result) |
| 17 | +} |
| 18 | + |
| 19 | +private fun wrapError(exception: Throwable): List<Any?> { |
| 20 | + return if (exception is NotificationsError) { |
| 21 | + listOf( |
| 22 | + exception.code, |
| 23 | + exception.message, |
| 24 | + exception.details |
| 25 | + ) |
| 26 | + } else { |
| 27 | + listOf( |
| 28 | + exception.javaClass.simpleName, |
| 29 | + exception.toString(), |
| 30 | + "Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception) |
| 31 | + ) |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +/** |
| 36 | + * Error class for passing custom error details to Flutter via a thrown PlatformException. |
| 37 | + * @property code The error code. |
| 38 | + * @property message The error message. |
| 39 | + * @property details The error details. Must be a datatype supported by the api codec. |
| 40 | + */ |
| 41 | +class NotificationsError ( |
| 42 | + val code: String, |
| 43 | + override val message: String? = null, |
| 44 | + val details: Any? = null |
| 45 | +) : Throwable() |
| 46 | +private object MediaScannerPigeonCodec : StandardMessageCodec() { |
| 47 | + override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { |
| 48 | + return super.readValueOfType(type, buffer) |
| 49 | + } |
| 50 | + override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { |
| 51 | + super.writeValue(stream, value) |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | + |
| 56 | +/** Generated interface from Pigeon that represents a handler of messages from Flutter. */ |
| 57 | +interface MediaScannerHostApi { |
| 58 | + /** |
| 59 | + * Scans the file at the given path to make it visible in the device's media library. |
| 60 | + * Returns a success message if the scan was initiated successfully. |
| 61 | + */ |
| 62 | + fun scanFile(filePath: String, callback: (Result<String>) -> Unit) |
| 63 | + |
| 64 | + companion object { |
| 65 | + /** The codec used by MediaScannerHostApi. */ |
| 66 | + val codec: MessageCodec<Any?> by lazy { |
| 67 | + MediaScannerPigeonCodec |
| 68 | + } |
| 69 | + /** Sets up an instance of `MediaScannerHostApi` to handle messages through the `binaryMessenger`. */ |
| 70 | + @JvmOverloads |
| 71 | + fun setUp(binaryMessenger: BinaryMessenger, api: MediaScannerHostApi?, messageChannelSuffix: String = "") { |
| 72 | + val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" |
| 73 | + run { |
| 74 | + val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.zulip.MediaScannerHostApi.scanFile$separatedMessageChannelSuffix", codec) |
| 75 | + if (api != null) { |
| 76 | + channel.setMessageHandler { message, reply -> |
| 77 | + val args = message as List<Any?> |
| 78 | + val filePathArg = args[0] as String |
| 79 | + api.scanFile(filePathArg) { result: Result<String> -> |
| 80 | + val error = result.exceptionOrNull() |
| 81 | + if (error != null) { |
| 82 | + reply.reply(wrapError(error)) |
| 83 | + } else { |
| 84 | + val data = result.getOrNull() |
| 85 | + reply.reply(wrapResult(data)) |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + } else { |
| 90 | + channel.setMessageHandler(null) |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | +} |
0 commit comments