[Android] Change SparseBooleanArrayParcelable implementation to Parcelize
Nicolas Pomepuy
git at videolan.org
Fri Aug 2 14:35:42 CEST 2019
vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Thu Aug 1 10:01:12 2019 +0200| [8de88d926dab32a942ac78cbe931399580676791] | committer: Nicolas Pomepuy
Change SparseBooleanArrayParcelable implementation to Parcelize
> https://code.videolan.org/videolan/vlc-android/commit/8de88d926dab32a942ac78cbe931399580676791
---
.../vlc/gui/browser/MediaBrowserFragment.kt | 2 +-
.../gui/helpers/SparseBooleanArrayParcelable.kt | 58 ++--------------------
2 files changed, 4 insertions(+), 56 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt b/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt
index c972a5321..1e135e5a1 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt
@@ -97,7 +97,7 @@ abstract class MediaBrowserFragment<T : SortableModel> : Fragment(), ActionMode.
mediaLibrary = AbstractMedialibrary.getInstance()
setHasOptionsMenu(!AndroidDevices.isAndroidTv)
if (savedInstanceState?.keySet()?.contains(KEY_SELECTION) == true) {
- savedSelection = savedInstanceState.getParcelable(KEY_SELECTION) as SparseBooleanArrayParcelable
+ savedSelection = (savedInstanceState.getParcelable(KEY_SELECTION) as SparseBooleanArrayParcelable).data
}
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/SparseBooleanArrayParcelable.kt b/vlc-android/src/org/videolan/vlc/gui/helpers/SparseBooleanArrayParcelable.kt
index 7e47b1bc7..de89b882c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/SparseBooleanArrayParcelable.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/SparseBooleanArrayParcelable.kt
@@ -1,60 +1,8 @@
package org.videolan.vlc.gui.helpers
-import android.os.Parcel
import android.os.Parcelable
import android.util.SparseBooleanArray
+import kotlinx.android.parcel.Parcelize
-class SparseBooleanArrayParcelable : SparseBooleanArray, Parcelable {
-
- constructor()
-
- constructor(sparseBooleanArray: SparseBooleanArray) {
- for (i in 0 until sparseBooleanArray.size()) {
- this.put(sparseBooleanArray.keyAt(i), sparseBooleanArray.valueAt(i))
- }
- }
-
- override fun describeContents(): Int {
- return 0
- }
-
- override fun writeToParcel(dest: Parcel, flags: Int) {
- val keys = IntArray(size())
- val values = BooleanArray(size())
-
- for (i in 0 until size()) {
- keys[i] = keyAt(i)
- values[i] = valueAt(i)
- }
-
- dest.writeInt(size())
- dest.writeIntArray(keys)
- dest.writeBooleanArray(values)
- }
-
- companion object {
- @JvmField
- var CREATOR: Parcelable.Creator<SparseBooleanArrayParcelable> = object : Parcelable.Creator<SparseBooleanArrayParcelable> {
- override fun createFromParcel(source: Parcel): SparseBooleanArrayParcelable {
- val read = SparseBooleanArrayParcelable()
- val size = source.readInt()
-
- val keys = IntArray(size)
- val values = BooleanArray(size)
-
- source.readIntArray(keys)
- source.readBooleanArray(values)
-
- for (i in 0 until size) {
- read.put(keys[i], values[i])
- }
-
- return read
- }
-
- override fun newArray(size: Int): Array<SparseBooleanArrayParcelable?> {
- return arrayOfNulls(size)
- }
- }
- }
-}
\ No newline at end of file
+ at Parcelize
+class SparseBooleanArrayParcelable(val data: SparseBooleanArray) : Parcelable
\ No newline at end of file
More information about the Android
mailing list