|
| 1 | +/* |
| 2 | + * Copyright (c) 2021. |
| 3 | + * Microsoft Corporation. All rights reserved. |
| 4 | + * |
| 5 | + * |
| 6 | + * This file is automatically generated |
| 7 | + * Please DO NOT modify |
| 8 | +*/ |
| 9 | + |
| 10 | +package com.microsoft.office.outlook.rooster.web.bridge |
| 11 | + |
| 12 | +import com.google.gson.Gson |
| 13 | +import com.microsoft.office.outlook.rooster.Callback |
| 14 | +import com.microsoft.office.outlook.rooster.web.JsBridge |
| 15 | +import com.microsoft.office.outlook.rooster.web.WebEditor |
| 16 | +import java.lang.reflect.Type |
| 17 | +import com.google.gson.JsonDeserializationContext |
| 18 | +import com.google.gson.JsonDeserializer |
| 19 | +import com.google.gson.JsonElement |
| 20 | +import com.google.gson.JsonPrimitive |
| 21 | +import com.google.gson.JsonSerializationContext |
| 22 | +import com.google.gson.JsonSerializer |
| 23 | +import com.google.gson.annotations.SerializedName |
| 24 | + |
| 25 | +interface IHtmlApiBridge { |
| 26 | + fun setMentionClassNames(idToClassNames: Map<String, Array<String>>) |
| 27 | + fun getHeight(callback: Callback<Float>) |
| 28 | + fun getHeightWithBottomAnchor(sta: Array<String>, callback: Callback<Float>) |
| 29 | + fun getHTML(title: String, callback: Callback<String>) |
| 30 | + fun requestRenderingResult() |
| 31 | + fun getSize(callback: Callback<OverriddenFullSize>) |
| 32 | + fun getAliasSize(callback: Callback<BaseSize>) |
| 33 | + fun testDictionaryWithAnyKey(dict: Map<String, String>) |
| 34 | +} |
| 35 | + |
| 36 | +open class IHtmlApiBridge(editor: WebEditor, gson: Gson) : JsBridge(editor, gson, "htmlApi"), IHtmlApiBridge { |
| 37 | + |
| 38 | + override fun setMentionClassNames(idToClassNames: Map<String, Array<String>>) { |
| 39 | + executeJs("setMentionClassNames", mapOf( |
| 40 | + "idToClassNames" to idToClassNames |
| 41 | + )) |
| 42 | + } |
| 43 | + |
| 44 | + override fun getHeight(callback: Callback<Float>) { |
| 45 | + executeJsForResponse(Float::class.java, "getHeight", callback) |
| 46 | + } |
| 47 | + |
| 48 | + override fun getHeightWithBottomAnchor(sta: Array<String>, callback: Callback<Float>) { |
| 49 | + executeJsForResponse(Float::class.java, "getHeightWithBottomAnchor", callback, mapOf( |
| 50 | + "sta" to sta |
| 51 | + )) |
| 52 | + } |
| 53 | + |
| 54 | + override fun getHTML(title: String, callback: Callback<String>) { |
| 55 | + executeJsForResponse(String::class.java, "getHTML", callback, mapOf( |
| 56 | + "title" to title |
| 57 | + )) |
| 58 | + } |
| 59 | + |
| 60 | + override fun requestRenderingResult() { |
| 61 | + executeJs("requestRenderingResult") |
| 62 | + } |
| 63 | + |
| 64 | + override fun getSize(callback: Callback<OverriddenFullSize>) { |
| 65 | + executeJsForResponse(OverriddenFullSize::class.java, "getSize", callback) |
| 66 | + } |
| 67 | + |
| 68 | + override fun getAliasSize(callback: Callback<BaseSize>) { |
| 69 | + executeJsForResponse(BaseSize::class.java, "getAliasSize", callback) |
| 70 | + } |
| 71 | + |
| 72 | + override fun testDictionaryWithAnyKey(dict: Map<String, String>) { |
| 73 | + executeJs("testDictionaryWithAnyKey", mapOf( |
| 74 | + "dict" to dict |
| 75 | + )) |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +data class OverriddenFullSize( |
| 80 | + @JvmField val size: Float, |
| 81 | + @JvmField val count: Int, |
| 82 | + @JvmField val stringEnum: StringEnum, |
| 83 | + @JvmField val numEnum: NumEnum, |
| 84 | + @JvmField val defEnum: DefaultEnum, |
| 85 | + @JvmField val width: Float, |
| 86 | + @JvmField val height: Float, |
| 87 | + @JvmField val scale: Float, |
| 88 | + @JvmField val member: NumEnum = NumEnum.ONE, |
| 89 | +) |
| 90 | + |
| 91 | +enum class NumEnum(val value: Int) { |
| 92 | + ONE(1), |
| 93 | + TWO(2); |
| 94 | + |
| 95 | + companion object { |
| 96 | + fun find(value: Int) = values().find { it.value == value } |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | +class NumEnumTypeAdapter : JsonSerializer<NumEnum>, JsonDeserializer<NumEnum> { |
| 101 | + override fun serialize(obj: NumEnum, type: Type, context: JsonSerializationContext): JsonElement { |
| 102 | + return JsonPrimitive(obj.value) |
| 103 | + } |
| 104 | + |
| 105 | + override fun deserialize(json: JsonElement, type: Type, context: JsonDeserializationContext): NumEnum? { |
| 106 | + return NumEnum.find(json.asInt) |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +enum class StringEnum { |
| 111 | + @SerializedName("a") A, |
| 112 | + @SerializedName("b") B |
| 113 | +} |
| 114 | + |
| 115 | +enum class DefaultEnum { |
| 116 | + @SerializedName("c") C, |
| 117 | + @SerializedName("d") D |
| 118 | +} |
| 119 | + |
| 120 | +data class BaseSize( |
| 121 | + @JvmField val width: Float, |
| 122 | + @JvmField val height: Float, |
| 123 | +) |
0 commit comments