From d35482dabaac8ae2da97fb920903a984cec525ca Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Thu, 29 Aug 2024 15:20:13 +1000 Subject: [PATCH] More bold fixes and UI tweaks --- .../DisappearingMessages.kt | 13 +++++---- .../conversation/v2/ConversationActivityV2.kt | 8 +---- .../main/res/layout/view_control_message.xml | 7 ++--- .../utilities/UpdateMessageBuilder.kt | 29 +++++++------------ .../org/session/libsession/utilities/Util.kt | 19 ------------ 5 files changed, 21 insertions(+), 55 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/DisappearingMessages.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/DisappearingMessages.kt index 08cfcd2768..e086c95924 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/DisappearingMessages.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/DisappearingMessages.kt @@ -2,8 +2,6 @@ package org.thoughtcrime.securesms.conversation.disappearingmessages import android.content.Context 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.libsession_util.util.ExpiryMode 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.SSKEnvironment.MessageExpirationManagerProtocol 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.getExpirationTypeDisplayValue import org.thoughtcrime.securesms.database.model.MessageRecord import org.thoughtcrime.securesms.showSessionDialog +import org.thoughtcrime.securesms.ui.getSubbedCharSequence import org.thoughtcrime.securesms.ui.getSubbedString 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, @@ -48,10 +49,10 @@ class DisappearingMessages @Inject constructor( fun showFollowSettingDialog(context: Context, message: MessageRecord) = context.showSessionDialog { title(R.string.disappearingMessagesFollowSetting) text(if (message.expiresIn == 0L) { - context.getString(R.string.disappearingMessagesFollowSettingOff) + context.getText(R.string.disappearingMessagesFollowSettingOff) } else { - context.getSubbedString(R.string.disappearingMessagesFollowSettingOn, - TIME_LARGE_KEY to ExpirationUtil.getExpirationDisplayValue(context, message.expiresIn.milliseconds), + context.getSubbedCharSequence(R.string.disappearingMessagesFollowSettingOn, + TIME_KEY to ExpirationUtil.getExpirationDisplayValue(context, message.expiresIn.milliseconds), DISAPPEARING_MESSAGES_TYPE_KEY to context.getExpirationTypeDisplayValue(message.isNotDisappearAfterRead)) }) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt index 7995ed0c47..fdd3f7d8b9 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt @@ -1106,8 +1106,6 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe val blindedRecipient = viewModel.blindedRecipient val openGroup = viewModel.openGroup - val isClosedGroup = recipient.isGroupRecipient - // Get the correct placeholder text for this type of empty conversation val isNoteToSelf = recipient.isLocalNumber val txtCS: CharSequence = when { @@ -1143,11 +1141,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe val showPlaceholder = adapter.itemCount == 0 binding.placeholderText.isVisible = showPlaceholder if (showPlaceholder) { - if (!isNoteToSelf) { - binding.placeholderText.text = org.session.libsession.utilities.Util.makeBoldBetweenTags(txtCS) - } else { - binding.placeholderText.text = txtCS - } + binding.placeholderText.text = txtCS } } diff --git a/app/src/main/res/layout/view_control_message.xml b/app/src/main/res/layout/view_control_message.xml index ff2652ab38..45b4ad733c 100644 --- a/app/src/main/res/layout/view_control_message.xml +++ b/app/src/main/res/layout/view_control_message.xml @@ -25,7 +25,7 @@ android:layout_height="12dp" android:layout_marginBottom="@dimen/small_spacing" android:visibility="gone" - app:tint="?android:textColorPrimary" + app:tint="?android:textColorTertiary" tools:src="@drawable/ic_timer" tools:visibility="visible"/> @@ -35,7 +35,7 @@ android:layout_height="12dp" android:layout_marginBottom="@dimen/small_spacing" android:visibility="gone" - app:tint="?android:textColorPrimary" + app:tint="?android:textColorTertiary" tools:src="@drawable/ic_timer" tools:visibility="visible"/> @@ -45,9 +45,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" - android:textColor="?android:textColorPrimary" + android:textColor="?android:textColorTertiary" android:textSize="@dimen/very_small_font_size" - android:textStyle="bold" tools:text="You disabled disappearing messages" /> { if (!isOutgoing) { - Util.makeBoldBetweenTags(SpannableString(context.getString(R.string.groupInviteYou))) + context.getText(R.string.groupInviteYou) } else { "" // 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 --- is UpdateMessageData.Kind.GroupNameChange -> { - if (isOutgoing) { - val cs = Phrase.from(context, R.string.groupNameNew) - .put(GROUP_NAME_KEY, updateData.name) - .format() - Util.makeBoldBetweenTags(cs) - } - else { - val cs = Phrase.from(context, R.string.groupNameNew) - .put(GROUP_NAME_KEY, updateData.name) - .format() - Util.makeBoldBetweenTags(cs) - } + Phrase.from(context, R.string.groupNameNew) + .put(GROUP_NAME_KEY, updateData.name) + .format() } // --- Group member(s) were added --- @@ -193,7 +184,7 @@ object UpdateMessageBuilder { isOutgoing: Boolean = false, timestamp: Long, expireStarted: Long - ): String { + ): CharSequence { if (!isOutgoing && senderId == null) { Log.w(TAG, "buildExpirationTimerMessage: Cannot build for outgoing message when senderId is null.") return "" @@ -205,13 +196,13 @@ object UpdateMessageBuilder { if (duration <= 0) { // ..by you.. return if (isOutgoing) { - context.getString(R.string.disappearingMessagesTurnedOffYou) + context.getText(R.string.disappearingMessagesTurnedOffYou) } else // ..or by someone else. { Phrase.from(context, R.string.disappearingMessagesTurnedOff) .put(NAME_KEY, senderName) - .format().toString() + .format() } } @@ -225,13 +216,13 @@ object UpdateMessageBuilder { Phrase.from(context, R.string.disappearingMessagesSetYou) .put(TIME_KEY, time) .put(DISAPPEARING_MESSAGES_TYPE_KEY, action) - .format().toString() + .format() } else { // 1-on-1 conversation Phrase.from(context, R.string.disappearingMessagesSetYou) .put(TIME_KEY, time) .put(DISAPPEARING_MESSAGES_TYPE_KEY, action) - .format().toString() + .format() } } else // ..or by someone else. @@ -240,7 +231,7 @@ object UpdateMessageBuilder { .put(NAME_KEY, senderName) .put(TIME_KEY, time) .put(DISAPPEARING_MESSAGES_TYPE_KEY, action) - .format().toString() + .format() } } diff --git a/libsession/src/main/java/org/session/libsession/utilities/Util.kt b/libsession/src/main/java/org/session/libsession/utilities/Util.kt index 9110066a45..e0c47c34c7 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/Util.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/Util.kt @@ -359,25 +359,6 @@ object Util { val digitGroups = (Math.log10(sizeBytes.toDouble()) / Math.log10(1024.0)).toInt() 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 world" and returns a SpannableString that will display the appropriate - // elements in bold. If there are no such or 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("", startIndex) - if (startIndex == -1) break - val endIndex = input.indexOf("", 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.runIf(condition: Boolean, block: T.() -> R): R where T: R = if (condition) block() else this