From 2b377db9efe5d34c6f3be4bd2c52ec20a054fb24 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Fri, 8 Sep 2023 20:15:08 +0530 Subject: [PATCH 1/2] refactor: Remove unused UpdateInfo properties --- .../com/github/libretube/obj/update/Asset.kt | 24 ----------------- .../github/libretube/obj/update/Reactions.kt | 16 ------------ .../github/libretube/obj/update/UpdateInfo.kt | 21 +-------------- .../com/github/libretube/obj/update/User.kt | 26 ------------------- 4 files changed, 1 insertion(+), 86 deletions(-) delete mode 100644 app/src/main/java/com/github/libretube/obj/update/Asset.kt delete mode 100644 app/src/main/java/com/github/libretube/obj/update/Reactions.kt delete mode 100644 app/src/main/java/com/github/libretube/obj/update/User.kt diff --git a/app/src/main/java/com/github/libretube/obj/update/Asset.kt b/app/src/main/java/com/github/libretube/obj/update/Asset.kt deleted file mode 100644 index 19102970f..000000000 --- a/app/src/main/java/com/github/libretube/obj/update/Asset.kt +++ /dev/null @@ -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 -) diff --git a/app/src/main/java/com/github/libretube/obj/update/Reactions.kt b/app/src/main/java/com/github/libretube/obj/update/Reactions.kt deleted file mode 100644 index 01cfdc21e..000000000 --- a/app/src/main/java/com/github/libretube/obj/update/Reactions.kt +++ /dev/null @@ -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 -) diff --git a/app/src/main/java/com/github/libretube/obj/update/UpdateInfo.kt b/app/src/main/java/com/github/libretube/obj/update/UpdateInfo.kt index 6d166add7..33100ef07 100644 --- a/app/src/main/java/com/github/libretube/obj/update/UpdateInfo.kt +++ b/app/src/main/java/com/github/libretube/obj/update/UpdateInfo.kt @@ -1,29 +1,10 @@ package com.github.libretube.obj.update -import kotlinx.datetime.Instant import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable data class UpdateInfo( - val assets: List = 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, - val id: Int, - @SerialName("mentions_count") val mentionsCount: Int, - 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 + val name: String ) diff --git a/app/src/main/java/com/github/libretube/obj/update/User.kt b/app/src/main/java/com/github/libretube/obj/update/User.kt deleted file mode 100644 index b2103e904..000000000 --- a/app/src/main/java/com/github/libretube/obj/update/User.kt +++ /dev/null @@ -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 -) From 4f1375a63d730bc907b905b61838588a860808b6 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Fri, 8 Sep 2023 20:17:41 +0530 Subject: [PATCH 2/2] refactor: Implement Parcelable in UpdateInfo --- .../java/com/github/libretube/obj/update/UpdateInfo.kt | 5 ++++- .../github/libretube/ui/dialogs/UpdateAvailableDialog.kt | 7 ++----- .../com/github/libretube/ui/preferences/MainSettings.kt | 3 +-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/github/libretube/obj/update/UpdateInfo.kt b/app/src/main/java/com/github/libretube/obj/update/UpdateInfo.kt index 33100ef07..175d54a7e 100644 --- a/app/src/main/java/com/github/libretube/obj/update/UpdateInfo.kt +++ b/app/src/main/java/com/github/libretube/obj/update/UpdateInfo.kt @@ -1,10 +1,13 @@ package com.github.libretube.obj.update +import android.os.Parcelable +import kotlinx.parcelize.Parcelize import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable +@Parcelize data class UpdateInfo( @SerialName("html_url") val htmlUrl: String, val name: String -) +) : Parcelable diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/UpdateAvailableDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/UpdateAvailableDialog.kt index a439889b0..33594a4ef 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/UpdateAvailableDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/UpdateAvailableDialog.kt @@ -7,19 +7,16 @@ import androidx.core.net.toUri import androidx.fragment.app.DialogFragment import com.github.libretube.R import com.github.libretube.constants.IntentData +import com.github.libretube.extensions.parcelable import com.github.libretube.obj.update.UpdateInfo import com.google.android.material.dialog.MaterialAlertDialogBuilder -import kotlinx.serialization.json.Json class UpdateAvailableDialog : DialogFragment() { private lateinit var updateInfo: UpdateInfo override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - arguments?.let { - val encodedString = it.getString(IntentData.updateInfo)!! - updateInfo = Json.decodeFromString(encodedString) - } + updateInfo = requireArguments().parcelable(IntentData.updateInfo)!! } override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { diff --git a/app/src/main/java/com/github/libretube/ui/preferences/MainSettings.kt b/app/src/main/java/com/github/libretube/ui/preferences/MainSettings.kt index 91b5edc87..0d6c7de7d 100644 --- a/app/src/main/java/com/github/libretube/ui/preferences/MainSettings.kt +++ b/app/src/main/java/com/github/libretube/ui/preferences/MainSettings.kt @@ -52,10 +52,9 @@ class MainSettings : BasePreferenceFragment() { if (BuildConfig.VERSION_NAME != updateInfo.name) { // show the UpdateAvailableDialog if there's an update available - val encodedUpdateInfo = Json.encodeToString(updateInfo) val newUpdateAvailableDialog = UpdateAvailableDialog() newUpdateAvailableDialog.arguments = - bundleOf(IntentData.updateInfo to encodedUpdateInfo) + bundleOf(IntentData.updateInfo to updateInfo) newUpdateAvailableDialog.show( childFragmentManager, UpdateAvailableDialog::class.java.name