More bold fixes and UI tweaks

This commit is contained in:
ThomasSession 2024-08-29 15:20:13 +10:00
parent 78a9ab7159
commit d35482daba
5 changed files with 21 additions and 55 deletions

View File

@ -2,8 +2,6 @@ package org.thoughtcrime.securesms.conversation.disappearingmessages
import android.content.Context import android.content.Context
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
import kotlin.time.Duration.Companion.milliseconds
import network.loki.messenger.R import network.loki.messenger.R
import network.loki.messenger.libsession_util.util.ExpiryMode import network.loki.messenger.libsession_util.util.ExpiryMode
import org.session.libsession.messaging.MessagingModuleConfiguration import org.session.libsession.messaging.MessagingModuleConfiguration
@ -15,13 +13,16 @@ import org.session.libsession.utilities.Address
import org.session.libsession.utilities.ExpirationUtil import org.session.libsession.utilities.ExpirationUtil
import org.session.libsession.utilities.SSKEnvironment.MessageExpirationManagerProtocol import org.session.libsession.utilities.SSKEnvironment.MessageExpirationManagerProtocol
import org.session.libsession.utilities.StringSubstitutionConstants.DISAPPEARING_MESSAGES_TYPE_KEY import org.session.libsession.utilities.StringSubstitutionConstants.DISAPPEARING_MESSAGES_TYPE_KEY
import org.session.libsession.utilities.StringSubstitutionConstants.TIME_LARGE_KEY import org.session.libsession.utilities.StringSubstitutionConstants.TIME_KEY
import org.session.libsession.utilities.TextSecurePreferences import org.session.libsession.utilities.TextSecurePreferences
import org.session.libsession.utilities.getExpirationTypeDisplayValue import org.session.libsession.utilities.getExpirationTypeDisplayValue
import org.thoughtcrime.securesms.database.model.MessageRecord import org.thoughtcrime.securesms.database.model.MessageRecord
import org.thoughtcrime.securesms.showSessionDialog import org.thoughtcrime.securesms.showSessionDialog
import org.thoughtcrime.securesms.ui.getSubbedCharSequence
import org.thoughtcrime.securesms.ui.getSubbedString import org.thoughtcrime.securesms.ui.getSubbedString
import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities
import javax.inject.Inject
import kotlin.time.Duration.Companion.milliseconds
class DisappearingMessages @Inject constructor( class DisappearingMessages @Inject constructor(
@ApplicationContext private val context: Context, @ApplicationContext private val context: Context,
@ -48,10 +49,10 @@ class DisappearingMessages @Inject constructor(
fun showFollowSettingDialog(context: Context, message: MessageRecord) = context.showSessionDialog { fun showFollowSettingDialog(context: Context, message: MessageRecord) = context.showSessionDialog {
title(R.string.disappearingMessagesFollowSetting) title(R.string.disappearingMessagesFollowSetting)
text(if (message.expiresIn == 0L) { text(if (message.expiresIn == 0L) {
context.getString(R.string.disappearingMessagesFollowSettingOff) context.getText(R.string.disappearingMessagesFollowSettingOff)
} else { } else {
context.getSubbedString(R.string.disappearingMessagesFollowSettingOn, context.getSubbedCharSequence(R.string.disappearingMessagesFollowSettingOn,
TIME_LARGE_KEY to ExpirationUtil.getExpirationDisplayValue(context, message.expiresIn.milliseconds), TIME_KEY to ExpirationUtil.getExpirationDisplayValue(context, message.expiresIn.milliseconds),
DISAPPEARING_MESSAGES_TYPE_KEY to context.getExpirationTypeDisplayValue(message.isNotDisappearAfterRead)) DISAPPEARING_MESSAGES_TYPE_KEY to context.getExpirationTypeDisplayValue(message.isNotDisappearAfterRead))
}) })

View File

@ -1106,8 +1106,6 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
val blindedRecipient = viewModel.blindedRecipient val blindedRecipient = viewModel.blindedRecipient
val openGroup = viewModel.openGroup val openGroup = viewModel.openGroup
val isClosedGroup = recipient.isGroupRecipient
// Get the correct placeholder text for this type of empty conversation // Get the correct placeholder text for this type of empty conversation
val isNoteToSelf = recipient.isLocalNumber val isNoteToSelf = recipient.isLocalNumber
val txtCS: CharSequence = when { val txtCS: CharSequence = when {
@ -1143,11 +1141,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
val showPlaceholder = adapter.itemCount == 0 val showPlaceholder = adapter.itemCount == 0
binding.placeholderText.isVisible = showPlaceholder binding.placeholderText.isVisible = showPlaceholder
if (showPlaceholder) { if (showPlaceholder) {
if (!isNoteToSelf) { binding.placeholderText.text = txtCS
binding.placeholderText.text = org.session.libsession.utilities.Util.makeBoldBetweenTags(txtCS)
} else {
binding.placeholderText.text = txtCS
}
} }
} }

View File

@ -25,7 +25,7 @@
android:layout_height="12dp" android:layout_height="12dp"
android:layout_marginBottom="@dimen/small_spacing" android:layout_marginBottom="@dimen/small_spacing"
android:visibility="gone" android:visibility="gone"
app:tint="?android:textColorPrimary" app:tint="?android:textColorTertiary"
tools:src="@drawable/ic_timer" tools:src="@drawable/ic_timer"
tools:visibility="visible"/> tools:visibility="visible"/>
@ -35,7 +35,7 @@
android:layout_height="12dp" android:layout_height="12dp"
android:layout_marginBottom="@dimen/small_spacing" android:layout_marginBottom="@dimen/small_spacing"
android:visibility="gone" android:visibility="gone"
app:tint="?android:textColorPrimary" app:tint="?android:textColorTertiary"
tools:src="@drawable/ic_timer" tools:src="@drawable/ic_timer"
tools:visibility="visible"/> tools:visibility="visible"/>
@ -45,9 +45,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center" android:gravity="center"
android:textColor="?android:textColorPrimary" android:textColor="?android:textColorTertiary"
android:textSize="@dimen/very_small_font_size" android:textSize="@dimen/very_small_font_size"
android:textStyle="bold"
tools:text="You disabled disappearing messages" /> tools:text="You disabled disappearing messages" />
<FrameLayout <FrameLayout

View File

@ -43,7 +43,7 @@ object UpdateMessageBuilder {
// --- Group created or joined --- // --- Group created or joined ---
is UpdateMessageData.Kind.GroupCreation -> { is UpdateMessageData.Kind.GroupCreation -> {
if (!isOutgoing) { if (!isOutgoing) {
Util.makeBoldBetweenTags(SpannableString(context.getString(R.string.groupInviteYou))) context.getText(R.string.groupInviteYou)
} else { } else {
"" // We no longer add a string like `disappearingMessagesNewGroup` ("You created a new group") and leave the group with its default empty state "" // We no longer add a string like `disappearingMessagesNewGroup` ("You created a new group") and leave the group with its default empty state
} }
@ -51,18 +51,9 @@ object UpdateMessageBuilder {
// --- Group name changed --- // --- Group name changed ---
is UpdateMessageData.Kind.GroupNameChange -> { is UpdateMessageData.Kind.GroupNameChange -> {
if (isOutgoing) { Phrase.from(context, R.string.groupNameNew)
val cs = Phrase.from(context, R.string.groupNameNew) .put(GROUP_NAME_KEY, updateData.name)
.put(GROUP_NAME_KEY, updateData.name) .format()
.format()
Util.makeBoldBetweenTags(cs)
}
else {
val cs = Phrase.from(context, R.string.groupNameNew)
.put(GROUP_NAME_KEY, updateData.name)
.format()
Util.makeBoldBetweenTags(cs)
}
} }
// --- Group member(s) were added --- // --- Group member(s) were added ---
@ -193,7 +184,7 @@ object UpdateMessageBuilder {
isOutgoing: Boolean = false, isOutgoing: Boolean = false,
timestamp: Long, timestamp: Long,
expireStarted: Long expireStarted: Long
): String { ): CharSequence {
if (!isOutgoing && senderId == null) { if (!isOutgoing && senderId == null) {
Log.w(TAG, "buildExpirationTimerMessage: Cannot build for outgoing message when senderId is null.") Log.w(TAG, "buildExpirationTimerMessage: Cannot build for outgoing message when senderId is null.")
return "" return ""
@ -205,13 +196,13 @@ object UpdateMessageBuilder {
if (duration <= 0) { if (duration <= 0) {
// ..by you.. // ..by you..
return if (isOutgoing) { return if (isOutgoing) {
context.getString(R.string.disappearingMessagesTurnedOffYou) context.getText(R.string.disappearingMessagesTurnedOffYou)
} }
else // ..or by someone else. else // ..or by someone else.
{ {
Phrase.from(context, R.string.disappearingMessagesTurnedOff) Phrase.from(context, R.string.disappearingMessagesTurnedOff)
.put(NAME_KEY, senderName) .put(NAME_KEY, senderName)
.format().toString() .format()
} }
} }
@ -225,13 +216,13 @@ object UpdateMessageBuilder {
Phrase.from(context, R.string.disappearingMessagesSetYou) Phrase.from(context, R.string.disappearingMessagesSetYou)
.put(TIME_KEY, time) .put(TIME_KEY, time)
.put(DISAPPEARING_MESSAGES_TYPE_KEY, action) .put(DISAPPEARING_MESSAGES_TYPE_KEY, action)
.format().toString() .format()
} else { } else {
// 1-on-1 conversation // 1-on-1 conversation
Phrase.from(context, R.string.disappearingMessagesSetYou) Phrase.from(context, R.string.disappearingMessagesSetYou)
.put(TIME_KEY, time) .put(TIME_KEY, time)
.put(DISAPPEARING_MESSAGES_TYPE_KEY, action) .put(DISAPPEARING_MESSAGES_TYPE_KEY, action)
.format().toString() .format()
} }
} }
else // ..or by someone else. else // ..or by someone else.
@ -240,7 +231,7 @@ object UpdateMessageBuilder {
.put(NAME_KEY, senderName) .put(NAME_KEY, senderName)
.put(TIME_KEY, time) .put(TIME_KEY, time)
.put(DISAPPEARING_MESSAGES_TYPE_KEY, action) .put(DISAPPEARING_MESSAGES_TYPE_KEY, action)
.format().toString() .format()
} }
} }

View File

@ -359,25 +359,6 @@ object Util {
val digitGroups = (Math.log10(sizeBytes.toDouble()) / Math.log10(1024.0)).toInt() val digitGroups = (Math.log10(sizeBytes.toDouble()) / Math.log10(1024.0)).toInt()
return DecimalFormat("#,##0.#").format(sizeBytes / Math.pow(1024.0, digitGroups.toDouble())) + " " + units[digitGroups] return DecimalFormat("#,##0.#").format(sizeBytes / Math.pow(1024.0, digitGroups.toDouble())) + " " + units[digitGroups]
} }
// Method that takes a char sequence that contains one or more elements surrounded in bold tags
// like "Hello <b>world</b>" and returns a SpannableString that will display the appropriate
// elements in bold. If there are no such <b> or </b> elements then the original string is returned
// as a SpannableString without any bold highlighting.
@JvmStatic
fun makeBoldBetweenTags(input: CharSequence): SpannableString {
val spannable = SpannableString(input)
var startIndex = 0
while (true) {
startIndex = input.indexOf("<b>", startIndex)
if (startIndex == -1) break
val endIndex = input.indexOf("</b>", startIndex + 3)
if (endIndex == -1) break
spannable.setSpan(StyleSpan(Typeface.BOLD),startIndex + 3, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
startIndex = endIndex + 4
}
return spannable
}
} }
fun <T, R> T.runIf(condition: Boolean, block: T.() -> R): R where T: R = if (condition) block() else this fun <T, R> T.runIf(condition: Boolean, block: T.() -> R): R where T: R = if (condition) block() else this