55 * @author Jose Antonio Barros Ramos
66 * @author Juan Carlos Garrote Gascón
77 * @author Manuel Plazas Palacio
8+ * @author Jorge Aguado Recio
89 *
9- * Copyright (C) 2023 ownCloud GmbH.
10+ * Copyright (C) 2024 ownCloud GmbH.
1011 *
1112 * This program is free software: you can redistribute it and/or modify
1213 * it under the terms of the GNU General Public License version 2,
2425package com.owncloud.android.presentation.files.filelist
2526
2627import android.annotation.SuppressLint
28+ import android.app.Dialog
29+ import android.content.Context
2730import android.content.Intent
2831import android.content.res.ColorStateList
2932import android.net.Uri
@@ -35,6 +38,7 @@ import android.view.MenuItem
3538import android.view.View
3639import android.view.ViewGroup
3740import android.view.WindowManager
41+ import android.widget.Button
3842import android.widget.ImageView
3943import android.widget.LinearLayout
4044import android.widget.TextView
@@ -475,8 +479,13 @@ class MainFileListFragment : Fragment(),
475479 }
476480
477481 FileMenuOption .REMOVE -> {
478- filesToRemove = listOf (file)
479- fileOperationsViewModel.showRemoveDialog(filesToRemove)
482+ if (file.isFolder) {
483+ filesToRemove = listOf (file)
484+ fileOperationsViewModel.showRemoveDialog(filesToRemove)
485+ } else {
486+ showRemoveCustomDialog(file, context)
487+ }
488+
480489 }
481490
482491 FileMenuOption .OPEN_WITH -> {
@@ -1123,8 +1132,12 @@ class MainFileListFragment : Fragment(),
11231132 }
11241133
11251134 R .id.action_remove_file -> {
1126- filesToRemove = checkedFiles
1127- fileOperationsViewModel.showRemoveDialog(filesToRemove)
1135+ if (checkedFiles.size == 1 && ! checkedFiles[0 ].isFolder) {
1136+ showRemoveCustomDialog(checkedFiles[0 ], requireContext())
1137+ } else {
1138+ filesToRemove = checkedFiles
1139+ fileOperationsViewModel.showRemoveDialog(filesToRemove)
1140+ }
11281141 return true
11291142 }
11301143
@@ -1357,6 +1370,52 @@ class MainFileListFragment : Fragment(),
13571370 }
13581371 }
13591372
1373+ private fun showRemoveCustomDialog (file : OCFile , context : Context ) {
1374+ val removeDialog = Dialog (context)
1375+ removeDialog.apply {
1376+ setContentView(R .layout.remove_files_dialog)
1377+ setCancelable(false )
1378+ show()
1379+ }
1380+
1381+ val thumbnailImageView = removeDialog.findViewById<ImageView >(R .id.dialog_remove_thumbnail)
1382+ val dialogText = removeDialog.findViewById<TextView >(R .id.dialog_remove_information)
1383+ val localRemoveButton = removeDialog.findViewById<Button >(R .id.dialog_remove_local_only)
1384+ val yesRemoveButton = removeDialog.findViewById<Button >(R .id.dialog_remove_yes)
1385+ val noRemoveButton = removeDialog.findViewById<Button >(R .id.dialog_remove_no)
1386+
1387+ dialogText.text = String .format(getString(R .string.confirmation_remove_file_alert), file.fileName)
1388+
1389+ // Show the thumbnail when the file has one
1390+ val thumbnail = ThumbnailsCacheManager .getBitmapFromDiskCache(file.remoteId)
1391+
1392+ if (thumbnail != null ) {
1393+ thumbnailImageView.setImageBitmap(thumbnail)
1394+ } else {
1395+ thumbnailImageView.visibility = View .GONE
1396+ }
1397+
1398+ // Hide "Local only" remove button when the file is not available locally
1399+ if (! file.isAvailableLocally) {
1400+ localRemoveButton.visibility = View .INVISIBLE
1401+ }
1402+
1403+ localRemoveButton.setOnClickListener {
1404+ fileOperationsViewModel.performOperation(FileOperation .RemoveOperation (listOf (file), removeOnlyLocalCopy = true ))
1405+ removeDialog.dismiss()
1406+ }
1407+
1408+ yesRemoveButton.setOnClickListener {
1409+ fileOperationsViewModel.performOperation(FileOperation .RemoveOperation (listOf (file), removeOnlyLocalCopy = false ))
1410+ removeDialog.dismiss()
1411+ }
1412+
1413+ noRemoveButton.setOnClickListener {
1414+ // Nothing special to do
1415+ removeDialog.dismiss()
1416+ }
1417+ }
1418+
13601419 interface FileActions {
13611420 fun onCurrentFolderUpdated (newCurrentFolder : OCFile , currentSpace : OCSpace ? = null)
13621421 fun onFileClicked (file : OCFile )
0 commit comments