forked from AndreyAsadchy/Xtra
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a12eb3a
commit 4d38676
Showing
9 changed files
with
240 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
app/src/main/java/com/github/andreyasadchy/xtra/model/helix/chat/UserEmotesDeserializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.github.andreyasadchy.xtra.model.helix.chat | ||
|
||
import com.google.gson.JsonDeserializationContext | ||
import com.google.gson.JsonDeserializer | ||
import com.google.gson.JsonElement | ||
import com.google.gson.JsonParseException | ||
import java.lang.reflect.Type | ||
|
||
class UserEmotesDeserializer : JsonDeserializer<UserEmotesResponse> { | ||
|
||
@Throws(JsonParseException::class) | ||
override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): UserEmotesResponse { | ||
val data = mutableListOf<EmoteSetResponse.EmoteTemplate>() | ||
val cursor = json.takeIf { it.isJsonObject }?.asJsonObject?.get("pagination")?.takeIf { it.isJsonObject }?.asJsonObject?.get("cursor")?.takeIf { it.isJsonPrimitive }?.asJsonPrimitive?.takeIf { it.isString }?.asString | ||
json.takeIf { it.isJsonObject }?.asJsonObject?.get("template")?.takeIf { it.isJsonPrimitive }?.asJsonPrimitive?.takeIf { it.isString }?.asString?.let { template -> | ||
json.takeIf { it.isJsonObject }?.asJsonObject?.get("data")?.takeIf { it.isJsonArray }?.asJsonArray?.forEach { item -> | ||
item.takeIf { it.isJsonObject }?.asJsonObject?.let { obj -> | ||
obj.get("name")?.takeIf { it.isJsonPrimitive }?.asJsonPrimitive?.takeIf { it.isString }?.asString?.let { name -> | ||
obj.get("id")?.takeIf { it.isJsonPrimitive }?.asJsonPrimitive?.takeIf { it.isString }?.asString?.let { id -> | ||
val formats = mutableListOf<String>() | ||
obj.get("format")?.takeIf { it.isJsonArray }?.asJsonArray?.forEach { element -> | ||
element.takeIf { it.isJsonPrimitive }?.asJsonPrimitive?.takeIf { it.isString }?.asString?.let { formats.add(it) } | ||
} | ||
val themes = mutableListOf<String>() | ||
obj.get("theme_mode")?.takeIf { it.isJsonArray }?.asJsonArray?.forEach { element -> | ||
element.takeIf { it.isJsonPrimitive }?.asJsonPrimitive?.takeIf { it.isString }?.asString?.let { themes.add(it) } | ||
} | ||
val scales = mutableListOf<String>() | ||
obj.get("scale")?.takeIf { it.isJsonArray }?.asJsonArray?.forEach { element -> | ||
element.takeIf { it.isJsonPrimitive }?.asJsonPrimitive?.takeIf { it.isString }?.asString?.let { scales.add(it) } | ||
} | ||
data.add(EmoteSetResponse.EmoteTemplate( | ||
template = template, | ||
id = id, | ||
formats = formats, | ||
themes = themes, | ||
scales = scales, | ||
name = name.removePrefix("\\").replace("?\\", ""), | ||
setId = obj.get("emote_set_id")?.takeIf { it.isJsonPrimitive }?.asJsonPrimitive?.takeIf { it.isString }?.asString, | ||
ownerId = obj.get("owner_id")?.takeIf { it.isJsonPrimitive }?.asJsonPrimitive?.takeIf { it.isString }?.asString | ||
)) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return UserEmotesResponse(data, cursor) | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
app/src/main/java/com/github/andreyasadchy/xtra/model/helix/chat/UserEmotesResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.github.andreyasadchy.xtra.model.helix.chat | ||
|
||
class UserEmotesResponse(val data: List<EmoteSetResponse.EmoteTemplate>, val cursor: String?) |
Oops, something went wrong.