Skip to content

Commit

Permalink
Merge branch 'master' into offset-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Lambada10 committed Nov 1, 2024
2 parents 5d762bc + 7fb1a85 commit 7ce22bc
Show file tree
Hide file tree
Showing 28 changed files with 86 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class LyricsProviderService {
neteaseID = it?.neteaseID ?: 0
} ?: throw NoTrackFoundException()

Providers.APPLE -> AppleAPI().getSongInfo(query).also {
Providers.APPLE -> AppleAPI().getSongInfo(query, offset).also {
appleID = it?.appleID ?: 0
} ?: throw NoTrackFoundException()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import java.net.URLEncoder
class AppleAPI {
private val baseURL = "https://paxsenix.alwaysdata.net/"

suspend fun getSongInfo(query: SongInfo): SongInfo? {
suspend fun getSongInfo(query: SongInfo, offset: Int = 0): SongInfo? {
val search = withContext(Dispatchers.IO) {
URLEncoder.encode(
"${query.songName} ${query.artistName}",
Expand All @@ -41,7 +41,11 @@ class AppleAPI {
return null
}

val result = json[0]
val result = try {
json[offset]
} catch (e: IndexOutOfBoundsException) {
return null
}

return SongInfo(
songName = result.songName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data class AppleSearchResponse(
val artistName: String,
val albumName: String,
val artwork: String,
val releaseDate: String,
val releaseDate: String?,
val duration: Int,
val isrc: String,
val url: String,
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/pl/lambada/songsync/ui/Navigator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import androidx.navigation.toRoute
import kotlinx.serialization.Serializable
import pl.lambada.songsync.data.remote.UserSettingsController
import pl.lambada.songsync.data.remote.lyrics_providers.LyricsProviderService
import pl.lambada.songsync.ui.screens.about.AboutScreen
import pl.lambada.songsync.ui.screens.about.AboutViewModel
import pl.lambada.songsync.ui.screens.settings.SettingsScreen
import pl.lambada.songsync.ui.screens.settings.SettingsViewModel
import pl.lambada.songsync.ui.screens.home.HomeScreen
import pl.lambada.songsync.ui.screens.home.HomeViewModel
import pl.lambada.songsync.ui.screens.lyricsFetch.LyricsFetchScreen
Expand Down Expand Up @@ -61,9 +61,9 @@ fun Navigator(
animatedVisibilityScope = this,
)
}
composable<ScreenAbout> {
AboutScreen(
viewModel = viewModel { AboutViewModel() },
composable<ScreenSettings> {
SettingsScreen(
viewModel = viewModel { SettingsViewModel() },
userSettingsController,
navController = navController
)
Expand Down Expand Up @@ -96,4 +96,4 @@ data class LocalSong(
)

@Serializable
object ScreenAbout
object ScreenSettings
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
fun AboutItem(
fun SettingsItem(
label: String,
modifier: Modifier = Modifier,
content: @Composable () -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Search
import androidx.compose.material3.Button
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
Expand All @@ -39,10 +36,8 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import pl.lambada.songsync.domain.model.SortOrders
import pl.lambada.songsync.domain.model.SortValues
import pl.lambada.songsync.ui.LyricsFetchScreen
import pl.lambada.songsync.ui.ScreenAbout
import pl.lambada.songsync.ui.ScreenSettings
import pl.lambada.songsync.ui.screens.home.components.BatchDownloadLyrics
import pl.lambada.songsync.ui.screens.home.components.FilterAndSongCount
import pl.lambada.songsync.ui.screens.home.components.FiltersDialog
Expand Down Expand Up @@ -98,7 +93,7 @@ fun HomeScreen(
showing = showing,
scrollBehavior = scrollBehavior,
onSelectedClearAction = viewModel.selectedSongs::clear,
onNavigateToAboutSectionRequest = { navController.navigate(ScreenAbout) },
onNavigateToSettingsSectionRequest = { navController.navigate(ScreenSettings) },
onProviderSelectRequest = viewModel.userSettingsController::updateSelectedProviders,
onBatchDownloadRequest = { isBatchDownload = true },
selectedProvider = viewModel.userSettingsController.selectedProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fun HomeAppBar(
scrollBehavior: TopAppBarScrollBehavior,
selectedProvider: Providers,
onSelectedClearAction: () -> Unit,
onNavigateToAboutSectionRequest: () -> Unit,
onNavigateToSettingsSectionRequest: () -> Unit,
onProviderSelectRequest: (Providers) -> Unit,
onBatchDownloadRequest: () -> Unit,
onSelectAllSongsRequest: () -> Unit,
Expand Down Expand Up @@ -120,7 +120,7 @@ fun HomeAppBar(
}
} else {
HomeTopAppBarDropDown(
onNavigateToAboutSectionRequest = onNavigateToAboutSectionRequest,
onNavigateToSettingsSectionRequest = onNavigateToSettingsSectionRequest,
selectedProvider = selectedProvider,
onProviderSelectRequest = onProviderSelectRequest,
onBatchDownloadRequest = onBatchDownloadRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import pl.lambada.songsync.util.set

@Composable
fun HomeTopAppBarDropDown(
onNavigateToAboutSectionRequest: () -> Unit,
onNavigateToSettingsSectionRequest: () -> Unit,
selectedProvider: Providers,
onProviderSelectRequest: (Providers) -> Unit,
embedLyrics: Boolean,
Expand Down Expand Up @@ -98,12 +98,12 @@ fun HomeTopAppBarDropDown(
DropdownMenuItem(
text = {
Text(
text = stringResource(id = R.string.about),
text = stringResource(id = R.string.settings),
modifier = Modifier.padding(horizontal = 6.dp),
)
},
onClick = {
onNavigateToAboutSectionRequest()
onNavigateToSettingsSectionRequest()
expanded = false
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ fun SharedTransitionScope.LyricsFetchScreen(
animatedVisibilityScope = animatedVisibilityScope,
disableMarquee = viewModel.userSettingsController.disableMarquee,
allowTryingAgain =
viewModel.userSettingsController.selectedProvider != Providers.APPLE &&
viewModel.userSettingsController.selectedProvider != Providers.MUSIXMATCH
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@file:Suppress("SpellCheckingInspection")

package pl.lambada.songsync.ui.screens.about
package pl.lambada.songsync.ui.screens.settings

import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
Expand All @@ -19,30 +19,30 @@ import androidx.navigation.NavController
import pl.lambada.songsync.R
import pl.lambada.songsync.data.remote.UpdateState
import pl.lambada.songsync.data.remote.UserSettingsController
import pl.lambada.songsync.ui.screens.about.components.AboutScreenTopBar
import pl.lambada.songsync.ui.screens.about.components.AppInfoSection
import pl.lambada.songsync.ui.screens.about.components.ContributorsSection
import pl.lambada.songsync.ui.screens.about.components.CreditsSection
import pl.lambada.songsync.ui.screens.about.components.ExternalLinkSection
import pl.lambada.songsync.ui.screens.about.components.MarqueeSwitch
import pl.lambada.songsync.ui.screens.about.components.MultiPersonSwitch
import pl.lambada.songsync.ui.screens.about.components.OffsetModeSwitch
import pl.lambada.songsync.ui.screens.about.components.PureBlackThemeSwitch
import pl.lambada.songsync.ui.screens.about.components.SdCardPathSetting
import pl.lambada.songsync.ui.screens.about.components.ShowPathSwitch
import pl.lambada.songsync.ui.screens.about.components.SupportSection
import pl.lambada.songsync.ui.screens.about.components.SyncedLyricsSwitch
import pl.lambada.songsync.ui.screens.about.components.TranslationSwitch
import pl.lambada.songsync.ui.screens.about.components.UpdateAvailableDialog
import pl.lambada.songsync.ui.screens.settings.components.SettingsScreenTopBar
import pl.lambada.songsync.ui.screens.settings.components.AppInfoSection
import pl.lambada.songsync.ui.screens.settings.components.ContributorsSection
import pl.lambada.songsync.ui.screens.settings.components.CreditsSection
import pl.lambada.songsync.ui.screens.settings.components.ExternalLinkSection
import pl.lambada.songsync.ui.screens.settings.components.MarqueeSwitch
import pl.lambada.songsync.ui.screens.settings.components.MultiPersonSwitch
import pl.lambada.songsync.ui.screens.settings.components.PureBlackThemeSwitch
import pl.lambada.songsync.ui.screens.settings.components.SdCardPathSetting
import pl.lambada.songsync.ui.screens.settings.components.ShowPathSwitch
import pl.lambada.songsync.ui.screens.settings.components.SupportSection
import pl.lambada.songsync.ui.screens.settings.components.SyncedLyricsSwitch
import pl.lambada.songsync.ui.screens.settings.components.TranslationSwitch
import pl.lambada.songsync.ui.screens.settings.components.UpdateAvailableDialog
import pl.lambada.songsync.util.ext.getVersion

/**
* Composable function for AboutScreen component.
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AboutScreen(
viewModel: AboutViewModel,
fun SettingsScreen(
viewModel: SettingsViewModel,
userSettingsController: UserSettingsController,
navController: NavController
) {
Expand All @@ -54,7 +54,7 @@ fun AboutScreen(
Scaffold(
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
AboutScreenTopBar(
SettingsScreenTopBar(
navController = navController,
scrollBehavior = scrollBehavior
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.lambada.songsync.ui.screens.about
package pl.lambada.songsync.ui.screens.settings

import android.content.Context
import androidx.compose.runtime.getValue
Expand All @@ -17,7 +17,7 @@ import pl.lambada.songsync.util.showToast
/**
* ViewModel class for the main functionality of the app.
*/
class AboutViewModel(
class SettingsViewModel(
private val updateService: UpdateService = UpdateService()
) : ViewModel() {
var updateState by mutableStateOf<UpdateState>(UpdateState.Idle)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.lambada.songsync.ui.screens.about.components
package pl.lambada.songsync.ui.screens.settings.components

import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
Expand All @@ -10,11 +10,11 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import pl.lambada.songsync.R
import pl.lambada.songsync.ui.components.AboutItem
import pl.lambada.songsync.ui.components.SettingsItem

@Composable
fun AppInfoSection(version: String, onCheckForUpdates: () -> Unit) {
AboutItem(
SettingsItem(
label = stringResource(R.string.about_songsync),
modifier = Modifier.padding(horizontal = 22.dp, vertical = 16.dp)
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.lambada.songsync.ui.screens.about.components
package pl.lambada.songsync.ui.screens.settings.components

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
Expand All @@ -13,11 +13,11 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import pl.lambada.songsync.R
import pl.lambada.songsync.ui.components.AboutItem
import pl.lambada.songsync.ui.components.SettingsItem

@Composable
fun ContributorsSection(uriHandler: UriHandler) {
AboutItem(stringResource(R.string.contributors)) {
SettingsItem(stringResource(R.string.contributors)) {
Contributor.entries.forEach {
val additionalInfo = stringResource(id = it.contributionLevel.stringResource)
Column(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.lambada.songsync.ui.screens.about.components
package pl.lambada.songsync.ui.screens.settings.components

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Row
Expand All @@ -18,12 +18,12 @@ import androidx.compose.ui.platform.UriHandler
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import pl.lambada.songsync.R
import pl.lambada.songsync.ui.components.AboutItem
import pl.lambada.songsync.ui.components.SettingsItem


@Composable
fun CreditsSection(uriHandler: UriHandler) {
AboutItem(label = stringResource(id = R.string.thanks_to)) {
SettingsItem(label = stringResource(id = R.string.thanks_to)) {
val credits = mapOf(
stringResource(R.string.spotify_api) to "https://developer.spotify.com/documentation/web-api",
stringResource(R.string.spotifylyrics_api) to "https://github.com/akashrchandran/spotify-lyrics-api",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.lambada.songsync.ui.screens.about.components
package pl.lambada.songsync.ui.screens.settings.components

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.padding
Expand All @@ -11,12 +11,12 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import pl.lambada.songsync.R
import pl.lambada.songsync.ui.components.AboutItem
import pl.lambada.songsync.ui.components.SettingsItem


@Composable
fun ExternalLinkSection(label: String, description: String, url: String, uriHandler: UriHandler) {
AboutItem(
SettingsItem(
label,
modifier = Modifier
.clickable { uriHandler.openUri(url) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package pl.lambada.songsync.ui.screens.about.components
package pl.lambada.songsync.ui.screens.settings.components

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import pl.lambada.songsync.R
import pl.lambada.songsync.ui.components.AboutItem
import pl.lambada.songsync.ui.components.SettingsItem
import pl.lambada.songsync.ui.components.SwitchItem


@Composable
fun MarqueeSwitch(selected: Boolean, onToggle: (Boolean) -> Unit) {
AboutItem(label = stringResource(R.string.disable_marquee)) {
SettingsItem(label = stringResource(R.string.disable_marquee)) {
SwitchItem(
label = stringResource(R.string.disable_marquee_summary),
selected = selected,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package pl.lambada.songsync.ui.screens.about.components
package pl.lambada.songsync.ui.screens.settings.components

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import pl.lambada.songsync.R
import pl.lambada.songsync.ui.components.AboutItem
import pl.lambada.songsync.ui.components.SettingsItem
import pl.lambada.songsync.ui.components.SwitchItem

@Composable
fun MultiPersonSwitch(selected: Boolean, onToggle: (Boolean) -> Unit) {
AboutItem(label = stringResource(id = R.string.multi_person_word_by_word)) {
SettingsItem(label = stringResource(id = R.string.multi_person_word_by_word)) {
SwitchItem(
label = stringResource(id = R.string.multi_person_word_by_word_summary),
selected = selected,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package pl.lambada.songsync.ui.screens.about.components
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import pl.lambada.songsync.R
import pl.lambada.songsync.ui.components.AboutItem
import pl.lambada.songsync.ui.components.SettingsItem
import pl.lambada.songsync.ui.components.SwitchItem

@Composable
fun OffsetModeSwitch(
selected: Boolean,
onToggle: (Boolean) -> Unit
) {
AboutItem(label = stringResource(R.string.offset_mode)) {
SettingsItem(label = stringResource(R.string.offset_mode)) {
SwitchItem(
label = stringResource(R.string.offset_mode_summary),
selected = selected,
Expand Down
Loading

0 comments on commit 7ce22bc

Please sign in to comment.