diff --git a/database/src/main/java/com/kunzisoft/keepass/database/element/Group.kt b/database/src/main/java/com/kunzisoft/keepass/database/element/Group.kt index 005c2dc27..5d38dd9ff 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/element/Group.kt +++ b/database/src/main/java/com/kunzisoft/keepass/database/element/Group.kt @@ -29,7 +29,9 @@ 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.readBooleanCompat import com.kunzisoft.keepass.utils.readParcelableCompat +import com.kunzisoft.keepass.utils.writeBooleanCompat import java.util.* import kotlin.collections.ArrayList @@ -78,7 +80,7 @@ class Group : Node, GroupVersionedInterface { constructor(parcel: Parcel) { groupKDB = parcel.readParcelableCompat() groupKDBX = parcel.readParcelableCompat() - isVirtual = parcel.readByte().toInt() != 0 + isVirtual = parcel.readBooleanCompat() } enum class ChildFilter { @@ -112,7 +114,7 @@ class Group : Node, GroupVersionedInterface { override fun writeToParcel(dest: Parcel, flags: Int) { dest.writeParcelable(groupKDB, flags) dest.writeParcelable(groupKDBX, flags) - dest.writeByte((if (isVirtual) 1 else 0).toByte()) + dest.writeBooleanCompat(isVirtual) } override val nodeId: NodeId<*> diff --git a/database/src/main/java/com/kunzisoft/keepass/database/element/binary/BinaryData.kt b/database/src/main/java/com/kunzisoft/keepass/database/element/binary/BinaryData.kt index 0a8ec4a0f..977b0d046 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/element/binary/BinaryData.kt +++ b/database/src/main/java/com/kunzisoft/keepass/database/element/binary/BinaryData.kt @@ -24,6 +24,8 @@ import android.content.Context import android.os.Parcel import android.os.Parcelable import android.util.Base64 +import com.kunzisoft.keepass.utils.readBooleanCompat +import com.kunzisoft.keepass.utils.writeBooleanCompat import org.apache.commons.io.output.CountingOutputStream import java.io.IOException import java.io.InputStream @@ -51,17 +53,17 @@ abstract class BinaryData : Parcelable { } protected constructor(parcel: Parcel) { - isCompressed = parcel.readByte().toInt() != 0 - isProtected = parcel.readByte().toInt() != 0 - isCorrupted = parcel.readByte().toInt() != 0 + isCompressed = parcel.readBooleanCompat() + isProtected = parcel.readBooleanCompat() + isCorrupted = parcel.readBooleanCompat() mLength = parcel.readLong() mBinaryHash = parcel.readInt() } override fun writeToParcel(dest: Parcel, flags: Int) { - dest.writeByte((if (isCompressed) 1 else 0).toByte()) - dest.writeByte((if (isProtected) 1 else 0).toByte()) - dest.writeByte((if (isCorrupted) 1 else 0).toByte()) + dest.writeBooleanCompat(isCompressed) + dest.writeBooleanCompat(isProtected) + dest.writeBooleanCompat(isCorrupted) dest.writeLong(mLength) dest.writeInt(mBinaryHash) } diff --git a/database/src/main/java/com/kunzisoft/keepass/database/element/entry/AutoType.kt b/database/src/main/java/com/kunzisoft/keepass/database/element/entry/AutoType.kt index 3c550db31..c9aa35303 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/element/entry/AutoType.kt +++ b/database/src/main/java/com/kunzisoft/keepass/database/element/entry/AutoType.kt @@ -22,6 +22,8 @@ package com.kunzisoft.keepass.database.element.entry import android.os.Parcel import android.os.Parcelable import com.kunzisoft.keepass.utils.UnsignedInt +import com.kunzisoft.keepass.utils.readBooleanCompat +import com.kunzisoft.keepass.utils.writeBooleanCompat class AutoType : Parcelable { @@ -41,7 +43,7 @@ class AutoType : Parcelable { } constructor(parcel: Parcel) { - this.enabled = parcel.readByte().toInt() != 0 + this.enabled = parcel.readBooleanCompat() this.obfuscationOptions = UnsignedInt(parcel.readInt()) this.defaultSequence = parcel.readString() ?: defaultSequence parcel.readTypedList(this.windowSeqPairs, AutoTypeItem.CREATOR) @@ -52,7 +54,7 @@ class AutoType : Parcelable { } override fun writeToParcel(dest: Parcel, flags: Int) { - dest.writeByte((if (enabled) 1 else 0).toByte()) + dest.writeBooleanCompat(enabled) dest.writeInt(obfuscationOptions.toKotlinInt()) dest.writeString(defaultSequence) dest.writeTypedList(windowSeqPairs) diff --git a/database/src/main/java/com/kunzisoft/keepass/database/element/group/GroupKDBX.kt b/database/src/main/java/com/kunzisoft/keepass/database/element/group/GroupKDBX.kt index eaff4f786..c08d79d72 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/element/group/GroupKDBX.kt +++ b/database/src/main/java/com/kunzisoft/keepass/database/element/group/GroupKDBX.kt @@ -34,6 +34,8 @@ import com.kunzisoft.keepass.database.element.node.Type import com.kunzisoft.keepass.utils.readParcelableCompat import com.kunzisoft.keepass.utils.readSerializableCompat import com.kunzisoft.keepass.utils.UnsignedLong +import com.kunzisoft.keepass.utils.readBooleanCompat +import com.kunzisoft.keepass.utils.writeBooleanCompat import java.util.* class GroupKDBX : GroupVersioned, NodeKDBXInterface { @@ -70,7 +72,7 @@ class GroupKDBX : GroupVersioned, NodeKDBXInte locationChanged = parcel.readParcelableCompat() ?: locationChanged customData = parcel.readParcelableCompat() ?: CustomData() notes = parcel.readString() ?: notes - isExpanded = parcel.readByte().toInt() != 0 + isExpanded = parcel.readBooleanCompat() val isSearchingEnabled = parcel.readInt() enableSearching = if (isSearchingEnabled == -1) null else isSearchingEnabled == 1 val isAutoTypeEnabled = parcel.readInt() @@ -95,7 +97,7 @@ class GroupKDBX : GroupVersioned, NodeKDBXInte dest.writeParcelable(locationChanged, flags) dest.writeParcelable(customData, flags) dest.writeString(notes) - dest.writeByte((if (isExpanded) 1 else 0).toByte()) + dest.writeBooleanCompat(isExpanded) dest.writeInt(if (enableSearching == null) -1 else if (enableSearching!!) 1 else 0) dest.writeInt(if (enableAutoType == null) -1 else if (enableAutoType!!) 1 else 0) dest.writeString(defaultAutoTypeSequence) diff --git a/database/src/main/java/com/kunzisoft/keepass/database/element/node/NodeVersioned.kt b/database/src/main/java/com/kunzisoft/keepass/database/element/node/NodeVersioned.kt index 86044e411..a854c23ac 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/element/node/NodeVersioned.kt +++ b/database/src/main/java/com/kunzisoft/keepass/database/element/node/NodeVersioned.kt @@ -26,7 +26,9 @@ 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.readBooleanCompat import com.kunzisoft.keepass.utils.readParcelableCompat +import com.kunzisoft.keepass.utils.writeBooleanCompat /** * Abstract class who manage Groups and Entries @@ -51,7 +53,7 @@ abstract class NodeVersioned> Parcel.readEnum() = readString()?.let { enumValueOf(it) } fun > Parcel.writeEnum(value: T?) = - writeString(value?.name) \ No newline at end of file + writeString(value?.name) + +fun Parcel.readBooleanCompat(): Boolean = readByte().toInt() != 0 + +fun Parcel.writeBooleanCompat(value: Boolean) = writeByte((if (value) 1 else 0).toByte()) \ No newline at end of file