Migrate to versionedparcelable
This commit is contained in:
@@ -75,7 +75,7 @@ class EBegFragment : DialogFragment(), PurchasesUpdatedListener, BillingClientSt
|
||||
val fragmentManager = fragmentManager
|
||||
if (fragmentManager == null) SmartSnackbar.make(message).show() else try {
|
||||
MessageDialogFragment().apply {
|
||||
arguments = bundleOf(Pair(KEY_TITLE, title), Pair(KEY_MESSAGE, message))
|
||||
arguments = bundleOf(KEY_TITLE to title, KEY_MESSAGE to message)
|
||||
}.show(fragmentManager, "MessageDialogFragment")
|
||||
} catch (e: IllegalStateException) {
|
||||
SmartSnackbar.make(message).show()
|
||||
|
||||
@@ -23,6 +23,7 @@ import androidx.recyclerview.widget.DefaultItemAnimator
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.versionedparcelable.ParcelUtils
|
||||
import be.mygod.vpnhotspot.AlertDialogFragment
|
||||
import be.mygod.vpnhotspot.App.Companion.app
|
||||
import be.mygod.vpnhotspot.R
|
||||
@@ -73,7 +74,7 @@ class ClientsFragment : Fragment() {
|
||||
}
|
||||
|
||||
private val title by lazy { arguments!!.getCharSequence(KEY_TITLE)!! }
|
||||
private val stats by lazy { arguments!!.getParcelable<ClientStats>(KEY_STATS)!! }
|
||||
private val stats by lazy { ParcelUtils.getVersionedParcelable<ClientStats>(arguments, KEY_STATS)!! }
|
||||
|
||||
override fun AlertDialog.Builder.prepare(listener: DialogInterface.OnClickListener) {
|
||||
setTitle(getString(R.string.clients_stats_title, title))
|
||||
@@ -143,9 +144,10 @@ class ClientsFragment : Fragment() {
|
||||
R.id.stats -> {
|
||||
val client = binding.client ?: return false
|
||||
StatsDialogFragment().apply {
|
||||
arguments = bundleOf(Pair(StatsDialogFragment.KEY_TITLE, client.title),
|
||||
Pair(StatsDialogFragment.KEY_STATS,
|
||||
AppDatabase.instance.trafficRecordDao.queryStats(client.mac.macToLong())))
|
||||
arguments = bundleOf(StatsDialogFragment.KEY_TITLE to client.title).apply {
|
||||
ParcelUtils.putVersionedParcelable(this, StatsDialogFragment.KEY_STATS,
|
||||
AppDatabase.instance.trafficRecordDao.queryStats(client.mac.macToLong()))
|
||||
}
|
||||
}.show(fragmentManager ?: return false, "StatsDialogFragment")
|
||||
true
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package be.mygod.vpnhotspot.room
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import androidx.room.*
|
||||
import androidx.versionedparcelable.VersionedParcelable
|
||||
import java.net.InetAddress
|
||||
|
||||
@Entity(foreignKeys = [ForeignKey(entity = TrafficRecord::class, parentColumns = ["id"], childColumns = ["previousId"],
|
||||
@@ -69,29 +68,4 @@ data class ClientStats(
|
||||
val sentBytes: Long = 0,
|
||||
val receivedPackets: Long = 0,
|
||||
val receivedBytes: Long = 0
|
||||
) : Parcelable {
|
||||
constructor(parcel: Parcel) : this(
|
||||
parcel.readLong(),
|
||||
parcel.readLong(),
|
||||
parcel.readLong(),
|
||||
parcel.readLong(),
|
||||
parcel.readLong(),
|
||||
parcel.readLong())
|
||||
|
||||
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
||||
parcel.writeLong(timestamp)
|
||||
parcel.writeLong(count)
|
||||
parcel.writeLong(sentPackets)
|
||||
parcel.writeLong(sentBytes)
|
||||
parcel.writeLong(receivedPackets)
|
||||
parcel.writeLong(receivedBytes)
|
||||
}
|
||||
|
||||
override fun describeContents() = 0
|
||||
|
||||
companion object CREATOR : Parcelable.Creator<ClientStats> {
|
||||
override fun createFromParcel(parcel: Parcel) = ClientStats(parcel)
|
||||
|
||||
override fun newArray(size: Int) = arrayOfNulls<ClientStats>(size)
|
||||
}
|
||||
}
|
||||
) : VersionedParcelable
|
||||
|
||||
Reference in New Issue
Block a user