DownloadRecord YT Art Fix

This commit is contained in:
Shabinder 2020-11-09 11:15:13 +05:30
parent ac423623e6
commit cac306e9e8
3 changed files with 33 additions and 19 deletions

View File

@ -25,6 +25,7 @@ import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.shabinder.spotiflyer.database.DownloadRecord
import com.shabinder.spotiflyer.databinding.DownloadRecordItemBinding
import com.shabinder.spotiflyer.models.spotify.Source
import com.shabinder.spotiflyer.ui.downloadrecord.DownloadRecordFragmentDirections
import com.shabinder.spotiflyer.utils.bindImage
import kotlinx.coroutines.CoroutineScope
@ -34,6 +35,8 @@ import kotlinx.coroutines.launch
class DownloadRecordAdapter: ListAdapter<DownloadRecord,DownloadRecordAdapter.ViewHolder>(DownloadRecordDiffCallback()) {
private val adapterScope = CoroutineScope(Dispatchers.Default)
//Remember To change when Submitting a Different List / Or Use New Submit List Fun
var source:Source = Source.Spotify
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val layoutInflater = LayoutInflater.from(parent.context)
@ -44,7 +47,7 @@ class DownloadRecordAdapter: ListAdapter<DownloadRecord,DownloadRecordAdapter.Vi
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val item = getItem(position)
adapterScope.launch {
bindImage(holder.binding.coverUrl,item.coverUrl,null)
bindImage(holder.binding.coverUrl,item.coverUrl,source)
}
holder.binding.itemName.text = item.name
holder.binding.totalItems.text = "Tracks: ${item.totalFiles}"
@ -58,6 +61,11 @@ class DownloadRecordAdapter: ListAdapter<DownloadRecord,DownloadRecordAdapter.Vi
}
}
class ViewHolder(val binding: DownloadRecordItemBinding) : RecyclerView.ViewHolder(binding.root)
fun submitList(list: MutableList<DownloadRecord>?,source: Source) {
super.submitList(list)
this.source = source
}
}
class DownloadRecordDiffCallback: DiffUtil.ItemCallback<DownloadRecord>(){

View File

@ -27,6 +27,7 @@ import androidx.lifecycle.ViewModelProvider
import com.google.android.material.tabs.TabLayout
import com.shabinder.spotiflyer.R
import com.shabinder.spotiflyer.databinding.DownloadRecordFragmentBinding
import com.shabinder.spotiflyer.models.spotify.Source
import com.shabinder.spotiflyer.recyclerView.DownloadRecordAdapter
import dagger.hilt.android.AndroidEntryPoint
@ -48,36 +49,40 @@ class DownloadRecordFragment : Fragment() {
downloadRecordViewModel.downloadRecordList.observe(viewLifecycleOwner, {
if(it.isNotEmpty()){
downloadRecordViewModel.spotifyList = mutableListOf()
downloadRecordViewModel.ytList = mutableListOf()
resetLists()
for (downloadRecord in it) {
if(downloadRecord.link.contains("spotify",true)) downloadRecordViewModel.spotifyList.add(downloadRecord)
else downloadRecordViewModel.ytList.add(downloadRecord)
when{
downloadRecord.link.contains("spotify",true) -> downloadRecordViewModel.spotifyList.add(downloadRecord)
downloadRecord.link.contains("gaana",true) -> downloadRecordViewModel.gaanaList.add(downloadRecord)
else -> downloadRecordViewModel.ytList.add(downloadRecord)
}
}
when(binding.tabLayout.selectedTabPosition){
0-> adapter.submitList(downloadRecordViewModel.spotifyList,Source.Spotify)
1-> adapter.submitList(downloadRecordViewModel.ytList,Source.YouTube)
}
if(binding.tabLayout.selectedTabPosition == 0) adapter.submitList(downloadRecordViewModel.spotifyList)
else adapter.submitList(downloadRecordViewModel.ytList)
}
})
binding.tabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab?) {
if(tab?.text == "Spotify"){
adapter.submitList(downloadRecordViewModel.spotifyList)
} else adapter.submitList(downloadRecordViewModel.ytList)
when(tab?.position){
0-> adapter.submitList(downloadRecordViewModel.spotifyList,Source.Spotify)
1-> adapter.submitList(downloadRecordViewModel.ytList,Source.YouTube)
}
override fun onTabReselected(tab: TabLayout.Tab?) {
// Handle tab reselect
}
override fun onTabUnselected(tab: TabLayout.Tab?) {
// Handle tab unselected
}
override fun onTabReselected(tab: TabLayout.Tab?) {}
override fun onTabUnselected(tab: TabLayout.Tab?) {}
})
return binding.root
}
private fun resetLists() {
downloadRecordViewModel.spotifyList = mutableListOf()
downloadRecordViewModel.ytList = mutableListOf()
downloadRecordViewModel.gaanaList = mutableListOf()
}
}

View File

@ -32,6 +32,7 @@ class DownloadRecordViewModel @ViewModelInject constructor(val databaseDAO: Data
private var viewModelJob = Job()
private val uiScope = CoroutineScope(Dispatchers.Default + viewModelJob)
var spotifyList = mutableListOf<DownloadRecord>()
var gaanaList = mutableListOf<DownloadRecord>()
var ytList = mutableListOf<DownloadRecord>()
val downloadRecordList = MutableLiveData<MutableList<DownloadRecord>>().apply {
value = mutableListOf()