Skip to content

Commit

Permalink
Show subscribed for folder and podcast
Browse files Browse the repository at this point in the history
  • Loading branch information
ashiagr committed Feb 13, 2023
1 parent dbaee22 commit 38f33b4
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SearchPodcastViewHolder(
PodcastItem(
podcast = podcast,
subscribed = podcast.isSubscribed,
showSubscribed = true,
onClick = { onPodcastClick(podcast) },
modifier = Modifier
.background(color = MaterialTheme.theme.colors.primaryUi01)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,21 @@ fun SearchHistoryView(
is SearchHistoryEntry.Episode -> Unit // TODO

is SearchHistoryEntry.Folder -> SearchHistoryRow(
entry = entry,
content = { SearchHistoryFolderView(entry) },
onCloseClick = { onCloseClick(entry) },
onRowClick = { onRowClick(entry) },
)

is SearchHistoryEntry.Podcast -> SearchHistoryRow(
entry = entry,
content = { SearchHistoryPodcastView(entry) },
onCloseClick = { onCloseClick(entry) },
onRowClick = { onRowClick(entry) },
)

is SearchHistoryEntry.SearchTerm -> SearchHistoryRow(
entry = entry,
content = { SearchHistoryTermView(entry) },
onCloseClick = { onCloseClick(entry) },
onRowClick = { onRowClick(entry) },
Expand All @@ -131,6 +134,7 @@ fun SearchHistoryView(

@Composable
fun SearchHistoryRow(
entry: SearchHistoryEntry,
onCloseClick: () -> Unit,
onRowClick: () -> Unit,
modifier: Modifier = Modifier,
Expand All @@ -146,12 +150,31 @@ fun SearchHistoryRow(
Box(Modifier.weight(weight = 1f, fill = true)) {
content.invoke()
}
SubscribedIcon(entry)
CloseButton(onCloseClick)
}
HorizontalDivider(startIndent = 16.dp)
}
}

@Composable
private fun SubscribedIcon(
entry: SearchHistoryEntry,
modifier: Modifier = Modifier,
) {
if (entry.isSubscribed) {
Icon(
painter = painterResource(IR.drawable.ic_tick),
contentDescription = stringResource(LR.string.podcast_subscribed),
tint = MaterialTheme.theme.colors.support02,
modifier = modifier
.size(IconSize)
.padding(start = 16.dp)

)
}
}

@Composable
private fun CloseButton(
onCloseClick: () -> Unit,
Expand Down Expand Up @@ -304,12 +327,14 @@ fun SearchHistoryViewPreview(
state = SearchHistoryViewModel.State(
entries = listOf(
SearchHistoryEntry.Folder(
isSubscribed = true,
uuid = UUID.randomUUID().toString(),
title = "Folder",
color = 0,
podcastIds = emptyList()
),
SearchHistoryEntry.Podcast(
isSubscribed = true,
uuid = UUID.randomUUID().toString(),
title = "Title",
author = "Author",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 74,
"identityHash": "aafaa8a64ee28bafd44a4e2e3bace027",
"identityHash": "df6021921bda23e872baace09d7c1ee7",
"entities": [
{
"tableName": "bump_stats",
Expand Down Expand Up @@ -950,7 +950,7 @@
},
{
"tableName": "search_history",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `modified` INTEGER NOT NULL, `term` TEXT, `podcast_uuid` TEXT, `podcast_title` TEXT, `podcast_author` TEXT, `folder_uuid` TEXT, `folder_title` TEXT, `folder_color` INTEGER, `folder_podcastIds` TEXT, `episode_uuid` TEXT, `episode_title` TEXT, `episode_publishedDate` INTEGER, `episode_duration` REAL)",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `modified` INTEGER NOT NULL, `subscribed` INTEGER NOT NULL, `term` TEXT, `podcast_uuid` TEXT, `podcast_title` TEXT, `podcast_author` TEXT, `folder_uuid` TEXT, `folder_title` TEXT, `folder_color` INTEGER, `folder_podcastIds` TEXT, `episode_uuid` TEXT, `episode_title` TEXT, `episode_publishedDate` INTEGER, `episode_duration` REAL)",
"fields": [
{
"fieldPath": "id",
Expand All @@ -964,6 +964,12 @@
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "isSubscribed",
"columnName": "subscribed",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "term",
"columnName": "term",
Expand Down Expand Up @@ -1388,7 +1394,7 @@
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'aafaa8a64ee28bafd44a4e2e3bace027')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'df6021921bda23e872baace09d7c1ee7')"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ abstract class AppDatabase : RoomDatabase() {
"""
CREATE TABLE IF NOT EXISTS search_history (
_id INTEGER PRIMARY KEY AUTOINCREMENT,
subscribed INTEGER NOT NULL,
modified INTEGER NOT NULL,
term TEXT,
podcast_uuid TEXT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import java.util.Date
data class SearchHistoryItem(
@PrimaryKey(autoGenerate = true) @ColumnInfo(name = "_id") var id: Long? = null,
@ColumnInfo(name = "modified") var modified: Long = System.currentTimeMillis(),
@ColumnInfo(name = "subscribed") var isSubscribed: Boolean = false,
@ColumnInfo(name = "term") var term: String? = null,
@Embedded(prefix = "podcast_") var podcast: Podcast? = null,
@Embedded(prefix = "folder_") var folder: Folder? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import au.com.shiftyjelly.pocketcasts.models.entity.Podcast as PodcastModel

sealed class SearchHistoryEntry(
val id: Long? = null,
open val isSubscribed: Boolean = false,
) {
class Episode(
id: Long? = null,
Expand All @@ -19,18 +20,20 @@ sealed class SearchHistoryEntry(

class Folder(
id: Long? = null,
override val isSubscribed: Boolean,
val uuid: String,
val title: String,
val color: Int,
val podcastIds: List<String>,
) : SearchHistoryEntry(id = id)
) : SearchHistoryEntry(id = id, isSubscribed = isSubscribed)

class Podcast(
id: Long? = null,
override val isSubscribed: Boolean,
val uuid: String,
val title: String,
val author: String,
) : SearchHistoryEntry(id = id)
) : SearchHistoryEntry(id = id, isSubscribed = isSubscribed)

class SearchTerm(
id: Long? = null,
Expand All @@ -50,6 +53,7 @@ sealed class SearchHistoryEntry(

is Folder -> SearchHistoryItem(
id = id,
isSubscribed = isSubscribed,
folder = SearchHistoryItem.Folder(
uuid = uuid,
title = title,
Expand All @@ -60,6 +64,7 @@ sealed class SearchHistoryEntry(

is Podcast -> SearchHistoryItem(
id = id,
isSubscribed = isSubscribed,
podcast = SearchHistoryItem.Podcast(
uuid = uuid,
title = title,
Expand All @@ -85,13 +90,15 @@ sealed class SearchHistoryEntry(
uuid = folder.uuid,
title = folder.name,
color = folder.color,
podcastIds = podcastIds
podcastIds = podcastIds,
isSubscribed = true,
)

fun fromPodcast(podcast: PodcastModel) = Podcast(
uuid = podcast.uuid,
title = podcast.title,
author = podcast.author
author = podcast.author,
isSubscribed = podcast.isSubscribed
)

fun fromSearchHistoryItem(item: SearchHistoryItem) = when {
Expand All @@ -110,17 +117,19 @@ sealed class SearchHistoryEntry(
val folder = item.folder as SearchHistoryItem.Folder
Folder(
id = item.id,
isSubscribed = item.isSubscribed,
uuid = folder.uuid,
title = folder.title,
color = folder.color,
podcastIds = folder.podcastIds.split(",")
podcastIds = folder.podcastIds.split(","),
)
}

item.podcast != null -> {
val podcast = item.podcast as SearchHistoryItem.Podcast
Podcast(
id = item.id,
isSubscribed = item.isSubscribed,
uuid = podcast.uuid,
title = podcast.title,
author = podcast.author
Expand Down

0 comments on commit 38f33b4

Please sign in to comment.