|  | 
|  | 1 | +// Autogenerated from Pigeon (v22.7.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.EventChannel | 
|  | 11 | +import io.flutter.plugin.common.MessageCodec | 
|  | 12 | +import io.flutter.plugin.common.StandardMethodCodec | 
|  | 13 | +import io.flutter.plugin.common.StandardMessageCodec | 
|  | 14 | +import java.io.ByteArrayOutputStream | 
|  | 15 | +import java.nio.ByteBuffer | 
|  | 16 | + | 
|  | 17 | +private fun wrapResult(result: Any?): List<Any?> { | 
|  | 18 | +  return listOf(result) | 
|  | 19 | +} | 
|  | 20 | + | 
|  | 21 | +private fun wrapError(exception: Throwable): List<Any?> { | 
|  | 22 | +  return if (exception is DownloadManagerError) { | 
|  | 23 | +    listOf( | 
|  | 24 | +      exception.code, | 
|  | 25 | +      exception.message, | 
|  | 26 | +      exception.details | 
|  | 27 | +    ) | 
|  | 28 | +  } else { | 
|  | 29 | +    listOf( | 
|  | 30 | +      exception.javaClass.simpleName, | 
|  | 31 | +      exception.toString(), | 
|  | 32 | +      "Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception) | 
|  | 33 | +    ) | 
|  | 34 | +  } | 
|  | 35 | +} | 
|  | 36 | + | 
|  | 37 | +/** | 
|  | 38 | + * Error class for passing custom error details to Flutter via a thrown PlatformException. | 
|  | 39 | + * @property code The error code. | 
|  | 40 | + * @property message The error message. | 
|  | 41 | + * @property details The error details. Must be a datatype supported by the api codec. | 
|  | 42 | + */ | 
|  | 43 | +class DownloadManagerError ( | 
|  | 44 | +  val code: String, | 
|  | 45 | +  override val message: String? = null, | 
|  | 46 | +  val details: Any? = null | 
|  | 47 | +) : Throwable() | 
|  | 48 | +private open class DownloadManagerPigeonCodec : StandardMessageCodec() { | 
|  | 49 | +  override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { | 
|  | 50 | +    return     super.readValueOfType(type, buffer) | 
|  | 51 | +  } | 
|  | 52 | +  override fun writeValue(stream: ByteArrayOutputStream, value: Any?)   { | 
|  | 53 | +    super.writeValue(stream, value) | 
|  | 54 | +  } | 
|  | 55 | +} | 
|  | 56 | + | 
|  | 57 | + | 
|  | 58 | +/** Generated interface from Pigeon that represents a handler of messages from Flutter. */ | 
|  | 59 | +interface DownloadManagerHostApi { | 
|  | 60 | +  /** | 
|  | 61 | +   * Downloads a file using the given URL and saves it with the specified file name in the Downloads directory. | 
|  | 62 | +   * Returns a success message or an error message. | 
|  | 63 | +   */ | 
|  | 64 | +  fun downloadFile(fileUrl: String, fileName: String, header: String, callback: (Result<String>) -> Unit) | 
|  | 65 | + | 
|  | 66 | +  companion object { | 
|  | 67 | +    /** The codec used by DownloadManagerHostApi. */ | 
|  | 68 | +    val codec: MessageCodec<Any?> by lazy { | 
|  | 69 | +      DownloadManagerPigeonCodec() | 
|  | 70 | +    } | 
|  | 71 | +    /** Sets up an instance of `DownloadManagerHostApi` to handle messages through the `binaryMessenger`. */ | 
|  | 72 | +    @JvmOverloads | 
|  | 73 | +    fun setUp(binaryMessenger: BinaryMessenger, api: DownloadManagerHostApi?, messageChannelSuffix: String = "") { | 
|  | 74 | +      val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" | 
|  | 75 | +      run { | 
|  | 76 | +        val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.zulip.DownloadManagerHostApi.downloadFile$separatedMessageChannelSuffix", codec) | 
|  | 77 | +        if (api != null) { | 
|  | 78 | +          channel.setMessageHandler { message, reply -> | 
|  | 79 | +            val args = message as List<Any?> | 
|  | 80 | +            val fileUrlArg = args[0] as String | 
|  | 81 | +            val fileNameArg = args[1] as String | 
|  | 82 | +            val headerArg = args[2] as String | 
|  | 83 | +            api.downloadFile(fileUrlArg, fileNameArg, headerArg) { result: Result<String> -> | 
|  | 84 | +              val error = result.exceptionOrNull() | 
|  | 85 | +              if (error != null) { | 
|  | 86 | +                reply.reply(wrapError(error)) | 
|  | 87 | +              } else { | 
|  | 88 | +                val data = result.getOrNull() | 
|  | 89 | +                reply.reply(wrapResult(data)) | 
|  | 90 | +              } | 
|  | 91 | +            } | 
|  | 92 | +          } | 
|  | 93 | +        } else { | 
|  | 94 | +          channel.setMessageHandler(null) | 
|  | 95 | +        } | 
|  | 96 | +      } | 
|  | 97 | +    } | 
|  | 98 | +  } | 
|  | 99 | +} | 
0 commit comments