Skip to content

Commit

Permalink
feat(home_screen): ytm account to homescreen closes #55
Browse files Browse the repository at this point in the history
  • Loading branch information
Malopieds committed Apr 17, 2024
1 parent db3d8f9 commit 453cfc8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
41 changes: 41 additions & 0 deletions app/src/main/java/com/zionhuang/music/ui/screens/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ fun HomeScreen(
val homeSecondContinuation by viewModel.homeSecondContinuation.collectAsState()
val homeThirdContinuation by viewModel.homeThirdContinuation.collectAsState()

val youtubePlaylists by viewModel.youtubePlaylists.collectAsState()

val isRefreshing by viewModel.isRefreshing.collectAsState()
val mostPlayedLazyGridState = rememberLazyGridState()

Expand Down Expand Up @@ -264,6 +266,45 @@ fun HomeScreen(
}
}

if (youtubePlaylists?.isNotEmpty() == true) {
NavigationTitle(
title = "Your Youtube playlists",
onClick = {
navController.navigate("account")
}
)
LazyRow(
contentPadding = WindowInsets.systemBars
.only(WindowInsetsSides.Horizontal)
.asPaddingValues()
) {
items(
items = youtubePlaylists.orEmpty(),
key = { it.id }
) { item ->
YouTubeGridItem(
item = item,
modifier = Modifier
.combinedClickable(
onClick = {
navController.navigate("online_playlist/${item.id}")
},
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
menuState.show {
YouTubePlaylistMenu(
playlist = item,
coroutineScope = coroutineScope,
onDismiss = menuState::dismiss
)
}
}
)
)
}
}
}

if (keepListening?.isNotEmpty() == true) {
keepListening?.let {
NavigationTitle(
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/zionhuang/music/viewmodels/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.zionhuang.music.viewmodels
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.zionhuang.innertube.YouTube
import com.zionhuang.innertube.models.PlaylistItem
import com.zionhuang.innertube.models.WatchEndpoint
import com.zionhuang.innertube.models.YTItem
import com.zionhuang.innertube.pages.AlbumUtils
Expand Down Expand Up @@ -52,6 +53,8 @@ class HomeViewModel @Inject constructor(
val homeSecondArtistRecommendation = MutableStateFlow<HomeArtistRecommendation?>(null)
val homeThirdArtistRecommendation = MutableStateFlow<HomeArtistRecommendation?>(null)

val youtubePlaylists = MutableStateFlow<List<PlaylistItem>?>(null)

private suspend fun load() {
quickPicks.value = database.quickPicks().first().shuffled().take(20)
val artists = database.mostPlayedArtists(System.currentTimeMillis() - 86400000 * 7 * 2).first().shuffled().take(5)
Expand Down Expand Up @@ -84,6 +87,14 @@ class HomeViewModel @Inject constructor(
songsAlbumRecommendation.value = database.getRecommendationAlbum(limit = 10).first().shuffled().take(2)

artistRecommendation.value = database.mostPlayedArtists(System.currentTimeMillis() - 86400000 * 7, limit = 10).first().shuffled().take(3)

viewModelScope.launch {
YouTube.likedPlaylists().onSuccess {
youtubePlaylists.value = it
}.onFailure {
reportException(it)
}
}
}

private suspend fun homeLoad() {
Expand Down

0 comments on commit 453cfc8

Please sign in to comment.