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

Fix MultiSelect download outside of default FileList #708

Merged
merged 2 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
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 @@ -27,7 +27,7 @@ import com.infomaniak.drive.data.cache.FileController
import com.infomaniak.drive.data.models.BulkOperationType
import com.infomaniak.drive.data.models.File
import com.infomaniak.drive.ui.fileList.multiSelect.FavoritesMultiSelectActionsBottomSheetDialog
import com.infomaniak.drive.ui.fileList.multiSelect.MultiSelectActionsBottomSheetDialogArgs
import com.infomaniak.drive.ui.fileList.multiSelect.MultiSelectActionsBottomSheetDialog
import com.infomaniak.drive.utils.Utils
import com.infomaniak.drive.utils.Utils.OTHER_ROOT_ID
import com.infomaniak.drive.utils.Utils.ROOT_ID
Expand Down Expand Up @@ -76,17 +76,14 @@ class FavoritesFragment : FileListFragment() {
multiSelectLayout?.selectAllButton?.isGone = true
}

override fun onMenuButtonClicked() {
val (fileIds, onlyFolders, onlyFavorite, onlyOffline, isAllSelected) = multiSelectManager.getMenuNavArgs()
FavoritesMultiSelectActionsBottomSheetDialog().apply {
arguments = MultiSelectActionsBottomSheetDialogArgs(
fileIds = fileIds,
onlyFolders = onlyFolders,
onlyFavorite = onlyFavorite,
onlyOffline = onlyOffline,
isAllSelected = isAllSelected
).toBundle()
}.show(childFragmentManager, "ActionFavoritesMultiSelectBottomSheetDialog")
override fun onMenuButtonClicked(
multiSelectBottomSheet: MultiSelectActionsBottomSheetDialog,
areAllFromTheSameFolder: Boolean,
) {
super.onMenuButtonClicked(
multiSelectBottomSheet = FavoritesMultiSelectActionsBottomSheetDialog(),
areAllFromTheSameFolder = false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to set areAllFromTheSameFolder =false by default.
To avoid dupplications because here I find 7 occurrences.

)
}

override fun performBulkOperation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import com.infomaniak.drive.databinding.MultiSelectLayoutBinding
import com.infomaniak.drive.ui.bottomSheetDialogs.ColorFolderBottomSheetDialog
import com.infomaniak.drive.ui.bottomSheetDialogs.FileInfoActionsBottomSheetDialogArgs
import com.infomaniak.drive.ui.fileList.multiSelect.FileListMultiSelectActionsBottomSheetDialog
import com.infomaniak.drive.ui.fileList.multiSelect.MultiSelectActionsBottomSheetDialogArgs
import com.infomaniak.drive.ui.fileList.multiSelect.MultiSelectFragment
import com.infomaniak.drive.utils.*
import com.infomaniak.drive.utils.FilePresenter.openBookmark
Expand Down Expand Up @@ -343,7 +342,12 @@ open class FileListFragment : MultiSelectFragment(MATOMO_CATEGORY), SwipeRefresh
toolbarMultiSelect.setNavigationOnClickListener { closeMultiSelect() }
moveButtonMultiSelect.setOnClickListener { moveFiles(folderId) }
deleteButtonMultiSelect.setOnClickListener { deleteFiles(getAllSelectedFilesCount()) }
menuButtonMultiSelect.setOnClickListener { onMenuButtonClicked() }
menuButtonMultiSelect.setOnClickListener {
onMenuButtonClicked(
multiSelectBottomSheet = FileListMultiSelectActionsBottomSheetDialog(),
areAllFromTheSameFolder = true,
)
}

selectAllButton.apply {
initProgress(viewLifecycleOwner)
Expand Down Expand Up @@ -662,19 +666,6 @@ open class FileListFragment : MultiSelectFragment(MATOMO_CATEGORY), SwipeRefresh
}
}

protected open fun onMenuButtonClicked() {
val (fileIds, onlyFolders, onlyFavorite, onlyOffline, isAllSelected) = multiSelectManager.getMenuNavArgs()
FileListMultiSelectActionsBottomSheetDialog().apply {
arguments = MultiSelectActionsBottomSheetDialogArgs(
fileIds = fileIds,
onlyFolders = onlyFolders,
onlyFavorite = onlyFavorite,
onlyOffline = onlyOffline,
isAllSelected = isAllSelected
).toBundle()
}.show(childFragmentManager, "ActionFileListMultiSelectBottomSheetDialog")
}

override fun performBulkOperation(
type: BulkOperationType,
areAllFromTheSameFolder: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ abstract class MultiSelectActionsBottomSheetDialog(private val matomoCategory: S
configureColoredFolder(areIndividualActionsVisible)
configureAddFavorites(areIndividualActionsVisible)
configureAvailableOffline()
configureDownloadFile()
configureDownload()
configureDuplicateFile()
configureRestoreFileIn()
configureRestoreFileToOriginalPlace()
Expand Down Expand Up @@ -122,18 +122,18 @@ abstract class MultiSelectActionsBottomSheetDialog(private val matomoCategory: S
onActionSelected(action)
}

protected open fun configureDownloadFile() {
protected open fun configureDownload() {
val drivePermissions = DrivePermissions().apply {
registerPermissions(this@MultiSelectActionsBottomSheetDialog) { authorized ->
if (authorized) downloadFileArchive()
if (authorized) download()
}
}

downloadFile.apply {
setOnClickListener {
if (drivePermissions.checkWriteStoragePermission()) {
context?.applicationContext?.trackEvent(matomoCategory, TrackerAction.CLICK, "bulkDownload")
downloadFileArchive()
download()
}
}

Expand All @@ -157,13 +157,14 @@ abstract class MultiSelectActionsBottomSheetDialog(private val matomoCategory: S
deletePermanently.isGone = true
}

private fun downloadFileArchive() {

fun downloadArchive(fileIds: IntArray) = liveData(Dispatchers.IO) {
emit(ApiRepository.getUUIDArchiveFiles(AccountUtils.currentDriveId, fileIds))
}
private fun download() {
if (navigationArgs.areAllFromTheSameFolder) downloadArchive() else downloadFiles()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here is that if you download only one file, it will always download an archive.
Even if it's still weird this action but it would be nice if it was avoided 😅

}

downloadArchive(navigationArgs.fileIds).observe(viewLifecycleOwner) { apiResponse ->
private fun downloadArchive() {
liveData(Dispatchers.IO) {
emit(ApiRepository.getUUIDArchiveFiles(AccountUtils.currentDriveId, navigationArgs.fileIds))
}.observe(viewLifecycleOwner) { apiResponse ->
if (apiResponse.isSuccess()) {
apiResponse.data?.let {
val downloadURL = Uri.parse(ApiRoutes.downloadArchiveFiles(AccountUtils.currentDriveId, it.uuid))
Expand All @@ -176,6 +177,17 @@ abstract class MultiSelectActionsBottomSheetDialog(private val matomoCategory: S
}
}

private fun downloadFiles() {
navigationArgs.fileIds.forEach { fileId ->
FileController.getFileProxyById(fileId = fileId, customRealm = mainViewModel.realm)?.let { file ->
val downloadUrl = Uri.parse(ApiRoutes.downloadFile(file))
val fileName = if (file.isFolder()) "${file.name}.zip" else file.name
requireContext().startDownloadFile(downloadUrl, fileName)
}
}
onActionSelected()
}

fun onActionSelected(type: SelectDialogAction? = null) {
val finalType = when (type) {
SelectDialogAction.COLOR_FOLDER -> BulkOperationType.COLOR_FOLDER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,27 @@ abstract class MultiSelectFragment(private val matomoCategory: String) : Fragmen
multiSelectLayout?.root?.isGone = true
}

open fun onMenuButtonClicked(
multiSelectBottomSheet: MultiSelectActionsBottomSheetDialog,
areAllFromTheSameFolder: Boolean,
) {
multiSelectBottomSheet.apply {
arguments = getMultiSelectBottomSheetArguments(areAllFromTheSameFolder)
}.show(childFragmentManager, "MultiSelectActionsBottomSheetDialog")
}

private fun getMultiSelectBottomSheetArguments(areAllFromTheSameFolder: Boolean): Bundle {
val (fileIds, onlyFolders, onlyFavorite, onlyOffline, isAllSelected) = multiSelectManager.getMenuNavArgs()
return MultiSelectActionsBottomSheetDialogArgs(
fileIds = fileIds,
onlyFolders = onlyFolders,
onlyFavorite = onlyFavorite,
onlyOffline = onlyOffline,
isAllSelected = isAllSelected,
areAllFromTheSameFolder = areAllFromTheSameFolder,
).toBundle()
}

fun moveFiles(folderId: Int?) {
requireContext().moveFileClicked(folderId, selectFolderResultLauncher)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TrashMultiSelectActionsBottomSheetDialog : MultiSelectActionsBottomSheetDi
availableOffline.isGone = true
}

override fun configureDownloadFile() {
override fun configureDownload() {
downloadFile.isGone = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.navigation.fragment.findNavController
import com.infomaniak.drive.R
import com.infomaniak.drive.databinding.FragmentMenuPicturesBinding
import com.infomaniak.drive.databinding.MultiSelectLayoutBinding
import com.infomaniak.drive.ui.fileList.multiSelect.PicturesMultiSelectActionsBottomSheetDialog

class MenuPicturesFragment : Fragment() {

Expand All @@ -53,7 +54,12 @@ class MenuPicturesFragment : Fragment() {
toolbarMultiSelect.setNavigationOnClickListener { closeMultiSelect() }
moveButtonMultiSelect.setOnClickListener { onMoveButtonClicked() }
deleteButtonMultiSelect.setOnClickListener { deleteFiles() }
menuButtonMultiSelect.setOnClickListener { onMenuButtonClicked() }
menuButtonMultiSelect.setOnClickListener {
onMenuButtonClicked(
multiSelectBottomSheet = PicturesMultiSelectActionsBottomSheetDialog(),
areAllFromTheSameFolder = false,
)
}
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand Down
21 changes: 9 additions & 12 deletions app/src/main/java/com/infomaniak/drive/ui/menu/MySharesFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import androidx.navigation.fragment.findNavController
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.infomaniak.drive.R
import com.infomaniak.drive.data.cache.FileController
import com.infomaniak.drive.ui.fileList.multiSelect.MultiSelectActionsBottomSheetDialogArgs
import com.infomaniak.drive.ui.fileList.multiSelect.MultiSelectActionsBottomSheetDialog
import com.infomaniak.drive.ui.fileList.multiSelect.MySharesMultiSelectActionsBottomSheetDialog
import com.infomaniak.drive.utils.Utils
import com.infomaniak.drive.utils.Utils.OTHER_ROOT_ID
Expand Down Expand Up @@ -69,17 +69,14 @@ class MySharesFragment : FileSubTypeListFragment() {
}
}

override fun onMenuButtonClicked() {
val (fileIds, onlyFolders, onlyFavorite, onlyOffline, isAllSelected) = multiSelectManager.getMenuNavArgs()
MySharesMultiSelectActionsBottomSheetDialog().apply {
arguments = MultiSelectActionsBottomSheetDialogArgs(
fileIds = fileIds,
onlyFolders = onlyFolders,
onlyFavorite = onlyFavorite,
onlyOffline = onlyOffline,
isAllSelected = isAllSelected
).toBundle()
}.show(childFragmentManager, "ActionMySharesMultiSelectBottomSheetDialog")
override fun onMenuButtonClicked(
multiSelectBottomSheet: MultiSelectActionsBottomSheetDialog,
areAllFromTheSameFolder: Boolean,
) {
super.onMenuButtonClicked(
multiSelectBottomSheet = MySharesMultiSelectActionsBottomSheetDialog(),
areAllFromTheSameFolder = false,
)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import android.os.Bundle
import android.view.View
import com.infomaniak.drive.R
import com.infomaniak.drive.data.cache.FileController
import com.infomaniak.drive.ui.fileList.multiSelect.MultiSelectActionsBottomSheetDialogArgs
import com.infomaniak.drive.ui.fileList.multiSelect.MultiSelectActionsBottomSheetDialog
import com.infomaniak.drive.ui.fileList.multiSelect.OfflineMultiSelectActionsBottomSheetDialog
import com.infomaniak.drive.utils.Utils
import kotlinx.android.synthetic.main.fragment_file_list.*
Expand All @@ -44,17 +44,14 @@ open class OfflineFileFragment : FileSubTypeListFragment() {
folderId = Utils.OTHER_ROOT_ID
}

override fun onMenuButtonClicked() {
val (fileIds, onlyFolders, onlyFavorite, onlyOffline, isAllSelected) = multiSelectManager.getMenuNavArgs()
OfflineMultiSelectActionsBottomSheetDialog().apply {
arguments = MultiSelectActionsBottomSheetDialogArgs(
fileIds = fileIds,
onlyFolders = onlyFolders,
onlyFavorite = onlyFavorite,
onlyOffline = onlyOffline,
isAllSelected = isAllSelected
).toBundle()
}.show(childFragmentManager, "ActionOfflineMultiSelectBottomSheetDialog")
override fun onMenuButtonClicked(
multiSelectBottomSheet: MultiSelectActionsBottomSheetDialog,
areAllFromTheSameFolder: Boolean,
) {
super.onMenuButtonClicked(
multiSelectBottomSheet = OfflineMultiSelectActionsBottomSheetDialog(),
areAllFromTheSameFolder = false,
)
}

companion object {
Expand Down
14 changes: 0 additions & 14 deletions app/src/main/java/com/infomaniak/drive/ui/menu/PicturesFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ import com.infomaniak.drive.data.models.*
import com.infomaniak.drive.data.services.DownloadWorker
import com.infomaniak.drive.databinding.FragmentMenuPicturesBinding
import com.infomaniak.drive.databinding.MultiSelectLayoutBinding
import com.infomaniak.drive.ui.fileList.multiSelect.MultiSelectActionsBottomSheetDialogArgs
import com.infomaniak.drive.ui.fileList.multiSelect.MultiSelectFragment
import com.infomaniak.drive.ui.fileList.multiSelect.PicturesMultiSelectActionsBottomSheetDialog
import com.infomaniak.drive.utils.*
import com.infomaniak.lib.core.utils.Utils.createRefreshTimer
import com.infomaniak.lib.core.utils.setPagination
Expand Down Expand Up @@ -238,18 +236,6 @@ class PicturesFragment : MultiSelectFragment(MATOMO_CATEGORY) {
moveFiles(folderId)
}

fun onMenuButtonClicked() {
val (fileIds, onlyFolders, onlyFavorite, onlyOffline) = multiSelectManager.getMenuNavArgs()
PicturesMultiSelectActionsBottomSheetDialog().apply {
arguments = MultiSelectActionsBottomSheetDialogArgs(
fileIds = fileIds,
onlyFolders = onlyFolders,
onlyFavorite = onlyFavorite,
onlyOffline = onlyOffline,
).toBundle()
}.show(childFragmentManager, "ActionPicturesMultiSelectBottomSheetDialog")
}

override fun performBulkOperation(
type: BulkOperationType,
areAllFromTheSameFolder: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import androidx.fragment.app.viewModels
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.infomaniak.drive.R
import com.infomaniak.drive.data.cache.FileController
import com.infomaniak.drive.ui.fileList.multiSelect.MultiSelectActionsBottomSheetDialogArgs
import com.infomaniak.drive.ui.fileList.multiSelect.MultiSelectActionsBottomSheetDialog
import com.infomaniak.drive.ui.fileList.multiSelect.RecentChangesMultiSelectActionsBottomSheetDialog
import com.infomaniak.drive.utils.AccountUtils
import com.infomaniak.drive.utils.Utils
Expand Down Expand Up @@ -63,17 +63,14 @@ class RecentChangesFragment : FileSubTypeListFragment() {
folderId = Utils.OTHER_ROOT_ID
}

override fun onMenuButtonClicked() {
val (fileIds, onlyFolders, onlyFavorite, onlyOffline, isAllSelected) = multiSelectManager.getMenuNavArgs()
RecentChangesMultiSelectActionsBottomSheetDialog().apply {
arguments = MultiSelectActionsBottomSheetDialogArgs(
fileIds = fileIds,
onlyFolders = onlyFolders,
onlyFavorite = onlyFavorite,
onlyOffline = onlyOffline,
isAllSelected = isAllSelected
).toBundle()
}.show(childFragmentManager, "ActionRecentChangesMultiSelectBottomSheetDialog")
override fun onMenuButtonClicked(
multiSelectBottomSheet: MultiSelectActionsBottomSheetDialog,
areAllFromTheSameFolder: Boolean,
) {
super.onMenuButtonClicked(
multiSelectBottomSheet = RecentChangesMultiSelectActionsBottomSheetDialog(),
areAllFromTheSameFolder = false,
)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ 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.ui.bottomSheetDialogs.DriveMaintenanceBottomSheetDialog
import com.infomaniak.drive.ui.fileList.multiSelect.MultiSelectActionsBottomSheetDialogArgs
import com.infomaniak.drive.ui.fileList.multiSelect.MultiSelectActionsBottomSheetDialog
import com.infomaniak.drive.ui.fileList.multiSelect.SharedWithMeMultiSelectActionsBottomSheetDialog
import com.infomaniak.drive.utils.AccountUtils
import com.infomaniak.drive.utils.Utils
Expand Down Expand Up @@ -125,17 +125,14 @@ class SharedWithMeFragment : FileSubTypeListFragment() {
}
}

override fun onMenuButtonClicked() {
val (fileIds, onlyFolders, onlyFavorite, onlyOffline, isAllSelected) = multiSelectManager.getMenuNavArgs()
SharedWithMeMultiSelectActionsBottomSheetDialog().apply {
arguments = MultiSelectActionsBottomSheetDialogArgs(
fileIds = fileIds,
onlyFolders = onlyFolders,
onlyFavorite = onlyFavorite,
onlyOffline = onlyOffline,
isAllSelected = isAllSelected
).toBundle()
}.show(childFragmentManager, "ActionSharedWithMeMultiSelectBottomSheetDialog")
override fun onMenuButtonClicked(
multiSelectBottomSheet: MultiSelectActionsBottomSheetDialog,
areAllFromTheSameFolder: Boolean,
) {
super.onMenuButtonClicked(
multiSelectBottomSheet = SharedWithMeMultiSelectActionsBottomSheetDialog(),
areAllFromTheSameFolder = false,
)
}

companion object {
Expand Down
Loading