Improved the exporting of bookmarks.

* Improved the location of exporting the bookmarks.
* Improved the messages that will clearly shows where and in which file bookmarks are exported.
This commit is contained in:
MohitMaliFtechiz 2024-06-03 17:39:16 +05:30 committed by Kelson
parent be1369f805
commit 20925efb60
2 changed files with 18 additions and 10 deletions

View File

@ -19,6 +19,7 @@
package org.kiwix.kiwixmobile.core.dao package org.kiwix.kiwixmobile.core.dao
import android.os.Build import android.os.Build
import android.os.Environment
import android.util.Base64 import android.util.Base64
import io.reactivex.BackpressureStrategy import io.reactivex.BackpressureStrategy
import io.reactivex.BackpressureStrategy.LATEST import io.reactivex.BackpressureStrategy.LATEST
@ -28,9 +29,7 @@ import io.reactivex.subjects.BehaviorSubject
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.kiwix.kiwixmobile.core.CoreApp
import org.kiwix.kiwixmobile.core.R import org.kiwix.kiwixmobile.core.R
import org.kiwix.kiwixmobile.core.extensions.deleteFile
import org.kiwix.kiwixmobile.core.extensions.isFileExist import org.kiwix.kiwixmobile.core.extensions.isFileExist
import org.kiwix.kiwixmobile.core.extensions.toast import org.kiwix.kiwixmobile.core.extensions.toast
import org.kiwix.kiwixmobile.core.page.adapter.Page import org.kiwix.kiwixmobile.core.page.adapter.Page
@ -287,7 +286,7 @@ class LibkiwixBookmarks @Inject constructor(
sharedPreferenceUtil.context.toast( sharedPreferenceUtil.context.toast(
sharedPreferenceUtil.context.getString( sharedPreferenceUtil.context.getString(
R.string.export_bookmark_saved, R.string.export_bookmark_saved,
"${bookmarkDestinationFile.parent}/" bookmarkDestinationFile.name
) )
) )
} catch (ignore: Exception) { } catch (ignore: Exception) {
@ -297,12 +296,21 @@ class LibkiwixBookmarks @Inject constructor(
} }
private fun exportedFile(fileName: String): File { private fun exportedFile(fileName: String): File {
val rootFolder = CoreApp.instance.externalMediaDirs[0] val rootFolder = File(
"${Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)}" +
"/org.kiwix"
)
if (!rootFolder.isFileExist()) rootFolder.mkdir() if (!rootFolder.isFileExist()) rootFolder.mkdir()
val file = File(rootFolder, fileName) return sequence {
if (file.isFileExist()) file.deleteFile() yield(File(rootFolder, fileName))
file.createNewFile() yieldAll(
return file generateSequence(1) { it + 1 }.map {
File(
rootFolder, fileName.replace(".", "_$it.")
)
}
)
}.first { !it.isFileExist() }
} }
companion object { companion object {

View File

@ -79,7 +79,7 @@
<string name="pref_permission">Permissions</string> <string name="pref_permission">Permissions</string>
<string name="pref_export_bookmark_title">Export Bookmarks</string> <string name="pref_export_bookmark_title">Export Bookmarks</string>
<string name="pref_export_bookmark_summary">Export all saved bookmarks</string> <string name="pref_export_bookmark_summary">Export all saved bookmarks</string>
<string name="export_bookmark_saved">Bookmarks are exported in %s folder</string> <string name="export_bookmark_saved">Bookmarks are exported in %s file</string>
<string name="all_history_cleared">All History Cleared</string> <string name="all_history_cleared">All History Cleared</string>
<string name="pref_clear_all_bookmarks_title">Clear bookmarks</string> <string name="pref_clear_all_bookmarks_title">Clear bookmarks</string>
<string name="clear_all_history_dialog_title">Clear All History?</string> <string name="clear_all_history_dialog_title">Clear All History?</string>
@ -295,7 +295,7 @@
<string name="delete_bookmarks">Delete All Bookmarks?</string> <string name="delete_bookmarks">Delete All Bookmarks?</string>
<string name="delete_selected_bookmarks">Delete Selected Bookmarks?</string> <string name="delete_selected_bookmarks">Delete Selected Bookmarks?</string>
<string name="export_all_bookmarks_dialog_title">Export All Bookmarks?</string> <string name="export_all_bookmarks_dialog_title">Export All Bookmarks?</string>
<string name="export_all_bookmarks_dialog_message">Exporting will generate bookmark.xml file in the Android/media/org.kiwix…/ folder. To import bookmarks, simply copy this file into the Android/data/org.kiwix…/files/Bookmarks/ folder.</string> <string name="export_all_bookmarks_dialog_message">Exporting will generate bookmark.xml file in the Download/org.kiwix…/ folder.</string>
<string name="on">On</string> <string name="on">On</string>
<string name="off">Off</string> <string name="off">Off</string>
<string name="auto">Auto</string> <string name="auto">Auto</string>