mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +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
|
package com.github.libretube.obj.update
|
||||||
|
|
||||||
|
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(
|
||||||
@SerialName("html_url") val htmlUrl: String,
|
@SerialName("html_url") val htmlUrl: String,
|
||||||
val name: String
|
val name: String
|
||||||
)
|
) : Parcelable
|
||||||
|
@ -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 {
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user