android: Fix crash on multiple selection of images
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
package chat.simplex.app.views.helpers
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.net.Uri
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import androidx.compose.runtime.saveable.Saver
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
|
||||
@@ -32,7 +33,40 @@ enum class NewChatSheetState {
|
||||
}
|
||||
}
|
||||
|
||||
sealed class UploadContent {
|
||||
data class SimpleImage(val uri: Uri): UploadContent()
|
||||
data class AnimatedImage(val uri: Uri): UploadContent()
|
||||
/**
|
||||
* [Parcelable] implementation is needed to prevent a crash. Without it this situation produce a crash:
|
||||
* - select images in SendMsgView
|
||||
* - do this again without sending or dismissing previous selection
|
||||
* */
|
||||
sealed class UploadContent: Parcelable {
|
||||
data class SimpleImage(val uri: Uri): UploadContent(), Parcelable {
|
||||
constructor(parcel: Parcel): this(parcel.readParcelable<Uri>(Uri::class.java.classLoader) as Uri)
|
||||
override fun describeContents(): Int = 0
|
||||
override fun writeToParcel(dest: Parcel?, flags: Int) {
|
||||
dest?.writeParcelable(uri, 0)
|
||||
}
|
||||
companion object CREATOR: Parcelable.Creator<SimpleImage> {
|
||||
override fun createFromParcel(parcel: Parcel): SimpleImage {
|
||||
return SimpleImage(parcel)
|
||||
}
|
||||
override fun newArray(size: Int): Array<SimpleImage?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
}
|
||||
data class AnimatedImage(val uri: Uri): UploadContent(), Parcelable {
|
||||
constructor(parcel: Parcel): this(parcel.readParcelable<Uri>(Uri::class.java.classLoader) as Uri)
|
||||
override fun describeContents(): Int = 0
|
||||
override fun writeToParcel(dest: Parcel?, flags: Int) {
|
||||
dest?.writeParcelable(uri, 0)
|
||||
}
|
||||
companion object CREATOR: Parcelable.Creator<AnimatedImage> {
|
||||
override fun createFromParcel(parcel: Parcel): AnimatedImage {
|
||||
return AnimatedImage(parcel)
|
||||
}
|
||||
override fun newArray(size: Int): Array<AnimatedImage?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user