Remove use of requireContext() and other minor cleanup

This commit is contained in:
Luna712 2024-07-18 10:42:38 -06:00 committed by GitHub
parent 49d9ec1fa6
commit b5acdc406d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 17 additions and 18 deletions

View file

@ -38,6 +38,7 @@ object DownloadButtonSetup {
} }
DialogInterface.BUTTON_NEGATIVE -> { DialogInterface.BUTTON_NEGATIVE -> {
// Do nothing on cancel
} }
} }
} }

View file

@ -26,6 +26,7 @@ import com.lagradost.cloudstream3.utils.UIHelper.setAppBarNoScrollFlagsOnTV
class DownloadChildFragment : Fragment() { class DownloadChildFragment : Fragment() {
private lateinit var downloadsViewModel: DownloadViewModel private lateinit var downloadsViewModel: DownloadViewModel
private var binding: FragmentChildDownloadsBinding? = null
companion object { companion object {
fun newInstance(headerName: String, folder: String): Bundle { fun newInstance(headerName: String, folder: String): Bundle {
@ -42,8 +43,6 @@ class DownloadChildFragment : Fragment() {
super.onDestroyView() super.onDestroyView()
} }
private var binding: FragmentChildDownloadsBinding? = null
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, inflater: LayoutInflater,
container: ViewGroup?, container: ViewGroup?,
@ -155,7 +154,7 @@ class DownloadChildFragment : Fragment() {
) )
} }
downloadsViewModel.updateChildList(requireContext(), folder) context?.let { downloadsViewModel.updateChildList(it, folder) }
} }
private fun handleSelectedChange(selected: MutableSet<Int>) { private fun handleSelectedChange(selected: MutableSet<Int>) {

View file

@ -56,6 +56,7 @@ const val DOWNLOAD_NAVIGATE_TO = "downloadpage"
class DownloadFragment : Fragment() { class DownloadFragment : Fragment() {
private lateinit var downloadsViewModel: DownloadViewModel private lateinit var downloadsViewModel: DownloadViewModel
private var binding: FragmentDownloadsBinding? = null
private fun View.setLayoutWidth(weight: Long) { private fun View.setLayoutWidth(weight: Long) {
val param = LinearLayout.LayoutParams( val param = LinearLayout.LayoutParams(
@ -72,8 +73,6 @@ class DownloadFragment : Fragment() {
super.onDestroyView() super.onDestroyView()
} }
private var binding: FragmentDownloadsBinding? = null
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, inflater: LayoutInflater,
container: ViewGroup?, container: ViewGroup?,
@ -218,7 +217,7 @@ class DownloadFragment : Fragment() {
handleScroll(scrollY - oldScrollY) handleScroll(scrollY - oldScrollY)
} }
} }
downloadsViewModel.updateList(requireContext()) context?.let { downloadsViewModel.updateHeaderList(it) }
fixPaddingStatusbar(binding?.downloadRoot) fixPaddingStatusbar(binding?.downloadRoot)
} }

View file

@ -117,7 +117,7 @@ class DownloadViewModel : ViewModel() {
} }
} }
fun updateList(context: Context) = viewModelScope.launchSafe { fun updateHeaderList(context: Context) = viewModelScope.launchSafe {
val visual = withContext(Dispatchers.IO) { val visual = withContext(Dispatchers.IO) {
val children = context.getKeys(DOWNLOAD_EPISODE_CACHE) val children = context.getKeys(DOWNLOAD_EPISODE_CACHE)
.mapNotNull { context.getKey<VideoDownloadHelper.DownloadEpisodeCached>(it) } .mapNotNull { context.getKey<VideoDownloadHelper.DownloadEpisodeCached>(it) }
@ -152,16 +152,16 @@ class DownloadViewModel : ViewModel() {
// parentId : downloadsCount // parentId : downloadsCount
val totalDownloads = mutableMapOf<Int, Int>() val totalDownloads = mutableMapOf<Int, Int>()
children.forEach { c -> children.forEach { child ->
val childFile = getDownloadFileInfoAndUpdateSettings(context, c.id) ?: return@forEach val childFile = getDownloadFileInfoAndUpdateSettings(context, child.id) ?: return@forEach
if (childFile.fileLength <= 1) return@forEach if (childFile.fileLength <= 1) return@forEach
val len = childFile.totalBytes val len = childFile.totalBytes
val flen = childFile.fileLength val flen = childFile.fileLength
totalBytesUsedByChild.merge(c.parentId, len, Long::plus) totalBytesUsedByChild.merge(child.parentId, len, Long::plus)
currentBytesUsedByChild.merge(c.parentId, flen, Long::plus) currentBytesUsedByChild.merge(child.parentId, flen, Long::plus)
totalDownloads.merge(c.parentId, 1, Int::plus) totalDownloads.merge(child.parentId, 1, Int::plus)
} }
return Triple(totalBytesUsedByChild, currentBytesUsedByChild, totalDownloads) return Triple(totalBytesUsedByChild, currentBytesUsedByChild, totalDownloads)
} }
@ -408,11 +408,11 @@ class DownloadViewModel : ViewModel() {
} }
private fun getSelectedItemsData(): List<VisualDownloadCached>? { private fun getSelectedItemsData(): List<VisualDownloadCached>? {
val currentHeaders = headerCards.value.orEmpty() val headers = headerCards.value.orEmpty()
val currentChildren = childCards.value.orEmpty() val children = childCards.value.orEmpty()
return selectedItemIds.value?.mapNotNull { id -> return selectedItemIds.value?.mapNotNull { id ->
currentHeaders.find { it.data.id == id } ?: currentChildren.find { it.data.id == id } headers.find { it.data.id == id } ?: children.find { it.data.id == id }
} }
} }