mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-26 20:06:37 -08:00
fix: Resolve dependencies and small changes
This commit is contained in:
1 parent
d5310e5c58
commit
65d7fdbf7e
65 files changed
+254
-252
No files matched your search
@@ -23,7 +23,7 @@ import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.element.binary.BinaryByte
|
||||
import com.kunzisoft.keepass.database.element.binary.BinaryData
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
|
||||
|
||||
data class Attachment(var name: String,
|
||||
|
||||
@@ -21,8 +21,8 @@ package com.kunzisoft.keepass.database.element
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readStringParcelableMap
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.writeStringParcelableMap
|
||||
import com.kunzisoft.keepass.utils.readStringParcelableMap
|
||||
import com.kunzisoft.keepass.utils.writeStringParcelableMap
|
||||
import java.util.*
|
||||
|
||||
class CustomData : Parcelable {
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.kunzisoft.keepass.database.element
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
|
||||
class CustomDataItem : Parcelable {
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ package com.kunzisoft.keepass.database.element
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readSerializableCompat
|
||||
import com.kunzisoft.keepass.utils.readSerializableCompat
|
||||
import com.kunzisoft.keepass.utils.readEnum
|
||||
import com.kunzisoft.keepass.utils.writeEnum
|
||||
import org.joda.time.Duration
|
||||
|
||||
@@ -23,7 +23,7 @@ import android.os.Parcel
|
||||
import android.os.ParcelUuid
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseVersioned
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
import java.util.*
|
||||
|
||||
class DeletedObject : Parcelable {
|
||||
|
||||
@@ -36,7 +36,7 @@ import com.kunzisoft.keepass.database.element.node.Type
|
||||
import com.kunzisoft.keepass.model.EntryInfo
|
||||
import com.kunzisoft.keepass.otp.OtpElement
|
||||
import com.kunzisoft.keepass.otp.OtpEntryFields
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.StringUtil.toFormattedColorInt
|
||||
import com.kunzisoft.keepass.utils.StringUtil.toFormattedColorString
|
||||
import java.util.UUID
|
||||
|
||||
@@ -22,7 +22,7 @@ package com.kunzisoft.keepass.database.element
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.element.security.ProtectedString
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
|
||||
class Field : Parcelable {
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import com.kunzisoft.keepass.database.element.icon.IconImage
|
||||
import com.kunzisoft.keepass.database.element.node.*
|
||||
import com.kunzisoft.keepass.model.EntryInfo
|
||||
import com.kunzisoft.keepass.model.GroupInfo
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
import com.kunzisoft.keepass.database.element.node.NodeIdUUID
|
||||
import com.kunzisoft.keepass.database.element.node.NodeKDBInterface
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,11 +36,11 @@ import com.kunzisoft.keepass.database.element.node.NodeIdUUID
|
||||
import com.kunzisoft.keepass.database.element.node.NodeKDBXInterface
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
import com.kunzisoft.keepass.database.element.security.ProtectedString
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readStringIntMap
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readStringParcelableMap
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.writeStringIntMap
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.writeStringParcelableMap
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readStringIntMap
|
||||
import com.kunzisoft.keepass.utils.readStringParcelableMap
|
||||
import com.kunzisoft.keepass.utils.writeStringIntMap
|
||||
import com.kunzisoft.keepass.utils.writeStringParcelableMap
|
||||
import com.kunzisoft.keepass.utils.UnsignedLong
|
||||
import java.util.Date
|
||||
import java.util.UUID
|
||||
|
||||
@@ -27,7 +27,7 @@ import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
import com.kunzisoft.keepass.database.element.node.NodeIdInt
|
||||
import com.kunzisoft.keepass.database.element.node.NodeKDBInterface
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
import java.util.*
|
||||
|
||||
class GroupKDB : GroupVersioned<Int, UUID, GroupKDB, EntryKDB>, NodeKDBInterface {
|
||||
|
||||
@@ -31,8 +31,8 @@ import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
import com.kunzisoft.keepass.database.element.node.NodeIdUUID
|
||||
import com.kunzisoft.keepass.database.element.node.NodeKDBXInterface
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readSerializableCompat
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readSerializableCompat
|
||||
import com.kunzisoft.keepass.utils.UnsignedLong
|
||||
import java.util.*
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ package com.kunzisoft.keepass.database.element.icon
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
|
||||
class IconImage() : IconImageDraw() {
|
||||
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ import android.os.ParcelUuid
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.element.DateInstant
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseVersioned
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
import java.util.UUID
|
||||
|
||||
class IconImageCustom : IconImageDraw {
|
||||
|
||||
@@ -22,7 +22,7 @@ package com.kunzisoft.keepass.database.element.node
|
||||
import android.os.Parcel
|
||||
import android.os.ParcelUuid
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.UuidUtil
|
||||
import java.util.*
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import com.kunzisoft.keepass.database.element.DateInstant
|
||||
import com.kunzisoft.keepass.database.element.entry.EntryVersionedInterface
|
||||
import com.kunzisoft.keepass.database.element.group.GroupVersionedInterface
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImage
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
|
||||
/**
|
||||
* Abstract class who manage Groups and Entries
|
||||
|
||||
@@ -23,8 +23,8 @@ import android.os.ParcelUuid
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseVersioned
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImage
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readListCompat
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readListCompat
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ package com.kunzisoft.keepass.database.element.template
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readEnum
|
||||
import com.kunzisoft.keepass.utils.writeEnum
|
||||
|
||||
|
||||
+2
-2
@@ -21,8 +21,8 @@ package com.kunzisoft.keepass.database.element.template
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.element.DateInstant
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readStringStringMap
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.writeStringStringMap
|
||||
import com.kunzisoft.keepass.utils.readStringStringMap
|
||||
import com.kunzisoft.keepass.utils.writeStringStringMap
|
||||
|
||||
class TemplateAttributeOption() : Parcelable {
|
||||
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ package com.kunzisoft.keepass.database.element.template
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readListCompat
|
||||
import com.kunzisoft.keepass.utils.readListCompat
|
||||
|
||||
class TemplateSection: Parcelable {
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ package com.kunzisoft.keepass.model
|
||||
import android.net.Uri
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readEnum
|
||||
import com.kunzisoft.keepass.utils.writeEnum
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ package com.kunzisoft.keepass.model
|
||||
import android.net.Uri
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readEnum
|
||||
import com.kunzisoft.keepass.utils.writeEnum
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.kunzisoft.keepass.model
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readSerializableCompat
|
||||
import com.kunzisoft.keepass.utils.readSerializableCompat
|
||||
import org.joda.time.DateTime
|
||||
|
||||
data class CreditCard(val cardholder: String?,
|
||||
|
||||
@@ -23,7 +23,7 @@ import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.element.Attachment
|
||||
import com.kunzisoft.keepass.database.element.binary.BinaryByte
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readEnum
|
||||
import com.kunzisoft.keepass.utils.writeEnum
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ import com.kunzisoft.keepass.database.element.template.TemplateField
|
||||
import com.kunzisoft.keepass.otp.OtpElement
|
||||
import com.kunzisoft.keepass.otp.OtpEntryFields
|
||||
import com.kunzisoft.keepass.otp.OtpEntryFields.OTP_TOKEN_FIELD
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readListCompat
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readListCompat
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
import java.util.*
|
||||
|
||||
class EntryInfo : NodeInfo {
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.kunzisoft.keepass.model
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.element.Field
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
|
||||
class FocusedEditField : Parcelable {
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.element.Tags
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageStandard
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageStandard.Companion.FOLDER_ID
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
import java.util.*
|
||||
|
||||
class GroupInfo : NodeInfo {
|
||||
|
||||
@@ -5,7 +5,7 @@ import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.element.CustomData
|
||||
import com.kunzisoft.keepass.database.element.DateInstant
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImage
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
|
||||
open class NodeInfo() : Parcelable {
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.kunzisoft.keepass.model
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
|
||||
import com.kunzisoft.keepass.utils.readParcelableCompat
|
||||
|
||||
data class RegisterInfo(val searchInfo: SearchInfo,
|
||||
val username: String?,
|
||||
|
||||
@@ -27,180 +27,187 @@ import android.os.Parcelable
|
||||
import java.io.Serializable
|
||||
import java.util.*
|
||||
|
||||
object ParcelableUtil {
|
||||
// -------- Intent --------
|
||||
inline fun <reified T : Parcelable> Intent.getParcelableExtraCompat(key: String?): T? = when {
|
||||
key == null -> null
|
||||
SDK_INT >= 33 -> getParcelableExtra(key, T::class.java)
|
||||
else -> @Suppress("DEPRECATION") getParcelableExtra(key) as? T
|
||||
}
|
||||
|
||||
inline fun <reified T : Parcelable> Intent.getParcelableExtraCompat(key: String?): T? = when {
|
||||
key == null -> null
|
||||
SDK_INT >= 33 -> getParcelableExtra(key, T::class.java)
|
||||
else -> @Suppress("DEPRECATION") getParcelableExtra(key) as? T
|
||||
inline fun <reified T : Serializable> Intent.getSerializableExtraCompat(key: String?): T? = when {
|
||||
key == null -> null
|
||||
SDK_INT >= 33 -> getSerializableExtra(key, T::class.java)
|
||||
else -> @Suppress("DEPRECATION") getSerializableExtra(key) as? T
|
||||
}
|
||||
|
||||
inline fun <reified E : Parcelable> Intent.putParcelableList(key: String?, list: MutableList<E>) {
|
||||
putExtra(key, list.toTypedArray())
|
||||
}
|
||||
|
||||
inline fun <reified E : Parcelable> Intent.getParcelableList(key: String?): MutableList<E>? = when {
|
||||
SDK_INT >= 33 -> getParcelableArrayExtra(key, E::class.java)?.toMutableList()
|
||||
else -> @Suppress("DEPRECATION", "UNCHECKED_CAST") (getParcelableArrayExtra(key) as? Array<E>)?.toMutableList()
|
||||
}
|
||||
|
||||
inline fun <reified T : Enum<T>> Intent.getEnumExtra(key: String?) =
|
||||
getStringExtra(key)?.let { enumValueOf<T>(it) }
|
||||
|
||||
fun <T : Enum<T>> Intent.putEnumExtra(key: String?, value: T?) =
|
||||
putExtra(key, value?.name)
|
||||
|
||||
// -------- Bundle --------
|
||||
inline fun <reified T : Parcelable> Bundle.getParcelableCompat(key: String?): T? = when {
|
||||
key == null -> null
|
||||
SDK_INT >= 33 -> getParcelable(key, T::class.java)
|
||||
else -> @Suppress("DEPRECATION") getParcelable(key) as? T
|
||||
}
|
||||
|
||||
inline fun <reified T : Serializable> Bundle.getSerializableCompat(key: String?): T? = when {
|
||||
SDK_INT >= 33 -> getSerializable(key, T::class.java)
|
||||
else -> @Suppress("DEPRECATION") getSerializable(key) as? T
|
||||
}
|
||||
|
||||
inline fun <reified T : Parcelable> Bundle.getParcelableArrayCompat(key: String?): Array<out T>? {
|
||||
return when {
|
||||
SDK_INT >= 33 -> getParcelableArray(key, T::class.java)
|
||||
else -> @Suppress("DEPRECATION", "UNCHECKED_CAST") (getParcelableArray(key) as? Array<T>)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified T : Serializable> Intent.getSerializableExtraCompat(key: String?): T? = when {
|
||||
key == null -> null
|
||||
SDK_INT >= 33 -> getSerializableExtra(key, T::class.java)
|
||||
else -> @Suppress("DEPRECATION") getSerializableExtra(key) as? T
|
||||
inline fun <reified E : Parcelable> Bundle.putParcelableList(key: String?, list: List<E>) {
|
||||
putParcelableArray(key, list.toTypedArray())
|
||||
}
|
||||
|
||||
inline fun <reified E : Parcelable> Bundle.getParcelableList(key: String?): MutableList<E>? = when {
|
||||
SDK_INT >= 33 -> getParcelableArray(key, E::class.java)?.toMutableList()
|
||||
else -> @Suppress("DEPRECATION", "UNCHECKED_CAST") (getParcelableArray(key) as? Array<E>)?.toMutableList()
|
||||
}
|
||||
|
||||
// -------- Parcel --------
|
||||
|
||||
inline fun <reified T : Parcelable> Parcel.readParcelableCompat(): T? = when {
|
||||
SDK_INT >= 33 -> readParcelable(T::class.java.classLoader, T::class.java)
|
||||
else -> @Suppress("DEPRECATION") readParcelable(T::class.java.classLoader) as? T
|
||||
}
|
||||
|
||||
fun <T> Parcel.readParcelableCompat(clazz: Class<T>): T? = when {
|
||||
SDK_INT >= 33 -> readParcelable(clazz.classLoader, clazz)
|
||||
else -> @Suppress("DEPRECATION") readParcelable(clazz.classLoader) as? T
|
||||
}
|
||||
|
||||
inline fun <reified T : Serializable> Parcel.readSerializableCompat(): T? = when {
|
||||
SDK_INT >= 33 -> readSerializable(T::class.java.classLoader, T::class.java)
|
||||
else -> @Suppress("DEPRECATION") readSerializable() as? T
|
||||
}
|
||||
|
||||
inline fun <reified T> Parcel.readListCompat(outVal: MutableList<T>) {
|
||||
when {
|
||||
SDK_INT >= 33 -> readList(outVal, T::class.java.classLoader, T::class.java)
|
||||
else -> @Suppress("DEPRECATION") readList(outVal, T::class.java.classLoader)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified T : Parcelable> Bundle.getParcelableCompat(key: String?): T? = when {
|
||||
key == null -> null
|
||||
SDK_INT >= 33 -> getParcelable(key, T::class.java)
|
||||
else -> @Suppress("DEPRECATION") getParcelable(key) as? T
|
||||
// For writing to a Parcel
|
||||
fun <K : Parcelable, V : Parcelable> Parcel.writeParcelableMap(map: Map<K, V>, flags: Int) {
|
||||
writeInt(map.size)
|
||||
for ((key, value) in map) {
|
||||
writeParcelable(key, flags)
|
||||
writeParcelable(value, flags)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified T : Serializable> Bundle.getSerializableCompat(key: String?): T? = when {
|
||||
SDK_INT >= 33 -> getSerializable(key, T::class.java)
|
||||
else -> @Suppress("DEPRECATION") getSerializable(key) as? T
|
||||
// For reading from a Parcel
|
||||
inline fun <reified K : Parcelable, reified V : Parcelable> Parcel.readParcelableMap(): Map<K, V> {
|
||||
val size = readInt()
|
||||
val map = HashMap<K, V>(size)
|
||||
for (i in 0 until size) {
|
||||
val key: K? = try {
|
||||
when {
|
||||
SDK_INT >= 33 -> readParcelable(K::class.java.classLoader, K::class.java)
|
||||
else -> @Suppress("DEPRECATION") readParcelable(K::class.java.classLoader)
|
||||
}
|
||||
} catch (e: Exception) { null }
|
||||
val value: V? = try {
|
||||
when {
|
||||
SDK_INT >= 33 -> readParcelable(V::class.java.classLoader, V::class.java)
|
||||
else -> @Suppress("DEPRECATION") readParcelable(V::class.java.classLoader)
|
||||
}
|
||||
} catch (e: Exception) { null }
|
||||
if (key != null && value != null)
|
||||
map[key] = value
|
||||
}
|
||||
return map
|
||||
}
|
||||
|
||||
inline fun <reified T : Parcelable> Bundle.getParcelableArrayCompat(key: String?): Array<out T>? {
|
||||
return when {
|
||||
SDK_INT >= 33 -> getParcelableArray(key, T::class.java)
|
||||
else -> @Suppress("DEPRECATION", "UNCHECKED_CAST") (getParcelableArray(key) as? Array<T>)
|
||||
}
|
||||
// For writing map with string key to a Parcel
|
||||
fun <V : Parcelable> Parcel.writeStringParcelableMap(map: HashMap<String, V>, flags: Int) {
|
||||
writeInt(map.size)
|
||||
for ((key, value) in map) {
|
||||
writeString(key)
|
||||
writeParcelable(value, flags)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified E : Parcelable> Intent.putParcelableList(key: String?, list: MutableList<E>) {
|
||||
putExtra(key, list.toTypedArray())
|
||||
// For reading map with string key from a Parcel
|
||||
inline fun <reified V : Parcelable> Parcel.readStringParcelableMap(): LinkedHashMap<String, V> {
|
||||
val size = readInt()
|
||||
val map = LinkedHashMap<String, V>(size)
|
||||
for (i in 0 until size) {
|
||||
val key: String? = readString()
|
||||
val value: V? = try {
|
||||
when {
|
||||
SDK_INT >= 33 -> readParcelable(V::class.java.classLoader, V::class.java)
|
||||
else -> @Suppress("DEPRECATION") readParcelable(V::class.java.classLoader)
|
||||
}
|
||||
} catch (e: Exception) { null }
|
||||
if (key != null && value != null)
|
||||
map[key] = value
|
||||
}
|
||||
return map
|
||||
}
|
||||
|
||||
inline fun <reified E : Parcelable> Intent.getParcelableList(key: String?): MutableList<E>? = when {
|
||||
SDK_INT >= 33 -> getParcelableArrayExtra(key, E::class.java)?.toMutableList()
|
||||
else -> @Suppress("DEPRECATION", "UNCHECKED_CAST") (getParcelableArrayExtra(key) as? Array<E>)?.toMutableList()
|
||||
// For writing map with string key and Int value to a Parcel
|
||||
fun Parcel.writeStringIntMap(map: LinkedHashMap<String, Int>) {
|
||||
writeInt(map.size)
|
||||
for ((key, value) in map) {
|
||||
writeString(key)
|
||||
writeInt(value)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified E : Parcelable> Bundle.putParcelableList(key: String?, list: List<E>) {
|
||||
putParcelableArray(key, list.toTypedArray())
|
||||
// For reading map with string key and Int value from a Parcel
|
||||
fun Parcel.readStringIntMap(): LinkedHashMap<String, Int> {
|
||||
val size = readInt()
|
||||
val map = LinkedHashMap<String, Int>(size)
|
||||
for (i in 0 until size) {
|
||||
val key: String? = readString()
|
||||
val value: Int = readInt()
|
||||
if (key != null)
|
||||
map[key] = value
|
||||
}
|
||||
return map
|
||||
}
|
||||
|
||||
inline fun <reified E : Parcelable> Bundle.getParcelableList(key: String?): MutableList<E>? = when {
|
||||
SDK_INT >= 33 -> getParcelableArray(key, E::class.java)?.toMutableList()
|
||||
else -> @Suppress("DEPRECATION", "UNCHECKED_CAST") (getParcelableArray(key) as? Array<E>)?.toMutableList()
|
||||
|
||||
// For writing map with string key and string value to a Parcel
|
||||
fun Parcel.writeStringStringMap(map: MutableMap<String, String>) {
|
||||
writeInt(map.size)
|
||||
for ((key, value) in map) {
|
||||
writeString(key)
|
||||
writeString(value)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified T : Parcelable> Parcel.readParcelableCompat(): T? = when {
|
||||
SDK_INT >= 33 -> readParcelable(T::class.java.classLoader, T::class.java)
|
||||
else -> @Suppress("DEPRECATION") readParcelable(T::class.java.classLoader) as? T
|
||||
}
|
||||
|
||||
fun <T> Parcel.readParcelableCompat(clazz: Class<T>): T? = when {
|
||||
SDK_INT >= 33 -> readParcelable(clazz.classLoader, clazz)
|
||||
else -> @Suppress("DEPRECATION") readParcelable(clazz.classLoader) as? T
|
||||
}
|
||||
|
||||
inline fun <reified T : Serializable> Parcel.readSerializableCompat(): T? = when {
|
||||
SDK_INT >= 33 -> readSerializable(T::class.java.classLoader, T::class.java)
|
||||
else -> @Suppress("DEPRECATION") readSerializable() as? T
|
||||
}
|
||||
|
||||
inline fun <reified T> Parcel.readListCompat(outVal: MutableList<T>) {
|
||||
when {
|
||||
SDK_INT >= 33 -> readList(outVal, T::class.java.classLoader, T::class.java)
|
||||
else -> @Suppress("DEPRECATION") readList(outVal, T::class.java.classLoader)
|
||||
}
|
||||
}
|
||||
|
||||
// For writing to a Parcel
|
||||
fun <K : Parcelable, V : Parcelable> Parcel.writeParcelableMap(map: Map<K, V>, flags: Int) {
|
||||
writeInt(map.size)
|
||||
for ((key, value) in map) {
|
||||
writeParcelable(key, flags)
|
||||
writeParcelable(value, flags)
|
||||
}
|
||||
}
|
||||
|
||||
// For reading from a Parcel
|
||||
inline fun <reified K : Parcelable, reified V : Parcelable> Parcel.readParcelableMap(): Map<K, V> {
|
||||
val size = readInt()
|
||||
val map = HashMap<K, V>(size)
|
||||
for (i in 0 until size) {
|
||||
val key: K? = try {
|
||||
when {
|
||||
SDK_INT >= 33 -> readParcelable(K::class.java.classLoader, K::class.java)
|
||||
else -> @Suppress("DEPRECATION") readParcelable(K::class.java.classLoader)
|
||||
}
|
||||
} catch (e: Exception) { null }
|
||||
val value: V? = try {
|
||||
when {
|
||||
SDK_INT >= 33 -> readParcelable(V::class.java.classLoader, V::class.java)
|
||||
else -> @Suppress("DEPRECATION") readParcelable(V::class.java.classLoader)
|
||||
}
|
||||
} catch (e: Exception) { null }
|
||||
if (key != null && value != null)
|
||||
map[key] = value
|
||||
}
|
||||
return map
|
||||
}
|
||||
|
||||
// For writing map with string key to a Parcel
|
||||
fun <V : Parcelable> Parcel.writeStringParcelableMap(map: HashMap<String, V>, flags: Int) {
|
||||
writeInt(map.size)
|
||||
for ((key, value) in map) {
|
||||
writeString(key)
|
||||
writeParcelable(value, flags)
|
||||
}
|
||||
}
|
||||
|
||||
// For reading map with string key from a Parcel
|
||||
inline fun <reified V : Parcelable> Parcel.readStringParcelableMap(): LinkedHashMap<String, V> {
|
||||
val size = readInt()
|
||||
val map = LinkedHashMap<String, V>(size)
|
||||
for (i in 0 until size) {
|
||||
val key: String? = readString()
|
||||
val value: V? = try {
|
||||
when {
|
||||
SDK_INT >= 33 -> readParcelable(V::class.java.classLoader, V::class.java)
|
||||
else -> @Suppress("DEPRECATION") readParcelable(V::class.java.classLoader)
|
||||
}
|
||||
} catch (e: Exception) { null }
|
||||
if (key != null && value != null)
|
||||
map[key] = value
|
||||
}
|
||||
return map
|
||||
}
|
||||
|
||||
// For writing map with string key and Int value to a Parcel
|
||||
fun Parcel.writeStringIntMap(map: LinkedHashMap<String, Int>) {
|
||||
writeInt(map.size)
|
||||
for ((key, value) in map) {
|
||||
writeString(key)
|
||||
writeInt(value)
|
||||
}
|
||||
}
|
||||
|
||||
// For reading map with string key and Int value from a Parcel
|
||||
fun Parcel.readStringIntMap(): LinkedHashMap<String, Int> {
|
||||
val size = readInt()
|
||||
val map = LinkedHashMap<String, Int>(size)
|
||||
for (i in 0 until size) {
|
||||
val key: String? = readString()
|
||||
val value: Int = readInt()
|
||||
if (key != null)
|
||||
map[key] = value
|
||||
}
|
||||
return map
|
||||
}
|
||||
|
||||
|
||||
// For writing map with string key and string value to a Parcel
|
||||
fun Parcel.writeStringStringMap(map: MutableMap<String, String>) {
|
||||
writeInt(map.size)
|
||||
for ((key, value) in map) {
|
||||
writeString(key)
|
||||
writeString(value)
|
||||
}
|
||||
}
|
||||
|
||||
fun Parcel.readStringStringMap(): LinkedHashMap<String, String> {
|
||||
val size = readInt()
|
||||
val map = LinkedHashMap<String, String>(size)
|
||||
for (i in 0 until size) {
|
||||
val key: String? = readString()
|
||||
val value: String? = readString()
|
||||
if (key != null && value != null)
|
||||
map[key] = value
|
||||
}
|
||||
return map
|
||||
fun Parcel.readStringStringMap(): LinkedHashMap<String, String> {
|
||||
val size = readInt()
|
||||
val map = LinkedHashMap<String, String>(size)
|
||||
for (i in 0 until size) {
|
||||
val key: String? = readString()
|
||||
val value: String? = readString()
|
||||
if (key != null && value != null)
|
||||
map[key] = value
|
||||
}
|
||||
return map
|
||||
}
|
||||
|
||||
fun Parcel.readByteArrayCompat(): ByteArray? {
|
||||
@@ -223,14 +230,8 @@ fun Parcel.writeByteArrayCompat(data: ByteArray?) {
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified T : Enum<T>> Intent.getEnumExtra(key: String?) =
|
||||
getStringExtra(key)?.let { enumValueOf<T>(it) }
|
||||
|
||||
fun <T : Enum<T>> Intent.putEnumExtra(key: String?, value: T?) =
|
||||
putExtra(key, value?.name)
|
||||
|
||||
inline fun <reified T : Enum<T>> Parcel.readEnum() =
|
||||
readString()?.let { enumValueOf<T>(it) }
|
||||
readString()?.let { enumValueOf<T>(it) }
|
||||
|
||||
fun <T : Enum<T>> Parcel.writeEnum(value: T?) =
|
||||
writeString(value?.name)
|
||||
writeString(value?.name)
|
||||
Reference in new issue
Block a user