Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ package io.ionic.backgroundrunner.plugin.api

import android.annotation.SuppressLint
import com.getcapacitor.plugin.util.AssetUtil
import org.json.JSONException
import org.json.JSONObject
import java.text.SimpleDateFormat
import java.util.Date
import java.util.TimeZone

/** Null when the key is missing or JSON null; any other non-string value is an error. */
private fun JSONObject.getStringOrNull(name: String): String? =
when (val value = opt(name)) {
null, JSONObject.NULL -> null
is String -> value
else -> throw JSONException("$name must be a string")
}

@SuppressLint("SimpleDateFormat")
class Notification(jsonObject: JSONObject) {
var id: Int
Expand Down Expand Up @@ -36,6 +45,7 @@ class Notification(jsonObject: JSONObject) {
ongoing = jsonObject.optBoolean("ongoing", false)
autoCancel = jsonObject.optBoolean("autoCancel", false)
actionTypeId = jsonObject.optString("actionTypeId", null)
channelId = jsonObject.getStringOrNull("channelId")

val scheduleDateString = jsonObject.optString("scheduleAt", "")
if (scheduleDateString.isNotEmpty()) {
Expand Down