mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Replace notifyDataSetChanged() with notifyItemRangeChanged() in setList(), use requireActivity().onBackPressedDispatcher.onBackPressed()
This commit is contained in:
parent
c06d13e786
commit
171b5b721e
3 changed files with 42 additions and 11 deletions
|
@ -18,6 +18,7 @@ import com.lagradost.cloudstream3.utils.VideoDownloadManager
|
||||||
import kotlinx.android.synthetic.main.fragment_child_downloads.*
|
import kotlinx.android.synthetic.main.fragment_child_downloads.*
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
class DownloadChildFragment : Fragment() {
|
class DownloadChildFragment : Fragment() {
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -39,6 +40,7 @@ class DownloadChildFragment : Fragment() {
|
||||||
return inflater.inflate(R.layout.fragment_child_downloads, container, false)
|
return inflater.inflate(R.layout.fragment_child_downloads, container, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun updateList(folder: String) = main {
|
private fun updateList(folder: String) = main {
|
||||||
context?.let { ctx ->
|
context?.let { ctx ->
|
||||||
val data = withContext(Dispatchers.IO) { ctx.getKeys(folder) }
|
val data = withContext(Dispatchers.IO) { ctx.getKeys(folder) }
|
||||||
|
@ -50,16 +52,38 @@ class DownloadChildFragment : Fragment() {
|
||||||
?: return@mapNotNull null
|
?: return@mapNotNull null
|
||||||
VisualDownloadChildCached(info.fileLength, info.totalBytes, it)
|
VisualDownloadChildCached(info.fileLength, info.totalBytes, it)
|
||||||
}
|
}
|
||||||
}.sortedBy { it.data.episode + (it.data.season?: 0)*100000 }
|
}.sortedBy { it.data.episode + (it.data.season ?: 0) * 100000 }
|
||||||
if (eps.isEmpty()) {
|
if (eps.isEmpty()) {
|
||||||
activity?.onBackPressed()
|
requireActivity().onBackPressedDispatcher.onBackPressed()
|
||||||
return@main
|
return@main
|
||||||
}
|
}
|
||||||
|
val adapter = download_child_list?.adapter as DownloadChildAdapter? ?: return@main
|
||||||
(download_child_list?.adapter as DownloadChildAdapter? ?: return@main).cardList = eps
|
val oldSize = adapter.cardList.size
|
||||||
download_child_list?.adapter?.notifyDataSetChanged()
|
adapter.cardList = eps
|
||||||
|
adapter.notifyItemRangeChanged(0, min(oldSize,eps.size))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// private fun updateList(folder: String) = main {
|
||||||
|
// context?.let { ctx ->
|
||||||
|
// val data = withContext(Dispatchers.IO) { ctx.getKeys(folder) }
|
||||||
|
// val eps = withContext(Dispatchers.IO) {
|
||||||
|
// data.mapNotNull { key ->
|
||||||
|
// context?.getKey<VideoDownloadHelper.DownloadEpisodeCached>(key)
|
||||||
|
// }.mapNotNull {
|
||||||
|
// val info = VideoDownloadManager.getDownloadFileInfoAndUpdateSettings(ctx, it.id)
|
||||||
|
// ?: return@mapNotNull null
|
||||||
|
// VisualDownloadChildCached(info.fileLength, info.totalBytes, it)
|
||||||
|
// }
|
||||||
|
// }.sortedBy { it.data.episode + (it.data.season?: 0)*100000 }
|
||||||
|
// if (eps.isEmpty()) {
|
||||||
|
// activity?.onBackPressed()
|
||||||
|
// return@main
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// (download_child_list?.adapter as DownloadChildAdapter? ?: return@main).cardList = eps
|
||||||
|
// download_child_list?.adapter?.notifyDataSetChanged()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
private var downloadDeleteEventListener: ((Int) -> Unit)? = null
|
private var downloadDeleteEventListener: ((Int) -> Unit)? = null
|
||||||
|
|
||||||
|
@ -69,7 +93,7 @@ class DownloadChildFragment : Fragment() {
|
||||||
val folder = arguments?.getString("folder")
|
val folder = arguments?.getString("folder")
|
||||||
val name = arguments?.getString("name")
|
val name = arguments?.getString("name")
|
||||||
if (folder == null) {
|
if (folder == null) {
|
||||||
activity?.onBackPressed() // TODO FIX
|
requireActivity().onBackPressedDispatcher.onBackPressed()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
context?.fixPaddingStatusbar(download_child_root)
|
context?.fixPaddingStatusbar(download_child_root)
|
||||||
|
@ -77,7 +101,7 @@ class DownloadChildFragment : Fragment() {
|
||||||
download_child_toolbar.title = name
|
download_child_toolbar.title = name
|
||||||
download_child_toolbar.setNavigationIcon(R.drawable.ic_baseline_arrow_back_24)
|
download_child_toolbar.setNavigationIcon(R.drawable.ic_baseline_arrow_back_24)
|
||||||
download_child_toolbar.setNavigationOnClickListener {
|
download_child_toolbar.setNavigationOnClickListener {
|
||||||
activity?.onBackPressed()
|
requireActivity().onBackPressedDispatcher.onBackPressed()
|
||||||
}
|
}
|
||||||
|
|
||||||
val adapter: RecyclerView.Adapter<RecyclerView.ViewHolder> =
|
val adapter: RecyclerView.Adapter<RecyclerView.ViewHolder> =
|
||||||
|
|
|
@ -24,7 +24,6 @@ import com.lagradost.cloudstream3.mvvm.observe
|
||||||
import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup.handleDownloadClick
|
import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup.handleDownloadClick
|
||||||
import com.lagradost.cloudstream3.ui.player.GeneratorPlayer
|
import com.lagradost.cloudstream3.ui.player.GeneratorPlayer
|
||||||
import com.lagradost.cloudstream3.ui.player.LinkGenerator
|
import com.lagradost.cloudstream3.ui.player.LinkGenerator
|
||||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
|
|
||||||
import com.lagradost.cloudstream3.utils.AppUtils.loadResult
|
import com.lagradost.cloudstream3.utils.AppUtils.loadResult
|
||||||
import com.lagradost.cloudstream3.utils.Coroutines.main
|
import com.lagradost.cloudstream3.utils.Coroutines.main
|
||||||
import com.lagradost.cloudstream3.utils.DOWNLOAD_EPISODE_CACHE
|
import com.lagradost.cloudstream3.utils.DOWNLOAD_EPISODE_CACHE
|
||||||
|
@ -58,10 +57,19 @@ class DownloadFragment : Fragment() {
|
||||||
this.layoutParams = param
|
this.layoutParams = param
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// private fun setList(list: List<VisualDownloadHeaderCached>) {
|
||||||
|
// main {
|
||||||
|
// (download_list?.adapter as DownloadHeaderAdapter?)?.cardList = list
|
||||||
|
// download_list?.adapter?.notifyDataSetChanged()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
private fun setList(list: List<VisualDownloadHeaderCached>) {
|
private fun setList(list: List<VisualDownloadHeaderCached>) {
|
||||||
main {
|
main {
|
||||||
(download_list?.adapter as DownloadHeaderAdapter?)?.cardList = list
|
val adapter = download_list?.adapter as DownloadHeaderAdapter?
|
||||||
download_list?.adapter?.notifyDataSetChanged()
|
if (adapter != null) {
|
||||||
|
adapter.cardList = list
|
||||||
|
adapter.notifyItemRangeChanged(0, list.size)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,6 @@ class SettingsPlayer : PreferenceFragmentCompat() {
|
||||||
}
|
}
|
||||||
return@setOnPreferenceClickListener true
|
return@setOnPreferenceClickListener true
|
||||||
}
|
}
|
||||||
|
|
||||||
getPref(R.string.player_pref_key)?.setOnPreferenceClickListener {
|
getPref(R.string.player_pref_key)?.setOnPreferenceClickListener {
|
||||||
val prefNames = resources.getStringArray(R.array.player_pref_names)
|
val prefNames = resources.getStringArray(R.array.player_pref_names)
|
||||||
val prefValues = resources.getIntArray(R.array.player_pref_values)
|
val prefValues = resources.getIntArray(R.array.player_pref_values)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue