Skip to content

Commit 9e6603f

Browse files
committed
Fix serializable CharSequenceText
1 parent cf8385e commit 9e6603f

File tree

1 file changed

+6
-5
lines changed
  • omegatypes/src/main/java/com/omega_r/libs/omegatypes

1 file changed

+6
-5
lines changed

omegatypes/src/main/java/com/omega_r/libs/omegatypes/Text.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.content.Context
55
import android.text.Html
66
import android.text.SpannableString
77
import android.text.SpannableStringBuilder
8+
import android.text.Spanned
89
import android.widget.EditText
910
import android.widget.TextView
1011
import android.widget.Toast
@@ -145,7 +146,7 @@ open class Text(protected val defaultTextStyle: TextStyle?) : Serializable, Text
145146
textStyle: TextStyle?) : Text(textStyle) {
146147

147148
companion object {
148-
private const val TYPE_SPANNABLE = 0.toByte()
149+
private const val TYPE_SPANNED = 0.toByte()
149150
private const val TYPE_STRING = 1.toByte()
150151
}
151152

@@ -163,8 +164,8 @@ open class Text(protected val defaultTextStyle: TextStyle?) : Serializable, Text
163164
private fun writeObject(stream: ObjectOutputStream) {
164165
charSequence.let { charSequence->
165166
when (charSequence) {
166-
is SpannableString -> {
167-
stream.writeByte(TYPE_SPANNABLE.toInt())
167+
is Spanned -> {
168+
stream.writeByte(TYPE_SPANNED.toInt())
168169
stream.writeObject(Html.toHtml(charSequence))
169170
}
170171
is String -> {
@@ -181,8 +182,8 @@ open class Text(protected val defaultTextStyle: TextStyle?) : Serializable, Text
181182
@Throws(IOException::class, ClassNotFoundException::class)
182183
private fun readObject(stream: ObjectInputStream) {
183184
charSequence = when (val type = stream.readByte()) {
184-
TYPE_SPANNABLE -> SpannableString(Html.fromHtml(stream.readObject() as String))
185-
TYPE_STRING -> stream.readObject() as String
185+
TYPE_SPANNED -> Html.fromHtml(stream.readObject() as String)
186+
TYPE_STRING -> stream.readUTF()
186187
else -> throw IOException("Unknown type = $type")
187188
}
188189
}

0 commit comments

Comments
 (0)