diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 41084f20..af9dfd78 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -14,8 +14,8 @@ android { applicationId = "com.maxrave.simpmusic" minSdk = 26 targetSdk = 34 - versionCode = 4 - versionName = "0.0.4-beta" + versionCode = 5 + versionName = "0.0.5-beta" resourceConfigurations += listOf("en", "vi") testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 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 f6a2baec..7d2edc75 100644 --- a/app/src/main/java/com/maxrave/simpmusic/ui/MainActivity.kt +++ b/app/src/main/java/com/maxrave/simpmusic/ui/MainActivity.kt @@ -37,6 +37,7 @@ import com.maxrave.simpmusic.common.Config import com.maxrave.simpmusic.common.FIRST_TIME_MIGRATION import com.maxrave.simpmusic.common.SELECTED_LANGUAGE import com.maxrave.simpmusic.common.STATUS_DONE +import com.maxrave.simpmusic.common.SUPPORTED_LANGUAGE import com.maxrave.simpmusic.data.queue.Queue import com.maxrave.simpmusic.databinding.ActivityMainBinding import com.maxrave.simpmusic.extension.connectArtists @@ -92,8 +93,13 @@ class MainActivity : AppCompatActivity(), NowPlayingFragment.OnNowPlayingSongCha // Check if the migration has already been done or not if (getString(FIRST_TIME_MIGRATION) != STATUS_DONE) { - putString(SELECTED_LANGUAGE, Locale.getDefault().toLanguageTag()) Log.d("Locale Key", "onCreate: ${Locale.getDefault().toLanguageTag()}") + if (SUPPORTED_LANGUAGE.codes.contains(Locale.getDefault().toLanguageTag())) { + Log.d("Contains", "onCreate: ${SUPPORTED_LANGUAGE.codes.contains(Locale.getDefault().toLanguageTag())}") + putString(SELECTED_LANGUAGE, Locale.getDefault().toLanguageTag()) + } else { + putString(SELECTED_LANGUAGE, "en-US") + } // Fetch the selected language from wherever it was stored. In this case its SharedPref getString(SELECTED_LANGUAGE)?.let { Log.d("Locale Key", "getString: $it") @@ -104,17 +110,6 @@ class MainActivity : AppCompatActivity(), NowPlayingFragment.OnNowPlayingSongCha putString(FIRST_TIME_MIGRATION, STATUS_DONE) } } - val currentLocaleName = if (!AppCompatDelegate.getApplicationLocales().isEmpty) { - // Fetches the current Application Locale from the list - AppCompatDelegate.getApplicationLocales()[0]?.toLanguageTag() - } else { - // Fetches the default System Locale - Locale.getDefault().toLanguageTag() - } - if (currentLocaleName != null) { - putString(SELECTED_LANGUAGE, currentLocaleName) - } - Log.d("Locale Key", "onCreate: $currentLocaleName") if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { WindowCompat.setDecorFitsSystemWindows(window, false) diff --git a/app/src/main/java/com/maxrave/simpmusic/viewModel/SharedViewModel.kt b/app/src/main/java/com/maxrave/simpmusic/viewModel/SharedViewModel.kt index 71683cac..9b507e17 100644 --- a/app/src/main/java/com/maxrave/simpmusic/viewModel/SharedViewModel.kt +++ b/app/src/main/java/com/maxrave/simpmusic/viewModel/SharedViewModel.kt @@ -196,34 +196,27 @@ class SharedViewModel @Inject constructor(private var dataStoreManager: DataStor } } val job2 = launch { - simpleMediaServiceHandler.changeTrack.collect { isChanged -> - Log.d("Check Change Track", "Change Track: $isChanged") - if (isChanged){ - if (simpleMediaServiceHandler.getCurrentMediaItem()?.mediaId != videoId.value && simpleMediaServiceHandler.getCurrentMediaItem() != null){ - videoId.postValue(simpleMediaServiceHandler.getCurrentMediaItem()?.mediaId) - _nowPlayingMediaItem.value = getCurrentMediaItem() - _songTransitions.value = true - } - Log.d("Change Track in ViewModel", "Change Track") - val song = getCurrentMediaItem() - if (song != null && getCurrentMediaItemIndex() > 0) { - val tempSong = musicSource.catalogMetadata[getCurrentMediaItemIndex()] - Log.d("Check tempSong", tempSong.toString()) - mainRepository.insertSong(tempSong.toSongEntity()) - mainRepository.getSongById(tempSong.videoId) - .collect { songEntity -> - _songDB.value = songEntity - if (songEntity != null) { - _liked.value = songEntity.liked - Log.d("Check like", songEntity.toString()) - } + simpleMediaServiceHandler.changeTrack.collectLatest { isChanged -> + val song = getCurrentMediaItem() + if (song != null && getCurrentMediaItemIndex() > 0) { + val tempSong = musicSource.catalogMetadata[getCurrentMediaItemIndex()] + Log.d("Check tempSong", tempSong.toString()) + mainRepository.insertSong(tempSong.toSongEntity()) + mainRepository.getSongById(tempSong.videoId) + .collectLatest { songEntity -> + _songDB.value = songEntity + if (songEntity != null) { + _liked.value = songEntity.liked + Log.d("Check like", songEntity.toString()) } - mainRepository.updateSongInLibrary(LocalDateTime.now(), tempSong.videoId) - mainRepository.updateListenCount(tempSong.videoId) -// resetLyrics() -// getLyrics(song.mediaMetadata.title.toString() + " " + song.mediaMetadata.artist, song.mediaId) - } + } + mainRepository.updateSongInLibrary(LocalDateTime.now(), tempSong.videoId) + mainRepository.updateListenCount(tempSong.videoId) + videoId.postValue(tempSong.videoId) + _nowPlayingMediaItem.value = song + _songTransitions.value = true } + Log.d("Check Change Track", "Change Track: $isChanged") } } val job3 = launch { @@ -419,6 +412,7 @@ class SharedViewModel @Inject constructor(private var dataStoreManager: DataStor quality = runBlocking { dataStoreManager.quality.first() } viewModelScope.launch { _firstTrackAdded.value = false + Queue.clear() simpleMediaServiceHandler.clearMediaItems() var uri = "" mainRepository.insertSong(track.toSongEntity()) diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml index 2703821f..cbe56072 100644 --- a/app/src/main/res/layout/fragment_settings.xml +++ b/app/src/main/res/layout/fragment_settings.xml @@ -318,7 +318,7 @@ android:layout_height="wrap_content" android:textSize="16sp" android:id="@+id/tvVersion" - android:text="v0.0.2-beta"> + android:text="v0.0.5-beta"> diff --git a/fastlane/metadata/android/en-US/changelogs/5.txt b/fastlane/metadata/android/en-US/changelogs/5.txt new file mode 100644 index 00000000..f35e351a --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/5.txt @@ -0,0 +1 @@ +Fixed crash caused locale default \ No newline at end of file diff --git a/fastlane/metadata/android/vi-VN/changelogs/5.txt b/fastlane/metadata/android/vi-VN/changelogs/5.txt new file mode 100644 index 00000000..9805aca1 --- /dev/null +++ b/fastlane/metadata/android/vi-VN/changelogs/5.txt @@ -0,0 +1 @@ +Sửa lỗi crash do lỗi vị trí mặc định \ No newline at end of file