mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Remove use of requireContext() and other minor cleanup
This commit is contained in:
parent
49d9ec1fa6
commit
b5acdc406d
4 changed files with 17 additions and 18 deletions
|
@ -38,6 +38,7 @@ object DownloadButtonSetup {
|
|||
}
|
||||
|
||||
DialogInterface.BUTTON_NEGATIVE -> {
|
||||
// Do nothing on cancel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -131,7 +132,7 @@ object DownloadButtonSetup {
|
|||
|
||||
id = click.data.id,
|
||||
parentId = click.data.parentId,
|
||||
name = act.getString(R.string.downloaded_file), //click.data.name ?: keyInfo.displayName
|
||||
name = act.getString(R.string.downloaded_file), // click.data.name ?: keyInfo.displayName
|
||||
season = click.data.season,
|
||||
episode = click.data.episode,
|
||||
headerName = parent.name,
|
||||
|
@ -144,7 +145,7 @@ object DownloadButtonSetup {
|
|||
)
|
||||
)
|
||||
)
|
||||
//R.id.global_to_navigation_player, PlayerFragment.newInstance(
|
||||
// R.id.global_to_navigation_player, PlayerFragment.newInstance(
|
||||
// UriData(
|
||||
// info.path.toString(),
|
||||
// keyInfo.basePath,
|
||||
|
@ -157,7 +158,7 @@ object DownloadButtonSetup {
|
|||
// click.data.season
|
||||
// ),
|
||||
// getViewPos(click.data.id)?.position ?: 0
|
||||
//)
|
||||
// )
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import com.lagradost.cloudstream3.utils.UIHelper.setAppBarNoScrollFlagsOnTV
|
|||
|
||||
class DownloadChildFragment : Fragment() {
|
||||
private lateinit var downloadsViewModel: DownloadViewModel
|
||||
private var binding: FragmentChildDownloadsBinding? = null
|
||||
|
||||
companion object {
|
||||
fun newInstance(headerName: String, folder: String): Bundle {
|
||||
|
@ -42,8 +43,6 @@ class DownloadChildFragment : Fragment() {
|
|||
super.onDestroyView()
|
||||
}
|
||||
|
||||
private var binding: FragmentChildDownloadsBinding? = null
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
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>) {
|
||||
|
|
|
@ -56,6 +56,7 @@ const val DOWNLOAD_NAVIGATE_TO = "downloadpage"
|
|||
|
||||
class DownloadFragment : Fragment() {
|
||||
private lateinit var downloadsViewModel: DownloadViewModel
|
||||
private var binding: FragmentDownloadsBinding? = null
|
||||
|
||||
private fun View.setLayoutWidth(weight: Long) {
|
||||
val param = LinearLayout.LayoutParams(
|
||||
|
@ -72,8 +73,6 @@ class DownloadFragment : Fragment() {
|
|||
super.onDestroyView()
|
||||
}
|
||||
|
||||
private var binding: FragmentDownloadsBinding? = null
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
|
@ -218,7 +217,7 @@ class DownloadFragment : Fragment() {
|
|||
handleScroll(scrollY - oldScrollY)
|
||||
}
|
||||
}
|
||||
downloadsViewModel.updateList(requireContext())
|
||||
context?.let { downloadsViewModel.updateHeaderList(it) }
|
||||
fixPaddingStatusbar(binding?.downloadRoot)
|
||||
}
|
||||
|
||||
|
|
|
@ -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 children = context.getKeys(DOWNLOAD_EPISODE_CACHE)
|
||||
.mapNotNull { context.getKey<VideoDownloadHelper.DownloadEpisodeCached>(it) }
|
||||
|
@ -152,16 +152,16 @@ class DownloadViewModel : ViewModel() {
|
|||
// parentId : downloadsCount
|
||||
val totalDownloads = mutableMapOf<Int, Int>()
|
||||
|
||||
children.forEach { c ->
|
||||
val childFile = getDownloadFileInfoAndUpdateSettings(context, c.id) ?: return@forEach
|
||||
children.forEach { child ->
|
||||
val childFile = getDownloadFileInfoAndUpdateSettings(context, child.id) ?: return@forEach
|
||||
if (childFile.fileLength <= 1) return@forEach
|
||||
|
||||
val len = childFile.totalBytes
|
||||
val flen = childFile.fileLength
|
||||
|
||||
totalBytesUsedByChild.merge(c.parentId, len, Long::plus)
|
||||
currentBytesUsedByChild.merge(c.parentId, flen, Long::plus)
|
||||
totalDownloads.merge(c.parentId, 1, Int::plus)
|
||||
totalBytesUsedByChild.merge(child.parentId, len, Long::plus)
|
||||
currentBytesUsedByChild.merge(child.parentId, flen, Long::plus)
|
||||
totalDownloads.merge(child.parentId, 1, Int::plus)
|
||||
}
|
||||
return Triple(totalBytesUsedByChild, currentBytesUsedByChild, totalDownloads)
|
||||
}
|
||||
|
@ -408,11 +408,11 @@ class DownloadViewModel : ViewModel() {
|
|||
}
|
||||
|
||||
private fun getSelectedItemsData(): List<VisualDownloadCached>? {
|
||||
val currentHeaders = headerCards.value.orEmpty()
|
||||
val currentChildren = childCards.value.orEmpty()
|
||||
val headers = headerCards.value.orEmpty()
|
||||
val children = childCards.value.orEmpty()
|
||||
|
||||
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 }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue