Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ import com.maxrave.simpmusic.ui.navigation.destination.list.PodcastDestination
import com.maxrave.simpmusic.ui.theme.typo
import com.maxrave.simpmusic.viewModel.LibraryViewModel
import com.maxrave.simpmusic.viewModel.SharedViewModel
import kotlinx.coroutines.runBlocking
import org.jetbrains.compose.resources.getString
import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.resources.stringResource
Expand Down Expand Up @@ -235,6 +234,7 @@ fun LibraryItem(
) {
items(state.data) { item ->
val song = item as? SongEntity ?: return@items
val radioLabel = stringResource(Res.string.radio)
Box(
Modifier
.padding(horizontal = 10.dp)
Expand All @@ -247,7 +247,7 @@ fun LibraryItem(
listTracks = arrayListOf(firstQueue),
firstPlayedTrack = firstQueue,
playlistId = "RDAMVM${firstQueue.videoId}",
playlistName = "\"${song.title}\" ${runBlocking { getString(Res.string.radio) }}",
playlistName = "\"${song.title}\" $radioLabel",
playlistType = DomainPlaylistType.RADIO,
continuation = null,
),
Expand Down Expand Up @@ -441,4 +441,4 @@ data class LibraryItemState(
val type: LibraryItemType,
val data: List<LibraryType>,
val isLoading: Boolean = true,
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import multiplatform.network.cmptoast.ToastGravity
import multiplatform.network.cmptoast.showToast
import org.jetbrains.compose.resources.StringResource
Expand Down Expand Up @@ -1433,6 +1432,7 @@ fun NowPlayingBottomSheet(
var isBottomSheetVisible by rememberSaveable { mutableStateOf(false) }
var changePlaybackSpeedPitch by remember { mutableStateOf(false) }
val crossfadeEnabled by dataStoreManager.crossfadeEnabled.collectAsState(DataStoreManager.FALSE)
val radioLabel = stringResource(Res.string.radio)

LaunchedEffect(uiState) {
if (uiState.songUIState.videoId.isNotEmpty() && !isBottomSheetVisible) {
Expand Down Expand Up @@ -1819,7 +1819,7 @@ fun NowPlayingBottomSheet(
viewModel.onUIEvent(
NowPlayingBottomSheetUIEvent.StartRadio(
videoId = uiState.songUIState.videoId,
name = "\"${uiState.songUIState.title}\" ${runBlocking { getString(Res.string.radio) }}",
name = "\"${uiState.songUIState.title}\" $radioLabel",
),
)
hideModalBottomSheet()
Expand Down Expand Up @@ -2185,6 +2185,7 @@ fun SleepTimerBottomSheet(
val coroutineScope = rememberCoroutineScope()
val modelBottomSheetState =
rememberModalBottomSheetState(skipPartiallyExpanded = true)
val sleepTimerError = stringResource(Res.string.sleep_timer_set_error)

// -1 = nothing selected, Int.MAX_VALUE = End of Song, else = minutes
var selectedPreset by rememberSaveable { mutableIntStateOf(-1) }
Expand Down Expand Up @@ -2423,7 +2424,7 @@ fun SleepTimerBottomSheet(
}
} else {
showToast(
runBlocking { getString(Res.string.sleep_timer_set_error) },
sleepTimerError,
ToastGravity.Bottom,
)
}
Expand All @@ -2437,7 +2438,7 @@ fun SleepTimerBottomSheet(
}
else -> {
showToast(
runBlocking { getString(Res.string.sleep_timer_set_error) },
sleepTimerError,
ToastGravity.Bottom,
)
}
Expand Down Expand Up @@ -3135,6 +3136,9 @@ fun DevLogInBottomSheet(

var value by rememberSaveable { mutableStateOf("") }
var secondValue by rememberSaveable { mutableStateOf("") }
val title = stringResource(type.titleRes())
val processingMessage = stringResource(Res.string.processing)
val emptyErrorMessage = stringResource(Res.string.can_not_be_empty)

ModalBottomSheet(
onDismissRequest = onDismiss,
Expand All @@ -3158,7 +3162,7 @@ fun DevLogInBottomSheet(
shape = RoundedCornerShape(50),
) {}
Spacer(modifier = Modifier.height(10.dp))
Text(text = runBlocking { type.getTitle() }, style = typo().labelSmall)
Text(text = title, style = typo().labelSmall)
Spacer(modifier = Modifier.height(5.dp))
OutlinedTextField(
value = value,
Expand All @@ -3183,11 +3187,11 @@ fun DevLogInBottomSheet(
if (value.isNotEmpty() && value.isNotBlank() &&
(type != DevLogInType.YouTube || (secondValue.isNotEmpty() && secondValue.isNotBlank()))
) {
showToast(runBlocking { getString(Res.string.processing) }, ToastGravity.Bottom)
showToast(processingMessage, ToastGravity.Bottom)
onDismiss()
onDone(value, secondValue)
} else {
showToast(runBlocking { getString(Res.string.can_not_be_empty) }, ToastGravity.Bottom)
showToast(emptyErrorMessage, ToastGravity.Bottom)
}
},
modifier = Modifier.fillMaxWidth().padding(horizontal = 20.dp),
Expand Down Expand Up @@ -3288,10 +3292,10 @@ sealed class DevLogInType {

data object Discord : DevLogInType()

suspend fun getTitle(): String =
fun titleRes(): StringResource =
when (this) {
is Spotify -> getString(Res.string.your_sp_dc_param_of_spotify_cookie)
is YouTube -> getString(Res.string.your_youtube_cookie)
is Discord -> getString(Res.string.your_discord_token)
Spotify -> Res.string.your_sp_dc_param_of_spotify_cookie
YouTube -> Res.string.your_youtube_cookie
Discord -> Res.string.your_discord_token
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import androidx.compose.material3.pulltorefresh.PullToRefreshBox
import androidx.compose.material3.pulltorefresh.PullToRefreshDefaults
import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -219,9 +220,6 @@ fun HomeScreen(
val moodMomentAndGenre by viewModel.exploreMoodItem.collectAsStateWithLifecycle()
val chartLoading by viewModel.loadingChart.collectAsStateWithLifecycle()
val loading by viewModel.loading.collectAsStateWithLifecycle()
var accountShow by rememberSaveable {
mutableStateOf(false)
}
val regionChart by viewModel.regionCodeChart.collectAsStateWithLifecycle()
val reloadDestination by sharedViewModel.reloadDestination.collectAsStateWithLifecycle()
val pullToRefreshState = rememberPullToRefreshState()
Expand All @@ -230,18 +228,49 @@ fun HomeScreen(
val params by viewModel.params.collectAsStateWithLifecycle()
val homeListState by viewModel.homeListState.collectAsStateWithLifecycle()
val continuation by viewModel.continuation.collectAsStateWithLifecycle()
val quickPicksTitle = stringResource(Res.string.quick_picks)
val quickPicksItem by remember(homeData, quickPicksTitle) {
derivedStateOf {
homeData.find { it.title == quickPicksTitle }?.let { content ->
content.copy(
contents =
content.contents.mapNotNull { ct ->
ct?.copy(
artists =
ct.artists?.let { art ->
if (art.size > 1) {
art.dropLast(1)
} else {
art
}
},
)
},
)
}
}
}

val shouldShowLogInAlert by viewModel.showLogInAlert.collectAsStateWithLifecycle()

val openAppTime by sharedViewModel.openAppTime.collectAsStateWithLifecycle()
val shareLyricsPermissions by sharedViewModel.shareSavedLyrics.collectAsStateWithLifecycle()

var topHeaderColor by remember {
mutableStateOf(md_theme_dark_background)
val accountShow by remember(homeData, accountInfo) {
derivedStateOf {
accountInfo == null || homeData.none { it.subtitle == accountInfo?.first }
}
}
var topHeaderColor by remember { mutableStateOf(md_theme_dark_background) }
val animatedColor by animateColorAsState(topHeaderColor, tween(500))
val mainHomeThumbnail by viewModel.mainHomeThumbnail.collectAsStateWithLifecycle()
val networkLoader = rememberNetworkLoader(HttpClient(CIO))
val paletteClient = remember { HttpClient(CIO) }
DisposableEffect(paletteClient) {
onDispose {
paletteClient.close()
}
}
val networkLoader = rememberNetworkLoader(paletteClient)
val dominantColorState =
rememberDominantColorState(
defaultColor = md_theme_dark_background,
Expand Down Expand Up @@ -314,9 +343,6 @@ fun HomeScreen(
}
}
}
LaunchedEffect(key1 = homeData) {
accountShow = homeData.find { it.subtitle == accountInfo?.first } == null
}
LaunchedEffect(openAppTime, shareLyricsPermissions) {
Logger.w("HomeScreen", "openAppTime: $openAppTime, shareLyricsPermissions: $shareLyricsPermissions")
if (openAppTime >= 10 && openAppTime % 10 == 0 && openAppTime <= 50) {
Expand Down Expand Up @@ -479,9 +505,13 @@ fun HomeScreen(
state = scrollState,
verticalArrangement = Arrangement.spacedBy(28.dp),
) {
itemsIndexed(homeData, key = { _, item ->
item.hashCode().toString() + (mainHomeThumbnail ?: "nothumb")
}) { index, item ->
itemsIndexed(
items = homeData,
key = { index, item ->
"${item.title}-${item.subtitle ?: "nosub"}-${item.channelId ?: index}"
},
contentType = { _, item -> item.title },
) { index, item ->
Box {
if (index == 0) {
Box(
Expand Down Expand Up @@ -530,42 +560,12 @@ fun HomeScreen(
)
Spacer(Modifier.height(8.dp))
}
if (item.title == stringResource(Res.string.quick_picks)) {
if (item.title == quickPicksTitle) {
AnimatedVisibility(
visible =
homeData.find {
it.title ==
stringResource(
Res.string.quick_picks,
)
} != null,
visible = quickPicksItem != null,
) {
QuickPicks(
homeItem =
(
homeData.find {
it.title ==
stringResource(
Res.string.quick_picks,
)
} ?: return@AnimatedVisibility
).let { content ->
content.copy(
contents =
content.contents.mapNotNull { ct ->
ct?.copy(
artists =
ct.artists?.let { art ->
if (art.size > 1) {
art.dropLast(1)
} else {
art
}
},
)
},
)
},
homeItem = quickPicksItem ?: return@AnimatedVisibility,
viewModel = viewModel,
)
}
Expand Down Expand Up @@ -593,7 +593,11 @@ fun HomeScreen(
}
}
if (homeListState == ListState.PAGINATION_EXHAUST) {
items(newRelease, key = { it.hashCode() }) {
items(
items = newRelease,
key = { "${it.title}-${it.subtitle ?: "nosub"}-${it.channelId ?: "new"}" },
contentType = { it.title },
) {
AnimatedVisibility(
visible = newRelease.isNotEmpty(),
) {
Expand Down Expand Up @@ -1153,4 +1157,4 @@ fun ChartData(
}
}
}
}
}
Loading