Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace kotlinx extension by ViewBinding in DownloadProgressDialog #1092

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.KeyEvent
import android.view.View
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.LiveDataScope
Expand All @@ -36,33 +35,31 @@ import com.infomaniak.drive.data.cache.FileController
import com.infomaniak.drive.data.models.File
import com.infomaniak.drive.data.models.UserDrive
import com.infomaniak.drive.data.services.DownloadWorker
import com.infomaniak.drive.databinding.DialogDownloadProgressBinding
import com.infomaniak.drive.utils.IsComplete
import com.infomaniak.drive.utils.showSnackbar
import com.infomaniak.lib.core.utils.setBackNavigationResult
import kotlinx.android.synthetic.main.dialog_download_progress.*
import kotlinx.android.synthetic.main.dialog_download_progress.view.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import okhttp3.Response

class DownloadProgressDialog : DialogFragment() {

private val binding: DialogDownloadProgressBinding by lazy { DialogDownloadProgressBinding.inflate(layoutInflater) }
private val navigationArgs: DownloadProgressDialogArgs by navArgs()
private val downloadViewModel: DownloadViewModel by viewModels()

private val dialogView: View by lazy { View.inflate(context, R.layout.dialog_download_progress, null) }

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = with(navigationArgs) {
isCancelable = false

FileController.getFileById(fileId, userDrive)?.let { file ->
dialogView.icon.setImageResource(file.getFileType().icon)
binding.icon.setImageResource(file.getFileType().icon)
observeDownloadedFile(file)
}

return MaterialAlertDialogBuilder(requireContext(), R.style.DialogStyle)
.setTitle(fileName)
.setView(dialogView)
.setView(binding.root)
.setOnKeyListener { _, keyCode, event ->
if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_UP) {
findNavController().popBackStack()
Expand All @@ -78,7 +75,7 @@ class DownloadProgressDialog : DialogFragment() {
if (isComplete) {
setBackNavigationResult(if (isOpenBookmark) OPEN_BOOKMARK else OPEN_WITH, fileId)
} else {
downloadProgress.progress = progress
binding.downloadProgress.progress = progress
}
} ?: run {
showSnackbar(R.string.anErrorHasOccurred)
Expand All @@ -87,8 +84,6 @@ class DownloadProgressDialog : DialogFragment() {
}
}

override fun getView() = dialogView

class DownloadViewModel : ViewModel() {

fun downloadFile(context: Context, file: File, userDrive: UserDrive) = liveData(Dispatchers.IO) {
Expand Down
Loading