Skip to content

Commit

Permalink
More bold fixes and UI tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasSession committed Aug 29, 2024
1 parent 78a9ab7 commit d35482d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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))
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}

Expand Down
7 changes: 3 additions & 4 deletions app/src/main/res/layout/view_control_message.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>

Expand All @@ -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"/>

Expand All @@ -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" />

<FrameLayout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,17 @@ object UpdateMessageBuilder {
// --- Group created or joined ---
is UpdateMessageData.Kind.GroupCreation -> {
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
}
}

// --- 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 ---
Expand Down Expand Up @@ -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 ""
Expand All @@ -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()
}
}

Expand All @@ -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.
Expand All @@ -240,7 +231,7 @@ object UpdateMessageBuilder {
.put(NAME_KEY, senderName)
.put(TIME_KEY, time)
.put(DISAPPEARING_MESSAGES_TYPE_KEY, action)
.format().toString()
.format()
}
}

Expand Down
19 changes: 0 additions & 19 deletions libsession/src/main/java/org/session/libsession/utilities/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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
Expand Down

0 comments on commit d35482d

Please sign in to comment.