-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Fixed #3 by adding condition for live_data
- Loading branch information
Showing
4 changed files
with
112 additions
and
11 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
app/src/main/java/com/kyhsgeekcode/dereinfo/SerializableSparseArray.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.kyhsgeekcode.dereinfo | ||
|
||
import android.util.SparseArray | ||
import java.io.IOException | ||
import java.io.ObjectInputStream | ||
import java.io.ObjectOutputStream | ||
|
||
typealias SerializableSparseIntArray = SerializableSparseArray<Int> | ||
|
||
class SerializableSparseArray<E> : SparseArray<E>, java.io.Serializable { | ||
|
||
constructor() : super() | ||
constructor(capacity: Int) : super(capacity) | ||
|
||
/** | ||
* This method is private but it is called using reflection by java | ||
* serialization mechanism. It overwrites the default object serialization. | ||
* | ||
* <br></br><br></br>**IMPORTANT** | ||
* The access modifier for this method MUST be set to **private** otherwise [java.io.StreamCorruptedException] | ||
* will be thrown. | ||
* | ||
* @param oos | ||
* the stream the data is stored into | ||
* @throws IOException | ||
* an exception that might occur during data storing | ||
*/ | ||
@Throws(IOException::class) | ||
private fun writeObject(oos: ObjectOutputStream) { | ||
val data = arrayOfNulls<Any>(size()) | ||
for (i in data.indices) { | ||
val pair = Pair<Int,E>(keyAt(i), valueAt(i)) | ||
data[i] = pair | ||
} | ||
oos.writeObject(data) | ||
} | ||
|
||
/** | ||
* This method is private but it is called using reflection by java | ||
* serialization mechanism. It overwrites the default object serialization. | ||
* | ||
* <br></br><br></br>**IMPORTANT** | ||
* The access modifier for this method MUST be set to **private** otherwise [java.io.StreamCorruptedException] | ||
* will be thrown. | ||
* | ||
* @param oos | ||
* the stream the data is read from | ||
* @throws IOException | ||
* an exception that might occur during data reading | ||
* @throws ClassNotFoundException | ||
* this exception will be raised when a class is read that is | ||
* not known to the current ClassLoader | ||
*/ | ||
@Throws(IOException::class, ClassNotFoundException::class) | ||
private fun readObject(ois: ObjectInputStream) { | ||
val data = ois.readObject() as Array<Any> | ||
for (i in data.indices) { | ||
val pair = data[i] as Pair<Int,E> | ||
this.append(pair.first, pair.second) | ||
} | ||
return | ||
} | ||
|
||
companion object { | ||
private const val serialVersionUID = 824056059663678000L | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters