DownloadFragment: Avoid capturing download object in listener

This results in their state never being updated when passed to menu fragment.
Store the ongoing downloads in a list and find it when required using the
package name instead.

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2024-01-09 19:42:16 +05:30
parent 8c7377efd6
commit 262ee94d84

View File

@@ -49,6 +49,7 @@ class DownloadFragment : BaseFragment(R.layout.fragment_download) {
@Inject @Inject
lateinit var downloadWorkerUtil: DownloadWorkerUtil lateinit var downloadWorkerUtil: DownloadWorkerUtil
lateinit var downloadList: List<Download>
private val AURORA_STORE_URL = "https://gitlab.com/AuroraOSS/AuroraStore" private val AURORA_STORE_URL = "https://gitlab.com/AuroraOSS/AuroraStore"
@@ -82,7 +83,10 @@ class DownloadFragment : BaseFragment(R.layout.fragment_download) {
} }
viewLifecycleOwner.lifecycleScope.launch { viewLifecycleOwner.lifecycleScope.launch {
downloadWorkerUtil.downloadsList.collectLatest { updateController(it) } downloadWorkerUtil.downloadsList.collectLatest {
downloadList = it
updateController(it)
}
} }
} }
@@ -113,7 +117,7 @@ class DownloadFragment : BaseFragment(R.layout.fragment_download) {
} }
} }
.longClick { _ -> .longClick { _ ->
openDownloadMenuSheet(it) openDownloadMenuSheet(it.packageName)
true true
} }
) )
@@ -123,7 +127,8 @@ class DownloadFragment : BaseFragment(R.layout.fragment_download) {
binding.swipeRefreshLayout.isRefreshing = false binding.swipeRefreshLayout.isRefreshing = false
} }
private fun openDownloadMenuSheet(download: Download) { private fun openDownloadMenuSheet(packageName: String) {
val download = downloadList.find { it.packageName == packageName }!!
findNavController().navigate( findNavController().navigate(
DownloadFragmentDirections.actionDownloadFragmentToDownloadMenuSheet(download) DownloadFragmentDirections.actionDownloadFragmentToDownloadMenuSheet(download)
) )