From 8b920443394da9c6b61e2b41dc9e61656ba69178 Mon Sep 17 00:00:00 2001 From: Ilian Delagrange Date: Wed, 1 Jan 2025 22:00:49 -0500 Subject: [PATCH 1/3] Added references to the gradle app version --- .../com/maxrave/simpmusic/ui/MainActivity.kt | 37 +- .../simpmusic/ui/component/EndOfPage.kt | 18 +- .../ui/fragment/other/CreditFragment.kt | 4 + .../simpmusic/ui/screen/home/SettingScreen.kt | 770 ++++++++++-------- .../simpmusic/viewModel/SettingsViewModel.kt | 27 +- app/src/main/res/layout/fragment_credit.xml | 59 +- app/src/main/res/values/strings.xml | 2 +- gradle.properties | 1 + 8 files changed, 494 insertions(+), 424 deletions(-) diff --git a/app/src/main/java/com/maxrave/simpmusic/ui/MainActivity.kt b/app/src/main/java/com/maxrave/simpmusic/ui/MainActivity.kt index 49e96cf5..a7a9b1ac 100644 --- a/app/src/main/java/com/maxrave/simpmusic/ui/MainActivity.kt +++ b/app/src/main/java/com/maxrave/simpmusic/ui/MainActivity.kt @@ -33,6 +33,7 @@ import androidx.media3.common.util.UnstableApi import androidx.navigation.fragment.findNavController import androidx.navigation.ui.setupWithNavController import com.google.android.material.dialog.MaterialAlertDialogBuilder +import com.maxrave.simpmusic.BuildConfig import com.maxrave.simpmusic.R import com.maxrave.simpmusic.common.Config import com.maxrave.simpmusic.common.FIRST_TIME_MIGRATION @@ -171,10 +172,10 @@ class MainActivity : AppCompatActivity() { // WindowCompat.setDecorFitsSystemWindows(window, false) enableEdgeToEdge( navigationBarStyle = - SystemBarStyle.auto( - lightScrim = Color.Transparent.toArgb(), - darkScrim = Color.Transparent.toArgb(), - ), + SystemBarStyle.auto( + lightScrim = Color.Transparent.toArgb(), + darkScrim = Color.Transparent.toArgb(), + ), ) viewModel.checkIsRestoring() viewModel.runWorker() @@ -214,15 +215,15 @@ class MainActivity : AppCompatActivity() { binding.miniplayer.visibility = View.GONE } binding.root.addOnLayoutChangeListener { - _, - left, - top, - right, - bottom, - oldLeft, - oldTop, - oldRight, - oldBottom, + _, + left, + top, + right, + bottom, + oldLeft, + oldTop, + oldRight, + oldBottom, -> val rect = Rect(left, top, right, bottom) val oldRect = Rect(oldLeft, oldTop, oldRight, oldBottom) @@ -292,7 +293,7 @@ class MainActivity : AppCompatActivity() { R.id.bottom_navigation_item_library, R.id.favoriteFragment, R.id.localPlaylistFragment, - -> { + -> { binding.bottomNavigationView.menu .findItem( R.id.bottom_navigation_item_library, @@ -305,7 +306,7 @@ class MainActivity : AppCompatActivity() { when (currentBackStack) { R.id.bottom_navigation_item_library, R.id.favoriteFragment, R.id.localPlaylistFragment, - -> { + -> { binding.bottomNavigationView.menu .findItem( R.id.bottom_navigation_item_library, @@ -344,7 +345,7 @@ class MainActivity : AppCompatActivity() { "fragment_log_in", "MusixmatchFragment", ) - ).contains(destination.label) + ).contains(destination.label) ) { lifecycleScope.launch { viewModel.showOrHideMiniplayer.emit(false) } Log.w("MainActivity", "onCreate: HIDE MINIPLAYER") @@ -544,7 +545,7 @@ class MainActivity : AppCompatActivity() { "fragment_log_in", "MusixmatchFragment", ) - ).contains(navController.currentDestination?.label) && + ).contains(navController.currentDestination?.label) && it.nowPlayingTitle.isNotEmpty() && binding.miniplayer.visibility != View.VISIBLE ) { @@ -686,7 +687,7 @@ class MainActivity : AppCompatActivity() { viewModel.checkForUpdate() viewModel.githubResponse.observe(this) { response -> if (response != null && !this.isInPictureInPictureMode && !viewModel.showedUpdateDialog) { - if (response.tagName != getString(R.string.version_name)) { + if (response.tagName != getString(R.string.version_format, BuildConfig.VERSION_NAME)) { viewModel.showedUpdateDialog = true val inputFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.getDefault()) diff --git a/app/src/main/java/com/maxrave/simpmusic/ui/component/EndOfPage.kt b/app/src/main/java/com/maxrave/simpmusic/ui/component/EndOfPage.kt index 55c9b2d2..b6862ecd 100644 --- a/app/src/main/java/com/maxrave/simpmusic/ui/component/EndOfPage.kt +++ b/app/src/main/java/com/maxrave/simpmusic/ui/component/EndOfPage.kt @@ -12,6 +12,7 @@ import androidx.compose.ui.draw.alpha import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp +import com.maxrave.simpmusic.BuildConfig import com.maxrave.simpmusic.R import com.maxrave.simpmusic.ui.theme.typo @@ -19,20 +20,21 @@ import com.maxrave.simpmusic.ui.theme.typo fun EndOfPage() { Box( modifier = - Modifier - .fillMaxWidth() - .height(280.dp), + Modifier + .fillMaxWidth() + .height(280.dp), contentAlignment = Alignment.TopCenter, ) { Text( - "@2024 " + stringResource(R.string.app_name) + " " + stringResource(R.string.version_name) + "\nmaxrave-dev", + "@2024 " + stringResource(R.string.app_name) + " " + stringResource(R.string.version_format, BuildConfig.VERSION_NAME) + "\nmaxrave-dev", style = typo.bodySmall, textAlign = TextAlign.Center, modifier = - Modifier - .padding( - top = 20.dp, - ).alpha(0.8f), + Modifier + .padding( + top = 20.dp, + ) + .alpha(0.8f), ) } } \ No newline at end of file diff --git a/app/src/main/java/com/maxrave/simpmusic/ui/fragment/other/CreditFragment.kt b/app/src/main/java/com/maxrave/simpmusic/ui/fragment/other/CreditFragment.kt index 1c45b707..cd58dbf3 100644 --- a/app/src/main/java/com/maxrave/simpmusic/ui/fragment/other/CreditFragment.kt +++ b/app/src/main/java/com/maxrave/simpmusic/ui/fragment/other/CreditFragment.kt @@ -9,6 +9,8 @@ import android.view.ViewGroup import androidx.core.view.WindowInsetsCompat import androidx.fragment.app.Fragment import androidx.navigation.fragment.findNavController +import com.maxrave.simpmusic.BuildConfig +import com.maxrave.simpmusic.R import com.maxrave.simpmusic.databinding.FragmentCreditBinding import dev.chrisbanes.insetter.Insetter @@ -35,6 +37,8 @@ class CreditFragment : Fragment() { savedInstanceState: Bundle?, ) { super.onViewCreated(view, savedInstanceState) + + binding.versionTextBox.text = getString(R.string.version_format, BuildConfig.VERSION_NAME) binding.btGithub.setOnClickListener { val urlIntent = Intent( diff --git a/app/src/main/java/com/maxrave/simpmusic/ui/screen/home/SettingScreen.kt b/app/src/main/java/com/maxrave/simpmusic/ui/screen/home/SettingScreen.kt index fba20078..5762538b 100644 --- a/app/src/main/java/com/maxrave/simpmusic/ui/screen/home/SettingScreen.kt +++ b/app/src/main/java/com/maxrave/simpmusic/ui/screen/home/SettingScreen.kt @@ -85,6 +85,7 @@ import coil3.compose.AsyncImage import coil3.request.ImageRequest import coil3.request.crossfade import com.maxrave.kotlinytmusicscraper.extension.isTwoLetterCode +import com.maxrave.simpmusic.BuildConfig import com.maxrave.simpmusic.R import com.maxrave.simpmusic.common.LIMIT_CACHE_SIZE import com.maxrave.simpmusic.common.QUALITY @@ -190,9 +191,6 @@ fun SettingScreen( var checkForUpdateSubtitle by rememberSaveable { mutableStateOf("") } - var showLibrary by rememberSaveable { - mutableStateOf(false) - } var showYouTubeAccountDialog by rememberSaveable { mutableStateOf(false) } @@ -217,7 +215,7 @@ fun SettingScreen( LaunchedEffect(githubResponse) { val res = githubResponse - if (res != null && res.tagName != context.getString(R.string.version_name)) { + if (res != null && res.tagName != context.getString(R.string.version_format, BuildConfig.VERSION_NAME)) { val inputFormat = SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss'Z'", @@ -236,12 +234,12 @@ fun SettingScreen( title = context.getString(R.string.update_available), message = context.getString(R.string.update_message, res.tagName, formatted, res.body), confirm = - context.getString(R.string.download) to { - uriHandler.openUri( - res.assets?.firstOrNull()?.browserDownloadUrl - ?: "https://github.com/maxrave-dev/SimpMusic/releases", - ) - }, + context.getString(R.string.download) to { + uriHandler.openUri( + res.assets?.firstOrNull()?.browserDownloadUrl + ?: "https://github.com/maxrave-dev/SimpMusic/releases", + ) + }, dismiss = context.getString(R.string.cancel), ), ) @@ -256,9 +254,9 @@ fun SettingScreen( LazyColumn( contentPadding = innerPadding, modifier = - Modifier - .padding(horizontal = 16.dp) - .padding(top = 64.dp), + Modifier + .padding(horizontal = 16.dp) + .padding(top = 64.dp), ) { item(key = "user_interface") { Column { @@ -291,29 +289,29 @@ fun SettingScreen( SettingAlertState( title = context.getString(R.string.language), selectOne = - SettingAlertState.SelectData( - listSelect = - SUPPORTED_LANGUAGE.items.map { - (it.toString() == SUPPORTED_LANGUAGE.getLanguageFromCode(language ?: "en-US")) to it.toString() - }, - ), - confirm = - context.getString(R.string.change) to { state -> - val code = SUPPORTED_LANGUAGE.getCodeFromLanguage(state.selectOne?.getSelected() ?: "English") - viewModel.setBasicAlertData( - SettingBasicAlertState( - title = context.getString(R.string.warning), - message = context.getString(R.string.change_language_warning), - confirm = - context.getString(R.string.change) to { - sharedViewModel.activityRecreate() - viewModel.setBasicAlertData(null) - viewModel.changeLanguage(code) - }, - dismiss = context.getString(R.string.cancel), - ), - ) + SettingAlertState.SelectData( + listSelect = + SUPPORTED_LANGUAGE.items.map { + (it.toString() == SUPPORTED_LANGUAGE.getLanguageFromCode(language ?: "en-US")) to it.toString() }, + ), + confirm = + context.getString(R.string.change) to { state -> + val code = SUPPORTED_LANGUAGE.getCodeFromLanguage(state.selectOne?.getSelected() ?: "English") + viewModel.setBasicAlertData( + SettingBasicAlertState( + title = context.getString(R.string.warning), + message = context.getString(R.string.change_language_warning), + confirm = + context.getString(R.string.change) to { + sharedViewModel.activityRecreate() + viewModel.setBasicAlertData(null) + viewModel.changeLanguage(code) + }, + dismiss = context.getString(R.string.cancel), + ), + ) + }, dismiss = context.getString(R.string.cancel), ), ) @@ -327,18 +325,18 @@ fun SettingScreen( SettingAlertState( title = context.getString(R.string.content_country), selectOne = - SettingAlertState.SelectData( - listSelect = - SUPPORTED_LOCATION.items.map { item -> - (item.toString() == location) to item.toString() - }, - ), - confirm = - context.getString(R.string.change) to { state -> - viewModel.changeLocation( - state.selectOne?.getSelected() ?: "US", - ) + SettingAlertState.SelectData( + listSelect = + SUPPORTED_LOCATION.items.map { item -> + (item.toString() == location) to item.toString() }, + ), + confirm = + context.getString(R.string.change) to { state -> + viewModel.changeLocation( + state.selectOne?.getSelected() ?: "US", + ) + }, ), ) }, @@ -352,16 +350,16 @@ fun SettingScreen( SettingAlertState( title = context.getString(R.string.quality), selectOne = - SettingAlertState.SelectData( - listSelect = - QUALITY.items.map { item -> - (item.toString() == quality) to item.toString() - }, - ), - confirm = - context.getString(R.string.change) to { state -> - viewModel.changeQuality(state.selectOne?.getSelected()) + SettingAlertState.SelectData( + listSelect = + QUALITY.items.map { item -> + (item.toString() == quality) to item.toString() }, + ), + confirm = + context.getString(R.string.change) to { state -> + viewModel.changeQuality(state.selectOne?.getSelected()) + }, dismiss = context.getString(R.string.cancel), ), ) @@ -397,16 +395,16 @@ fun SettingScreen( SettingAlertState( title = context.getString(R.string.video_quality), selectOne = - SettingAlertState.SelectData( - listSelect = - VIDEO_QUALITY.items.map { item -> - (item.toString() == videoQuality) to item.toString() - }, - ), - confirm = - context.getString(R.string.change) to { state -> - viewModel.changeVideoQuality(state.selectOne?.getSelected() ?: "") + SettingAlertState.SelectData( + listSelect = + VIDEO_QUALITY.items.map { item -> + (item.toString() == videoQuality) to item.toString() }, + ), + confirm = + context.getString(R.string.change) to { state -> + viewModel.changeVideoQuality(state.selectOne?.getSelected() ?: "") + }, dismiss = context.getString(R.string.cancel), ), ) @@ -415,10 +413,10 @@ fun SettingScreen( SettingItem( title = stringResource(R.string.send_back_listening_data_to_google), subtitle = - stringResource( - R.string - .upload_your_listening_history_to_youtube_music_server_it_will_make_yt_music_recommendation_system_better_working_only_if_logged_in, - ), + stringResource( + R.string + .upload_your_listening_history_to_youtube_music_server_it_will_make_yt_music_recommendation_system_better_working_only_if_logged_in, + ), smallSubtitle = true, switch = (sendData to { viewModel.setSendBackToGoogle(it) }), ) @@ -436,38 +434,38 @@ fun SettingScreen( SettingItem( title = stringResource(R.string.proxy_type), subtitle = - when (proxyType) { - DataStoreManager.Settings.ProxyType.PROXY_TYPE_HTTP -> stringResource(R.string.http) - DataStoreManager.Settings.ProxyType.PROXY_TYPE_SOCKS -> stringResource(R.string.socks) - }, + when (proxyType) { + DataStoreManager.Settings.ProxyType.PROXY_TYPE_HTTP -> stringResource(R.string.http) + DataStoreManager.Settings.ProxyType.PROXY_TYPE_SOCKS -> stringResource(R.string.socks) + }, onClick = { viewModel.setAlertData( SettingAlertState( title = context.getString(R.string.proxy_type), selectOne = - SettingAlertState.SelectData( - listSelect = - listOf( - (proxyType == DataStoreManager.Settings.ProxyType.PROXY_TYPE_HTTP) to - context.getString( - R.string.http, - ), - (proxyType == DataStoreManager.Settings.ProxyType.PROXY_TYPE_SOCKS) to - context.getString(R.string.socks), + SettingAlertState.SelectData( + listSelect = + listOf( + (proxyType == DataStoreManager.Settings.ProxyType.PROXY_TYPE_HTTP) to + context.getString( + R.string.http, ), + (proxyType == DataStoreManager.Settings.ProxyType.PROXY_TYPE_SOCKS) to + context.getString(R.string.socks), ), + ), confirm = - context.getString(R.string.change) to { state -> - viewModel.setProxy( - if (state.selectOne?.getSelected() == context.getString(R.string.socks)) { - DataStoreManager.Settings.ProxyType.PROXY_TYPE_SOCKS - } else { - DataStoreManager.Settings.ProxyType.PROXY_TYPE_HTTP - }, - proxyHost, - proxyPort, - ) - }, + context.getString(R.string.change) to { state -> + viewModel.setProxy( + if (state.selectOne?.getSelected() == context.getString(R.string.socks)) { + DataStoreManager.Settings.ProxyType.PROXY_TYPE_SOCKS + } else { + DataStoreManager.Settings.ProxyType.PROXY_TYPE_HTTP + }, + proxyHost, + proxyPort, + ) + }, dismiss = context.getString(R.string.cancel), ), ) @@ -482,21 +480,21 @@ fun SettingScreen( title = context.getString(R.string.proxy_host), message = context.getString(R.string.proxy_host_message), textField = - SettingAlertState.TextFieldData( - label = context.getString(R.string.proxy_host), - value = proxyHost, - verifyCodeBlock = { - (it.toHttpUrlOrNull() != null) to context.getString(R.string.invalid_host) - }, - ), - confirm = - context.getString(R.string.change) to { state -> - viewModel.setProxy( - proxyType, - state.textField?.value ?: "", - proxyPort, - ) + SettingAlertState.TextFieldData( + label = context.getString(R.string.proxy_host), + value = proxyHost, + verifyCodeBlock = { + (it.toHttpUrlOrNull() != null) to context.getString(R.string.invalid_host) }, + ), + confirm = + context.getString(R.string.change) to { state -> + viewModel.setProxy( + proxyType, + state.textField?.value ?: "", + proxyPort, + ) + }, dismiss = context.getString(R.string.cancel), ), ) @@ -511,21 +509,21 @@ fun SettingScreen( title = context.getString(R.string.proxy_port), message = context.getString(R.string.proxy_port_message), textField = - SettingAlertState.TextFieldData( - label = context.getString(R.string.proxy_port), - value = proxyPort.toString(), - verifyCodeBlock = { - (it.toIntOrNull() != null) to context.getString(R.string.invalid_port) - }, - ), - confirm = - context.getString(R.string.change) to { state -> - viewModel.setProxy( - proxyType, - proxyHost, - state.textField?.value?.toIntOrNull() ?: 0, - ) + SettingAlertState.TextFieldData( + label = context.getString(R.string.proxy_port), + value = proxyPort.toString(), + verifyCodeBlock = { + (it.toIntOrNull() != null) to context.getString(R.string.invalid_port) }, + ), + confirm = + context.getString(R.string.change) to { state -> + viewModel.setProxy( + proxyType, + proxyHost, + state.textField?.value?.toIntOrNull() ?: 0, + ) + }, dismiss = context.getString(R.string.cancel), ), ) @@ -589,50 +587,50 @@ fun SettingScreen( SettingItem( title = stringResource(R.string.main_lyrics_provider), subtitle = - when (mainLyricsProvider) { - DataStoreManager.MUSIXMATCH -> stringResource(R.string.musixmatch) - DataStoreManager.YOUTUBE -> stringResource(R.string.youtube_transcript) - else -> stringResource(R.string.unknown) - }, + when (mainLyricsProvider) { + DataStoreManager.MUSIXMATCH -> stringResource(R.string.musixmatch) + DataStoreManager.YOUTUBE -> stringResource(R.string.youtube_transcript) + else -> stringResource(R.string.unknown) + }, onClick = { viewModel.setAlertData( SettingAlertState( title = context.getString(R.string.main_lyrics_provider), selectOne = - SettingAlertState.SelectData( - listSelect = - listOf( - (mainLyricsProvider == DataStoreManager.MUSIXMATCH) to context.getString(R.string.musixmatch), - (mainLyricsProvider == DataStoreManager.YOUTUBE) to context.getString(R.string.youtube_transcript), - ), + SettingAlertState.SelectData( + listSelect = + listOf( + (mainLyricsProvider == DataStoreManager.MUSIXMATCH) to context.getString(R.string.musixmatch), + (mainLyricsProvider == DataStoreManager.YOUTUBE) to context.getString(R.string.youtube_transcript), ), + ), confirm = - context.getString(R.string.change) to { state -> - viewModel.setLyricsProvider( - when (state.selectOne?.getSelected()) { - context.getString(R.string.musixmatch) -> DataStoreManager.MUSIXMATCH - context.getString(R.string.youtube_transcript) -> DataStoreManager.YOUTUBE - else -> DataStoreManager.MUSIXMATCH - }, - ) - }, + context.getString(R.string.change) to { state -> + viewModel.setLyricsProvider( + when (state.selectOne?.getSelected()) { + context.getString(R.string.musixmatch) -> DataStoreManager.MUSIXMATCH + context.getString(R.string.youtube_transcript) -> DataStoreManager.YOUTUBE + else -> DataStoreManager.MUSIXMATCH + }, + ) + }, ), ) }, ) SettingItem( title = - if (musixmatchLoggedIn) { - stringResource(R.string.log_out_from_musixmatch) - } else { - stringResource(R.string.log_in_to_Musixmatch) - }, + if (musixmatchLoggedIn) { + stringResource(R.string.log_out_from_musixmatch) + } else { + stringResource(R.string.log_in_to_Musixmatch) + }, subtitle = - if (musixmatchLoggedIn) { - stringResource(R.string.logged_in) - } else { - stringResource(R.string.only_support_email_and_password_type) - }, + if (musixmatchLoggedIn) { + stringResource(R.string.logged_in) + } else { + stringResource(R.string.only_support_email_and_password_type) + }, onClick = { if (musixmatchLoggedIn) { viewModel.clearMusixmatchCookie() @@ -655,18 +653,18 @@ fun SettingScreen( SettingAlertState( title = context.getString(R.string.translation_language), textField = - SettingAlertState.TextFieldData( - label = context.getString(R.string.translation_language), - value = musixmatchTranslationLanguage ?: "", - verifyCodeBlock = { - (it.length == 2 && it.isTwoLetterCode()) to context.getString(R.string.invalid_language_code) - }, - ), + SettingAlertState.TextFieldData( + label = context.getString(R.string.translation_language), + value = musixmatchTranslationLanguage ?: "", + verifyCodeBlock = { + (it.length == 2 && it.isTwoLetterCode()) to context.getString(R.string.invalid_language_code) + }, + ), message = context.getString(R.string.translation_language_message), confirm = - context.getString(R.string.change) to { state -> - viewModel.setTranslationLanguage(state.textField?.value ?: "") - }, + context.getString(R.string.change) to { state -> + viewModel.setTranslationLanguage(state.textField?.value ?: "") + }, ), ) }, @@ -680,11 +678,11 @@ fun SettingScreen( SettingItem( title = stringResource(R.string.log_in_to_spotify), subtitle = - if (spotifyLoggedIn) { - stringResource(R.string.logged_in) - } else { - stringResource(R.string.intro_login_to_spotify) - }, + if (spotifyLoggedIn) { + stringResource(R.string.logged_in) + } else { + stringResource(R.string.intro_login_to_spotify) + }, onClick = { if (spotifyLoggedIn) { viewModel.setSpotifyLogIn(false) @@ -727,34 +725,34 @@ fun SettingScreen( SettingAlertState( title = context.getString(R.string.categories_sponsor_block), multipleSelect = - SettingAlertState.SelectData( - listSelect = - listName - .mapIndexed { index, item -> - ( - skipSegments?.contains( - SPONSOR_BLOCK.list.getOrNull(index), - ) == true - ) to item - }.also { - Log.w("SettingScreen", "SettingAlertState: $skipSegments") - Log.w("SettingScreen", "SettingAlertState: $it") - }, - ), + SettingAlertState.SelectData( + listSelect = + listName + .mapIndexed { index, item -> + ( + skipSegments?.contains( + SPONSOR_BLOCK.list.getOrNull(index), + ) == true + ) to item + }.also { + Log.w("SettingScreen", "SettingAlertState: $skipSegments") + Log.w("SettingScreen", "SettingAlertState: $it") + }, + ), confirm = - context.getString(R.string.save) to { state -> - viewModel.setSponsorBlockCategories( - state.multipleSelect - ?.getListSelected() - ?.map { selected -> - listName.indexOf(selected) - }?.mapNotNull { s -> - SPONSOR_BLOCK.list.getOrNull(s).let { - it?.toString() - } - }?.toCollection(ArrayList()) ?: arrayListOf(), - ) - }, + context.getString(R.string.save) to { state -> + viewModel.setSponsorBlockCategories( + state.multipleSelect + ?.getListSelected() + ?.map { selected -> + listName.indexOf(selected) + }?.mapNotNull { s -> + SPONSOR_BLOCK.list.getOrNull(s).let { + it?.toString() + } + }?.toCollection(ArrayList()) ?: arrayListOf(), + ) + }, dismiss = context.getString(R.string.cancel), ), ) @@ -793,9 +791,9 @@ fun SettingScreen( title = context.getString(R.string.clear_player_cache), message = null, confirm = - context.getString(R.string.clear) to { - viewModel.clearPlayerCache() - }, + context.getString(R.string.clear) to { + viewModel.clearPlayerCache() + }, dismiss = context.getString(R.string.cancel), ), ) @@ -810,9 +808,9 @@ fun SettingScreen( title = context.getString(R.string.clear_downloaded_cache), message = null, confirm = - context.getString(R.string.clear) to { - viewModel.clearDownloadedCache() - }, + context.getString(R.string.clear) to { + viewModel.clearDownloadedCache() + }, dismiss = context.getString(R.string.cancel), ), ) @@ -827,9 +825,9 @@ fun SettingScreen( title = context.getString(R.string.clear_thumbnail_cache), message = null, confirm = - context.getString(R.string.clear) to { - viewModel.clearThumbnailCache() - }, + context.getString(R.string.clear) to { + viewModel.clearThumbnailCache() + }, dismiss = context.getString(R.string.cancel), ), ) @@ -844,9 +842,9 @@ fun SettingScreen( title = context.getString(R.string.clear_canvas_cache), message = null, confirm = - context.getString(R.string.clear) to { - viewModel.clearCanvasCache() - }, + context.getString(R.string.clear) to { + viewModel.clearCanvasCache() + }, dismiss = context.getString(R.string.cancel), ), ) @@ -860,18 +858,18 @@ fun SettingScreen( SettingAlertState( title = context.getString(R.string.limit_player_cache), selectOne = - SettingAlertState.SelectData( - listSelect = - LIMIT_CACHE_SIZE.items.map { item -> - (item == LIMIT_CACHE_SIZE.getItemFromData(limitPlayerCache)) to item.toString() - }, - ), - confirm = - context.getString(R.string.change) to { state -> - viewModel.setPlayerCacheLimit( - LIMIT_CACHE_SIZE.getDataFromItem(state.selectOne?.getSelected()), - ) + SettingAlertState.SelectData( + listSelect = + LIMIT_CACHE_SIZE.items.map { item -> + (item == LIMIT_CACHE_SIZE.getItemFromData(limitPlayerCache)) to item.toString() }, + ), + confirm = + context.getString(R.string.change) to { state -> + viewModel.setPlayerCacheLimit( + LIMIT_CACHE_SIZE.getDataFromItem(state.selectOne?.getSelected()), + ) + }, dismiss = context.getString(R.string.cancel), ), ) @@ -886,95 +884,108 @@ fun SettingScreen( LazyRow( horizontalArrangement = Arrangement.spacedBy(0.dp), modifier = - Modifier - .fillMaxWidth() - .height(8.dp) - .clip(RoundedCornerShape(8.dp)) - .onGloballyPositioned { layoutCoordinates -> - with(localDensity) { - width = - layoutCoordinates.size.width - .toDp() - .value - .toInt() - } - }, + Modifier + .fillMaxWidth() + .height(8.dp) + .clip(RoundedCornerShape(8.dp)) + .onGloballyPositioned { layoutCoordinates -> + with(localDensity) { + width = + layoutCoordinates.size.width + .toDp() + .value + .toInt() + } + }, ) { item { Box( modifier = - Modifier - .width( - (fraction.otherApp * width).dp, - ).background( - md_theme_dark_primary, - ).fillMaxHeight(), + Modifier + .width( + (fraction.otherApp * width).dp, + ) + .background( + md_theme_dark_primary, + ) + .fillMaxHeight(), ) } item { Box( modifier = - Modifier - .width( - (fraction.downloadCache * width).dp, - ).background( - Color(0xD540FF17), - ).fillMaxHeight(), + Modifier + .width( + (fraction.downloadCache * width).dp, + ) + .background( + Color(0xD540FF17), + ) + .fillMaxHeight(), ) } item { Box( modifier = - Modifier - .width( - (fraction.playerCache * width).dp, - ).background( - Color(0xD5FFFF00), - ).fillMaxHeight(), + Modifier + .width( + (fraction.playerCache * width).dp, + ) + .background( + Color(0xD5FFFF00), + ) + .fillMaxHeight(), ) } item { Box( modifier = - Modifier - .width( - (fraction.canvasCache * width).dp, - ).background( - Color.Cyan, - ).fillMaxHeight(), + Modifier + .width( + (fraction.canvasCache * width).dp, + ) + .background( + Color.Cyan, + ) + .fillMaxHeight(), ) } item { Box( modifier = - Modifier - .width( - (fraction.thumbCache * width).dp, - ).background( - Color.Magenta, - ).fillMaxHeight(), + Modifier + .width( + (fraction.thumbCache * width).dp, + ) + .background( + Color.Magenta, + ) + .fillMaxHeight(), ) } item { Box( modifier = - Modifier - .width( - (fraction.appDatabase * width).dp, - ).background( - Color.White, - ), + Modifier + .width( + (fraction.appDatabase * width).dp, + ) + .background( + Color.White, + ), ) } item { Box( modifier = - Modifier - .width( - (fraction.freeSpace * width).dp, - ).background( - Color.DarkGray, - ).fillMaxHeight(), + Modifier + .width( + (fraction.freeSpace * width).dp, + ) + .background( + Color.DarkGray, + ) + .fillMaxHeight(), ) } } @@ -984,9 +995,12 @@ fun SettingScreen( modifier = Modifier.padding(horizontal = 24.dp, vertical = 4.dp), ) { Box( - Modifier.size(12.dp).clip(CircleShape).background( - md_theme_dark_primary, - ), + Modifier + .size(12.dp) + .clip(CircleShape) + .background( + md_theme_dark_primary, + ), ) Spacer(Modifier.width(8.dp)) Text(text = stringResource(R.string.other_app), style = typo.bodySmall) @@ -996,9 +1010,12 @@ fun SettingScreen( modifier = Modifier.padding(horizontal = 24.dp, vertical = 4.dp), ) { Box( - Modifier.size(12.dp).clip(CircleShape).background( - Color.Green, - ), + Modifier + .size(12.dp) + .clip(CircleShape) + .background( + Color.Green, + ), ) Spacer(Modifier.width(8.dp)) Text(text = stringResource(R.string.downloaded_cache), style = typo.bodySmall) @@ -1008,9 +1025,12 @@ fun SettingScreen( modifier = Modifier.padding(horizontal = 24.dp, vertical = 4.dp), ) { Box( - Modifier.size(12.dp).clip(CircleShape).background( - Color.Yellow, - ), + Modifier + .size(12.dp) + .clip(CircleShape) + .background( + Color.Yellow, + ), ) Spacer(Modifier.width(8.dp)) Text(text = stringResource(R.string.player_cache), style = typo.bodySmall) @@ -1020,9 +1040,12 @@ fun SettingScreen( modifier = Modifier.padding(horizontal = 24.dp, vertical = 4.dp), ) { Box( - Modifier.size(12.dp).clip(CircleShape).background( - Color.Cyan, - ), + Modifier + .size(12.dp) + .clip(CircleShape) + .background( + Color.Cyan, + ), ) Spacer(Modifier.width(8.dp)) Text(text = stringResource(R.string.spotify_canvas_cache), style = typo.bodySmall) @@ -1032,9 +1055,12 @@ fun SettingScreen( modifier = Modifier.padding(horizontal = 24.dp, vertical = 4.dp), ) { Box( - Modifier.size(12.dp).clip(CircleShape).background( - Color.Magenta, - ), + Modifier + .size(12.dp) + .clip(CircleShape) + .background( + Color.Magenta, + ), ) Spacer(Modifier.width(8.dp)) Text(text = stringResource(R.string.thumbnail_cache), style = typo.bodySmall) @@ -1044,9 +1070,12 @@ fun SettingScreen( modifier = Modifier.padding(horizontal = 24.dp, vertical = 4.dp), ) { Box( - Modifier.size(12.dp).clip(CircleShape).background( - Color.White, - ), + Modifier + .size(12.dp) + .clip(CircleShape) + .background( + Color.White, + ), ) Spacer(Modifier.width(8.dp)) Text(text = stringResource(R.string.database), style = typo.bodySmall) @@ -1056,9 +1085,12 @@ fun SettingScreen( modifier = Modifier.padding(horizontal = 24.dp, vertical = 4.dp), ) { Box( - Modifier.size(12.dp).clip(CircleShape).background( - Color.LightGray, - ), + Modifier + .size(12.dp) + .clip(CircleShape) + .background( + Color.LightGray, + ), ) Spacer(Modifier.width(8.dp)) Text(text = stringResource(R.string.free_space), style = typo.bodySmall) @@ -1090,7 +1122,7 @@ fun SettingScreen( Text(text = stringResource(R.string.about_us), style = typo.labelMedium, modifier = Modifier.padding(vertical = 8.dp)) SettingItem( title = stringResource(R.string.version), - subtitle = stringResource(R.string.version_name), + subtitle = stringResource(R.string.version_format, BuildConfig.VERSION_NAME), onClick = { navController.navigateSafe(R.id.action_global_creditFragment) }, @@ -1203,21 +1235,29 @@ fun SettingScreen( LaunchedEffect(googleAccounts) { Log.w( "SettingScreen", - "LaunchedEffect: ${googleAccounts.data?.map { - it.name to it.isUsed - }}", + "LaunchedEffect: ${ + googleAccounts.data?.map { + it.name to it.isUsed + } + }", ) } LazyColumn(modifier = Modifier.padding(8.dp)) { item { - Box(modifier = Modifier.fillMaxWidth().height(48.dp)) { + Box( + modifier = Modifier + .fillMaxWidth() + .height(48.dp) + ) { IconButton( onClick = { showYouTubeAccountDialog = false }, colors = - IconButtonDefaults.iconButtonColors().copy( - contentColor = Color.White, - ), - modifier = Modifier.align(Alignment.CenterStart).fillMaxHeight(), + IconButtonDefaults.iconButtonColors().copy( + contentColor = Color.White, + ), + modifier = Modifier + .align(Alignment.CenterStart) + .fillMaxHeight(), ) { Icon(Icons.Outlined.Close, null, tint = Color.White) } @@ -1225,10 +1265,10 @@ fun SettingScreen( stringResource(R.string.youtube_account), style = typo.titleMedium, modifier = - Modifier - .align(Alignment.Center) - .wrapContentHeight(align = Alignment.CenterVertically) - .wrapContentWidth(), + Modifier + .align(Alignment.Center) + .wrapContentHeight(align = Alignment.CenterVertically) + .wrapContentWidth(), ) } } @@ -1240,35 +1280,37 @@ fun SettingScreen( stringResource(R.string.no_account), style = typo.bodyMedium, textAlign = TextAlign.Center, - modifier = Modifier.padding(12.dp).fillMaxWidth(), + modifier = Modifier + .padding(12.dp) + .fillMaxWidth(), ) } } else { items(data) { Row( modifier = - Modifier - .padding(vertical = 8.dp) - .clickable { - viewModel.setUsedAccount(it) - }, + Modifier + .padding(vertical = 8.dp) + .clickable { + viewModel.setUsedAccount(it) + }, verticalAlignment = Alignment.CenterVertically, ) { Spacer(Modifier.width(24.dp)) AsyncImage( model = - ImageRequest - .Builder(LocalContext.current) - .data(it.thumbnailUrl) - .crossfade(550) - .build(), + ImageRequest + .Builder(LocalContext.current) + .data(it.thumbnailUrl) + .crossfade(550) + .build(), placeholder = painterResource(R.drawable.baseline_people_alt_24), error = painterResource(R.drawable.baseline_people_alt_24), contentDescription = it.name, modifier = - Modifier - .size(48.dp) - .clip(CircleShape), + Modifier + .size(48.dp) + .clip(CircleShape), ) Spacer(Modifier.width(12.dp)) Column(Modifier.weight(1f)) { @@ -1291,7 +1333,11 @@ fun SettingScreen( } } else { item { - CenterLoadingBox(Modifier.fillMaxWidth().height(54.dp)) + CenterLoadingBox( + Modifier + .fillMaxWidth() + .height(54.dp) + ) } } item { @@ -1312,10 +1358,10 @@ fun SettingScreen( title = context.getString(R.string.warning), message = context.getString(R.string.log_out_warning), confirm = - context.getString(R.string.log_out) to { - viewModel.logOutAllYouTube() - showYouTubeAccountDialog = false - }, + context.getString(R.string.log_out) to { + viewModel.logOutAllYouTube() + showYouTubeAccountDialog = false + }, dismiss = context.getString(R.string.cancel), ), ) @@ -1360,9 +1406,9 @@ fun SettingScreen( viewModel.setAlertData( alertState.copy( textField = - alertState.textField.copy( - value = it, - ), + alertState.textField.copy( + value = it, + ), ), ) }, @@ -1383,7 +1429,9 @@ fun SettingScreen( } }, modifier = - Modifier.fillMaxWidth().padding( + Modifier + .fillMaxWidth() + .padding( vertical = 6.dp, ), ) @@ -1400,16 +1448,16 @@ fun SettingScreen( viewModel.setAlertData( alertState.copy( selectOne = - alertState.selectOne.copy( - listSelect = - alertState.selectOne.listSelect.toMutableList().map { - if (it == item) { - true to it.second - } else { - false to it.second - } - }, - ), + alertState.selectOne.copy( + listSelect = + alertState.selectOne.listSelect.toMutableList().map { + if (it == item) { + true to it.second + } else { + false to it.second + } + }, + ), ), ) } @@ -1418,7 +1466,8 @@ fun SettingScreen( .padding(vertical = 4.dp) .clickable { onSelect.invoke() - }.fillMaxWidth(), + } + .fillMaxWidth(), verticalAlignment = Alignment.CenterVertically, ) { RadioButton( @@ -1441,16 +1490,16 @@ fun SettingScreen( viewModel.setAlertData( alertState.copy( multipleSelect = - alertState.multipleSelect.copy( - listSelect = - alertState.multipleSelect.listSelect.toMutableList().map { - if (it == item) { - !it.first to it.second - } else { - it - } - }, - ), + alertState.multipleSelect.copy( + listSelect = + alertState.multipleSelect.listSelect.toMutableList().map { + if (it == item) { + !it.first to it.second + } else { + it + } + }, + ), ), ) } @@ -1459,7 +1508,8 @@ fun SettingScreen( .padding(vertical = 4.dp) .clickable { onCheck.invoke() - }.fillMaxWidth(), + } + .fillMaxWidth(), verticalAlignment = Alignment.CenterVertically, ) { Checkbox( @@ -1482,14 +1532,14 @@ fun SettingScreen( viewModel.setAlertData(null) }, enabled = - if (alertState.textField?.verifyCodeBlock != null) { - alertState.textField.verifyCodeBlock - .invoke( - alertState.textField.value, - ).first - } else { - true - }, + if (alertState.textField?.verifyCodeBlock != null) { + alertState.textField.verifyCodeBlock + .invoke( + alertState.textField.value, + ).first + } else { + true + }, ) { Text(text = alertState.confirm.first) } @@ -1510,9 +1560,9 @@ fun SettingScreen( title = { Text( text = - stringResource( - R.string.settings, - ), + stringResource( + R.string.settings, + ), style = typo.titleMedium, ) }, diff --git a/app/src/main/java/com/maxrave/simpmusic/viewModel/SettingsViewModel.kt b/app/src/main/java/com/maxrave/simpmusic/viewModel/SettingsViewModel.kt index 25d0d9f3..12338059 100644 --- a/app/src/main/java/com/maxrave/simpmusic/viewModel/SettingsViewModel.kt +++ b/app/src/main/java/com/maxrave/simpmusic/viewModel/SettingsViewModel.kt @@ -17,6 +17,7 @@ import androidx.media3.datasource.cache.SimpleCache import coil3.annotation.ExperimentalCoilApi import coil3.imageLoader import com.maxrave.kotlinytmusicscraper.models.simpmusic.GithubResponse +import com.maxrave.simpmusic.BuildConfig import com.maxrave.simpmusic.R import com.maxrave.simpmusic.common.Config import com.maxrave.simpmusic.common.DB_NAME @@ -265,20 +266,20 @@ class SettingsViewModel( it.copy( otherApp = otherApp.toFloat().div(totalByte.toFloat()), downloadCache = - downloadCache.cacheSpace - .bytesToMB() - .toFloat() - .div(totalByte.toFloat()), + downloadCache.cacheSpace + .bytesToMB() + .toFloat() + .div(totalByte.toFloat()), playerCache = - playerCache.cacheSpace - .bytesToMB() - .toFloat() - .div(totalByte.toFloat()), + playerCache.cacheSpace + .bytesToMB() + .toFloat() + .div(totalByte.toFloat()), canvasCache = - canvasCache.cacheSpace - .bytesToMB() - .toFloat() - .div(totalByte.toFloat()), + canvasCache.cacheSpace + .bytesToMB() + .toFloat() + .div(totalByte.toFloat()), thumbCache = thumbSize.toFloat().div(totalByte.toFloat()), freeSpace = freeSpace.toFloat().div(totalByte.toFloat()), appDatabase = databaseSize.toFloat().div(totalByte.toFloat()), @@ -393,7 +394,7 @@ class SettingsViewModel( "CheckForUpdateAt", System.currentTimeMillis().toString(), ) - if (response?.tagName == getString(R.string.version_name)) { + if (response?.tagName == String.format(getString(R.string.version_format), BuildConfig.VERSION_NAME)) { makeToast(getString(R.string.no_update)) } _githubResponse.emit(response) diff --git a/app/src/main/res/layout/fragment_credit.xml b/app/src/main/res/layout/fragment_credit.xml index c61b1e2f..1c730ba6 100644 --- a/app/src/main/res/layout/fragment_credit.xml +++ b/app/src/main/res/layout/fragment_credit.xml @@ -1,42 +1,45 @@ - + android:layout_height="match_parent" + tools:context=".ui.fragment.library.FavoriteFragment"> + + app:title="@string/app_name" + app:titleTextAppearance="@style/TextAppearance.Material3.TitleMedium" /> + + android:layout_height="match_parent" + android:layout_below="@id/topAppBarLayout" + android:padding="10sp"> + + android:layout_gravity="center_horizontal" + android:layout_marginVertical="30dp"> + + + android:textStyle="bold"> + + android:textSize="13sp"> + + android:layout_marginBottom="20dp" + android:text="@string/maxrave_dev"> + + android:layout_marginBottom="5dp" + android:text="@string/credit_app"> @@ -95,6 +102,7 @@ android:text="@string/github"> + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0a044d71..941fc78d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -155,7 +155,7 @@ Your device doesn\'t have equalizer Open system equalizer Use your system equalizer - v0.2.8 + v%s Streaming data provider (Piped) Itag Mime Type diff --git a/gradle.properties b/gradle.properties index 017fe006..95b0e2c9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,3 +20,4 @@ kotlin.jvm.target.validation.mode=IGNORE org.gradle.daemon=true org.gradle.jvmargs=-Xmx2560m org.gradle.unsafe.configuration-cache=true +android.defaults.buildfeatures.buildconfig=true \ No newline at end of file From 334b000543009d8f0f7843fb3195cfa6fd23a5e9 Mon Sep 17 00:00:00 2001 From: Ilian Delagrange Date: Wed, 1 Jan 2025 22:52:33 -0500 Subject: [PATCH 2/3] BuildConfig is actually deprecated --- app/build.gradle.kts | 4 ++-- .../com/maxrave/simpmusic/ui/MainActivity.kt | 5 ++-- .../simpmusic/ui/component/EndOfPage.kt | 7 ++++-- .../ui/fragment/other/CreditFragment.kt | 4 ++-- .../simpmusic/ui/screen/home/SettingScreen.kt | 6 ++--- .../maxrave/simpmusic/utils/VersionManager.kt | 24 +++++++++++++++++++ .../simpmusic/viewModel/SettingsViewModel.kt | 4 ++-- gradle.properties | 5 +++- 8 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 app/src/main/java/com/maxrave/simpmusic/utils/VersionManager.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 9fbccf0f..12dea527 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -17,8 +17,8 @@ android { applicationId = "com.maxrave.simpmusic" minSdk = 26 targetSdk = 35 - versionCode = 25 - versionName = "0.2.8" + versionCode = project.property("VERSION_CODE").toString().toInt() + versionName = project.property("VERSION_NAME").toString() vectorDrawables.useSupportLibrary = true ksp { diff --git a/app/src/main/java/com/maxrave/simpmusic/ui/MainActivity.kt b/app/src/main/java/com/maxrave/simpmusic/ui/MainActivity.kt index a7a9b1ac..71873969 100644 --- a/app/src/main/java/com/maxrave/simpmusic/ui/MainActivity.kt +++ b/app/src/main/java/com/maxrave/simpmusic/ui/MainActivity.kt @@ -33,7 +33,6 @@ import androidx.media3.common.util.UnstableApi import androidx.navigation.fragment.findNavController import androidx.navigation.ui.setupWithNavController import com.google.android.material.dialog.MaterialAlertDialogBuilder -import com.maxrave.simpmusic.BuildConfig import com.maxrave.simpmusic.R import com.maxrave.simpmusic.common.Config import com.maxrave.simpmusic.common.FIRST_TIME_MIGRATION @@ -48,6 +47,7 @@ import com.maxrave.simpmusic.extension.navigateSafe import com.maxrave.simpmusic.service.SimpleMediaService import com.maxrave.simpmusic.ui.screen.MiniPlayer import com.maxrave.simpmusic.ui.theme.AppTheme +import com.maxrave.simpmusic.utils.VersionManager import com.maxrave.simpmusic.viewModel.SharedViewModel import dev.chrisbanes.insetter.applyInsetter import kotlinx.coroutines.delay @@ -111,6 +111,7 @@ class MainActivity : AppCompatActivity() { // if (viewModel.simpleMediaServiceHandler == null) { // startMusicService() // } + VersionManager.initialize(applicationContext) checkForUpdate() if (viewModel.recreateActivity.value == true) { viewModel.activityRecreateDone() @@ -687,7 +688,7 @@ class MainActivity : AppCompatActivity() { viewModel.checkForUpdate() viewModel.githubResponse.observe(this) { response -> if (response != null && !this.isInPictureInPictureMode && !viewModel.showedUpdateDialog) { - if (response.tagName != getString(R.string.version_format, BuildConfig.VERSION_NAME)) { + if (response.tagName != getString(R.string.version_format, VersionManager.getVersionName())) { viewModel.showedUpdateDialog = true val inputFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.getDefault()) diff --git a/app/src/main/java/com/maxrave/simpmusic/ui/component/EndOfPage.kt b/app/src/main/java/com/maxrave/simpmusic/ui/component/EndOfPage.kt index b6862ecd..a20f260c 100644 --- a/app/src/main/java/com/maxrave/simpmusic/ui/component/EndOfPage.kt +++ b/app/src/main/java/com/maxrave/simpmusic/ui/component/EndOfPage.kt @@ -12,9 +12,9 @@ import androidx.compose.ui.draw.alpha import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp -import com.maxrave.simpmusic.BuildConfig import com.maxrave.simpmusic.R import com.maxrave.simpmusic.ui.theme.typo +import com.maxrave.simpmusic.utils.VersionManager @Composable fun EndOfPage() { @@ -26,7 +26,10 @@ fun EndOfPage() { contentAlignment = Alignment.TopCenter, ) { Text( - "@2024 " + stringResource(R.string.app_name) + " " + stringResource(R.string.version_format, BuildConfig.VERSION_NAME) + "\nmaxrave-dev", + "@2024 " + stringResource(R.string.app_name) + " " + stringResource( + R.string.version_format, + VersionManager.getVersionName() + ) + "\nmaxrave-dev", style = typo.bodySmall, textAlign = TextAlign.Center, modifier = diff --git a/app/src/main/java/com/maxrave/simpmusic/ui/fragment/other/CreditFragment.kt b/app/src/main/java/com/maxrave/simpmusic/ui/fragment/other/CreditFragment.kt index cd58dbf3..6ad2bf23 100644 --- a/app/src/main/java/com/maxrave/simpmusic/ui/fragment/other/CreditFragment.kt +++ b/app/src/main/java/com/maxrave/simpmusic/ui/fragment/other/CreditFragment.kt @@ -9,9 +9,9 @@ import android.view.ViewGroup import androidx.core.view.WindowInsetsCompat import androidx.fragment.app.Fragment import androidx.navigation.fragment.findNavController -import com.maxrave.simpmusic.BuildConfig import com.maxrave.simpmusic.R import com.maxrave.simpmusic.databinding.FragmentCreditBinding +import com.maxrave.simpmusic.utils.VersionManager import dev.chrisbanes.insetter.Insetter class CreditFragment : Fragment() { @@ -38,7 +38,7 @@ class CreditFragment : Fragment() { ) { super.onViewCreated(view, savedInstanceState) - binding.versionTextBox.text = getString(R.string.version_format, BuildConfig.VERSION_NAME) + binding.versionTextBox.text = getString(R.string.version_format, VersionManager.getVersionName()) binding.btGithub.setOnClickListener { val urlIntent = Intent( diff --git a/app/src/main/java/com/maxrave/simpmusic/ui/screen/home/SettingScreen.kt b/app/src/main/java/com/maxrave/simpmusic/ui/screen/home/SettingScreen.kt index 5762538b..6d82d90e 100644 --- a/app/src/main/java/com/maxrave/simpmusic/ui/screen/home/SettingScreen.kt +++ b/app/src/main/java/com/maxrave/simpmusic/ui/screen/home/SettingScreen.kt @@ -85,7 +85,6 @@ import coil3.compose.AsyncImage import coil3.request.ImageRequest import coil3.request.crossfade import com.maxrave.kotlinytmusicscraper.extension.isTwoLetterCode -import com.maxrave.simpmusic.BuildConfig import com.maxrave.simpmusic.R import com.maxrave.simpmusic.common.LIMIT_CACHE_SIZE import com.maxrave.simpmusic.common.QUALITY @@ -106,6 +105,7 @@ import com.maxrave.simpmusic.ui.theme.DarkColors import com.maxrave.simpmusic.ui.theme.md_theme_dark_primary import com.maxrave.simpmusic.ui.theme.typo import com.maxrave.simpmusic.utils.LocalResource +import com.maxrave.simpmusic.utils.VersionManager import com.maxrave.simpmusic.viewModel.SettingAlertState import com.maxrave.simpmusic.viewModel.SettingBasicAlertState import com.maxrave.simpmusic.viewModel.SettingsViewModel @@ -215,7 +215,7 @@ fun SettingScreen( LaunchedEffect(githubResponse) { val res = githubResponse - if (res != null && res.tagName != context.getString(R.string.version_format, BuildConfig.VERSION_NAME)) { + if (res != null && res.tagName != context.getString(R.string.version_format, VersionManager.getVersionName())) { val inputFormat = SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss'Z'", @@ -1122,7 +1122,7 @@ fun SettingScreen( Text(text = stringResource(R.string.about_us), style = typo.labelMedium, modifier = Modifier.padding(vertical = 8.dp)) SettingItem( title = stringResource(R.string.version), - subtitle = stringResource(R.string.version_format, BuildConfig.VERSION_NAME), + subtitle = stringResource(R.string.version_format, VersionManager.getVersionName()), onClick = { navController.navigateSafe(R.id.action_global_creditFragment) }, diff --git a/app/src/main/java/com/maxrave/simpmusic/utils/VersionManager.kt b/app/src/main/java/com/maxrave/simpmusic/utils/VersionManager.kt new file mode 100644 index 00000000..ed241871 --- /dev/null +++ b/app/src/main/java/com/maxrave/simpmusic/utils/VersionManager.kt @@ -0,0 +1,24 @@ +package com.maxrave.simpmusic.utils + +import android.content.Context + +object VersionManager { + + private var versionName: String? = null + + fun initialize(context: Context) { + if (versionName == null) { + versionName = try { + val packageInfo = context.packageManager.getPackageInfo(context.packageName, 0) + packageInfo.versionName + } catch (_: Exception) { + String() + } + } + } + + + fun getVersionName(): String { + return versionName ?: String() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/maxrave/simpmusic/viewModel/SettingsViewModel.kt b/app/src/main/java/com/maxrave/simpmusic/viewModel/SettingsViewModel.kt index 12338059..fb3a7b3a 100644 --- a/app/src/main/java/com/maxrave/simpmusic/viewModel/SettingsViewModel.kt +++ b/app/src/main/java/com/maxrave/simpmusic/viewModel/SettingsViewModel.kt @@ -17,7 +17,6 @@ import androidx.media3.datasource.cache.SimpleCache import coil3.annotation.ExperimentalCoilApi import coil3.imageLoader import com.maxrave.kotlinytmusicscraper.models.simpmusic.GithubResponse -import com.maxrave.simpmusic.BuildConfig import com.maxrave.simpmusic.R import com.maxrave.simpmusic.common.Config import com.maxrave.simpmusic.common.DB_NAME @@ -36,6 +35,7 @@ import com.maxrave.simpmusic.extension.zipOutputStream import com.maxrave.simpmusic.service.SimpleMediaService import com.maxrave.simpmusic.service.test.download.DownloadUtils import com.maxrave.simpmusic.utils.LocalResource +import com.maxrave.simpmusic.utils.VersionManager import com.maxrave.simpmusic.viewModel.base.BaseViewModel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay @@ -394,7 +394,7 @@ class SettingsViewModel( "CheckForUpdateAt", System.currentTimeMillis().toString(), ) - if (response?.tagName == String.format(getString(R.string.version_format), BuildConfig.VERSION_NAME)) { + if (response?.tagName == String.format(getString(R.string.version_format), VersionManager.getVersionName())) { makeToast(getString(R.string.no_update)) } _githubResponse.emit(response) diff --git a/gradle.properties b/gradle.properties index 95b0e2c9..a4bf7b04 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,4 +20,7 @@ kotlin.jvm.target.validation.mode=IGNORE org.gradle.daemon=true org.gradle.jvmargs=-Xmx2560m org.gradle.unsafe.configuration-cache=true -android.defaults.buildfeatures.buildconfig=true \ No newline at end of file +# Constants +# Increment the versions here +VERSION_NAME=0.2.8 +VERSION_CODE=25 \ No newline at end of file From 85f3416560b41bbc657ef99efb29529aea50369f Mon Sep 17 00:00:00 2001 From: maxrave-dev Date: Thu, 9 Jan 2025 23:03:26 +0700 Subject: [PATCH 3/3] =?UTF-8?q?=E2=9C=85=20refactor(build):=20Use=20libs.v?= =?UTF-8?q?ersions=20for=20versionCode=20and=20versionName?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle.kts | 9 ++++++--- .../simpmusic/ui/screen/home/SettingScreen.kt | 19 +++++-------------- gradle.properties | 6 +----- gradle/libs.versions.toml | 4 ++++ 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 12dea527..81336232 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,4 +1,5 @@ import com.android.build.gradle.internal.tasks.CompileArtProfileTask +import org.jetbrains.kotlin.compose.compiler.gradle.ComposeFeatureFlag plugins { alias(libs.plugins.android.application) @@ -17,8 +18,8 @@ android { applicationId = "com.maxrave.simpmusic" minSdk = 26 targetSdk = 35 - versionCode = project.property("VERSION_CODE").toString().toInt() - versionName = project.property("VERSION_NAME").toString() + versionCode = libs.versions.version.code.get().toInt() + versionName = libs.versions.version.name.get() vectorDrawables.useSupportLibrary = true ksp { @@ -89,7 +90,9 @@ android { compose = true } composeCompiler { - enableStrongSkippingMode = true + featureFlags = setOf( + ComposeFeatureFlag.StrongSkipping + ) } packaging { jniLibs.useLegacyPackaging = true diff --git a/app/src/main/java/com/maxrave/simpmusic/ui/screen/home/SettingScreen.kt b/app/src/main/java/com/maxrave/simpmusic/ui/screen/home/SettingScreen.kt index 9eb00d7c..d7409d9d 100644 --- a/app/src/main/java/com/maxrave/simpmusic/ui/screen/home/SettingScreen.kt +++ b/app/src/main/java/com/maxrave/simpmusic/ui/screen/home/SettingScreen.kt @@ -481,20 +481,11 @@ fun SettingScreen( title = context.getString(R.string.proxy_host), message = context.getString(R.string.proxy_host_message), textField = - SettingAlertState.TextFieldData( - label = context.getString(R.string.proxy_host), - value = proxyHost, - verifyCodeBlock = { - isValidProxyHost(it) to context.getString(R.string.invalid_host) - }, - ), - confirm = - context.getString(R.string.change) to { state -> - viewModel.setProxy( - proxyType, - state.textField?.value ?: "", - proxyPort, - ) + SettingAlertState.TextFieldData( + label = context.getString(R.string.proxy_host), + value = proxyHost, + verifyCodeBlock = { + isValidProxyHost(it) to context.getString(R.string.invalid_host) }, ), confirm = diff --git a/gradle.properties b/gradle.properties index a4bf7b04..d527cc96 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,8 +19,4 @@ kotlin.code.style=official kotlin.jvm.target.validation.mode=IGNORE org.gradle.daemon=true org.gradle.jvmargs=-Xmx2560m -org.gradle.unsafe.configuration-cache=true -# Constants -# Increment the versions here -VERSION_NAME=0.2.8 -VERSION_CODE=25 \ No newline at end of file +org.gradle.unsafe.configuration-cache=true \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1f21c27e..aac8542b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,4 +1,8 @@ [versions] +# App version +version-name="0.2.8" +version-code="25" + android = "8.7.3" kotlin = "2.1.0" serialization = "2.1.0"