Skip to content

Commit

Permalink
Improving Share card
Browse files Browse the repository at this point in the history
  • Loading branch information
shub39 committed Aug 17, 2024
1 parent 6188414 commit cc8db97
Show file tree
Hide file tree
Showing 12 changed files with 218 additions and 213 deletions.
14 changes: 7 additions & 7 deletions app/src/main/java/com/shub39/rush/database/SettingsDataStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ object SettingsDataStore {
private val TOGGLE_THEME = stringPreferencesKey("toggle_theme")
private val SORT_ORDER = stringPreferencesKey("sort_order")
private val CARD_COLOR = stringPreferencesKey("card_color")
private val CARD_WIDTH = stringPreferencesKey("card_width")
private val CARD_ROUNDNESS = stringPreferencesKey("card_roundness")
private val LOGO = stringPreferencesKey("logo")

fun getCardColorFlow(context: Context): Flow<String> = context.dataStore.data
.catch {
Expand All @@ -31,12 +31,12 @@ object SettingsDataStore {
preferences[CARD_COLOR] ?: "Vibrant"
}

fun getCardWidthFlow(context: Context): Flow<String> = context.dataStore.data
fun getLogoFlow(context: Context): Flow<String> = context.dataStore.data
.catch {
Log.e(TAG, it.message, it)
}
.map { preferences ->
preferences[CARD_WIDTH] ?: "Small"
preferences[LOGO] ?: "None"
}

fun getCardRoundnessFlow(context: Context): Flow<String> = context.dataStore.data
Expand Down Expand Up @@ -77,15 +77,15 @@ object SettingsDataStore {
}
}

suspend fun updateCardColor(context: Context, newCardColor: String) {
suspend fun updateLogo(context: Context, newLogo: String) {
context.dataStore.edit { settings ->
settings[CARD_COLOR] = newCardColor
settings[LOGO] = newLogo
}
}

suspend fun updateCardWidth(context: Context, newCardWidth: String) {
suspend fun updateCardColor(context: Context, newCardColor: String) {
context.dataStore.edit { settings ->
settings[CARD_WIDTH] = newCardWidth
settings[CARD_COLOR] = newCardColor
}
}

Expand Down
26 changes: 15 additions & 11 deletions app/src/main/java/com/shub39/rush/page/LyricsPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,11 @@ fun LyricsPage(
rushViewModel: RushViewModel,
lazyListState: LazyListState,
bottomSheet: () -> Unit,
bottomSheetAutofill: () -> Unit
bottomSheetAutofill: () -> Unit,
) {
val song by rushViewModel.currentSong.collectAsState()
val fetching by rushViewModel.isFetchingLyrics.collectAsState()
val context = LocalContext.current
var isSharePageVisible by remember { mutableStateOf(false) }
var syncedAvailable by remember { mutableStateOf(false) }
var sync by remember { mutableStateOf(false) }
var source by remember { mutableStateOf("") }
Expand All @@ -82,14 +81,10 @@ fun LyricsPage(
val currentPlayingSong by rushViewModel.currentPlayingSongInfo.collectAsState()
val artGraphicsLayer = rememberGraphicsLayer()
val coroutineScope = rememberCoroutineScope()
var isShareSheetOpen by remember { mutableStateOf(false) }

if (isSharePageVisible) {
SharePage(
onShare = { isSharePageVisible = false },
onDismiss = { isSharePageVisible = false },
song = song!!,
selectedLines = selectedLines
)
if (isShareSheetOpen) {
SharePage(onDismiss = { isShareSheetOpen = false }, rushViewModel = rushViewModel)
}

if (fetching) {
Expand All @@ -108,9 +103,11 @@ fun LyricsPage(
source == "LrcLib" && nonNullSong.lyrics.isNotEmpty() -> {
breakLyrics(nonNullSong.lyrics).entries.toList()
}

source == "Genius" && nonNullSong.geniusLyrics != null -> {
breakLyrics(nonNullSong.geniusLyrics).entries.toList()
}

else -> {
emptyList()
}
Expand Down Expand Up @@ -214,7 +211,11 @@ fun LyricsPage(
}
}
}
Box(modifier = Modifier.fillMaxWidth().padding(end = 16.dp), contentAlignment = Alignment.CenterEnd){
Box(
modifier = Modifier
.fillMaxWidth()
.padding(end = 16.dp), contentAlignment = Alignment.CenterEnd
) {
Row(verticalAlignment = Alignment.CenterVertically) {
IconButton(
onClick = {
Expand Down Expand Up @@ -271,7 +272,10 @@ fun LyricsPage(
}
AnimatedVisibility(visible = selectedLines.isNotEmpty()) {
Row {
IconButton(onClick = { isSharePageVisible = true }) {
IconButton(onClick = {
rushViewModel.updateShareLines(selectedLines)
isShareSheetOpen = true
}) {
Icon(
painter = painterResource(id = R.drawable.round_share_24),
contentDescription = null
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/shub39/rush/page/RushApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ fun RushApp(
lazyListState.scrollToItem(0)
}
},
rushViewModel = rushViewModel
rushViewModel = rushViewModel,
)
}
composable("settings") {
Expand Down Expand Up @@ -278,7 +278,7 @@ fun RushPager(
lazyListState = lazyListState,
rushViewModel = rushViewModel,
bottomSheet = bottomSheet,
bottomSheetAutofill = bottomSheetAutofill
bottomSheetAutofill = bottomSheetAutofill,
)

1 -> SavedPage(
Expand Down
Loading

0 comments on commit cc8db97

Please sign in to comment.