Skip to content

Commit

Permalink
Revert "feat(feed): parse favicon for feed's site (Ashinch#471)"
Browse files Browse the repository at this point in the history
This reverts commit f5c6e5f.
  • Loading branch information
mbestavros committed Jan 10, 2024
1 parent 5a00a46 commit 6a5e938
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import me.ash.reader.domain.repository.AccountDao
import me.ash.reader.domain.repository.ArticleDao
import me.ash.reader.domain.repository.FeedDao
import me.ash.reader.domain.repository.GroupDao
import me.ash.reader.infrastructure.android.NotificationHelper
import me.ash.reader.infrastructure.preference.KeepArchivedPreference
import me.ash.reader.infrastructure.preference.SyncIntervalPreference
import me.ash.reader.infrastructure.rss.RssHelper
import me.ash.reader.infrastructure.android.NotificationHelper
import me.ash.reader.ui.ext.currentAccountId
import me.ash.reader.ui.ext.spacerDollar
import java.util.*
Expand Down Expand Up @@ -146,9 +146,17 @@ abstract class AbstractRssRepository(
private suspend fun syncFeed(feed: Feed): FeedWithArticle {
val latest = articleDao.queryLatestByFeedId(context.currentAccountId, feed.id)
val articles = rssHelper.queryRssXml(feed, latest?.link)
if (feed.icon == null) {
rssHelper.queryRssIcon(feedDao, feed)
}
// try {
// if (feed.icon == null && !articles.isNullOrEmpty()) {
// rssHelper.queryRssIcon(feedDao, feed, articles.first().link)
// }
// } catch (e: Exception) {
// Log.e("RLog", "queryRssIcon[${feed.name}]: ${e.message}")
// return FeedWithArticle(
// feed = feed.apply { isNotification = false },
// articles = listOf()
// )
// }
return FeedWithArticle(
feed = feed.apply { isNotification = feed.isNotification && articles.isNotEmpty() },
articles = articles
Expand Down
16 changes: 0 additions & 16 deletions app/src/main/java/me/ash/reader/infrastructure/rss/Favicon.kt

This file was deleted.

31 changes: 25 additions & 6 deletions app/src/main/java/me/ash/reader/infrastructure/rss/RssHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package me.ash.reader.infrastructure.rss
import android.content.Context
import android.text.Html
import android.util.Log
import com.google.gson.Gson
import com.rometools.rome.feed.synd.SyndEntry
import com.rometools.rome.io.SyndFeedInput
import com.rometools.rome.io.XmlReader
Expand Down Expand Up @@ -144,14 +143,34 @@ class RssHelper @Inject constructor(
suspend fun queryRssIcon(
feedDao: FeedDao,
feed: Feed,
articleLink: String,
) {
withContext(ioDispatcher) {
val request = response(okHttpClient, "https://besticon-demo.herokuapp.com/allicons.json?url=${feed.url}")
val domainRegex = Regex("(http|https)://(www.)?(\\w+(\\.)?)+")
val request = response(okHttpClient, articleLink)
val content = request.body.string()
val favicon = Gson().fromJson(content, Favicon::class.java)
favicon?.icons?.first { it.width != null && it.width >= 20 }?.url?.let {
saveRssIcon(feedDao, feed, it)
}?: return@withContext
val regex = Regex("""<link(.+?)rel="shortcut icon"(.+?)href="(.+?)"""")
var iconLink = regex
.find(content)
?.groups?.get(3)
?.value
Log.i("rlog", "queryRssIcon: $iconLink")
if (iconLink != null) {
if (iconLink.startsWith("//")) {
iconLink = "http:$iconLink"
}
if (iconLink.startsWith("/")) {
iconLink = "${domainRegex.find(articleLink)?.value}$iconLink"
}
saveRssIcon(feedDao, feed, iconLink)
} else {
domainRegex.find(articleLink)?.value?.let {
Log.i("RLog", "favicon: ${it}")
if (response(okHttpClient, "$it/favicon.ico").isSuccessful) {
saveRssIcon(feedDao, feed, it)
}
}
}
}
}

Expand Down
64 changes: 26 additions & 38 deletions app/src/main/java/me/ash/reader/ui/component/FeedIcon.kt
Original file line number Diff line number Diff line change
@@ -1,57 +1,45 @@
package me.ash.reader.ui.component

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import me.ash.reader.ui.component.base.RYAsyncImage

@Composable
fun FeedIcon(
feedName: String,
iconUrl: String?,
size: Dp = 20.dp,
) {
if (iconUrl == null) {
Box(
modifier = Modifier
.size(20.dp)
.clip(CircleShape)
.background(MaterialTheme.colorScheme.primary),
contentAlignment = Alignment.Center,
) {
Text(
text = feedName.ifEmpty { " " }.first().toString(),
fontWeight = FontWeight.Bold,
color = MaterialTheme.colorScheme.onPrimary,
fontSize = 10.sp,
)
}
} else {
RYAsyncImage(
modifier = Modifier
.size(size)
.clip(CircleShape),
contentDescription = feedName,
data = iconUrl,
placeholder = null,
)
}
}
Row(
modifier = Modifier
.size(20.dp)
.clip(CircleShape)
.background(MaterialTheme.colorScheme.outline.copy(alpha = 0.2f))
) {}

@Preview
@Composable
fun FeedIconPrev(){
FeedIcon("AFF", null)
// val url by remember {
// mutableStateOf(
// "https://ui-avatars.com/api/?length=1&background=random&name=${
// URLEncoder.encode(
// feedName,
// Charsets.UTF_8.toString()
// )
// }"
// )
// }
//
// AsyncImage(
// modifier = Modifier
// .size(size)
// .clip(CircleShape),
// contentDescription = feedName,
// data = url,
// placeholder = null,
// )
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fun FeedItem(
verticalAlignment = Alignment.CenterVertically,
) {
Row(modifier = Modifier.weight(1f)) {
FeedIcon(feed.name, feed.icon)
FeedIcon(feed.name)
Text(
modifier = Modifier.padding(start = 12.dp, end = 6.dp),
text = feed.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fun FeedOptionDrawer(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
FeedIcon(feedName = feed?.name ?: "", iconUrl = feed?.icon, size = 24.dp)
FeedIcon(feedName = feed?.name ?: "", size = 24.dp)
// Icon(
// modifier = Modifier.roundClick { },
// imageVector = Icons.Rounded.RssFeed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fun ArticleItem(
) {
// Feed icon
if (articleListFeedIcon.value) {
FeedIcon(articleWithFeed.feed.name, iconUrl = articleWithFeed.feed.icon)
FeedIcon(articleWithFeed.feed.name)
Spacer(modifier = Modifier.width(10.dp))
}

Expand Down

0 comments on commit 6a5e938

Please sign in to comment.