From cac306e9e8b9f3f45219728ef8ce36bcfe233197 Mon Sep 17 00:00:00 2001 From: Shabinder Date: Mon, 9 Nov 2020 11:15:13 +0530 Subject: [PATCH] DownloadRecord YT Art Fix --- .../recyclerView/DownloadRecordAdapter.kt | 10 ++++- .../downloadrecord/DownloadRecordFragment.kt | 41 +++++++++++-------- .../downloadrecord/DownloadRecordViewModel.kt | 1 + 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/shabinder/spotiflyer/recyclerView/DownloadRecordAdapter.kt b/app/src/main/java/com/shabinder/spotiflyer/recyclerView/DownloadRecordAdapter.kt index 670abecf..6648d542 100755 --- a/app/src/main/java/com/shabinder/spotiflyer/recyclerView/DownloadRecordAdapter.kt +++ b/app/src/main/java/com/shabinder/spotiflyer/recyclerView/DownloadRecordAdapter.kt @@ -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(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?,source: Source) { + super.submitList(list) + this.source = source + } } class DownloadRecordDiffCallback: DiffUtil.ItemCallback(){ diff --git a/app/src/main/java/com/shabinder/spotiflyer/ui/downloadrecord/DownloadRecordFragment.kt b/app/src/main/java/com/shabinder/spotiflyer/ui/downloadrecord/DownloadRecordFragment.kt index e6e60b89..03ac9fdb 100755 --- a/app/src/main/java/com/shabinder/spotiflyer/ui/downloadrecord/DownloadRecordFragment.kt +++ b/app/src/main/java/com/shabinder/spotiflyer/ui/downloadrecord/DownloadRecordFragment.kt @@ -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) - } - - override fun onTabReselected(tab: TabLayout.Tab?) { - // Handle tab reselect - } - - override fun onTabUnselected(tab: TabLayout.Tab?) { - // Handle tab unselected + when(tab?.position){ + 0-> adapter.submitList(downloadRecordViewModel.spotifyList,Source.Spotify) + 1-> adapter.submitList(downloadRecordViewModel.ytList,Source.YouTube) + } } + 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() + } + } \ No newline at end of file diff --git a/app/src/main/java/com/shabinder/spotiflyer/ui/downloadrecord/DownloadRecordViewModel.kt b/app/src/main/java/com/shabinder/spotiflyer/ui/downloadrecord/DownloadRecordViewModel.kt index 7f9cc1a7..8ce7a1e8 100755 --- a/app/src/main/java/com/shabinder/spotiflyer/ui/downloadrecord/DownloadRecordViewModel.kt +++ b/app/src/main/java/com/shabinder/spotiflyer/ui/downloadrecord/DownloadRecordViewModel.kt @@ -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() + var gaanaList = mutableListOf() var ytList = mutableListOf() val downloadRecordList = MutableLiveData>().apply { value = mutableListOf()