Support RTL language in the reading page
This commit is contained in:
parent
a94017d564
commit
1384012c44
|
@ -4,7 +4,6 @@ import android.content.Context
|
||||||
import android.text.Html
|
import android.text.Html
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.rometools.rome.feed.synd.SyndEntry
|
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.SyndFeedInput
|
||||||
import com.rometools.rome.io.XmlReader
|
import com.rometools.rome.io.XmlReader
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
|
@ -37,16 +36,15 @@ class RssHelper @Inject constructor(
|
||||||
suspend fun searchFeed(feedLink: String): FeedWithArticle {
|
suspend fun searchFeed(feedLink: String): FeedWithArticle {
|
||||||
return withContext(dispatcherIO) {
|
return withContext(dispatcherIO) {
|
||||||
val accountId = context.currentAccountId
|
val accountId = context.currentAccountId
|
||||||
val parseRss: SyndFeed =
|
val syndFeed = SyndFeedInput().build(XmlReader(inputStream(okHttpClient, feedLink)))
|
||||||
SyndFeedInput().build(XmlReader(inputStream(okHttpClient, feedLink)))
|
|
||||||
val feed = Feed(
|
val feed = Feed(
|
||||||
id = accountId.spacerDollar(UUID.randomUUID().toString()),
|
id = accountId.spacerDollar(UUID.randomUUID().toString()),
|
||||||
name = parseRss.title!!,
|
name = syndFeed.title!!,
|
||||||
url = feedLink,
|
url = feedLink,
|
||||||
groupId = "",
|
groupId = "",
|
||||||
accountId = accountId,
|
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)
|
FeedWithArticle(feed, list)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,9 +60,8 @@ class RssHelper @Inject constructor(
|
||||||
suspend fun parseFullContent(link: String, title: String): String {
|
suspend fun parseFullContent(link: String, title: String): String {
|
||||||
return withContext(dispatcherIO) {
|
return withContext(dispatcherIO) {
|
||||||
val response = response(okHttpClient, link)
|
val response = response(okHttpClient, link)
|
||||||
val content = response.body!!.string()
|
val content = response.body.string()
|
||||||
val readability4J: Readability4J =
|
val readability4J = Readability4JExtended(link, content)
|
||||||
Readability4JExtended(link, content)
|
|
||||||
val articleContent = readability4J.parse().articleContent
|
val articleContent = readability4J.parse().articleContent
|
||||||
if (articleContent == null) {
|
if (articleContent == null) {
|
||||||
""
|
""
|
||||||
|
@ -85,10 +82,8 @@ class RssHelper @Inject constructor(
|
||||||
): List<Article> {
|
): List<Article> {
|
||||||
return withContext(dispatcherIO) {
|
return withContext(dispatcherIO) {
|
||||||
val accountId = context.currentAccountId
|
val accountId = context.currentAccountId
|
||||||
val parseRss: SyndFeed = SyndFeedInput().build(
|
val syndFeed = SyndFeedInput().build(XmlReader(inputStream(okHttpClient, feed.url)))
|
||||||
XmlReader(inputStream(okHttpClient, feed.url))
|
syndFeed.entries.asSequence()
|
||||||
)
|
|
||||||
parseRss.entries.asSequence()
|
|
||||||
.takeWhile { latestLink == null || latestLink != it.link }
|
.takeWhile { latestLink == null || latestLink != it.link }
|
||||||
.map { article(feed, accountId, it) }
|
.map { article(feed, accountId, it) }
|
||||||
.toList()
|
.toList()
|
||||||
|
@ -124,7 +119,7 @@ class RssHelper @Inject constructor(
|
||||||
rawDescription = (content ?: desc) ?: "",
|
rawDescription = (content ?: desc) ?: "",
|
||||||
shortDescription = (Readability4JExtended("", desc ?: content ?: "")
|
shortDescription = (Readability4JExtended("", desc ?: content ?: "")
|
||||||
.parse().textContent ?: "")
|
.parse().textContent ?: "")
|
||||||
.take(100)
|
.take(110)
|
||||||
.trim(),
|
.trim(),
|
||||||
fullContent = content,
|
fullContent = content,
|
||||||
img = findImg((content ?: desc) ?: ""),
|
img = findImg((content ?: desc) ?: ""),
|
||||||
|
@ -150,9 +145,8 @@ class RssHelper @Inject constructor(
|
||||||
withContext(dispatcherIO) {
|
withContext(dispatcherIO) {
|
||||||
val domainRegex = Regex("(http|https)://(www.)?(\\w+(\\.)?)+")
|
val domainRegex = Regex("(http|https)://(www.)?(\\w+(\\.)?)+")
|
||||||
val request = response(okHttpClient, articleLink)
|
val request = response(okHttpClient, articleLink)
|
||||||
val content = request.body!!.string()
|
val content = request.body.string()
|
||||||
val regex =
|
val regex = Regex("""<link(.+?)rel="shortcut icon"(.+?)href="(.+?)"""")
|
||||||
Regex("""<link(.+?)rel="shortcut icon"(.+?)href="(.+?)"""")
|
|
||||||
var iconLink = regex
|
var iconLink = regex
|
||||||
.find(content)
|
.find(content)
|
||||||
?.groups?.get(3)
|
?.groups?.get(3)
|
||||||
|
@ -188,7 +182,7 @@ class RssHelper @Inject constructor(
|
||||||
private suspend fun inputStream(
|
private suspend fun inputStream(
|
||||||
client: OkHttpClient,
|
client: OkHttpClient,
|
||||||
url: String
|
url: String
|
||||||
): InputStream = response(client, url).body!!.byteStream()
|
): InputStream = response(client, url).body.byteStream()
|
||||||
|
|
||||||
private suspend fun response(
|
private suspend fun response(
|
||||||
client: OkHttpClient,
|
client: OkHttpClient,
|
||||||
|
|
|
@ -44,43 +44,50 @@ fun bodyForeground(): Color =
|
||||||
@Composable
|
@Composable
|
||||||
fun bodyStyle(): TextStyle =
|
fun bodyStyle(): TextStyle =
|
||||||
MaterialTheme.typography.bodyLarge.copy(
|
MaterialTheme.typography.bodyLarge.copy(
|
||||||
color = bodyForeground()
|
color = bodyForeground(),
|
||||||
|
textAlign = TextAlign.Start,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun h1Style(): TextStyle =
|
fun h1Style(): TextStyle =
|
||||||
MaterialTheme.typography.displayMedium.copy(
|
MaterialTheme.typography.displayMedium.copy(
|
||||||
color = bodyForeground()
|
color = bodyForeground(),
|
||||||
|
textAlign = TextAlign.Start,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun h2Style(): TextStyle =
|
fun h2Style(): TextStyle =
|
||||||
MaterialTheme.typography.displaySmall.copy(
|
MaterialTheme.typography.displaySmall.copy(
|
||||||
color = bodyForeground()
|
color = bodyForeground(),
|
||||||
|
textAlign = TextAlign.Start,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun h3Style(): TextStyle =
|
fun h3Style(): TextStyle =
|
||||||
MaterialTheme.typography.headlineLarge.copy(
|
MaterialTheme.typography.headlineLarge.copy(
|
||||||
color = bodyForeground()
|
color = bodyForeground(),
|
||||||
|
textAlign = TextAlign.Start,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun h4Style(): TextStyle =
|
fun h4Style(): TextStyle =
|
||||||
MaterialTheme.typography.headlineMedium.copy(
|
MaterialTheme.typography.headlineMedium.copy(
|
||||||
color = bodyForeground()
|
color = bodyForeground(),
|
||||||
|
textAlign = TextAlign.Start,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun h5Style(): TextStyle =
|
fun h5Style(): TextStyle =
|
||||||
MaterialTheme.typography.headlineSmall.copy(
|
MaterialTheme.typography.headlineSmall.copy(
|
||||||
color = bodyForeground(),
|
color = bodyForeground(),
|
||||||
|
textAlign = TextAlign.Start,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun h6Style(): TextStyle =
|
fun h6Style(): TextStyle =
|
||||||
MaterialTheme.typography.titleLarge.copy(
|
MaterialTheme.typography.titleLarge.copy(
|
||||||
color = bodyForeground()
|
color = bodyForeground(),
|
||||||
|
textAlign = TextAlign.Start,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|
|
@ -8,6 +8,7 @@ import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.alpha
|
import androidx.compose.ui.draw.alpha
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import me.ash.reader.ui.ext.formatAsString
|
import me.ash.reader.ui.ext.formatAsString
|
||||||
import me.ash.reader.ui.ext.openURL
|
import me.ash.reader.ui.ext.openURL
|
||||||
|
@ -40,12 +41,14 @@ fun Header(
|
||||||
text = dateString,
|
text = dateString,
|
||||||
color = MaterialTheme.colorScheme.outline,
|
color = MaterialTheme.colorScheme.outline,
|
||||||
style = MaterialTheme.typography.labelMedium,
|
style = MaterialTheme.typography.labelMedium,
|
||||||
|
textAlign = TextAlign.Start,
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(4.dp))
|
Spacer(modifier = Modifier.height(4.dp))
|
||||||
Text(
|
Text(
|
||||||
text = title,
|
text = title,
|
||||||
color = MaterialTheme.colorScheme.onSurface,
|
color = MaterialTheme.colorScheme.onSurface,
|
||||||
style = MaterialTheme.typography.headlineLarge,
|
style = MaterialTheme.typography.headlineLarge,
|
||||||
|
textAlign = TextAlign.Start,
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(4.dp))
|
Spacer(modifier = Modifier.height(4.dp))
|
||||||
author?.let {
|
author?.let {
|
||||||
|
@ -55,6 +58,7 @@ fun Header(
|
||||||
text = it,
|
text = it,
|
||||||
color = MaterialTheme.colorScheme.outline,
|
color = MaterialTheme.colorScheme.outline,
|
||||||
style = MaterialTheme.typography.labelMedium,
|
style = MaterialTheme.typography.labelMedium,
|
||||||
|
textAlign = TextAlign.Start,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,6 +67,7 @@ fun Header(
|
||||||
text = feedName,
|
text = feedName,
|
||||||
color = MaterialTheme.colorScheme.outline,
|
color = MaterialTheme.colorScheme.outline,
|
||||||
style = MaterialTheme.typography.labelMedium,
|
style = MaterialTheme.typography.labelMedium,
|
||||||
|
textAlign = TextAlign.Start,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user