mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
refactor: Implement Parcelable in UpdateInfo
This commit is contained in:
parent
2b377db9ef
commit
4f1375a63d
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user