Skip to content

Commit

Permalink
fix: update some styles.
Browse files Browse the repository at this point in the history
fix: pinned categories are not pinned.
  • Loading branch information
oxyroid committed May 15, 2024
1 parent d9ccf3b commit 7f16a82
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 191 deletions.
56 changes: 47 additions & 9 deletions data/src/main/java/com/m3u/data/database/dao/StreamDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,18 @@ internal interface StreamDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertOrReplaceAll(vararg streams: Stream)

@Query("SELECT DISTINCT `group` FROM streams WHERE playlistUrl = :playlistUrl")
suspend fun getCategoriesByPlaylistUrl(playlistUrl: String): List<String>
@Query(
"""
SELECT DISTINCT `group`
FROM streams
WHERE playlistUrl = :playlistUrl
AND title LIKE '%'||:query||'%'
"""
)
suspend fun getCategoriesByPlaylistUrl(
playlistUrl: String,
query: String
): List<String>

@Delete
suspend fun delete(stream: Stream)
Expand All @@ -44,22 +54,26 @@ internal interface StreamDao {
@Query("SELECT * FROM streams WHERE id = :id")
suspend fun get(id: Int): Stream?

@Query("""
@Query(
"""
SELECT * FROM streams
WHERE hidden = 0
AND playlistUrl NOT IN (:seriesPlaylistUrls)
ORDER BY RANDOM()
LIMIT 1
""")
"""
)
suspend fun randomIgnoreSeriesAndHidden(vararg seriesPlaylistUrls: String): Stream?

@Query("""
@Query(
"""
SELECT * FROM streams
WHERE favourite = 1
AND playlistUrl NOT IN (:seriesPlaylistUrls)
ORDER BY RANDOM()
LIMIT 1
""")
"""
)
suspend fun randomIgnoreSeriesInFavourite(vararg seriesPlaylistUrls: String): Stream?

@Query("SELECT * FROM streams WHERE url = :url")
Expand Down Expand Up @@ -106,21 +120,45 @@ internal interface StreamDao {
query: String
): PagingSource<Int, Stream>

@Query("SELECT * FROM streams WHERE playlistUrl = :url AND title LIKE '%'||:query||'%' AND `group` = :category ORDER BY title ASC")
@Query(
"""
SELECT * FROM streams
WHERE playlistUrl = :url
AND title LIKE '%'||:query||'%'
AND `group` = :category
ORDER BY title ASC
"""
)
fun pagingAllByPlaylistUrlAsc(
url: String,
category: String,
query: String
): PagingSource<Int, Stream>

@Query("SELECT * FROM streams WHERE playlistUrl = :url AND title LIKE '%'||:query||'%' AND `group` = :category ORDER BY title DESC")
@Query(
"""
SELECT * FROM streams
WHERE playlistUrl = :url
AND title LIKE '%'||:query||'%'
AND `group` = :category
ORDER BY title DESC
"""
)
fun pagingAllByPlaylistUrlDesc(
url: String,
category: String,
query: String
): PagingSource<Int, Stream>

@Query("SELECT * FROM streams WHERE playlistUrl = :url AND title LIKE '%'||:query||'%' AND `group` = :category ORDER BY seen DESC")
@Query(
"""
SELECT * FROM streams
WHERE playlistUrl = :url
AND title LIKE '%'||:query||'%'
AND `group` = :category
ORDER BY seen DESC
"""
)
fun pagingAllByPlaylistUrlRecently(
url: String,
category: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface PlaylistRepository {
fun observeAllEpgs(): Flow<List<Playlist>>
fun observePlaylistUrls(): Flow<List<String>>
suspend fun get(url: String): Playlist?
suspend fun getCategoriesByPlaylistUrlIgnoreHidden(url: String): List<String>
suspend fun getCategoriesByPlaylistUrlIgnoreHidden(url: String, query: String): List<String>
fun observe(url: String): Flow<Playlist?>
fun observeWithStreams(url: String): Flow<PlaylistWithStreams?>
suspend fun getWithStreams(url: String): PlaylistWithStreams?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,14 +514,17 @@ internal class PlaylistRepositoryImpl @Inject constructor(
playlistDao.getByUrl(url)
}

override suspend fun getCategoriesByPlaylistUrlIgnoreHidden(url: String): List<String> =
logger.execute {
val playlist = playlistDao.getByUrl(url)
val hiddenCategories = playlist?.hiddenCategories ?: emptyList()
streamDao
.getCategoriesByPlaylistUrl(url)
.filterNot { it in hiddenCategories }
} ?: emptyList()
override suspend fun getCategoriesByPlaylistUrlIgnoreHidden(
url: String,
query: String
): List<String> = playlistDao.getByUrl(url).let { playlist ->
val pinnedCategories = playlist?.pinnedCategories ?: emptyList()
val hiddenCategories = playlist?.hiddenCategories ?: emptyList()
streamDao
.getCategoriesByPlaylistUrl(url, query)
.filterNot { it in hiddenCategories }
.sortedByDescending { it in pinnedCategories }
}

override suspend fun unsubscribe(url: String): Playlist? = logger.execute {
val playlist = playlistDao.getByUrl(url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import kotlin.time.Duration.Companion.days
import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds
import androidx.tv.material3.ListItem as TvListItem

@Composable
internal fun FavoriteItem(
Expand All @@ -37,7 +38,6 @@ internal fun FavoriteItem(
onLongClick: () -> Unit,
modifier: Modifier = Modifier
) {
// TODO: split smartphone and television impl.
val tv = isTelevision()
if (!tv) {
SmartphoneFavoriteItemImpl(
Expand All @@ -49,7 +49,7 @@ internal fun FavoriteItem(
modifier = modifier
)
} else {
TelevisionFavouriteItemImpl(
TvFavouriteItemImpl(
stream = stream,
onClick = onClick,
onLongClick = onLongClick,
Expand Down Expand Up @@ -123,13 +123,13 @@ private fun SmartphoneFavoriteItemImpl(
}

@Composable
private fun TelevisionFavouriteItemImpl(
private fun TvFavouriteItemImpl(
stream: Stream,
onClick: () -> Unit,
onLongClick: () -> Unit,
modifier: Modifier = Modifier,
) {
androidx.tv.material3.ListItem(
TvListItem(
selected = false,
onClick = onClick,
onLongClick = onLongClick,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.cachedIn
import androidx.paging.filter
import androidx.work.WorkInfo
import androidx.work.WorkManager
import androidx.work.WorkQuery
Expand Down Expand Up @@ -248,28 +247,33 @@ class PlaylistViewModel @Inject constructor(
val playlistUrl: String,
val query: String,
val sort: Sort,
val categories: List<String>
val categories: List<String>,
)

data class Channel(
val category: String,
val streams: Flow<PagingData<Stream>>
val streams: Flow<PagingData<Stream>>,
)

internal val channels: StateFlow<List<Channel>> = combine(
playlistUrl,
playlistUrl.flatMapLatest { playlistRepository.observe(it) },
query,
sort
) { playlistUrl, query, sort ->
val categories = playlistRepository.getCategoriesByPlaylistUrlIgnoreHidden(playlistUrl)
) { playlist, query, sort ->
val playlistUrl = playlist?.url ?: return@combine null
val categories = playlistUrl.let {
playlistRepository.getCategoriesByPlaylistUrlIgnoreHidden(it, query)
}
PagingStreamParameters(
playlistUrl = playlistUrl,
query = query,
sort = sort,
categories = categories
)
}
.map { (playlistUrl, query, sort, categories) ->
.map { params ->
params ?: return@map emptyList()
val (playlistUrl, query, sort, categories) = params
categories.map { category ->
Channel(
category = category,
Expand All @@ -287,7 +291,6 @@ class PlaylistViewModel @Inject constructor(
)
}
.flow
.map { data -> data.filter { !it.hidden } }
.cachedIn(viewModelScope)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.material.icons.rounded.BrokenImage
import androidx.compose.material.icons.rounded.Star
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ListItem
import androidx.compose.material3.ListItemDefaults
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedCard
Expand Down Expand Up @@ -107,7 +108,8 @@ internal fun SmartphoneStreamItem(
OutlinedCard(
modifier = Modifier.semantics(mergeDescendants = true) { },
border = CardDefaults.outlinedCardBorder(zapping),
shape = AbsoluteSmoothCornerShape(spacing.medium, 65),
colors = CardDefaults.cardColors(Color.Transparent),
shape = AbsoluteSmoothCornerShape(spacing.medium, 65)
) {
when {
!noPictureMode && isVodOrSeriesPlaylist -> {
Expand Down Expand Up @@ -229,6 +231,7 @@ internal fun SmartphoneStreamItem(
trailingContent = {
star()
},
colors = ListItemDefaults.colors(Color.Transparent),
modifier = Modifier
.combinedClickable(
onClick = onClick,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ package com.m3u.features.playlist.internal
import android.content.res.Configuration.ORIENTATION_LANDSCAPE
import android.content.res.Configuration.ORIENTATION_PORTRAIT
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.staggeredgrid.rememberLazyStaggeredGridState
import androidx.compose.material.BackdropScaffold
Expand Down Expand Up @@ -58,7 +60,6 @@ import com.m3u.material.ktx.isAtTop
import com.m3u.material.ktx.split
import com.m3u.material.model.LocalHazeState
import com.m3u.material.model.LocalSpacing
import com.m3u.material.texture.MeshContainer
import com.m3u.ui.EventHandler
import com.m3u.ui.MediaSheet
import com.m3u.ui.MediaSheetValue
Expand Down Expand Up @@ -180,58 +181,60 @@ internal fun SmartphonePlaylistScreenImpl(
onValueChange = onQuery,
fontWeight = FontWeight.Bold,
placeholder = stringResource(string.feat_playlist_query_placeholder).uppercase(),
modifier = Modifier.focusRequester(focusRequester)
modifier = Modifier
.focusRequester(focusRequester)
.heightIn(max = 48.dp)
)
}
},
frontLayerContent = {
MeshContainer {
val state = rememberLazyStaggeredGridState()
LaunchedEffect(Unit) {
snapshotFlow { state.isAtTop }
.onEach { isAtTopState.value = it }
.launchIn(this)
}
EventHandler(scrollUp) {
state.scrollToItem(0)
}
val orientation = configuration.orientation
val actualRowCount = remember(orientation, rowCount) {
when (orientation) {
ORIENTATION_LANDSCAPE -> rowCount + 2
ORIENTATION_PORTRAIT -> rowCount
else -> rowCount
}
val state = rememberLazyStaggeredGridState()
LaunchedEffect(Unit) {
snapshotFlow { state.isAtTop }
.onEach { isAtTopState.value = it }
.launchIn(this)
}
EventHandler(scrollUp) {
state.scrollToItem(0)
}
val orientation = configuration.orientation
val actualRowCount = remember(orientation, rowCount) {
when (orientation) {
ORIENTATION_LANDSCAPE -> rowCount + 2
ORIENTATION_PORTRAIT -> rowCount
else -> rowCount
}
Column {
PlaylistTabRow(
selectedCategory = category,
categories = categories,
onCategoryChanged = { category = it },
pinnedCategories = pinnedCategories,
onPinOrUnpinCategory = onPinOrUnpinCategory,
onHideCategory = onHideCategory
)
val channel = channels.find { it.category == category }
SmartphoneStreamGallery(
state = state,
rowCount = actualRowCount,
channel = channel,
zapping = zapping,
recently = sort == Sort.RECENTLY,
isVodOrSeriesPlaylist = isVodOrSeriesPlaylist,
onClick = onStream,
contentPadding = inner,
onLongClick = {
mediaSheetValue = MediaSheetValue.PlaylistScreen(it)
},
getProgrammeCurrently = getProgrammeCurrently,
modifier = modifier.haze(
LocalHazeState.current,
HazeDefaults.style(MaterialTheme.colorScheme.surface)
)
}
Column(
Modifier.background(MaterialTheme.colorScheme.background)
) {
PlaylistTabRow(
selectedCategory = category,
categories = categories,
onCategoryChanged = { category = it },
pinnedCategories = pinnedCategories,
onPinOrUnpinCategory = onPinOrUnpinCategory,
onHideCategory = onHideCategory
)
val channel = channels.find { it.category == category }
SmartphoneStreamGallery(
state = state,
rowCount = actualRowCount,
channel = channel,
zapping = zapping,
recently = sort == Sort.RECENTLY,
isVodOrSeriesPlaylist = isVodOrSeriesPlaylist,
onClick = onStream,
contentPadding = inner,
onLongClick = {
mediaSheetValue = MediaSheetValue.PlaylistScreen(it)
},
getProgrammeCurrently = getProgrammeCurrently,
modifier = modifier.haze(
LocalHazeState.current,
HazeDefaults.style(MaterialTheme.colorScheme.surface)
)
}
)
}
},
backLayerBackgroundColor = Color.Transparent,
Expand Down
Loading

0 comments on commit 7f16a82

Please sign in to comment.