Skip to content

Commit

Permalink
Fixed (#15) and (#20) crash
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrave-dev committed Aug 4, 2023
1 parent cecaab3 commit a831a97
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 41 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 7 additions & 12 deletions app/src/main/java/com/maxrave/simpmusic/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

</TextView>
</LinearLayout>
Expand Down
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed crash caused locale default
1 change: 1 addition & 0 deletions fastlane/metadata/android/vi-VN/changelogs/5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sửa lỗi crash do lỗi vị trí mặc định

0 comments on commit a831a97

Please sign in to comment.