Skip to content

Commit

Permalink
Add support for loading fav icons using Coil based on feed homepage l…
Browse files Browse the repository at this point in the history
…ink (#710)
  • Loading branch information
msasikanth authored Aug 10, 2024
1 parent d941f0f commit 55a8d77
Show file tree
Hide file tree
Showing 16 changed files with 484 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class RssRepository(
id: String,
name: String,
feedIds: List<String>,
feedIcons: String,
feedHomepageLinks: String,
createdAt: Instant,
updatedAt: Instant,
pinnedAt: Instant?,
Expand All @@ -289,7 +289,7 @@ class RssRepository(
id = id,
name = name,
feedIds = feedIds.filterNot { it.isBlank() },
feedIcons = feedIcons.split(",").filterNot { it.isBlank() },
feedHomepageLinks = feedHomepageLinks.split(",").filterNot { it.isBlank() },
createdAt = createdAt,
updatedAt = updatedAt,
pinnedAt = pinnedAt,
Expand Down Expand Up @@ -626,15 +626,16 @@ class RssRepository(
lastCleanUpAt: Instant?,
numberOfUnreadPosts: Long,
feedIds: List<String>?,
feedIcons: String?,
feedHomepageLinks: String?,
updatedAt: Instant?,
pinnedPosition: Double ->
if (type == "group") {
FeedGroup(
id = id,
name = name,
feedIds = feedIds?.filterNot { it.isBlank() }.orEmpty(),
feedIcons = feedIcons?.split(",")?.filterNot { it.isBlank() }.orEmpty(),
feedHomepageLinks =
feedHomepageLinks?.split(",")?.filterNot { it.isBlank() }.orEmpty(),
createdAt = createdAt!!,
updatedAt = updatedAt!!,
pinnedAt = pinnedAt,
Expand Down Expand Up @@ -689,14 +690,15 @@ class RssRepository(
lastCleanUpAt: Instant?,
numberOfUnreadPosts: Long,
feedIds: List<String>?,
feedIcons: String?,
feedHomepageLinks: String?,
updatedAt: Instant? ->
if (type == "group") {
FeedGroup(
id = id,
name = name,
feedIds = feedIds?.filterNot { it.isBlank() }.orEmpty(),
feedIcons = feedIcons?.split(",")?.filterNot { it.isBlank() }.orEmpty(),
feedHomepageLinks =
feedHomepageLinks?.split(",")?.filterNot { it.isBlank() }.orEmpty(),
createdAt = createdAt,
updatedAt = updatedAt!!,
pinnedAt = pinnedAt,
Expand Down Expand Up @@ -735,7 +737,7 @@ class RssRepository(
id: String,
name: String,
feedIds: List<String>,
feedIcons: String,
feedHomepageLinks: String,
createdAt: Instant,
updatedAt: Instant,
pinnedAt: Instant?,
Expand All @@ -744,7 +746,7 @@ class RssRepository(
id = id,
name = name,
feedIds = feedIds.filterNot { it.isBlank() },
feedIcons = feedIcons.split(",").filterNot { it.isBlank() },
feedHomepageLinks = feedHomepageLinks.split(",").filterNot { it.isBlank() },
createdAt = createdAt,
updatedAt = updatedAt,
pinnedAt = pinnedAt,
Expand All @@ -769,15 +771,15 @@ class RssRepository(
id: String,
name: String,
feedIds: List<String>,
feedIcons: String,
feedHomepageLinks: String,
createdAt: Instant,
updatedAt: Instant,
pinnedAt: Instant? ->
FeedGroup(
id = id,
name = name,
feedIds = feedIds.filterNot { it.isBlank() },
feedIcons = feedIcons.split(",").filterNot { it.isBlank() },
feedHomepageLinks = feedHomepageLinks.split(",").filterNot { it.isBlank() },
createdAt = createdAt,
updatedAt = updatedAt,
pinnedAt = pinnedAt,
Expand All @@ -796,15 +798,15 @@ class RssRepository(
id: String,
name: String,
feedIds: List<String>,
feedIcons: String,
feedHomepageLinks: String,
createdAt: Instant,
updatedAt: Instant,
pinnedAt: Instant? ->
FeedGroup(
id = id,
name = name,
feedIds = feedIds.filterNot { it.isBlank() },
feedIcons = feedIcons.split(",").filterNot { it.isBlank() },
feedHomepageLinks = feedHomepageLinks.split(",").filterNot { it.isBlank() },
createdAt = createdAt,
updatedAt = updatedAt,
pinnedAt = pinnedAt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ SELECT
id,
name,
feedIds,
COALESCE((SELECT GROUP_CONCAT(feed.icon)
COALESCE((SELECT GROUP_CONCAT(feed.homepageLink)
FROM feed
WHERE INSTR(feedGroup.feedIds, feed.id)
LIMIT 4), '') AS feedIcons,
LIMIT 4), '') AS feedHomepageLinks,
createdAt,
updatedAt,
pinnedAt,
Expand All @@ -42,10 +42,10 @@ SELECT
id,
name,
feedIds,
COALESCE((SELECT GROUP_CONCAT(feed.icon)
COALESCE((SELECT GROUP_CONCAT(feed.homepageLink)
FROM feed
WHERE INSTR(feedGroup.feedIds, feed.id)
LIMIT 4), '') AS feedIcons,
LIMIT 4), '') AS feedHomepageLinks,
createdAt,
updatedAt,
pinnedAt,
Expand Down Expand Up @@ -79,10 +79,10 @@ SELECT
id,
name,
feedIds,
COALESCE((SELECT GROUP_CONCAT(feed.icon)
COALESCE((SELECT GROUP_CONCAT(feed.homepageLink)
FROM feed
WHERE INSTR(feedGroup.feedIds, feed.id)
LIMIT 4), '') AS feedIcons,
LIMIT 4), '') AS feedHomepageLinks,
createdAt,
updatedAt,
pinnedAt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ FROM (
NULL AS lastCleanUpAt,
COUNT(CASE WHEN p.read == 0 THEN 1 ELSE NULL END) AS numberOfUnreadPosts,
fg.feedIds,
COALESCE((SELECT GROUP_CONCAT(feed.icon)
COALESCE((SELECT GROUP_CONCAT(feed.homepageLink)
FROM feed
WHERE INSTR(fg.feedIds, feed.id)
LIMIT 4), '') AS feedIcons,
LIMIT 4), '') AS feedHomepageLinks,
fg.createdAt,
fg.pinnedAt,
fg.updatedAt,
Expand Down Expand Up @@ -123,10 +123,10 @@ FROM (
NULL AS lastCleanUpAt,
COUNT(CASE WHEN p.read == 0 THEN 1 ELSE NULL END) AS numberOfUnreadPosts,
fg.feedIds,
COALESCE((SELECT GROUP_CONCAT(feed.icon)
COALESCE((SELECT GROUP_CONCAT(feed.homepageLink)
FROM feed
WHERE INSTR(fg.feedIds, feed.id)
LIMIT 4), '') AS feedIcons,
LIMIT 4), '') AS feedHomepageLinks,
fg.createdAt,
fg.pinnedAt,
fg.updatedAt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ data class FeedGroup(
override val id: String,
val name: String,
val feedIds: List<String>,
val feedIcons: List<String>,
val feedHomepageLinks: List<String>,
val numberOfUnreadPosts: Long = 0,
val createdAt: Instant,
val updatedAt: Instant,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package dev.sasikanth.rss.reader.components.image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2024 Sasikanth Miriyampalli
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.sasikanth.rss.reader.components.image

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.RssFeed
import androidx.compose.material.icons.rounded.RssFeed
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import coil3.compose.LocalPlatformContext
import coil3.compose.SubcomposeAsyncImage
import coil3.request.ImageRequest
import coil3.size.Dimension
import coil3.size.Size
import dev.sasikanth.rss.reader.favicons.FavIconImageLoader
import dev.sasikanth.rss.reader.ui.AppTheme

@Composable
internal fun FeedFavIcon(
url: String,
contentDescription: String?,
modifier: Modifier = Modifier,
contentScale: ContentScale = ContentScale.Fit,
size: Size = Size(Dimension.Undefined, 500)
) {
Box(modifier.background(Color.White)) {
val context = LocalPlatformContext.current
val imageRequest = ImageRequest.Builder(context).data(url).diskCacheKey(url).size(size).build()
val imageLoader = FavIconImageLoader.get(context)

SubcomposeAsyncImage(
model = imageRequest,
contentDescription = contentDescription,
modifier = Modifier.matchParentSize(),
contentScale = contentScale,
imageLoader = imageLoader,
error = { PlaceHolderIcon() },
loading = { PlaceHolderIcon() }
)
}
}

@Composable
private fun PlaceHolderIcon() {
Icon(
imageVector = Icons.Rounded.RssFeed,
contentDescription = null,
tint = AppTheme.colorScheme.tintedBackground,
)
}
Loading

0 comments on commit 55a8d77

Please sign in to comment.