Merge pull request #186 from rashedswen/main

temporary solution for mirroring arabic text
This commit is contained in:
Vitor Pamplona 2023-03-03 18:06:46 -05:00 committed by GitHub
commit 2a65b7241a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 28 additions and 5 deletions

View File

@ -13,6 +13,7 @@ import androidx.compose.material.ButtonDefaults
import androidx.compose.material.MaterialTheme import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
@ -22,11 +23,13 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.compositeOver import androidx.compose.ui.graphics.compositeOver
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.navigation.NavController import androidx.navigation.NavController
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.R
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.LayoutDirection
@Composable @Composable
fun ExpandableRichTextViewer( fun ExpandableRichTextViewer(
@ -43,7 +46,17 @@ fun ExpandableRichTextViewer(
val text = if (showFullText) content else content.take(350) val text = if (showFullText) content else content.take(350)
Box(contentAlignment = Alignment.BottomCenter) { Box(contentAlignment = Alignment.BottomCenter) {
RichTextViewer(text, canPreview, modifier, tags, backgroundColor, accountViewModel, navController) CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) {
RichTextViewer(
text,
canPreview,
modifier,
tags,
backgroundColor,
accountViewModel,
navController
)
}
if (content.length > 350 && !showFullText) { if (content.length > 350 && !showFullText) {
Row( Row(

View File

@ -29,6 +29,7 @@ import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.style.TextDirection import androidx.compose.ui.text.style.TextDirection
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@ -132,8 +133,8 @@ fun RichTextViewer(
// FlowRow doesn't work well with paragraphs. So we need to split them // FlowRow doesn't work well with paragraphs. So we need to split them
content.split('\n').forEach { paragraph -> content.split('\n').forEach { paragraph ->
FlowRow() { FlowRow() {
paragraph.split(' ').forEach { word: String -> val s = if (isArabic(paragraph)) paragraph.split(' ').reversed() else paragraph.split(' ');
s.forEach { word: String ->
if (canPreview) { if (canPreview) {
// Explicit URL // Explicit URL
val lnInvoice = LnInvoiceUtil.findInvoice(word) val lnInvoice = LnInvoiceUtil.findInvoice(word)
@ -191,6 +192,10 @@ fun RichTextViewer(
} }
} }
private fun isArabic(text: String): Boolean {
return text.any { it in '\u0600'..'\u06FF' || it in '\u0750'..'\u077F' }
}
fun isBechLink(word: String): Boolean { fun isBechLink(word: String): Boolean {
return word.startsWith("nostr:", true) return word.startsWith("nostr:", true)

View File

@ -183,7 +183,6 @@ fun TranslateableRichTextViewer(
Spacer(modifier = Modifier.size(10.dp)) Spacer(modifier = Modifier.size(10.dp))
// TODO : Rashed translate this
Text( Text(
"${stringResource(R.string.show_in)} ${Locale(source).displayName} ${ "${stringResource(R.string.show_in)} ${Locale(source).displayName} ${
stringResource( stringResource(

View File

@ -241,7 +241,7 @@ fun NoteCompose(
if (noteEvent is RepostEvent) { if (noteEvent is RepostEvent) {
Text( Text(
" boosted", " ${stringResource(id = R.string.boosted)}",
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f) color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f)
) )

View File

@ -35,6 +35,7 @@
<string name="zaps">Zaps</string> <string name="zaps">Zaps</string>
<string name="view_count">مشاهدة العد</string> <string name="view_count">مشاهدة العد</string>
<string name="boost">تعزيز</string> <string name="boost">تعزيز</string>
<string name="boosted">معزز</string>
<string name="quote">إقتباس</string> <string name="quote">إقتباس</string>
<string name="new_amount_in_sats">مبلغ جديد في Sats</string> <string name="new_amount_in_sats">مبلغ جديد في Sats</string>
<string name="add">إضافة</string> <string name="add">إضافة</string>

View File

@ -37,6 +37,7 @@
<string name="zaps">Zaps</string> <string name="zaps">Zaps</string>
<string name="view_count">Total vistas</string> <string name="view_count">Total vistas</string>
<string name="boost">Impulsar</string> <string name="boost">Impulsar</string>
<string name="boosted">boosted</string>
<string name="quote">Cita</string> <string name="quote">Cita</string>
<string name="new_amount_in_sats">Nueva cantidad en Sats</string> <string name="new_amount_in_sats">Nueva cantidad en Sats</string>
<string name="add">Añadir</string> <string name="add">Añadir</string>

View File

@ -35,6 +35,7 @@
<string name="zaps">Zaps</string> <string name="zaps">Zaps</string>
<string name="view_count">Contagem de visualizações</string> <string name="view_count">Contagem de visualizações</string>
<string name="boost">Impulsionar</string> <string name="boost">Impulsionar</string>
<string name="boosted">boosted</string>
<string name="quote">Citar</string> <string name="quote">Citar</string>
<string name="new_amount_in_sats">Novo Valor em Sats</string> <string name="new_amount_in_sats">Novo Valor em Sats</string>
<string name="add">Adicionar</string> <string name="add">Adicionar</string>

View File

@ -36,6 +36,7 @@
<string name="zaps">Запы</string> <string name="zaps">Запы</string>
<string name="view_count">Просмотры</string> <string name="view_count">Просмотры</string>
<string name="boost">Продвинуть</string> <string name="boost">Продвинуть</string>
<string name="boosted">boosted</string>
<string name="quote">Цитировать</string> <string name="quote">Цитировать</string>
<string name="new_amount_in_sats">Новая сумма в sat</string> <string name="new_amount_in_sats">Новая сумма в sat</string>
<string name="add">Добавить</string> <string name="add">Добавить</string>

View File

@ -36,6 +36,7 @@
<string name="zaps">Запи</string> <string name="zaps">Запи</string>
<string name="view_count">Перегляди</string> <string name="view_count">Перегляди</string>
<string name="boost">Просувати</string> <string name="boost">Просувати</string>
<string name="boosted">boosted</string>
<string name="quote">Цитувати</string> <string name="quote">Цитувати</string>
<string name="new_amount_in_sats">Нова сума в sat</string> <string name="new_amount_in_sats">Нова сума в sat</string>
<string name="add">Додати</string> <string name="add">Додати</string>

View File

@ -36,6 +36,7 @@
<string name="zaps">Zaps</string> <string name="zaps">Zaps</string>
<string name="view_count">View count</string> <string name="view_count">View count</string>
<string name="boost">Boost</string> <string name="boost">Boost</string>
<string name="boosted">boosted</string>
<string name="quote">Quote</string> <string name="quote">Quote</string>
<string name="new_amount_in_sats">New Amount in Sats</string> <string name="new_amount_in_sats">New Amount in Sats</string>
<string name="add">Add</string> <string name="add">Add</string>