Skip to content

Commit

Permalink
refractor: Apply suggestion from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasBourdin88 committed Nov 22, 2024
1 parent c707760 commit 7fe900c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
*/
package com.infomaniak.mail.ui.main.thread.actions

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.view.isVisible
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
Expand All @@ -31,7 +37,12 @@ class DownloadAttachmentProgressDialog : DownloadProgressDialog() {
private val downloadAttachmentViewModel: DownloadAttachmentViewModel by viewModels()

override val dialogTitle: String? by lazy { navigationArgs.attachmentName }
override val dialogIconDrawableRes: Int? by lazy { navigationArgs.attachmentType.icon }

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
binding.icon.isVisible = true
binding.icon.setImageDrawable(AppCompatResources.getDrawable(requireContext(), navigationArgs.attachmentType.icon))
return super.onCreateView(inflater, container, savedInstanceState)
}

override fun download() {
downloadAttachmentViewModel.downloadAttachment().observe(this) { cachedAttachment ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class DownloadMessagesProgressDialog : DownloadProgressDialog() {
private val downloadThreadsViewModel: DownloadMessagesViewModel by viewModels()
private val navigationArgs: DownloadMessagesProgressDialogArgs by navArgs()
override val dialogTitle: String? by lazy { getDialogTitleFromArgs() }
override val dialogIconDrawableRes: Int? by lazy { null }

override fun download() {
downloadThreadsViewModel.downloadThreads(mainViewModel.currentMailbox.value).observe(this) { threadUris ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ package com.infomaniak.mail.ui.main.thread.actions
import android.app.Dialog
import android.os.Bundle
import android.view.KeyEvent
import androidx.annotation.DrawableRes
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.view.isVisible
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.lifecycleScope
Expand All @@ -38,10 +35,11 @@ import kotlinx.coroutines.launch

@AndroidEntryPoint
abstract class DownloadProgressDialog : DialogFragment() {

protected val binding by lazy { DialogDownloadProgressBinding.inflate(layoutInflater) }
protected val mainViewModel: MainViewModel by activityViewModels()

abstract val dialogTitle: String?
@get:DrawableRes abstract val dialogIconDrawableRes: Int?

override fun onStart() {
download()
Expand All @@ -50,10 +48,6 @@ abstract class DownloadProgressDialog : DialogFragment() {

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val context = requireContext()

dialogIconDrawableRes?.let { binding.icon.setImageDrawable(AppCompatResources.getDrawable(requireContext(), it)) }
binding.icon.isVisible = dialogIconDrawableRes == null

isCancelable = false

return MaterialAlertDialogBuilder(context)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/dialog_download_progress.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
android:layout_marginStart="@dimen/marginStandardMedium"
android:importantForAccessibility="no"
android:src="@drawable/ic_file_unknown"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand Down

0 comments on commit 7fe900c

Please sign in to comment.