Skip to content

Commit

Permalink
Migrate LiveData to StateFlow in SettingsFragment
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrave-dev committed Jan 21, 2024
1 parent 940c524 commit 8b26301
Show file tree
Hide file tree
Showing 10 changed files with 1,007 additions and 806 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1099,27 +1099,44 @@ class MainRepository @Inject constructor(private val localDataSource: LocalDataS
}.flowOn(Dispatchers.IO)
suspend fun getRelatedData(videoId: String): Flow<Resource<ArrayList<Track>>> = flow {
runCatching {
YouTube.nextCustom(videoId).onSuccess { result ->
val listSongs: ArrayList<Track> = arrayListOf()
val data =
result.contents.singleColumnMusicWatchNextResultsRenderer.tabbedRenderer.watchNextTabbedResultsRenderer.tabs[0].tabRenderer.content?.musicQueueRenderer?.content?.playlistPanelRenderer?.contents
parseRelated(data)?.let { list ->
listSongs.addAll(list)
}
val nextContinuation =
result.contents.singleColumnMusicWatchNextResultsRenderer.tabbedRenderer.watchNextTabbedResultsRenderer.tabs[0].tabRenderer.content?.musicQueueRenderer?.content?.playlistPanelRenderer?.continuations?.get(
0
)?.nextContinuationData?.continuation
if (nextContinuation != null) {
Queue.setContinuation(Pair("RDAMVM$videoId", nextContinuation))
} else {
Queue.setContinuation(null)
YouTube.next(WatchEndpoint(playlistId = "RDAMVM$videoId"))
.onSuccess { next ->
val data: ArrayList<SongItem> = arrayListOf()
data.addAll(next.items)
val nextContinuation = next.continuation
if (nextContinuation != null) {
Queue.setContinuation(Pair("RDAMVM$videoId", nextContinuation))
} else {
Queue.setContinuation(null)
}
emit(Resource.Success<ArrayList<Track>>(data.toListTrack()))
}.onFailure { exception ->
exception.printStackTrace()
Queue.setContinuation(null)
emit(Resource.Error<ArrayList<Track>>(exception.message.toString()))
}
emit(Resource.Success<ArrayList<Track>>(listSongs))
}.onFailure { e ->
Log.d("Related", "Error: ${e.message}")
emit(Resource.Error<ArrayList<Track>>(e.message.toString()))
}
// YouTube.nextCustom(videoId).onSuccess { result ->
// val listSongs: ArrayList<Track> = arrayListOf()
// val data =
// result.contents.singleColumnMusicWatchNextResultsRenderer.tabbedRenderer.watchNextTabbedResultsRenderer.tabs[0].tabRenderer.content?.musicQueueRenderer?.content?.playlistPanelRenderer?.contents
// parseRelated(data)?.let { list ->
// listSongs.addAll(list)
// }
// val nextContinuation =
// result.contents.singleColumnMusicWatchNextResultsRenderer.tabbedRenderer.watchNextTabbedResultsRenderer.tabs[0].tabRenderer.content?.musicQueueRenderer?.content?.playlistPanelRenderer?.continuations?.get(
// 0
// )?.nextContinuationData?.continuation
// if (nextContinuation != null) {
// Queue.setContinuation(Pair("RDAMVM$videoId", nextContinuation))
// } else {
// Queue.setContinuation(null)
// }
// emit(Resource.Success<ArrayList<Track>>(listSongs))
// }.onFailure { e ->
// Log.d("Related", "Error: ${e.message}")
// emit(Resource.Error<ArrayList<Track>>(e.message.toString()))
// }
}
}.flowOn(Dispatchers.IO)
suspend fun getYouTubeCaption(videoId: String): Flow<Resource<Lyrics>> = flow {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.maxrave.simpmusic.ui.fragment.home

import android.animation.Animator
import android.animation.Animator.AnimatorListener
import android.content.Intent
import android.os.Bundle
import android.util.Log
Expand Down Expand Up @@ -831,36 +829,8 @@ class HomeFragment : Fragment() {

private fun showData() {
binding.shimmerLayout.stopShimmer()
val shortAnimationDuration = resources.getInteger(android.R.integer.config_shortAnimTime)
binding.fullLayout.apply {
// Set the content view to 0% opacity but visible, so that it is
// visible but fully transparent during the animation.
alpha = 0f
visibility = View.VISIBLE

// Animate the content view to 100% opacity and clear any animation
// listener set on the view.
animate()
.alpha(1f)
.setDuration(shortAnimationDuration.toLong())
.setListener(
object : AnimatorListener {
override fun onAnimationStart(animation: Animator) {
binding.shimmerLayout.visibility = View.GONE
}

override fun onAnimationEnd(animation: Animator) {
}

override fun onAnimationCancel(animation: Animator) {
}

override fun onAnimationRepeat(animation: Animator) {
}

}
)
}
binding.shimmerLayout.visibility = View.GONE
binding.fullLayout.visibility = View.VISIBLE
binding.swipeRefreshLayout.isRefreshing = false
}

Expand Down

0 comments on commit 8b26301

Please sign in to comment.