Use Kotlinx Serialization with the update check API.

Also replace Author and Uploader data classes with a single User class.
This commit is contained in:
Isira Seneviratne 2023-01-19 06:22:48 +05:30
parent fccb198f04
commit 0cf5853a3a
7 changed files with 83 additions and 100 deletions

View File

@ -1,20 +1,22 @@
package com.github.libretube.obj.update package com.github.libretube.obj.update
import com.fasterxml.jackson.annotation.JsonIgnoreProperties import kotlinx.datetime.Instant
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@JsonIgnoreProperties(ignoreUnknown = true) @Serializable
data class Asset( data class Asset(
val browser_download_url: String? = null, @SerialName("browser_download_url") val browserDownloadUrl: String,
val content_type: String? = null, @SerialName("content_type") val contentType: String,
val created_at: String? = null, @SerialName("created_at") val createdAt: Instant,
val download_count: Int? = null, @SerialName("download_count") val downloadCount: Int,
val id: Int? = null, val id: Int,
val label: Any? = null, val label: String? = null,
val name: String? = null, val name: String,
val node_id: String? = null, @SerialName("node_id") val nodeId: String,
val size: Int? = null, val size: Int,
val state: String? = null, val state: String,
val updated_at: String? = null, @SerialName("updated_at") val updatedAt: Instant,
val uploader: Uploader? = null, val uploader: User,
val url: String? = null val url: String
) )

View File

@ -1,25 +0,0 @@
package com.github.libretube.obj.update
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
@JsonIgnoreProperties(ignoreUnknown = true)
data class Author(
val avatar_url: String? = null,
val events_url: String? = null,
val followers_url: String? = null,
val following_url: String? = null,
val gists_url: String? = null,
val gravatar_id: String? = null,
val html_url: String? = null,
val id: Int? = null,
val login: String? = null,
val node_id: String? = null,
val organizations_url: String? = null,
val received_events_url: String? = null,
val repos_url: String? = null,
val site_admin: Boolean? = null,
val starred_url: String? = null,
val subscriptions_url: String? = null,
val type: String? = null,
val url: String? = null
)

View File

@ -1,15 +1,16 @@
package com.github.libretube.obj.update package com.github.libretube.obj.update
import com.fasterxml.jackson.annotation.JsonIgnoreProperties import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@JsonIgnoreProperties(ignoreUnknown = true) @Serializable
data class Reactions( data class Reactions(
val confused: Int? = null, val confused: Int,
val eyes: Int? = null, val eyes: Int,
val heart: Int? = null, val heart: Int,
val hooray: Int? = null, val hooray: Int,
val laugh: Int? = null, val laugh: Int,
val rocket: Int? = null, val rocket: Int,
val total_count: Int? = null, @SerialName("total_count") val totalCount: Int,
val url: String? = null val url: String
) )

View File

@ -1,27 +1,29 @@
package com.github.libretube.obj.update package com.github.libretube.obj.update
import com.fasterxml.jackson.annotation.JsonIgnoreProperties import kotlinx.datetime.Instant
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@JsonIgnoreProperties(ignoreUnknown = true) @Serializable
data class UpdateInfo( data class UpdateInfo(
val assets: List<Asset>? = null, val assets: List<Asset> = emptyList(),
val assets_url: String? = null, @SerialName("assets_url") val assetsUrl: String,
val author: Author? = null, val author: User,
val body: String? = null, val body: String,
val created_at: String? = null, @SerialName("created_at") val createdAt: Instant,
val draft: Boolean? = null, val draft: Boolean,
val html_url: String? = null, @SerialName("html_url") val htmlUrl: String,
val id: Int? = null, val id: Int,
val mentions_count: Int? = null, @SerialName("mentions_count") val mentionsCount: Int,
val name: String? = null, val name: String,
val node_id: String? = null, @SerialName("node_id") val nodeId: String,
val prerelease: Boolean? = null, val prerelease: Boolean,
val published_at: String? = null, @SerialName("published_at") val publishedAt: Instant,
val reactions: Reactions? = null, val reactions: Reactions,
val tag_name: String? = null, @SerialName("tag_name") val tagName: String,
val tarball_url: String? = null, @SerialName("tarball_url") val tarballUrl: String,
val target_commitish: String? = null, @SerialName("target_commitish") val targetCommitish: String,
val upload_url: String? = null, @SerialName("upload_url") val uploadUrl: String,
val url: String? = null, val url: String,
val zipball_url: String? = null @SerialName("zipball_url") val zipballUrl: String
) )

View File

@ -1,25 +0,0 @@
package com.github.libretube.obj.update
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
@JsonIgnoreProperties(ignoreUnknown = true)
data class Uploader(
val avatar_url: String? = null,
val events_url: String? = null,
val followers_url: String? = null,
val following_url: String? = null,
val gists_url: String? = null,
val gravatar_id: String? = null,
val html_url: String? = null,
val id: Int? = null,
val login: String? = null,
val node_id: String? = null,
val organizations_url: String? = null,
val received_events_url: String? = null,
val repos_url: String? = null,
val site_admin: Boolean? = null,
val starred_url: String? = null,
val subscriptions_url: String? = null,
val type: String? = null,
val url: String? = null
)

View File

@ -0,0 +1,26 @@
package com.github.libretube.obj.update
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class User(
@SerialName("avatar_url") val avatarUrl: String,
@SerialName("events_url") val eventsUrl: String,
@SerialName("followers_url") val followersUrl: String,
@SerialName("following_url") val followingUrl: String,
@SerialName("gists_url") val gistsUrl: String,
@SerialName("gravatar_id") val gravatarId: String,
@SerialName("html_url") val htmlUrl: String,
val id: Int,
val login: String,
@SerialName("node_id") val nodeId: String,
@SerialName("organizations_url") val organizationsUrl: String,
@SerialName("received_events_url") val receivedEventsUrl: String,
@SerialName("repos_url") val reposUrl: String,
@SerialName("site_admin") val siteAdmin: Boolean,
@SerialName("starred_url") val starredUrl: String,
@SerialName("subscriptions_url") val subscriptionsUrl: String,
val type: String,
val url: String
)

View File

@ -29,7 +29,7 @@ class UpdateDialog(
intent.putExtra("downloadUrl", downloadUrl) intent.putExtra("downloadUrl", downloadUrl)
context?.startService(intent) context?.startService(intent)
} else { } else {
val uri = Uri.parse(updateInfo.html_url) val uri = Uri.parse(updateInfo.htmlUrl)
val intent = Intent(Intent.ACTION_VIEW).setData(uri) val intent = Intent(Intent.ACTION_VIEW).setData(uri)
startActivity(intent) startActivity(intent)
} }
@ -40,8 +40,10 @@ class UpdateDialog(
private fun getDownloadUrl(updateInfo: UpdateInfo): String? { private fun getDownloadUrl(updateInfo: UpdateInfo): String? {
val supportedArchitectures = Build.SUPPORTED_ABIS val supportedArchitectures = Build.SUPPORTED_ABIS
supportedArchitectures.forEach { arch -> supportedArchitectures.forEach { arch ->
updateInfo.assets?.forEach { asset -> updateInfo.assets.forEach { asset ->
if (asset.name?.contains(arch) == true) return asset.browser_download_url if (asset.name.contains(arch)) {
return asset.browserDownloadUrl
}
} }
} }
return null return null