Skip to content

Commit

Permalink
Added copy, move, cancel options in permission dialog.
Browse files Browse the repository at this point in the history
* Using the error message from string file instead of a hardcoded string.
  • Loading branch information
MohitMaliDeveloper committed Sep 2, 2024
1 parent a5b967f commit 55a586d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,7 @@ class LocalLibraryFragment : BaseFragment(), CopyMoveFileHandler.FileCopyMoveCal
}

override fun filesystemDoesNotSupportedCopyMoveFilesOver4GB() {
val message = "Your fileSystem does not support files over 4GB"
showStorageSelectionSnackBar(message)
showStorageSelectionSnackBar(getString(R.string.file_system_does_not_support_4gb))
}

override fun insufficientSpaceInStorage(availableSpace: Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,32 +91,54 @@ class CopyMoveFileHandler @Inject constructor(
uri?.let { selectedFileUri = it }
file?.let { selectedFile = it }
if (!sharedPreferenceUtil.copyMoveZimFilePermissionDialog) {
alertDialogShower.show(
KiwixDialog.MoveFileToPublicDirectoryPermissionDialog,
{
sharedPreferenceUtil.copyMoveZimFilePermissionDialog = true
validateAndShowCopyMoveDialog()
}
)
showMoveToPublicDirectoryPermissionDialog()
} else {
validateAndShowCopyMoveDialog()
if (validateZimFileCanCopyOrMove()) {
showCopyMoveDialog()
}
}
}

private fun showMoveToPublicDirectoryPermissionDialog() {
alertDialogShower.show(
KiwixDialog.MoveFileToPublicDirectoryPermissionDialog,
{
sharedPreferenceUtil.copyMoveZimFilePermissionDialog = true
if (validateZimFileCanCopyOrMove()) {
performCopyOperation()
}
},
{
sharedPreferenceUtil.copyMoveZimFilePermissionDialog = true
if (validateZimFileCanCopyOrMove()) {
performMoveOperation()
}
}
)
}

private fun isBookLessThan4GB(): Boolean =
(selectedFile?.length() ?: 0L) < FOUR_GIGABYTES_IN_KILOBYTES

private fun validateAndShowCopyMoveDialog() {
private fun validateZimFileCanCopyOrMove(): Boolean {
hidePreparingCopyMoveDialog() // hide the dialog if already showing
val availableSpace = storageCalculator.availableBytes()
if (hasNotSufficientStorageSpace(availableSpace)) {
fileCopyMoveCallback?.insufficientSpaceInStorage(availableSpace)
return
return false
}
when (fat32Checker.fileSystemStates.value) {
DetectingFileSystem -> handleDetectingFileSystemState()
CannotWrite4GbFile -> handleCannotWrite4GbFileState()
else -> showCopyMoveDialog()
return when (fat32Checker.fileSystemStates.value) {
DetectingFileSystem -> {
handleDetectingFileSystemState()
false
}

CannotWrite4GbFile -> {
handleCannotWrite4GbFileState()
false
}

else -> true
}
}

Expand All @@ -143,24 +165,31 @@ class CopyMoveFileHandler @Inject constructor(
fileSystemDisposable = fat32Checker.fileSystemStates
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
validateAndShowCopyMoveDialog()
hidePreparingCopyMoveDialog()
if (validateZimFileCanCopyOrMove()) {
showCopyMoveDialog()
}
}
}

private fun showCopyMoveDialog() {
alertDialogShower.show(
KiwixDialog.CopyMoveFileToPublicDirectoryDialog,
{
isMoveOperation = false
copyZimFileToPublicAppDirectory()
},
{
isMoveOperation = true
moveZimFileToPublicAppDirectory()
}
::performCopyOperation,
::performMoveOperation
)
}

private fun performCopyOperation() {
isMoveOperation = false
copyZimFileToPublicAppDirectory()
}

private fun performMoveOperation() {
isMoveOperation = true
moveZimFileToPublicAppDirectory()
}

private fun copyZimFileToPublicAppDirectory() {
lifecycleScope?.launch {
val destinationFile = getDestinationFile()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ sealed class KiwixDialog(
data object MoveFileToPublicDirectoryPermissionDialog : KiwixDialog(
R.string.move_files_permission_dialog_title,
R.string.move_files_permission_dialog_description,
R.string.yes,
R.string.no,
R.string.copy,
R.string.move,
neutralMessage = R.string.cancel,
cancelable = false
)

Expand Down

0 comments on commit 55a586d

Please sign in to comment.