Skip to content

Commit

Permalink
Updated metadata and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
shub39 committed Jul 17, 2024
1 parent c33e7c5 commit 0104afe
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 84 deletions.
4 changes: 2 additions & 2 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
- [x] Download Lyrics
- [x] Share Lyrics
- [x] Customisations
- [x] Auto-Search current playing song
- [x] Auto-fill current playing song in search

## Why ❔
Spotify removed its feature to see and share lyrics from its free tier. So I made this app to get and store lyrics for my favorite songs from Genius and share them like Spotify, all in Material 3 look.
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
Binary file modified app/release/baselineProfiles/0/app-release.dm
Binary file not shown.
Binary file modified app/release/baselineProfiles/1/app-release.dm
Binary file not shown.
2 changes: 0 additions & 2 deletions app/src/main/java/com/shub39/rush/genius/LyricsFetcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ object LyricsFetcher {
lyrics += formatGeniusLyrics(it.wholeText())
lyrics += "\n"
}
Log.d("Scraper", document.toString())
lyrics
}
}
Expand All @@ -74,7 +73,6 @@ object LyricsFetcher {
if (!jsonSong.isNullOrEmpty()) {
val song = jsonSong[0]
val lyrics = song.plainLyrics
Log.d(TAG, "Lyrics: $lyrics")
return lyrics
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ object MediaListener {
private fun updateTitle(context: Context, metadata: MediaMetadata?) {
val title = metadata?.getString(MediaMetadata.METADATA_KEY_TITLE) ?: ""
val artist = metadata?.getString(MediaMetadata.METADATA_KEY_ARTIST) ?: metadata?.getString(MediaMetadata.METADATA_KEY_ALBUM_ARTIST) ?: ""
val searchTerm = "${getMainTitle(title)} \n$artist"
val searchTerm = "${getMainTitle(title)} $artist"
CoroutineScope(Dispatchers.IO).launch {
SettingsDataStore.updateCurrentPlayingSong(context, searchTerm)
Log.d(TAG, "searchTerm: $searchTerm")
Expand Down
54 changes: 32 additions & 22 deletions app/src/main/java/com/shub39/rush/page/LyricsPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.FloatingActionButtonDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
Expand Down Expand Up @@ -43,6 +45,7 @@ import com.shub39.rush.R
import com.shub39.rush.component.ArtFromUrl
import com.shub39.rush.component.Empty
import com.shub39.rush.database.SettingsDataStore
import com.shub39.rush.listener.NotificationListener
import com.shub39.rush.viewmodel.RushViewModel
import kotlinx.coroutines.launch

Expand All @@ -51,29 +54,16 @@ fun LyricsPage(
rushViewModel: RushViewModel,
lazyListState: LazyListState,
bottomSheet: () -> Unit,
lazyListRefresh: () -> 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 selectedLines by remember { mutableStateOf<Map<Int, String>>(emptyMap()) }
val maxLinesFlow by SettingsDataStore.getMaxLinesFlow(context).collectAsState(initial = 6)
val songAutofill by SettingsDataStore.getSongAutofillFlow(context)
.collectAsState(initial = false)
val currentPlayingSong by SettingsDataStore.getCurrentPlayingSongFlow(context)
.collectAsState(initial = "")
var previousSong by remember { mutableStateOf("") }
val coroutineScope = rememberCoroutineScope()

LaunchedEffect(currentPlayingSong) {
if (songAutofill && currentPlayingSong.isNotBlank() && currentPlayingSong != previousSong) {
rushViewModel.autoSearch(currentPlayingSong)
previousSong = currentPlayingSong
lazyListRefresh()
}
}

if (isSharePageVisible) {
SharePage(
onShare = { isSharePageVisible = false },
Expand Down Expand Up @@ -228,35 +218,55 @@ fun LyricsPage(
}

item {
Spacer(modifier = Modifier.padding(20.dp))
Spacer(modifier = Modifier.padding(10.dp))
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceEvenly
) {
OutlinedButton(
FloatingActionButton(
onClick = {
coroutineScope.launch {
lazyListState.scrollToItem(0)
}
}
},
elevation = FloatingActionButtonDefaults.elevation(0.dp),
shape = MaterialTheme.shapes.extraLarge,
containerColor = MaterialTheme.colorScheme.primary
) {
Icon(
painter = painterResource(id = R.drawable.round_arrow_upward_24),
contentDescription = null,
)
Spacer(modifier = Modifier.size(4.dp))
Text(text = stringResource(id = R.string.back_to_top))
}

OutlinedButton(onClick = { bottomSheet() }) {
if (NotificationListener.canAccessNotifications(context)) {
FloatingActionButton(
onClick = { bottomSheetAutofill() },
elevation = FloatingActionButtonDefaults.elevation(0.dp),
shape = MaterialTheme.shapes.extraLarge,
containerColor = MaterialTheme.colorScheme.primary
) {
Icon(
painter = painterResource(id = R.drawable.round_play_arrow_24),
contentDescription = null
)
}
}

FloatingActionButton(
onClick = { bottomSheet() },
elevation = FloatingActionButtonDefaults.elevation(0.dp),
shape = MaterialTheme.shapes.extraLarge,
containerColor = MaterialTheme.colorScheme.primary
) {
Icon(
painter = painterResource(id = R.drawable.round_search_24),
contentDescription = null
)
Spacer(modifier = Modifier.size(4.dp))
Text(text = stringResource(id = R.string.search_another))
}

}
Spacer(modifier = Modifier.padding(10.dp))
}
}
}
Expand Down
27 changes: 20 additions & 7 deletions app/src/main/java/com/shub39/rush/page/RushApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ fun RushApp(
var query by remember { mutableStateOf("") }
val searchResults by rushViewModel.searchResults.collectAsState()
val isFetchingLyrics by rushViewModel.isSearchingLyrics.collectAsState()
val currentSong by SettingsDataStore.getCurrentPlayingSongFlow(context)
.collectAsState(initial = "")

if (searchSheetState) {
ModalBottomSheet(
Expand All @@ -89,8 +91,12 @@ fun RushApp(
val keyboardController = LocalSoftwareKeyboardController.current
val focusRequester = remember { FocusRequester() }
LaunchedEffect(Unit) {
focusRequester.requestFocus()
keyboardController?.show()
if (query.isNotBlank()) {
rushViewModel.searchSong(query)
} else {
focusRequester.requestFocus()
keyboardController?.show()
}
}

Column(
Expand Down Expand Up @@ -218,7 +224,13 @@ fun RushApp(
RushPager(
lazyListState = lazyListState,
pagerState = pagerState,
bottomSheet = { searchSheetState = true },
bottomSheet = {
searchSheetState = true
},
bottomSheetAutofill = {
query = currentSong
searchSheetState = true
},
onPageChange = { page ->
coroutineScope.launch {
pagerState.animateScrollToPage(page)
Expand Down Expand Up @@ -246,6 +258,7 @@ fun RushPager(
lazyListState: LazyListState,
pagerState: PagerState,
bottomSheet: () -> Unit = {},
bottomSheetAutofill: () -> Unit = {},
onPageChange: (Int) -> Unit,
lazyListRefresh: () -> Unit,
rushViewModel: RushViewModel
Expand All @@ -257,14 +270,14 @@ fun RushPager(
0 -> LyricsPage(
lazyListState = lazyListState,
rushViewModel = rushViewModel,
bottomSheet = { bottomSheet() },
lazyListRefresh = lazyListRefresh

bottomSheet = bottomSheet,
bottomSheetAutofill = bottomSheetAutofill
)

1 -> SavedPage(
rushViewModel = rushViewModel,
bottomSheet = { bottomSheet() },
bottomSheet = bottomSheet,
bottomSheetAutofill = bottomSheetAutofill,
onClick = {
onPageChange(0)
lazyListRefresh()
Expand Down
26 changes: 7 additions & 19 deletions app/src/main/java/com/shub39/rush/page/SavedPage.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.shub39.rush.page

import androidx.annotation.StringRes
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateContentSize
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
Expand Down Expand Up @@ -45,6 +42,7 @@ import kotlinx.coroutines.launch
fun SavedPage(
rushViewModel: RushViewModel,
bottomSheet: () -> Unit,
bottomSheetAutofill: () -> Unit,
onClick: () -> Unit
) {
val context = LocalContext.current
Expand All @@ -53,8 +51,6 @@ fun SavedPage(
val lazyListState = rememberLazyListState()
val sortOrder by SettingsDataStore.getSortOrderFlow(context)
.collectAsState(initial = "title_asc")
val songAutofill by SettingsDataStore.getSongAutofillFlow(context)
.collectAsState(initial = true)
val sortedSongs = when (sortOrder) {
"title_asc" -> songs.value.sortedBy { it.title }
else -> songs.value.sortedByDescending { it.title }
Expand Down Expand Up @@ -163,30 +159,22 @@ fun SavedPage(
)
}

AnimatedVisibility(
modifier = Modifier
.align(Alignment.BottomEnd)
.padding(top = 16.dp, end = 80.dp, bottom = 16.dp),
visible = !songAutofill && NotificationListener.canAccessNotifications(context),
enter = fadeIn(),
exit = fadeOut()
) {
if (NotificationListener.canAccessNotifications(context)) {
FloatingActionButton(
onClick = {
coroutineScope.launch {
SettingsDataStore.updateSongAutofill(context, true)
}
onClick()
bottomSheetAutofill()
},
shape = MaterialTheme.shapes.extraLarge
shape = MaterialTheme.shapes.extraLarge,
modifier = Modifier
.align(Alignment.BottomEnd)
.padding(top = 16.dp, end = 80.dp, bottom = 16.dp),
) {
Icon(
painter = painterResource(id = R.drawable.round_play_arrow_24),
contentDescription = null
)
}
}

}
}

Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/shub39/rush/page/SharePage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ fun SharePage(
modifier = Modifier
.size(100.dp)
.clip(MaterialTheme.shapes.small),
imageLoader = imageLoader
)
Column(
modifier = Modifier.padding(start = 16.dp, end = 16.dp)
Expand Down
28 changes: 0 additions & 28 deletions app/src/main/java/com/shub39/rush/viewmodel/RushViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,6 @@ class RushViewModel(
}
}

fun autoSearch(query: String) {
if (query.isEmpty()) return

if (query.lines().first().trim() in songs.value.map { it.title } && query.lines().last().trim() in songs.value.map { it.artists }) {
changeCurrentSong(songs.value.first { it.title == query.lines().first().trim() }.id)
Log.d("ViewModel", "Query is already in the list of songs")
return
}

viewModelScope.launch {
_isFetchingLyrics.value = true
try {
val result = withContext(Dispatchers.IO) {
SongProvider.search(query)
}
if (result.isSuccess) {
val searchResults = result.getOrNull()
if (searchResults != null) {
changeCurrentSong(searchResults.first().id)
}
}
} catch (e: Exception) {
Log.e("ViewModel AutoSearch", "Error searching for song", e)
_isFetchingLyrics.value = false
}
}
}

fun searchSong(query: String) {
if (query.isEmpty()) return

Expand Down
2 changes: 1 addition & 1 deletion fastlane/metadata/android/en-US/full_description.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Features 🌠

- Search, View and store lyrics
- Share lyrics as a customisable card to your friends!
- Auto-search the lyrics of your current song (Requires Notification Access permission)
- Auto-fill current playing song in search(Requires Notification Access permission)

0 comments on commit 0104afe

Please sign in to comment.