Skip to content

Commit

Permalink
Fixed #414
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrave-dev committed Jun 29, 2024
1 parent 4f83f63 commit 5d0aeec
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 108 deletions.
14 changes: 12 additions & 2 deletions app/src/main/java/com/maxrave/simpmusic/data/db/DatabaseDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -414,14 +414,24 @@ interface DatabaseDao {
): List<PairSongLocalPlaylist>?

@Query(
"SELECT * FROM pair_song_local_playlist WHERE playlistId = :playlistId ORDER BY position " +
"DESC LIMIT 50 OFFSET :offset",
"SELECT * FROM pair_song_local_playlist WHERE playlistId = :playlistId AND position >= :offset ORDER BY position " +
"LIMIT 50",
)
suspend fun getPlaylistPairSongByOffsetDesc(
playlistId: Long,
offset: Int,
): List<PairSongLocalPlaylist>?

@Query(
"SELECT * FROM pair_song_local_playlist WHERE playlistId = :playlistId AND position >= :from AND position < :to ORDER BY position " +
"LIMIT 50",
)
suspend fun getPlaylistPairSongByFromToDesc(
playlistId: Long,
from: Int,
to: Int,
): List<PairSongLocalPlaylist>?

@Query(
"DELETE FROM pair_song_local_playlist WHERE songId = :videoId AND playlistId = :playlistId",
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.maxrave.simpmusic.data.db

import android.util.Log
import com.maxrave.simpmusic.data.db.entities.AlbumEntity
import com.maxrave.simpmusic.data.db.entities.ArtistEntity
import com.maxrave.simpmusic.data.db.entities.FollowedArtistSingleAndAlbum
Expand Down Expand Up @@ -239,13 +240,32 @@ class LocalDataSource
playlistId: Long,
offset: Int,
filterState: FilterState,
totalCount: Int
) = if (filterState == FilterState.OlderFirst) {
databaseDao.getPlaylistPairSongByOffsetAsc(
playlistId,
offset * 50,
)
} else {
databaseDao.getPlaylistPairSongByOffsetDesc(playlistId, offset * 50)
Log.w("Pair LocalPlaylistViewModel", "getPlaylistPairSongByOffset: ${totalCount - (offset+1) * 50}")
if ((totalCount - (offset+1) * 50) > 0) {
databaseDao.getPlaylistPairSongByOffsetDesc(
playlistId, totalCount - (offset+1) * 50
)?.reversed()
}
else if ((totalCount - (offset + 1) * 50) >= -50 ) {
databaseDao.getPlaylistPairSongByFromToDesc(
playlistId, 0, totalCount - (offset + 1) * 50 + 50
)?.reversed()
}
else if (offset == 0) {
databaseDao.getPlaylistPairSongByOffsetDesc(
playlistId, 0
)?.reversed()
}
else {
null
}
}

suspend fun deletePairSongLocalPlaylist(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,10 @@ class MainRepository
playlistId: Long,
offset: Int,
filterState: FilterState,
totalCount: Int
): Flow<List<PairSongLocalPlaylist>?> =
flow {
emit(localDataSource.getPlaylistPairSongByOffset(playlistId, offset, filterState))
emit(localDataSource.getPlaylistPairSongByOffset(playlistId, offset, filterState, totalCount))
}.flowOn(Dispatchers.IO)

suspend fun deletePairSongLocalPlaylist(
Expand Down Expand Up @@ -936,6 +937,10 @@ class MainRepository
)?.tabRenderer?.content?.sectionListRenderer?.continuations?.get(
0,
)?.nextContinuationData?.continuation
?:
result.contents?.twoColumnBrowseResultsRenderer?.secondaryContents
?.sectionListRenderer?.continuations?.firstOrNull()
?.nextContinuationData?.continuation
val dataResult: ArrayList<MusicShelfRenderer.Content> = arrayListOf()
var reloadParams: String? = null
println("continueParam: $continueParam")
Expand Down
168 changes: 86 additions & 82 deletions app/src/main/java/com/maxrave/simpmusic/ui/screen/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,17 @@ fun HomeScreen(
HomeTopAppBar(navController)
Box(
modifier =
Modifier
.nestedScroll(pullToRefreshState.nestedScrollConnection)
.padding(vertical = 8.dp),
Modifier
.nestedScroll(pullToRefreshState.nestedScrollConnection)
.padding(vertical = 8.dp),
contentAlignment = Alignment.Center,
) {
PullToRefreshContainer(
modifier =
Modifier
.align(Alignment.TopCenter)
.padding(top = 15.dp)
.graphicsLayer(scaleX = scaleFraction, scaleY = scaleFraction),
Modifier
.align(Alignment.TopCenter)
.padding(top = 15.dp)
.graphicsLayer(scaleX = scaleFraction, scaleY = scaleFraction),
state = pullToRefreshState,
)
Spacer(modifier = Modifier.height(8.dp))
Expand Down Expand Up @@ -237,54 +237,58 @@ fun HomeScreen(
}
}
item {
Column(
Modifier
.padding(vertical = 10.dp),
verticalArrangement = Arrangement.SpaceBetween,
) {
ChartTitle()
Spacer(modifier = Modifier.height(5.dp))
Crossfade(targetState = regionChart) {
Log.w("HomeScreen", "regionChart: $it")
if (it != null) {
DropdownButton(
items = CHART_SUPPORTED_COUNTRY.itemsData.toList(),
defaultSelected =
CHART_SUPPORTED_COUNTRY.itemsData.getOrNull(
CHART_SUPPORTED_COUNTRY.items.indexOf(it),
)
?: CHART_SUPPORTED_COUNTRY.itemsData[1],
) {
viewModel.exploreChart(
CHART_SUPPORTED_COUNTRY.items[
CHART_SUPPORTED_COUNTRY.itemsData.indexOf(
it,
),
],
)
Crossfade(targetState = chart == null && !chartLoading) { noData ->
if (!noData) {
Column(
Modifier
.padding(vertical = 10.dp),
verticalArrangement = Arrangement.SpaceBetween,
) {
ChartTitle()
Spacer(modifier = Modifier.height(5.dp))
Crossfade(targetState = regionChart) {
Log.w("HomeScreen", "regionChart: $it")
if (it != null) {
DropdownButton(
items = CHART_SUPPORTED_COUNTRY.itemsData.toList(),
defaultSelected =
CHART_SUPPORTED_COUNTRY.itemsData.getOrNull(
CHART_SUPPORTED_COUNTRY.items.indexOf(it),
)
?: CHART_SUPPORTED_COUNTRY.itemsData[1],
) {
viewModel.exploreChart(
CHART_SUPPORTED_COUNTRY.items[
CHART_SUPPORTED_COUNTRY.itemsData.indexOf(
it,
),
],
)
}
}
}
}
}
Spacer(modifier = Modifier.height(5.dp))
Crossfade(
targetState = chartLoading,
label = "Chart",
) { loading ->
if (!loading) {
chart?.let {
ChartData(
chart = it,
navController = navController,
context = context,
)
Spacer(modifier = Modifier.height(5.dp))
Crossfade(
targetState = chartLoading,
label = "Chart",
) { loading ->
if (!loading) {
chart?.let {
ChartData(
chart = it,
navController = navController,
context = context,
)
}
} else {
CenterLoadingBox(
modifier =
Modifier
.fillMaxWidth()
.height(400.dp),
)
}
}
} else {
CenterLoadingBox(
modifier =
Modifier
.fillMaxWidth()
.height(400.dp),
)
}
}
}
Expand Down Expand Up @@ -391,11 +395,11 @@ fun AccountLayout(
)
},
modifier =
Modifier
.size(40.dp)
.clip(
CircleShape,
),
Modifier
.size(40.dp)
.clip(
CircleShape,
),
)
Text(
text = accountName,
Expand Down Expand Up @@ -427,9 +431,9 @@ fun QuickPicks(
style = typo.headlineMedium,
maxLines = 1,
modifier =
Modifier
.fillMaxWidth()
.padding(vertical = 5.dp),
Modifier
.fillMaxWidth()
.padding(vertical = 5.dp),
)
LazyHorizontalGrid(rows = GridCells.Fixed(3), modifier = Modifier.height(210.dp)) {
items(homeItem.contents) {
Expand Down Expand Up @@ -472,9 +476,9 @@ fun MoodMomentAndGenre(
style = typo.headlineMedium,
maxLines = 1,
modifier =
Modifier
.fillMaxWidth()
.padding(vertical = 5.dp),
Modifier
.fillMaxWidth()
.padding(vertical = 5.dp),
)
LazyHorizontalGrid(rows = GridCells.Fixed(3), modifier = Modifier.height(210.dp)) {
items(mood.moodsMoments) {
Expand All @@ -493,9 +497,9 @@ fun MoodMomentAndGenre(
style = typo.headlineMedium,
maxLines = 1,
modifier =
Modifier
.fillMaxWidth()
.padding(vertical = 5.dp),
Modifier
.fillMaxWidth()
.padding(vertical = 5.dp),
)
LazyHorizontalGrid(rows = GridCells.Fixed(3), modifier = Modifier.height(210.dp)) {
items(mood.genres) {
Expand Down Expand Up @@ -524,9 +528,9 @@ fun ChartTitle() {
style = typo.headlineMedium,
maxLines = 1,
modifier =
Modifier
.fillMaxWidth()
.padding(vertical = 5.dp),
Modifier
.fillMaxWidth()
.padding(vertical = 5.dp),
)
}
}
Expand All @@ -549,9 +553,9 @@ fun ChartData(
style = typo.headlineMedium,
maxLines = 1,
modifier =
Modifier
.fillMaxWidth()
.padding(vertical = 10.dp),
Modifier
.fillMaxWidth()
.padding(vertical = 10.dp),
)
if (!chart.songs.isNullOrEmpty()) {
LazyHorizontalGrid(
Expand Down Expand Up @@ -585,9 +589,9 @@ fun ChartData(
style = typo.headlineMedium,
maxLines = 1,
modifier =
Modifier
.fillMaxWidth()
.padding(vertical = 10.dp),
Modifier
.fillMaxWidth()
.padding(vertical = 10.dp),
)
LazyRow {
items(chart.videos.items.size) {
Expand Down Expand Up @@ -616,9 +620,9 @@ fun ChartData(
style = typo.headlineMedium,
maxLines = 1,
modifier =
Modifier
.fillMaxWidth()
.padding(vertical = 10.dp),
Modifier
.fillMaxWidth()
.padding(vertical = 10.dp),
)
LazyHorizontalGrid(rows = GridCells.Fixed(3), modifier = Modifier.height(240.dp)) {
items(chart.artists.itemArtists.size) {
Expand All @@ -637,9 +641,9 @@ fun ChartData(
style = typo.headlineMedium,
maxLines = 1,
modifier =
Modifier
.fillMaxWidth()
.padding(vertical = 10.dp),
Modifier
.fillMaxWidth()
.padding(vertical = 10.dp),
)
if (!chart.trending.isNullOrEmpty()) {
LazyHorizontalGrid(
Expand Down
Loading

0 comments on commit 5d0aeec

Please sign in to comment.