Support RTL language in the reading page

This commit is contained in:
Ash 2022-06-02 09:44:03 +08:00
parent a94017d564
commit 1384012c44
3 changed files with 29 additions and 23 deletions

View File

@ -4,7 +4,6 @@ import android.content.Context
import android.text.Html
import android.util.Log
import com.rometools.rome.feed.synd.SyndEntry
import com.rometools.rome.feed.synd.SyndFeed
import com.rometools.rome.io.SyndFeedInput
import com.rometools.rome.io.XmlReader
import dagger.hilt.android.qualifiers.ApplicationContext
@ -37,16 +36,15 @@ class RssHelper @Inject constructor(
suspend fun searchFeed(feedLink: String): FeedWithArticle {
return withContext(dispatcherIO) {
val accountId = context.currentAccountId
val parseRss: SyndFeed =
SyndFeedInput().build(XmlReader(inputStream(okHttpClient, feedLink)))
val syndFeed = SyndFeedInput().build(XmlReader(inputStream(okHttpClient, feedLink)))
val feed = Feed(
id = accountId.spacerDollar(UUID.randomUUID().toString()),
name = parseRss.title!!,
name = syndFeed.title!!,
url = feedLink,
groupId = "",
accountId = accountId,
)
val list = parseRss.entries.map { article(feed, context.currentAccountId, it) }
val list = syndFeed.entries.map { article(feed, context.currentAccountId, it) }
FeedWithArticle(feed, list)
}
}
@ -62,9 +60,8 @@ class RssHelper @Inject constructor(
suspend fun parseFullContent(link: String, title: String): String {
return withContext(dispatcherIO) {
val response = response(okHttpClient, link)
val content = response.body!!.string()
val readability4J: Readability4J =
Readability4JExtended(link, content)
val content = response.body.string()
val readability4J = Readability4JExtended(link, content)
val articleContent = readability4J.parse().articleContent
if (articleContent == null) {
""
@ -85,10 +82,8 @@ class RssHelper @Inject constructor(
): List<Article> {
return withContext(dispatcherIO) {
val accountId = context.currentAccountId
val parseRss: SyndFeed = SyndFeedInput().build(
XmlReader(inputStream(okHttpClient, feed.url))
)
parseRss.entries.asSequence()
val syndFeed = SyndFeedInput().build(XmlReader(inputStream(okHttpClient, feed.url)))
syndFeed.entries.asSequence()
.takeWhile { latestLink == null || latestLink != it.link }
.map { article(feed, accountId, it) }
.toList()
@ -124,7 +119,7 @@ class RssHelper @Inject constructor(
rawDescription = (content ?: desc) ?: "",
shortDescription = (Readability4JExtended("", desc ?: content ?: "")
.parse().textContent ?: "")
.take(100)
.take(110)
.trim(),
fullContent = content,
img = findImg((content ?: desc) ?: ""),
@ -150,9 +145,8 @@ class RssHelper @Inject constructor(
withContext(dispatcherIO) {
val domainRegex = Regex("(http|https)://(www.)?(\\w+(\\.)?)+")
val request = response(okHttpClient, articleLink)
val content = request.body!!.string()
val regex =
Regex("""<link(.+?)rel="shortcut icon"(.+?)href="(.+?)"""")
val content = request.body.string()
val regex = Regex("""<link(.+?)rel="shortcut icon"(.+?)href="(.+?)"""")
var iconLink = regex
.find(content)
?.groups?.get(3)
@ -188,7 +182,7 @@ class RssHelper @Inject constructor(
private suspend fun inputStream(
client: OkHttpClient,
url: String
): InputStream = response(client, url).body!!.byteStream()
): InputStream = response(client, url).body.byteStream()
private suspend fun response(
client: OkHttpClient,

View File

@ -44,43 +44,50 @@ fun bodyForeground(): Color =
@Composable
fun bodyStyle(): TextStyle =
MaterialTheme.typography.bodyLarge.copy(
color = bodyForeground()
color = bodyForeground(),
textAlign = TextAlign.Start,
)
@Composable
fun h1Style(): TextStyle =
MaterialTheme.typography.displayMedium.copy(
color = bodyForeground()
color = bodyForeground(),
textAlign = TextAlign.Start,
)
@Composable
fun h2Style(): TextStyle =
MaterialTheme.typography.displaySmall.copy(
color = bodyForeground()
color = bodyForeground(),
textAlign = TextAlign.Start,
)
@Composable
fun h3Style(): TextStyle =
MaterialTheme.typography.headlineLarge.copy(
color = bodyForeground()
color = bodyForeground(),
textAlign = TextAlign.Start,
)
@Composable
fun h4Style(): TextStyle =
MaterialTheme.typography.headlineMedium.copy(
color = bodyForeground()
color = bodyForeground(),
textAlign = TextAlign.Start,
)
@Composable
fun h5Style(): TextStyle =
MaterialTheme.typography.headlineSmall.copy(
color = bodyForeground(),
textAlign = TextAlign.Start,
)
@Composable
fun h6Style(): TextStyle =
MaterialTheme.typography.titleLarge.copy(
color = bodyForeground()
color = bodyForeground(),
textAlign = TextAlign.Start,
)
@Composable

View File

@ -8,6 +8,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import me.ash.reader.ui.ext.formatAsString
import me.ash.reader.ui.ext.openURL
@ -40,12 +41,14 @@ fun Header(
text = dateString,
color = MaterialTheme.colorScheme.outline,
style = MaterialTheme.typography.labelMedium,
textAlign = TextAlign.Start,
)
Spacer(modifier = Modifier.height(4.dp))
Text(
text = title,
color = MaterialTheme.colorScheme.onSurface,
style = MaterialTheme.typography.headlineLarge,
textAlign = TextAlign.Start,
)
Spacer(modifier = Modifier.height(4.dp))
author?.let {
@ -55,6 +58,7 @@ fun Header(
text = it,
color = MaterialTheme.colorScheme.outline,
style = MaterialTheme.typography.labelMedium,
textAlign = TextAlign.Start,
)
}
}
@ -63,6 +67,7 @@ fun Header(
text = feedName,
color = MaterialTheme.colorScheme.outline,
style = MaterialTheme.typography.labelMedium,
textAlign = TextAlign.Start,
)
}
}