mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 10:46:53 -04:00
Improved the copying/moving of ZIM chunks.
* Now all the ZIM chunks are copying/moving correctly. * Improved the warning message to inform user what should they do after copying/moving all the ZIM chunks. * Implement a feature to directly view the copied/moved ZIM chunks by clicking on the button in warning dialog.
This commit is contained in:
parent
be81ca5405
commit
4e16102bc4
@ -52,6 +52,7 @@ import org.kiwix.kiwixmobile.core.utils.INTERNAL_SELECT_POSITION
|
||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.AlertDialogShower
|
||||
import org.kiwix.kiwixmobile.core.utils.dialog.KiwixDialog
|
||||
import org.kiwix.kiwixmobile.core.utils.files.FileUtils
|
||||
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
||||
import org.kiwix.kiwixmobile.zimManager.Fat32Checker
|
||||
import org.kiwix.kiwixmobile.zimManager.Fat32Checker.Companion.FOUR_GIGABYTES_IN_KILOBYTES
|
||||
@ -405,6 +406,9 @@ class CopyMoveFileHandler @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun isValidZimFile(destinationFile: File): Boolean =
|
||||
FileUtils.isSplittedZimFile(destinationFile.name) || validateZimFileValid(destinationFile)
|
||||
|
||||
fun handleInvalidZimFile(destinationFile: File, sourceUri: Uri) {
|
||||
val errorMessage = activity.getString(R.string.error_file_invalid)
|
||||
if (isMoveOperation) {
|
||||
@ -428,7 +432,7 @@ class CopyMoveFileHandler @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun isValidZimFile(destinationFile: File): Boolean {
|
||||
private suspend fun validateZimFileValid(destinationFile: File): Boolean {
|
||||
var archive: Archive? = null
|
||||
return try {
|
||||
// create archive object, and check if it has the mainEntry or not to validate the ZIM file.
|
||||
|
@ -44,6 +44,7 @@ import androidx.appcompat.widget.Toolbar
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.core.net.toUri
|
||||
import androidx.core.view.MenuHost
|
||||
import androidx.core.view.MenuProvider
|
||||
@ -423,7 +424,7 @@ class LocalLibraryFragment : BaseFragment(), CopyMoveFileHandler.FileCopyMoveCal
|
||||
// If the file name is not found, then let them to copy the file
|
||||
// and we will handle this later.
|
||||
val fileName = documentFile?.name
|
||||
if (fileName != null && !FileUtils.isValidZimFile(fileName)) {
|
||||
if (fileName != null && !isValidZimFile(fileName)) {
|
||||
activity.toast(string.error_file_invalid)
|
||||
return@launch
|
||||
}
|
||||
@ -440,6 +441,9 @@ class LocalLibraryFragment : BaseFragment(), CopyMoveFileHandler.FileCopyMoveCal
|
||||
}
|
||||
}
|
||||
|
||||
private fun isValidZimFile(fileName: String): Boolean =
|
||||
FileUtils.isValidZimFile(fileName) || FileUtils.isSplittedZimFile(fileName)
|
||||
|
||||
private suspend fun getZimFileFromUri(
|
||||
uri: Uri
|
||||
): File? {
|
||||
@ -707,7 +711,26 @@ class LocalLibraryFragment : BaseFragment(), CopyMoveFileHandler.FileCopyMoveCal
|
||||
private fun showWarningDialogForSplittedZimFile() {
|
||||
dialogShower.show(
|
||||
KiwixDialog.ShowWarningAboutSplittedZimFile,
|
||||
{}
|
||||
::openCopiedMovedDirectory
|
||||
)
|
||||
}
|
||||
|
||||
private fun openCopiedMovedDirectory() {
|
||||
val downloadedDirectoryPath = FileProvider.getUriForFile(
|
||||
requireActivity(),
|
||||
requireActivity().applicationContext.packageName + ".fileprovider",
|
||||
File(sharedPreferenceUtil.prefStorage)
|
||||
)
|
||||
val intent = Intent(Intent.ACTION_VIEW).apply {
|
||||
setDataAndType(downloadedDirectoryPath, "*/*")
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
try {
|
||||
requireActivity().startActivity(intent)
|
||||
} catch (ignore: Exception) {
|
||||
// TODO change the message
|
||||
activity.toast(org.kiwix.kiwixmobile.core.R.string.no_reader_application_installed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ sealed class KiwixDialog(
|
||||
data object ShowWarningAboutSplittedZimFile : KiwixDialog(
|
||||
null,
|
||||
R.string.verify_zim_chunk_copied_moved_properly,
|
||||
android.R.string.ok,
|
||||
R.string.view,
|
||||
android.R.string.ok,
|
||||
cancelable = false
|
||||
)
|
||||
|
@ -334,7 +334,8 @@
|
||||
<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="verify_zim_chunk_copied_moved_properly">Be cautious: verify that all the ZIM chunks have been moved/copied properly! \nAfter copying/moving all the ZIM chunks please refresh the library screen by swipe down. The Split ZIM file will add in library.</string>
|
||||
<string name="view">View</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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user