mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-25 11:46:06 +02:00
feat(notification): implement Android and iOS APIs (#340)
This commit is contained in:
committed by
GitHub
parent
1397172e95
commit
be1c775b8d
@@ -0,0 +1,47 @@
|
||||
package app.tauri.notification
|
||||
|
||||
import app.tauri.Logger
|
||||
import app.tauri.plugin.JSArray
|
||||
import app.tauri.plugin.JSObject
|
||||
import org.json.JSONObject
|
||||
|
||||
class NotificationAction() {
|
||||
var id: String? = null
|
||||
var title: String? = null
|
||||
var input = false
|
||||
|
||||
constructor(id: String?, title: String?, input: Boolean): this() {
|
||||
this.id = id
|
||||
this.title = title
|
||||
this.input = input
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun buildTypes(types: JSArray): Map<String, List<NotificationAction>> {
|
||||
val actionTypeMap: MutableMap<String, List<NotificationAction>> = HashMap()
|
||||
try {
|
||||
val objects: List<JSONObject> = types.toList()
|
||||
for (obj in objects) {
|
||||
val jsObject = JSObject.fromJSONObject(
|
||||
obj
|
||||
)
|
||||
val actionGroupId = jsObject.getString("id")
|
||||
val actions = jsObject.getJSONArray("actions")
|
||||
val typesArray = mutableListOf<NotificationAction>()
|
||||
for (i in 0 until actions.length()) {
|
||||
val notificationAction = NotificationAction()
|
||||
val action = JSObject.fromJSONObject(actions.getJSONObject(i))
|
||||
notificationAction.id = action.getString("id")
|
||||
notificationAction.title = action.getString("title")
|
||||
notificationAction.input = action.getBoolean("input")
|
||||
typesArray.add(notificationAction)
|
||||
}
|
||||
actionTypeMap[actionGroupId] = typesArray.toList()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Logger.error(Logger.tags("Notification"), "Error when building action types", e)
|
||||
}
|
||||
return actionTypeMap
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user