mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +00:00
Fix legacy options
This commit is contained in:
parent
56878dbd35
commit
d3911fbedd
@ -30,6 +30,12 @@ data class State(
|
|||||||
|
|
||||||
val typeOptionsHidden get() = isNoteToSelf || (isGroup && isNewConfigEnabled)
|
val typeOptionsHidden get() = isNoteToSelf || (isGroup && isNewConfigEnabled)
|
||||||
|
|
||||||
|
val nextType get() = when {
|
||||||
|
expiryType == ExpiryType.AFTER_READ -> ExpiryType.AFTER_READ
|
||||||
|
isNewConfigEnabled -> ExpiryType.AFTER_SEND
|
||||||
|
else -> ExpiryType.LEGACY
|
||||||
|
}
|
||||||
|
|
||||||
val duration get() = expiryMode?.duration
|
val duration get() = expiryMode?.duration
|
||||||
val expiryType get() = expiryMode?.type
|
val expiryType get() = expiryMode?.type
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import network.loki.messenger.libsession_util.util.ExpiryMode
|
|||||||
import org.thoughtcrime.securesms.conversation.disappearingmessages.ExpiryType
|
import org.thoughtcrime.securesms.conversation.disappearingmessages.ExpiryType
|
||||||
import org.thoughtcrime.securesms.conversation.disappearingmessages.State
|
import org.thoughtcrime.securesms.conversation.disappearingmessages.State
|
||||||
import org.thoughtcrime.securesms.ui.GetString
|
import org.thoughtcrime.securesms.ui.GetString
|
||||||
|
import kotlin.time.Duration
|
||||||
import kotlin.time.Duration.Companion.days
|
import kotlin.time.Duration.Companion.days
|
||||||
import kotlin.time.Duration.Companion.hours
|
import kotlin.time.Duration.Companion.hours
|
||||||
import kotlin.time.Duration.Companion.minutes
|
import kotlin.time.Duration.Companion.minutes
|
||||||
@ -29,16 +30,15 @@ private fun State.typeOptions(): List<ExpiryRadioOption>? = if (typeOptionsHidde
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun State.timeOptions(): List<ExpiryRadioOption>? {
|
private fun State.timeOptions(): List<ExpiryRadioOption>? {
|
||||||
val type = takeUnless {
|
// Don't show times card if we have a types card, and type is off.
|
||||||
it.typeOptionsHidden
|
if (!typeOptionsHidden && expiryType == ExpiryType.NONE) return null
|
||||||
}?.expiryType ?: if (isNewConfigEnabled) ExpiryType.AFTER_SEND else ExpiryType.LEGACY
|
|
||||||
|
|
||||||
return when (type) {
|
return nextType.let { type ->
|
||||||
ExpiryType.AFTER_READ -> afterReadModes
|
when (type) {
|
||||||
ExpiryType.AFTER_SEND -> afterSendModes
|
ExpiryType.AFTER_READ -> afterReadTimes
|
||||||
ExpiryType.LEGACY -> legacyModes
|
else -> afterSendTimes
|
||||||
else -> null
|
}.map { timeOption(type, it) }
|
||||||
}?.map { timeOption(it) }?.let {
|
}.let {
|
||||||
buildList {
|
buildList {
|
||||||
if (typeOptionsHidden) add(offTypeOption())
|
if (typeOptionsHidden) add(offTypeOption())
|
||||||
addAll(debugOptions())
|
addAll(debugOptions())
|
||||||
@ -69,20 +69,20 @@ private fun debugTimes(isDebug: Boolean) = if (isDebug) listOf(10.seconds, 1.min
|
|||||||
private fun debugModes(isDebug: Boolean, type: ExpiryType) =
|
private fun debugModes(isDebug: Boolean, type: ExpiryType) =
|
||||||
debugTimes(isDebug).map { type.mode(it.inWholeSeconds) }
|
debugTimes(isDebug).map { type.mode(it.inWholeSeconds) }
|
||||||
private fun State.debugOptions(): List<ExpiryRadioOption> =
|
private fun State.debugOptions(): List<ExpiryRadioOption> =
|
||||||
debugModes(showDebugOptions, expiryType.takeIf { it == ExpiryType.AFTER_READ } ?: ExpiryType.AFTER_SEND)
|
debugModes(showDebugOptions, nextType).map { timeOption(it, subtitle = GetString("for testing purposes")) }
|
||||||
.map { timeOption(it, subtitle = GetString("for testing purposes")) }
|
|
||||||
|
|
||||||
private val afterSendTimes = listOf(12.hours, 1.days, 7.days, 14.days)
|
private val afterSendTimes = listOf(12.hours, 1.days, 7.days, 14.days)
|
||||||
|
|
||||||
private val afterSendModes = afterSendTimes.map { it.inWholeSeconds }.map(ExpiryMode::AfterSend)
|
|
||||||
private val legacyModes = afterSendTimes.map { it.inWholeSeconds }.map(ExpiryMode::Legacy)
|
|
||||||
|
|
||||||
private val afterReadTimes = buildList {
|
private val afterReadTimes = buildList {
|
||||||
add(5.minutes)
|
add(5.minutes)
|
||||||
add(1.hours)
|
add(1.hours)
|
||||||
addAll(afterSendTimes)
|
addAll(afterSendTimes)
|
||||||
}
|
}
|
||||||
private val afterReadModes = afterReadTimes.map { it.inWholeSeconds }.map(ExpiryMode::AfterRead)
|
|
||||||
|
private fun State.timeOption(
|
||||||
|
type: ExpiryType,
|
||||||
|
time: Duration
|
||||||
|
) = timeOption(type.mode(time))
|
||||||
|
|
||||||
private fun State.timeOption(
|
private fun State.timeOption(
|
||||||
mode: ExpiryMode,
|
mode: ExpiryMode,
|
||||||
@ -93,6 +93,6 @@ private fun State.timeOption(
|
|||||||
title = title,
|
title = title,
|
||||||
subtitle = subtitle,
|
subtitle = subtitle,
|
||||||
contentDescription = title,
|
contentDescription = title,
|
||||||
selected = expiryMode == mode,
|
selected = mode.duration == expiryMode?.duration,
|
||||||
enabled = isTimeOptionsEnabled
|
enabled = isTimeOptionsEnabled
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user