mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-31 05:48:19 +01:00
[Firebase/Vulcan] Fix not converting received string to JsonObject.
This commit is contained in:
parent
367f46fac8
commit
aa5e225148
@ -40,6 +40,7 @@ import com.google.android.gms.security.ProviderInstaller
|
|||||||
import com.google.gson.JsonArray
|
import com.google.gson.JsonArray
|
||||||
import com.google.gson.JsonElement
|
import com.google.gson.JsonElement
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
|
import com.google.gson.JsonParser
|
||||||
import im.wangchao.mhttp.Response
|
import im.wangchao.mhttp.Response
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.delay
|
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.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 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: JsonElement) = this.add(key, value)
|
||||||
operator fun JsonObject.set(key: String, value: Boolean) = this.addProperty(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)
|
operator fun JsonObject.set(key: String, value: String?) = this.addProperty(key, value)
|
||||||
|
@ -42,6 +42,8 @@ abstract class IApiTask(open val profileId: Int) {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun enqueueAll(context: Context, tasks: List<IApiTask>) {
|
fun enqueueAll(context: Context, tasks: List<IApiTask>) {
|
||||||
|
if (tasks.isEmpty())
|
||||||
|
return
|
||||||
Intent(context, ApiService::class.java).let {
|
Intent(context, ApiService::class.java).let {
|
||||||
if (SDK_INT >= O)
|
if (SDK_INT >= O)
|
||||||
context.startForegroundService(it)
|
context.startForegroundService(it)
|
||||||
|
@ -26,7 +26,7 @@ class SzkolnyVulcanFirebase(val app: App, val profiles: List<Profile>, val messa
|
|||||||
"message: "Uczeń Janósz otrzymał nieobecność na 7 lekcji"
|
"message: "Uczeń Janósz otrzymał nieobecność na 7 lekcji"
|
||||||
}*/
|
}*/
|
||||||
init { run {
|
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 type = data.getString("table") ?: return@run
|
||||||
val studentId = data.getInt("pupilid")
|
val studentId = data.getInt("pupilid")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user