Push before changing over all the Phrase.from to extension method calls

This commit is contained in:
alansley 2024-08-28 15:30:02 +10:00
parent 1f68791da9
commit 114066ad5f
4 changed files with 20 additions and 12 deletions

View File

@ -30,6 +30,7 @@ import org.session.libsession.utilities.modifyLayoutParams
import org.session.libsession.utilities.recipients.Recipient import org.session.libsession.utilities.recipients.Recipient
import org.thoughtcrime.securesms.database.GroupDatabase import org.thoughtcrime.securesms.database.GroupDatabase
import org.thoughtcrime.securesms.database.LokiAPIDatabase import org.thoughtcrime.securesms.database.LokiAPIDatabase
import org.thoughtcrime.securesms.ui.getSubbedString
@AndroidEntryPoint @AndroidEntryPoint
class ConversationActionBarView @JvmOverloads constructor( class ConversationActionBarView @JvmOverloads constructor(
@ -107,10 +108,10 @@ class ConversationActionBarView @JvmOverloads constructor(
val durationAbbreviated = ExpirationUtil.getExpirationAbbreviatedDisplayValue(config.expiryMode.expirySeconds) val durationAbbreviated = ExpirationUtil.getExpirationAbbreviatedDisplayValue(config.expiryMode.expirySeconds)
// ..then substitute into the string.. // ..then substitute into the string..
val subtitleTxt = Phrase.from(context, R.string.disappearingMessagesDisappear) val subtitleTxt = context.getSubbedString(R.string.disappearingMessagesDisappear,
.put(DISAPPEARING_MESSAGES_TYPE_KEY, dmTypeString) DISAPPEARING_MESSAGES_TYPE_KEY to dmTypeString,
.put(TIME_KEY, durationAbbreviated) TIME_KEY to durationAbbreviated
.format().toString() ).toString()
// .. and apply to the subtitle. // .. and apply to the subtitle.
settings += ConversationSetting( settings += ConversationSetting(
@ -127,9 +128,7 @@ class ConversationActionBarView @JvmOverloads constructor(
?.let { ?.let {
val mutedDuration = (it - System.currentTimeMillis()).milliseconds val mutedDuration = (it - System.currentTimeMillis()).milliseconds
val durationString = LocalisedTimeUtil.getDurationWithSingleLargestTimeUnit(context, mutedDuration) val durationString = LocalisedTimeUtil.getDurationWithSingleLargestTimeUnit(context, mutedDuration)
Phrase.from(context, R.string.notificationsMuteFor) context.getSubbedString(R.string.notificationsMuteFor, TIME_LARGE_KEY to durationString).toString()
.put(TIME_LARGE_KEY, durationString)
.format().toString()
} }
?: context.getString(R.string.notificationsMuted), ?: context.getString(R.string.notificationsMuted),
ConversationSettingType.NOTIFICATION, ConversationSettingType.NOTIFICATION,

View File

@ -19,6 +19,8 @@ import com.squareup.phrase.Phrase
import network.loki.messenger.R import network.loki.messenger.R
import network.loki.messenger.databinding.FragmentModalUrlBottomSheetBinding import network.loki.messenger.databinding.FragmentModalUrlBottomSheetBinding
import org.session.libsession.utilities.StringSubstitutionConstants.URL_KEY import org.session.libsession.utilities.StringSubstitutionConstants.URL_KEY
import org.session.libsignal.utilities.Log
import org.thoughtcrime.securesms.ui.getSubbedString
class ModalUrlBottomSheet(private val url: String): BottomSheetDialogFragment(), View.OnClickListener { class ModalUrlBottomSheet(private val url: String): BottomSheetDialogFragment(), View.OnClickListener {
private lateinit var binding: FragmentModalUrlBottomSheetBinding private lateinit var binding: FragmentModalUrlBottomSheetBinding
@ -30,9 +32,8 @@ class ModalUrlBottomSheet(private val url: String): BottomSheetDialogFragment(),
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
val explanation = Phrase.from(context, R.string.urlOpenDescription) if (context == null) { return Log.w("MUBS", "Context is null") }
.put(URL_KEY, url) val explanation = requireContext().getSubbedString(R.string.urlOpenDescription, URL_KEY to url)
.format()
val spannable = SpannableStringBuilder(explanation) val spannable = SpannableStringBuilder(explanation)
val startIndex = explanation.indexOf(url) val startIndex = explanation.indexOf(url)
spannable.setSpan(StyleSpan(Typeface.BOLD), startIndex, startIndex + url.count(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) spannable.setSpan(StyleSpan(Typeface.BOLD), startIndex, startIndex + url.count(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)

View File

@ -19,6 +19,14 @@ fun Context.createThemedComposeView(content: @Composable () -> Unit): ComposeVie
setThemedContent(content) setThemedContent(content)
} }
fun Context.getSubbedString(stringId: Int, vararg substitutionPairs: Pair<String, String>): CharSequence {
val phrase = Phrase.from(this, stringId)
for ((key, value) in substitutionPairs) {
phrase.put(key, value)
}
return phrase.format()
}
fun ComposeView.setThemedContent(content: @Composable () -> Unit) = setContent { fun ComposeView.setThemedContent(content: @Composable () -> Unit) = setContent {
SessionMaterialTheme { SessionMaterialTheme {
content() content()

View File

@ -20,6 +20,7 @@ import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.os.Build import android.os.Build
import android.text.format.DateFormat import android.text.format.DateFormat
import androidx.compose.ui.text.capitalize
import org.session.libsignal.utilities.Log import org.session.libsignal.utilities.Log
import java.text.DateFormat.SHORT import java.text.DateFormat.SHORT
import java.text.DateFormat.getTimeInstance import java.text.DateFormat.getTimeInstance
@ -93,8 +94,7 @@ object DateUtils : android.text.format.DateUtils() {
fun getDisplayFormattedTimeSpanString(c: Context, locale: Locale, timestamp: Long): String { fun getDisplayFormattedTimeSpanString(c: Context, locale: Locale, timestamp: Long): String {
// If the timestamp is invalid (ie. 0) then assume we're waiting on data and just use the 'Now' copy // If the timestamp is invalid (ie. 0) then assume we're waiting on data and just use the 'Now' copy
return if (timestamp == 0L || isWithin(timestamp, 1, TimeUnit.MINUTES)) { return if (timestamp == 0L || isWithin(timestamp, 1, TimeUnit.MINUTES)) {
// TODO ACL: We need a string for "Now" because I can't seem to coax a localised version from DateUtils - // TODO ACL: Adjust as per SES-360
// TODO: although anyone seeing is this is more than welcome to try! - 2024-08-26
"Now" "Now"
} else if (isToday(timestamp)) { } else if (isToday(timestamp)) {
getFormattedDateTime(timestamp, getHourFormat(c), locale) getFormattedDateTime(timestamp, getHourFormat(c), locale)