Merge pull request #4721 from Isira-Seneviratne/UpdateInfo

refactor: Improve UpdateInfo
This commit is contained in:
Isira Seneviratne 2023-09-08 20:56:11 +05:30 committed by GitHub
commit 5ac7920497
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 8 additions and 94 deletions

View File

@ -1,24 +0,0 @@
package com.github.libretube.obj.update
import kotlinx.datetime.Instant
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonNull
@Serializable
data class Asset(
@SerialName("browser_download_url") val browserDownloadUrl: String,
@SerialName("content_type") val contentType: String,
@SerialName("created_at") val createdAt: Instant,
@SerialName("download_count") val downloadCount: Int,
val id: Int,
val label: JsonElement = JsonNull,
val name: String,
@SerialName("node_id") val nodeId: String,
val size: Int,
val state: String,
@SerialName("updated_at") val updatedAt: Instant,
val uploader: User,
val url: String
)

View File

@ -1,16 +0,0 @@
package com.github.libretube.obj.update
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class Reactions(
val confused: Int,
val eyes: Int,
val heart: Int,
val hooray: Int,
val laugh: Int,
val rocket: Int,
@SerialName("total_count") val totalCount: Int,
val url: String
)

View File

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

View File

@ -1,26 +0,0 @@
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

@ -7,19 +7,16 @@ import androidx.core.net.toUri
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.constants.IntentData import com.github.libretube.constants.IntentData
import com.github.libretube.extensions.parcelable
import com.github.libretube.obj.update.UpdateInfo import com.github.libretube.obj.update.UpdateInfo
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.serialization.json.Json
class UpdateAvailableDialog : DialogFragment() { class UpdateAvailableDialog : DialogFragment() {
private lateinit var updateInfo: UpdateInfo private lateinit var updateInfo: UpdateInfo
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
arguments?.let { updateInfo = requireArguments().parcelable(IntentData.updateInfo)!!
val encodedString = it.getString(IntentData.updateInfo)!!
updateInfo = Json.decodeFromString(encodedString)
}
} }
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {

View File

@ -52,10 +52,9 @@ class MainSettings : BasePreferenceFragment() {
if (BuildConfig.VERSION_NAME != updateInfo.name) { if (BuildConfig.VERSION_NAME != updateInfo.name) {
// show the UpdateAvailableDialog if there's an update available // show the UpdateAvailableDialog if there's an update available
val encodedUpdateInfo = Json.encodeToString(updateInfo)
val newUpdateAvailableDialog = UpdateAvailableDialog() val newUpdateAvailableDialog = UpdateAvailableDialog()
newUpdateAvailableDialog.arguments = newUpdateAvailableDialog.arguments =
bundleOf(IntentData.updateInfo to encodedUpdateInfo) bundleOf(IntentData.updateInfo to updateInfo)
newUpdateAvailableDialog.show( newUpdateAvailableDialog.show(
childFragmentManager, childFragmentManager,
UpdateAvailableDialog::class.java.name UpdateAvailableDialog::class.java.name