refactor: Implement Parcelable in UpdateInfo

This commit is contained in:
Isira Seneviratne 2023-09-08 20:17:41 +05:30
parent 2b377db9ef
commit 4f1375a63d
3 changed files with 7 additions and 8 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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