Skip to content

Commit

Permalink
Fixed LIKE, Add Japanese and Arabic languages
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrave-dev committed Mar 27, 2024
1 parent ad5d8eb commit 6f9840d
Show file tree
Hide file tree
Showing 13 changed files with 788 additions and 87 deletions.
8 changes: 5 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ android {
applicationId = "com.maxrave.simpmusic"
minSdk = 26
targetSdk = 34
versionCode = 16
versionName = "0.2.0"
versionCode = 17
versionName = "0.2.1"
vectorDrawables.useSupportLibrary = true

ksp {
Expand All @@ -36,7 +36,9 @@ android {
"fr",
"es",
"zh",
"in"
"in",
"ar",
"ja",
)
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/com/maxrave/simpmusic/common/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ object Config {

val REMOVED_SONG_DATE_TIME = LocalDateTime.of(2003, Month.AUGUST, 26, 3, 0)

const val OPEN_NOTIFICATION_ACTION = "com.maxrave.simpmusic.service.test.notification.NOTIFICATION"
}

object DownloadState {
Expand Down Expand Up @@ -172,6 +171,8 @@ object SUPPORTED_LANGUAGE {
"Español",
"简体中文",
"Bahasa Indonesia",
"اللغة العربية",
"日本語"
)
val codes: Array<String> =
arrayOf(
Expand All @@ -188,6 +189,8 @@ object SUPPORTED_LANGUAGE {
"es-ES",
"zh-CN",
"in-ID",
"ar-SA",
"ja-JP"
)
}

Expand Down
35 changes: 12 additions & 23 deletions app/src/main/java/com/maxrave/simpmusic/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,9 @@ class MainActivity : AppCompatActivity() {
}
val likedJob =
launch {
viewModel.liked.collect {
if (binding.cbFavorite.isChecked != it) {
binding.cbFavorite.isChecked = it
}
viewModel.liked.collectLatest {
Log.w("Check Like", "Collect from main activity $it")
binding.cbFavorite.isChecked = it
}
}
job2.join()
Expand Down Expand Up @@ -365,14 +364,14 @@ class MainActivity : AppCompatActivity() {
YouTube.locale =
YouTubeLocale(
gl = getString("location") ?: "US",
hl = Locale.getDefault().toLanguageTag(),
hl = Locale.getDefault().toLanguageTag().substring(0..1),
)
} else {
putString(SELECTED_LANGUAGE, "en-US")
YouTube.locale =
YouTubeLocale(
gl = getString("location") ?: "US",
hl = "en-US",
hl = "en-US".substring(0..1),
)
}
// Fetch the selected language from wherever it was stored. In this case its SharedPref
Expand All @@ -398,7 +397,7 @@ class MainActivity : AppCompatActivity() {
YouTube.locale =
YouTubeLocale(
gl = getString("location") ?: "US",
hl = AppCompatDelegate.getApplicationLocales().toLanguageTags(),
hl = AppCompatDelegate.getApplicationLocales().toLanguageTags().substring(0..1),
)
}
//
Expand Down Expand Up @@ -731,22 +730,12 @@ class MainActivity : AppCompatActivity() {
job1.join()
}
binding.card.animation = AnimationUtils.loadAnimation(this, R.anim.bottom_to_top)
binding.cbFavorite.setOnCheckedChangeListener { _, isChecked ->
if (isChecked != runBlocking { viewModel.liked.first() }) {
if (!isChecked) {
Log.d("cbFavorite", "onCheckedChanged: $isChecked")
viewModel.nowPlayingMediaItem.value?.let { nowPlayingSong ->
viewModel.updateLikeStatus(nowPlayingSong.mediaId, false)
viewModel.updateLikeInNotification(false)
}
} else {
Log.d("cbFavorite", "onCheckedChanged: $isChecked")
viewModel.nowPlayingMediaItem.value?.let { nowPlayingSong ->
viewModel.updateLikeStatus(nowPlayingSong.mediaId, true)
viewModel.updateLikeInNotification(true)
}
}
Log.w("Where like", "Like in MainActivity listener")
binding.cbFavorite.setOnClickListener {
viewModel.nowPlayingMediaItem.value?.let { nowPlayingSong ->
viewModel.updateLikeStatus(
nowPlayingSong.mediaId,
!runBlocking { viewModel.liked.first() },
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -824,10 +824,9 @@ class NowPlayingFragment : Fragment() {
}
val job10 =
launch {
viewModel.liked.collect { liked ->
if (binding.cbFavorite.isChecked != liked) {
binding.cbFavorite.isChecked = liked
}
viewModel.liked.collectLatest { liked ->
Log.w("Check Like", "Collect from main activity $liked")
binding.cbFavorite.isChecked = liked
}
}
val job11 =
Expand Down Expand Up @@ -1394,25 +1393,12 @@ class NowPlayingFragment : Fragment() {
binding.btSongInfo.setOnClickListener {
findNavController().navigateSafe(R.id.action_global_infoFragment)
}
binding.cbFavorite.setOnCheckedChangeListener { _, isChecked ->
Log.w("Where Like", isChecked.toString() + "Now Playing Listener")
if (isChecked != runBlocking { viewModel.liked.first() }) {
viewModel.updateLikeInNotification(isChecked)
if (!isChecked) {
viewModel.nowPlayingMediaItem.value?.let { nowPlayingSong ->
viewModel.updateLikeStatus(
nowPlayingSong.mediaId,
false,
)
}
} else {
viewModel.nowPlayingMediaItem.value?.let { nowPlayingSong ->
viewModel.updateLikeStatus(
nowPlayingSong.mediaId,
true,
)
}
}
binding.cbFavorite.setOnClickListener {
viewModel.nowPlayingMediaItem.value?.let { nowPlayingSong ->
viewModel.updateLikeStatus(
nowPlayingSong.mediaId,
!runBlocking { viewModel.liked.first() },
)
}
}
binding.uploaderLayout.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,8 @@ class SettingsViewModel @Inject constructor(
fun changeLanguage(code: String) {
viewModelScope.launch {
dataStoreManager.putString(SELECTED_LANGUAGE, code)
YouTube.locale = YouTubeLocale(location.value!!, code)
Log.w("SettingsViewModel", "changeLanguage: $code")
YouTube.locale = YouTubeLocale(location.value!!, code.substring(0..1))
getLanguage()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,10 @@ class SharedViewModel
.collectLatest { songEntity ->
_songDB.value = songEntity
if (songEntity != null) {
Log.w("Check like", "SharedViewModel nowPlaying collect ${songEntity.liked}")
_liked.value = songEntity.liked
downloaded =
songEntity.downloadState == DownloadState.STATE_DOWNLOADED
Log.d("Check like", songEntity.toString())
}
}
mainRepository.updateSongInLibrary(
Expand Down Expand Up @@ -852,6 +852,7 @@ class SharedViewModel
.collect { songEntity ->
_songDB.value = songEntity
if (songEntity != null) {
Log.w("Check like", "loadMediaItemFromTrack ${songEntity.liked}")
_liked.value = songEntity.liked
}
}
Expand Down Expand Up @@ -1191,7 +1192,6 @@ class SharedViewModel
println("Update Like Status $videoId $likeStatus")
viewModelScope.launch {
if (simpleMediaServiceHandler?.nowPlaying?.first()?.mediaId == videoId) {
_liked.value = likeStatus
if (likeStatus) {
mainRepository.updateLikeStatus(videoId, 1)
} else {
Expand All @@ -1212,6 +1212,7 @@ class SharedViewModel
mainRepository.getSongById(videoId).collect { songEntity ->
_songDB.value = songEntity
if (songEntity != null) {
Log.w("Check like", "SharedViewModel updateDownloadState ${songEntity.liked}")
_liked.value = songEntity.liked
}
}
Expand All @@ -1221,10 +1222,13 @@ class SharedViewModel

fun refreshSongDB() {
viewModelScope.launch {
mainRepository.getSongById(videoId.value!!).collect { songEntity ->
_songDB.value = songEntity
if (songEntity != null) {
_liked.value = songEntity.liked
nowPlayingMediaItem.value?.mediaId?.let {
mainRepository.getSongById(it).collect { songEntity ->
_songDB.value = songEntity
if (songEntity != null) {
Log.w("Check like", "SharedViewModel refreshSongDB ${songEntity.liked}")
_liked.value = songEntity.liked
}
}
}
}
Expand Down
Loading

0 comments on commit 6f9840d

Please sign in to comment.