-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
90 changed files
with
2,041 additions
and
758 deletions.
There are no files selected for viewing
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
43 changes: 43 additions & 0 deletions
43
app/src/main/java/org/thoughtcrime/securesms/attachments/AttachmentCreator.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,43 @@ | ||
/* | ||
* Copyright 2023 Signal Messenger, LLC | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
package org.thoughtcrime.securesms.attachments | ||
|
||
import android.os.Parcel | ||
import android.os.Parcelable | ||
|
||
/** | ||
* Parcelable Creator for Attachments. Encapsulates the logic around dealing with | ||
* subclasses, since Attachment is abstract and has several children. | ||
*/ | ||
object AttachmentCreator : Parcelable.Creator<Attachment> { | ||
enum class Subclass(val clazz: Class<out Attachment>, val code: String) { | ||
DATABASE(DatabaseAttachment::class.java, "database"), | ||
MMS_NOTIFICATION(MmsNotificationAttachment::class.java, "mms_notification"), | ||
POINTER(PointerAttachment::class.java, "pointer"), | ||
TOMBSTONE(TombstoneAttachment::class.java, "tombstone"), | ||
URI(UriAttachment::class.java, "uri") | ||
} | ||
|
||
@JvmStatic | ||
fun writeSubclass(dest: Parcel, instance: Attachment) { | ||
val subclass = Subclass.values().firstOrNull { it.clazz == instance::class.java } ?: error("Unexpected subtype ${instance::class.java.simpleName}") | ||
dest.writeString(subclass.code) | ||
} | ||
|
||
override fun createFromParcel(source: Parcel): Attachment { | ||
val rawCode = source.readString()!! | ||
|
||
return when (Subclass.values().first { rawCode == it.code }) { | ||
Subclass.DATABASE -> DatabaseAttachment(source) | ||
Subclass.MMS_NOTIFICATION -> MmsNotificationAttachment(source) | ||
Subclass.POINTER -> PointerAttachment(source) | ||
Subclass.TOMBSTONE -> TombstoneAttachment(source) | ||
Subclass.URI -> UriAttachment(source) | ||
} | ||
} | ||
|
||
override fun newArray(size: Int): Array<Attachment?> = arrayOfNulls(size) | ||
} |
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
Oops, something went wrong.