Skip to content

Commit

Permalink
Add some missing apply { … }
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Oct 18, 2023
1 parent 3aa30d4 commit 3da8bc4
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,40 @@ class AccessDeniedBottomSheetDialog : InformationBottomSheetDialog() {
title.setText(R.string.accessDeniedTitle)

if (navigationArgs.isAdmin) {

description.setText(R.string.accessDeniedDescriptionIsAdmin)
actionButton.initProgress(this@AccessDeniedBottomSheetDialog)
actionButton.setText(R.string.buttonConfirmNotify)
actionButton.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.red_error))
actionButton.setOnClickListener {
actionButton.showProgress()
informationBottomSheetViewModel.forceFolderAccess(navigationArgs.folderId)
.observe(viewLifecycleOwner) { apiResponse ->
if (apiResponse.data == null) {
SnackbarUtils.showSnackbar(requireView(), apiResponse.translateError())
} else {
apiResponse.data?.let { hasAccess ->
if (hasAccess) navigateToTargetFolder() else closeAndShowRightError()

actionButton.apply {
initProgress(this@AccessDeniedBottomSheetDialog)
setText(R.string.buttonConfirmNotify)
setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.red_error))
setOnClickListener {
showProgress()
informationBottomSheetViewModel.forceFolderAccess(navigationArgs.folderId)
.observe(viewLifecycleOwner) { apiResponse ->
if (apiResponse.data == null) {
SnackbarUtils.showSnackbar(requireView(), apiResponse.translateError())
} else {
apiResponse.data?.let { hasAccess ->
if (hasAccess) navigateToTargetFolder() else closeAndShowRightError()
}
}
hideProgress(R.string.buttonConfirmNotify)
}
actionButton.hideProgress(R.string.buttonConfirmNotify)
}
}
}

secondaryActionButton.setText(R.string.buttonBack)

} else {

description.setText(R.string.accessDeniedDescriptionIsNotAdmin)
actionButton.setText(R.string.buttonClose)
actionButton.setOnClickListener { dismiss() }

actionButton.apply {
setText(R.string.buttonClose)
setOnClickListener { dismiss() }
}

secondaryActionButton.isGone = true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,40 @@ class NotSupportedExtensionBottomSheetDialog : InformationBottomSheetDialog() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?): Unit = with(binding) {
super.onViewCreated(view, savedInstanceState)

FileController.getFileById(navigationArgs.fileId)?.let { currentFile ->

title.text = getString(R.string.notSupportedExtensionTitle, currentFile.getFileExtension())
description.text = getString(R.string.notSupportedExtensionDescription, currentFile.name)
illu.layoutParams.height = 50.toPx()
illu.layoutParams.width = 50.toPx()
illu.setImageResource(R.drawable.ic_info)

secondaryActionButton.setText(R.string.buttonOpenReadOnly)
secondaryActionButton.setOnClickListener {
requireContext().openOnlyOfficeActivity(currentFile)
dismiss()
illu.apply {
layoutParams.height = 50.toPx()
layoutParams.width = 50.toPx()
setImageResource(R.drawable.ic_info)
}

secondaryActionButton.apply {
setText(R.string.buttonOpenReadOnly)
setOnClickListener {
requireContext().openOnlyOfficeActivity(currentFile)
dismiss()
}
}

actionButton.initProgress(this@NotSupportedExtensionBottomSheetDialog)
actionButton.text = getString(R.string.buttonCreateOnlyOfficeCopy, currentFile.conversion?.onlyofficeExtension)
actionButton.setOnClickListener {
actionButton.showProgress()
mainViewModel.convertFile(currentFile).observe(viewLifecycleOwner) { apiResponse ->
when (apiResponse?.result) {
ApiResponse.Status.SUCCESS -> apiResponse.data?.let { newFile ->
requireContext().openOnlyOfficeActivity(newFile)
actionButton.apply {
initProgress(this@NotSupportedExtensionBottomSheetDialog)
text = getString(R.string.buttonCreateOnlyOfficeCopy, currentFile.conversion?.onlyofficeExtension)
setOnClickListener {
showProgress()
mainViewModel.convertFile(currentFile).observe(viewLifecycleOwner) { apiResponse ->
when (apiResponse?.result) {
ApiResponse.Status.SUCCESS -> apiResponse.data?.let { newFile ->
requireContext().openOnlyOfficeActivity(newFile)
}
else -> showSnackbar(apiResponse.translateError())
}
else -> showSnackbar(apiResponse.translateError())
dismiss()
}
dismiss()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.infomaniak.drive.MatomoDrive.trackShareRightsEvent
import com.infomaniak.drive.R
import com.infomaniak.drive.data.models.*
import com.infomaniak.drive.data.models.Shareable.*
import com.infomaniak.drive.databinding.FragmentBottomSheetFileShareBinding
import com.infomaniak.drive.ui.bottomSheetDialogs.SelectPermissionBottomSheetDialog
import com.infomaniak.drive.ui.bottomSheetDialogs.SelectPermissionBottomSheetDialog.Companion.PERMISSION_BUNDLE_KEY
Expand Down Expand Up @@ -60,7 +61,7 @@ class FileShareAddUserDialog : FullScreenBottomSheetDialog() {
private val navigationArgs: FileShareAddUserDialogArgs by navArgs()
private val selectedItems: Share = Share()

private var selectedPermission: Shareable.ShareablePermission = Shareable.ShareablePermission.READ
private var selectedPermission: ShareablePermission = ShareablePermission.READ
set(value) {
binding.filePermissionsIcon.setImageResource(value.icon)
binding.filePermissionsValue.setText(value.translation)
Expand All @@ -71,7 +72,7 @@ class FileShareAddUserDialog : FullScreenBottomSheetDialog() {
return FragmentBottomSheetFileShareBinding.inflate(inflater, container, false).also { binding = it }.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) = with(binding) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?): Unit = with(binding) {
super.onViewCreated(view, savedInstanceState)

toolbar.setNavigationOnClickListener {
Expand Down Expand Up @@ -107,12 +108,14 @@ class FileShareAddUserDialog : FullScreenBottomSheetDialog() {
selectedPermission = bundle.getParcelable(PERMISSION_BUNDLE_KEY)!!
}

shareButton.initProgress(this@FileShareAddUserDialog)
shareButton.setOnClickListener {
shareButton.showProgress()
trackShareRightsEvent("inviteUser")
checkShare(selectedPermission) { file, body ->
createShareAndCloseDialog(file, body)
shareButton.apply {
initProgress(this@FileShareAddUserDialog)
setOnClickListener {
showProgress()
trackShareRightsEvent("inviteUser")
checkShare(selectedPermission) { file, body ->
createShareAndCloseDialog(file, body)
}
}
}
}
Expand Down Expand Up @@ -202,9 +205,10 @@ class FileShareAddUserDialog : FullScreenBottomSheetDialog() {
}

private fun checkShare(
newPermission: Shareable.ShareablePermission,
onCheckApproved: (file: File, body: MutableMap<String, Serializable>) -> Unit
newPermission: ShareablePermission,
onCheckApproved: (file: File, body: MutableMap<String, Serializable>) -> Unit,
) = with(binding) {

fileShareViewModel.currentFile.value?.let { file ->
val body = mutableMapOf(
"emails" to ArrayList(selectedItems.invitations.map { it.email }),
Expand Down Expand Up @@ -234,9 +238,9 @@ class FileShareAddUserDialog : FullScreenBottomSheetDialog() {
}

private fun showConflictDialog(
newPermission: Shareable.ShareablePermission,
newPermission: ShareablePermission,
checkResults: ArrayList<FileCheckResult>,
onConflictApproved: () -> Unit
onConflictApproved: () -> Unit,
) {
val conflictedUsers = checkResults.filter { it.isConflict }

Expand Down

0 comments on commit 3da8bc4

Please sign in to comment.