Skip to content

Commit

Permalink
Showing a warning dialog when copying/moving the ZIM chunks in PS ver…
Browse files Browse the repository at this point in the history
…sion.
  • Loading branch information
MohitMaliDeveloper committed Jan 8, 2025
1 parent 283d845 commit 141d6df
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ import org.kiwix.kiwixmobile.core.utils.SimpleRecyclerViewScrollListener.Compani
import org.kiwix.kiwixmobile.core.utils.dialog.DialogShower
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog
import org.kiwix.kiwixmobile.core.utils.files.FileUtils
import org.kiwix.kiwixmobile.core.utils.files.FileUtils.isSplittedZimFile
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BookOnDiskDelegate
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskAdapter
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem
Expand Down Expand Up @@ -633,11 +634,11 @@ class LocalLibraryFragment : BaseFragment(), CopyMoveFileHandler.FileCopyMoveCal
!shouldShowRationalePermission()

override fun onFileCopied(file: File) {
navigateToReaderFragment(file = file)
validateAndOpenZimInReader(file)
}

override fun onFileMoved(file: File) {
navigateToReaderFragment(file = file)
validateAndOpenZimInReader(file)
}

override fun onError(errorMessage: String) {
Expand Down Expand Up @@ -694,4 +695,19 @@ class LocalLibraryFragment : BaseFragment(), CopyMoveFileHandler.FileCopyMoveCal
copyMoveFileHandler?.copyMoveZIMFileInSelectedStorage(storageDevice)
}
}

private fun validateAndOpenZimInReader(file: File) {
if (isSplittedZimFile(file.path)) {
showWarningDialogForSplittedZimFile()
} else {
navigateToReaderFragment(file = file)
}
}

private fun showWarningDialogForSplittedZimFile() {
dialogShower.show(
KiwixDialog.ShowWarningAboutSplittedZimFile,
{}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ sealed class KiwixDialog(
cancelable = false
)

data object ShowWarningAboutSplittedZimFile : KiwixDialog(
null,
R.string.verify_zim_chunk_copied_moved_properly,
android.R.string.ok,
android.R.string.ok,
cancelable = false
)

object SaveOrOpenUnsupportedFiles : KiwixDialog(
R.string.save_or_open_unsupported_files_dialog_title,
R.string.save_or_open_unsupported_files_dialog_message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,19 @@ object FileUtils {
fun isValidZimFile(filePath: String): Boolean =
filePath.endsWith(".zim") || filePath.endsWith(".zimaa")

/**
* Determines whether the given file path corresponds to a split ZIM file.
*
* A split ZIM file has an extension that starts with ".zima" followed by a single character,
* such as ".zimaa", ".zimab", etc. This method checks if the file path ends with this specific pattern.
*
* @param filePath The file path to evaluate.
* @return `true` if the file path corresponds to a split ZIM file, `false` otherwise.
*/
@JvmStatic
fun isSplittedZimFile(filePath: String): Boolean =
filePath.matches(Regex(".*\\.zima.$"))

/**
* Get the main storage path for a given storage name (SD card or USB stick).
*
Expand Down
1 change: 1 addition & 0 deletions core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@
<string name="moving_zim_file">Moving ZIM file…</string>
<string name="copy_move_files_dialog_description">Kiwix requires the ZIM file to be in its own data directory. Do you want to copy or move it there?</string>
<string name="copy_file_error_message">Error in copying the ZIM file: %s.</string>
<string name="verify_zim_chunk_copied_moved_properly">Be cautious: verify that all the ZIM chunks have been moved/copied properly!</string>
<string name="why_copy_move_files_to_app_directory">Why copy/move files to app public directory?</string>
<string name="copy_move_files_to_app_directory_description">Due to Google Play policies on Android 11 and above, our app can no longer directly access files stored elsewhere on your device. To let you view your selected files, we need to move or copy them into a special folder within our application directory. This allows us to access and open the files.</string>
<string name="choose_storage_to_copy_move_zim_file">Choose storage to copy/move ZIM file</string>
Expand Down

0 comments on commit 141d6df

Please sign in to comment.