Separated Suggestions from Home sections
This commit is contained in:
parent
75cdf4d57f
commit
80f3926210
9 changed files with 114 additions and 122 deletions
|
@ -40,6 +40,7 @@ class LibraryViewModel(
|
|||
|
||||
private val _paletteColor = MutableLiveData<Int>()
|
||||
private val home = MutableLiveData<List<Home>>()
|
||||
private val suggestions = MutableLiveData<List<Song>>()
|
||||
private val albums = MutableLiveData<List<Album>>()
|
||||
private val songs = MutableLiveData<List<Song>>()
|
||||
private val artists = MutableLiveData<List<Artist>>()
|
||||
|
@ -56,6 +57,7 @@ class LibraryViewModel(
|
|||
|
||||
private fun loadLibraryContent() = viewModelScope.launch(IO) {
|
||||
fetchHomeSections()
|
||||
fetchSuggestions()
|
||||
fetchSongs()
|
||||
fetchAlbums()
|
||||
fetchArtists()
|
||||
|
@ -93,6 +95,10 @@ class LibraryViewModel(
|
|||
return home
|
||||
}
|
||||
|
||||
fun getSuggestions(): LiveData<List<Song>> {
|
||||
return suggestions
|
||||
}
|
||||
|
||||
fun getFabMargin(): LiveData<Int> {
|
||||
return fabMargin
|
||||
}
|
||||
|
@ -132,6 +138,10 @@ class LibraryViewModel(
|
|||
home.postValue(repository.homeSections())
|
||||
}
|
||||
|
||||
private suspend fun fetchSuggestions() {
|
||||
suggestions.postValue(repository.suggestions())
|
||||
}
|
||||
|
||||
fun search(query: String?, filter: Filter) {
|
||||
viewModelScope.launch(IO) {
|
||||
val result = repository.search(query, filter)
|
||||
|
@ -147,6 +157,7 @@ class LibraryViewModel(
|
|||
HomeSections -> fetchHomeSections()
|
||||
Playlists -> fetchPlaylists()
|
||||
Genres -> fetchGenres()
|
||||
Suggestions -> fetchSuggestions()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -391,4 +402,5 @@ enum class ReloadType {
|
|||
HomeSections,
|
||||
Playlists,
|
||||
Genres,
|
||||
Suggestions
|
||||
}
|
||||
|
|
|
@ -28,4 +28,5 @@ class HomeBindingAdapter(
|
|||
?: bannerHomeBinding?.homeContent?.recyclerView!!
|
||||
val titleWelcome = homeBinding?.titleWelcome ?: bannerHomeBinding?.titleWelcome!!
|
||||
val appNameText = homeBinding?.appNameText ?: bannerHomeBinding?.appNameText!!
|
||||
val suggestions = homeBinding?.homeContent?.suggestions ?: bannerHomeBinding?.homeContent?.suggestions!!
|
||||
}
|
|
@ -28,7 +28,9 @@ import androidx.core.view.doOnPreDraw
|
|||
import androidx.navigation.fragment.FragmentNavigatorExtras
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.common.ATHToolbarActivity
|
||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
||||
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
|
||||
import code.name.monkey.retromusic.*
|
||||
import code.name.monkey.retromusic.adapter.HomeAdapter
|
||||
|
@ -43,7 +45,9 @@ import code.name.monkey.retromusic.fragments.ReloadType
|
|||
import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment
|
||||
import code.name.monkey.retromusic.glide.GlideApp
|
||||
import code.name.monkey.retromusic.glide.RetroGlideExtension
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||
import code.name.monkey.retromusic.interfaces.IScrollHelper
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import com.google.android.gms.cast.framework.CastButtonFactory
|
||||
import com.google.android.material.shape.MaterialShapeDrawable
|
||||
|
@ -76,6 +80,9 @@ class HomeFragment :
|
|||
libraryViewModel.getHome().observe(viewLifecycleOwner, {
|
||||
homeAdapter.swapData(it)
|
||||
})
|
||||
libraryViewModel.getSuggestions().observe(viewLifecycleOwner, {
|
||||
loadSuggestions(it)
|
||||
})
|
||||
|
||||
loadProfile()
|
||||
setupTitle()
|
||||
|
@ -151,6 +158,8 @@ class HomeFragment :
|
|||
)
|
||||
)
|
||||
}
|
||||
// Reload suggestions
|
||||
binding.suggestions.refreshButton.setOnClickListener { libraryViewModel.forceReload(ReloadType.Suggestions) }
|
||||
}
|
||||
|
||||
private fun getBinding(homeBanner: Boolean, view: View): HomeBindingAdapter {
|
||||
|
@ -235,6 +244,47 @@ class HomeFragment :
|
|||
reenterTransition = MaterialSharedAxis(MaterialSharedAxis.Y, false)
|
||||
}
|
||||
|
||||
private fun loadSuggestions(songs: List<Song>) {
|
||||
val images = listOf(
|
||||
binding.suggestions.image1,
|
||||
binding.suggestions.image2,
|
||||
binding.suggestions.image3,
|
||||
binding.suggestions.image4,
|
||||
binding.suggestions.image5,
|
||||
binding.suggestions.image6,
|
||||
binding.suggestions.image7,
|
||||
binding.suggestions.image8
|
||||
)
|
||||
val color = ThemeStore.accentColor(requireContext())
|
||||
binding.suggestions.message.apply {
|
||||
setTextColor(color)
|
||||
setOnClickListener {
|
||||
it.isClickable = false
|
||||
it.postDelayed({ it.isClickable = true }, 500)
|
||||
MusicPlayerRemote.playNext(songs.subList(0, 8))
|
||||
if (!MusicPlayerRemote.isPlaying) {
|
||||
MusicPlayerRemote.playNextSong()
|
||||
}
|
||||
}
|
||||
}
|
||||
binding.suggestions.card6.setCardBackgroundColor(ColorUtil.withAlpha(color, 0.12f))
|
||||
images.forEachIndexed { index, imageView ->
|
||||
imageView.setOnClickListener {
|
||||
it.isClickable = false
|
||||
it.postDelayed({ it.isClickable = true }, 500)
|
||||
MusicPlayerRemote.playNext(songs)
|
||||
if (!MusicPlayerRemote.isPlaying) {
|
||||
MusicPlayerRemote.playNextSong()
|
||||
}
|
||||
}
|
||||
GlideApp.with(this)
|
||||
.asBitmap()
|
||||
.songCoverOptions(songs[index])
|
||||
.load(RetroGlideExtension.getSongModel(songs[index]))
|
||||
.into(imageView)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
const val TAG: String = "BannerHomeFragment"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue