Skip to content

Commit

Permalink
Merge pull request #2084 from Infomaniak/fix-dialog-download
Browse files Browse the repository at this point in the history
Don't use viewLifecycleOwner in DialogFragment and use "this" instead as per Google recommandation
  • Loading branch information
KevinBoulongne authored Oct 28, 2024
2 parents ddc9d76 + 7c0d9e2 commit 7d971ba
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ class DownloadAttachmentProgressDialog : DialogFragment() {
val iconDrawable = AppCompatResources.getDrawable(requireContext(), navigationArgs.attachmentType.icon)
binding.icon.setImageDrawable(iconDrawable)

downloadAttachment()

return MaterialAlertDialogBuilder(requireContext())
.setTitle(navigationArgs.attachmentName)
.setView(binding.root)
Expand All @@ -66,8 +64,13 @@ class DownloadAttachmentProgressDialog : DialogFragment() {
.create()
}

override fun onStart() {
super.onStart()
downloadAttachment()
}

private fun downloadAttachment() {
downloadAttachmentViewModel.downloadAttachment().observe(viewLifecycleOwner) { cachedAttachment ->
downloadAttachmentViewModel.downloadAttachment().observe(this) { cachedAttachment ->
if (cachedAttachment == null) {
popBackStackWithError()
} else {
Expand All @@ -79,7 +82,7 @@ class DownloadAttachmentProgressDialog : DialogFragment() {
}

private fun popBackStackWithError() {
viewLifecycleOwner.lifecycleScope.launch {
lifecycleScope.launch {
mainViewModel.isNetworkAvailable.first { it != null }?.let { isNetworkAvailable ->
showSnackbar(title = if (isNetworkAvailable) R.string.anErrorHasOccurred else R.string.noConnection)
findNavController().popBackStack()
Expand Down

0 comments on commit 7d971ba

Please sign in to comment.