mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +00:00
Refactor follow setting dialog
This commit is contained in:
parent
06c258364f
commit
a3b6f685c0
@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.conversation.disappearingmessages
|
||||
|
||||
import android.content.Context
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import network.loki.messenger.R
|
||||
import network.loki.messenger.libsession_util.util.ExpiryMode
|
||||
import org.session.libsession.messaging.MessagingModuleConfiguration
|
||||
import org.session.libsession.messaging.messages.ExpirationConfiguration
|
||||
@ -9,11 +10,15 @@ import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
|
||||
import org.session.libsession.messaging.sending_receiving.MessageSender
|
||||
import org.session.libsession.snode.SnodeAPI
|
||||
import org.session.libsession.utilities.Address
|
||||
import org.session.libsession.utilities.SSKEnvironment
|
||||
import org.session.libsession.utilities.ExpirationUtil
|
||||
import org.session.libsession.utilities.SSKEnvironment.MessageExpirationManagerProtocol
|
||||
import org.session.libsession.utilities.TextSecurePreferences
|
||||
import org.session.libsession.utilities.getExpirationTypeDisplayValue
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord
|
||||
import org.thoughtcrime.securesms.showSessionDialog
|
||||
import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities
|
||||
import javax.inject.Inject
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
|
||||
class DisappearingMessages @Inject constructor(
|
||||
@ApplicationContext private val context: Context,
|
||||
@ -35,4 +40,30 @@ class DisappearingMessages @Inject constructor(
|
||||
MessageSender.send(message, address)
|
||||
ConfigurationMessageUtilities.forceSyncConfigurationNowIfNeeded(context)
|
||||
}
|
||||
|
||||
fun showFollowSettingDialog(context: Context, message: MessageRecord) = context.showSessionDialog {
|
||||
title(R.string.dialog_disappearing_messages_follow_setting_title)
|
||||
if (message.expiresIn == 0L) {
|
||||
text(R.string.dialog_disappearing_messages_follow_setting_off_body)
|
||||
} else {
|
||||
text(
|
||||
context.getString(
|
||||
R.string.dialog_disappearing_messages_follow_setting_on_body,
|
||||
ExpirationUtil.getExpirationDisplayValue(
|
||||
context,
|
||||
message.expiresIn.milliseconds
|
||||
),
|
||||
context.getExpirationTypeDisplayValue(message.isNotDisappearAfterRead)
|
||||
)
|
||||
)
|
||||
}
|
||||
destructiveButton(if (message.expiresIn == 0L) R.string.dialog_disappearing_messages_follow_setting_confirm else R.string.dialog_disappearing_messages_follow_setting_set) {
|
||||
set(message.threadId, message.recipient.address, message.expiryMode)
|
||||
}
|
||||
cancelButton()
|
||||
}
|
||||
}
|
||||
|
||||
val MessageRecord.expiryMode get() = if (expiresIn <= 0) ExpiryMode.NONE
|
||||
else if (expireStarted == timestamp) ExpiryMode.AfterSend(expiresIn / 1000)
|
||||
else ExpiryMode.AfterRead(expiresIn / 1000)
|
||||
|
@ -14,18 +14,10 @@ import network.loki.messenger.databinding.ViewControlMessageBinding
|
||||
import network.loki.messenger.libsession_util.util.ExpiryMode
|
||||
import org.session.libsession.messaging.MessagingModuleConfiguration
|
||||
import org.session.libsession.messaging.messages.ExpirationConfiguration
|
||||
import org.session.libsession.utilities.ExpirationUtil.getExpirationDisplayValue
|
||||
import org.session.libsession.utilities.getExpirationTypeDisplayValue
|
||||
import org.thoughtcrime.securesms.conversation.disappearingmessages.DisappearingMessages
|
||||
import org.thoughtcrime.securesms.conversation.disappearingmessages.expiryMode
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord
|
||||
import org.thoughtcrime.securesms.showSessionDialog
|
||||
import javax.inject.Inject
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
private val MessageRecord.expiryMode get() = if (expiresIn <= 0) ExpiryMode.NONE
|
||||
else if (expireStarted == timestamp) ExpiryMode.AfterSend(expiresIn / 1000)
|
||||
else ExpiryMode.AfterRead(expiresIn / 1000)
|
||||
|
||||
@AndroidEntryPoint
|
||||
class ControlMessageView : LinearLayout {
|
||||
@ -62,26 +54,7 @@ class ControlMessageView : LinearLayout {
|
||||
&& !message.isOutgoing
|
||||
&& message.expiryMode != (MessagingModuleConfiguration.shared.storage.getExpirationConfiguration(message.threadId)?.expiryMode ?: ExpiryMode.NONE)
|
||||
|
||||
followSetting.setOnClickListener {
|
||||
context.showSessionDialog {
|
||||
title(R.string.dialog_disappearing_messages_follow_setting_title)
|
||||
if (message.expiresIn == 0L) {
|
||||
text(R.string.dialog_disappearing_messages_follow_setting_off_body)
|
||||
} else {
|
||||
text(
|
||||
context.getString(
|
||||
R.string.dialog_disappearing_messages_follow_setting_on_body,
|
||||
getExpirationDisplayValue(context, message.expiresIn.milliseconds),
|
||||
context.getExpirationTypeDisplayValue(message.isNotDisappearAfterRead)
|
||||
)
|
||||
)
|
||||
}
|
||||
destructiveButton(if (message.expiresIn == 0L) R.string.dialog_disappearing_messages_follow_setting_confirm else R.string.dialog_disappearing_messages_follow_setting_set) {
|
||||
disappearingMessages.set(message.threadId, message.recipient.address, message.expiryMode)
|
||||
}
|
||||
cancelButton()
|
||||
}
|
||||
}
|
||||
followSetting.setOnClickListener { disappearingMessages.showFollowSettingDialog(context, message) }
|
||||
}
|
||||
}
|
||||
message.isMediaSavedNotification -> {
|
||||
|
Loading…
Reference in New Issue
Block a user