diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt b/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt index e4ad829e..c491c71e 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt @@ -40,6 +40,7 @@ import com.google.android.gms.security.ProviderInstaller import com.google.gson.JsonArray import com.google.gson.JsonElement import com.google.gson.JsonObject +import com.google.gson.JsonParser import im.wangchao.mhttp.Response import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.delay @@ -115,6 +116,8 @@ fun JsonArray.getChar(key: Int): Char? = if (key >= size()) null else get(key)?. fun JsonArray.getJsonObject(key: Int): JsonObject? = if (key >= size()) null else get(key)?.let { if (it.isJsonObject) it.asJsonObject else null } fun JsonArray.getJsonArray(key: Int): JsonArray? = if (key >= size()) null else get(key)?.let { if (it.isJsonArray) it.asJsonArray else null } +fun String.toJsonObject(): JsonObject? = try { JsonParser().parse(this).asJsonObject } catch (ignore: Exception) { null } + operator fun JsonObject.set(key: String, value: JsonElement) = this.add(key, value) operator fun JsonObject.set(key: String, value: Boolean) = this.addProperty(key, value) operator fun JsonObject.set(key: String, value: String?) = this.addProperty(key, value) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/task/IApiTask.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/task/IApiTask.kt index 2d0efe0d..2bff4267 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/task/IApiTask.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/task/IApiTask.kt @@ -42,6 +42,8 @@ abstract class IApiTask(open val profileId: Int) { companion object { fun enqueueAll(context: Context, tasks: List) { + if (tasks.isEmpty()) + return Intent(context, ApiService::class.java).let { if (SDK_INT >= O) context.startForegroundService(it) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/firebase/SzkolnyVulcanFirebase.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/firebase/SzkolnyVulcanFirebase.kt index a03a2199..b7d3af9e 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/firebase/SzkolnyVulcanFirebase.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/firebase/SzkolnyVulcanFirebase.kt @@ -26,7 +26,7 @@ class SzkolnyVulcanFirebase(val app: App, val profiles: List, val messa "message: "Uczeń Janósz otrzymał nieobecność na 7 lekcji" }*/ init { run { - val data = message.data.getJsonObject("data") ?: return@run + val data = message.data.getString("data")?.toJsonObject() ?: return@run val type = data.getString("table") ?: return@run val studentId = data.getInt("pupilid")