2021-09-02 20:04:43 +00:00
|
|
|
package org.thoughtcrime.securesms.mediasend.v2
|
|
|
|
|
|
|
|
import android.os.Bundle
|
2022-02-24 17:40:28 +00:00
|
|
|
import org.thoughtcrime.securesms.contacts.paged.ContactSearchKey
|
2021-09-02 20:04:43 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientId
|
|
|
|
|
|
|
|
sealed class MediaSelectionDestination {
|
|
|
|
|
|
|
|
object Wallpaper : MediaSelectionDestination() {
|
|
|
|
override fun toBundle(): Bundle {
|
|
|
|
return Bundle().apply {
|
|
|
|
putBoolean(WALLPAPER, true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
object Avatar : MediaSelectionDestination() {
|
|
|
|
override fun toBundle(): Bundle {
|
|
|
|
return Bundle().apply {
|
|
|
|
putBoolean(AVATAR, true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
object ChooseAfterMediaSelection : MediaSelectionDestination() {
|
|
|
|
override fun toBundle(): Bundle {
|
|
|
|
return Bundle.EMPTY
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class SingleRecipient(private val id: RecipientId) : MediaSelectionDestination() {
|
2023-01-18 14:49:47 +00:00
|
|
|
override fun getRecipientSearchKey(): ContactSearchKey.RecipientSearchKey = ContactSearchKey.RecipientSearchKey(id, false)
|
2021-09-02 20:04:43 +00:00
|
|
|
|
|
|
|
override fun toBundle(): Bundle {
|
|
|
|
return Bundle().apply {
|
|
|
|
putParcelable(RECIPIENT, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-29 17:12:56 +00:00
|
|
|
class SingleStory(private val id: RecipientId) : MediaSelectionDestination() {
|
2023-01-18 14:49:47 +00:00
|
|
|
override fun getRecipientSearchKey(): ContactSearchKey.RecipientSearchKey = ContactSearchKey.RecipientSearchKey(id, true)
|
2022-11-29 17:12:56 +00:00
|
|
|
|
|
|
|
override fun toBundle(): Bundle {
|
|
|
|
return Bundle().apply {
|
|
|
|
putParcelable(STORY, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-07 18:47:56 +00:00
|
|
|
class MultipleRecipients(val recipientSearchKeys: List<ContactSearchKey.RecipientSearchKey>) : MediaSelectionDestination() {
|
|
|
|
|
|
|
|
companion object {
|
2023-01-18 14:49:47 +00:00
|
|
|
fun fromParcel(parcelables: List<ContactSearchKey.RecipientSearchKey>): MultipleRecipients {
|
|
|
|
return MultipleRecipients(parcelables)
|
2022-04-07 18:47:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-08 16:06:44 +00:00
|
|
|
override fun getRecipientSearchKey(): ContactSearchKey.RecipientSearchKey? {
|
|
|
|
return if (recipientSearchKeys.size == 1) {
|
|
|
|
recipientSearchKeys[0]
|
|
|
|
} else {
|
|
|
|
super.getRecipientSearchKey()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-07 18:47:56 +00:00
|
|
|
override fun getRecipientSearchKeyList(): List<ContactSearchKey.RecipientSearchKey> = recipientSearchKeys
|
2021-09-02 20:04:43 +00:00
|
|
|
|
|
|
|
override fun toBundle(): Bundle {
|
|
|
|
return Bundle().apply {
|
2023-01-18 14:49:47 +00:00
|
|
|
putParcelableArrayList(RECIPIENT_LIST, ArrayList(recipientSearchKeys.map { it.requireRecipientSearchKey() }))
|
2021-09-02 20:04:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-07 18:47:56 +00:00
|
|
|
open fun getRecipientSearchKey(): ContactSearchKey.RecipientSearchKey? = null
|
|
|
|
open fun getRecipientSearchKeyList(): List<ContactSearchKey.RecipientSearchKey> = emptyList()
|
2021-09-02 20:04:43 +00:00
|
|
|
|
|
|
|
abstract fun toBundle(): Bundle
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
private const val WALLPAPER = "wallpaper"
|
|
|
|
private const val AVATAR = "avatar"
|
|
|
|
private const val RECIPIENT = "recipient"
|
2022-11-29 17:12:56 +00:00
|
|
|
private const val STORY = "story"
|
2021-09-02 20:04:43 +00:00
|
|
|
private const val RECIPIENT_LIST = "recipient_list"
|
|
|
|
|
|
|
|
fun fromBundle(bundle: Bundle): MediaSelectionDestination {
|
|
|
|
return when {
|
|
|
|
bundle.containsKey(WALLPAPER) -> Wallpaper
|
|
|
|
bundle.containsKey(AVATAR) -> Avatar
|
|
|
|
bundle.containsKey(RECIPIENT) -> SingleRecipient(requireNotNull(bundle.getParcelable(RECIPIENT)))
|
2022-11-29 17:12:56 +00:00
|
|
|
bundle.containsKey(STORY) -> SingleStory(requireNotNull(bundle.getParcelable(STORY)))
|
2022-04-07 18:47:56 +00:00
|
|
|
bundle.containsKey(RECIPIENT_LIST) -> MultipleRecipients.fromParcel(requireNotNull(bundle.getParcelableArrayList(RECIPIENT_LIST)))
|
2021-09-02 20:04:43 +00:00
|
|
|
else -> ChooseAfterMediaSelection
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|