mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-08 06:42:21 -04:00
Fixed: Download zim files in Android/media/org.kiwix/kiwixmobile/
folder instead of internal app-specific directory.
* Now all the downloading files will store in this public app-specific directory. * Refactored the code to show this new location in storageSelection dialog for both internal and external storage. * Updated the `README.md` file to educate user that how they can read already downloaded zim files in PS version. * Refactored the test cases according to this change.
This commit is contained in:
parent
a6de67e6de
commit
34618aec05
@ -28,7 +28,11 @@ Play Store policies. The Play Store variant of Kiwix does not require
|
|||||||
the `MANAGE_EXTERNAL_STORAGE` permission anymore, which is necessary
|
the `MANAGE_EXTERNAL_STORAGE` permission anymore, which is necessary
|
||||||
to scan storage and access ZIM files at arbitrary locations.
|
to scan storage and access ZIM files at arbitrary locations.
|
||||||
Therefore, the storage scanning & file picking functionalities are not
|
Therefore, the storage scanning & file picking functionalities are not
|
||||||
available in this variant anymore. To use the full version of Kiwix
|
available in this variant anymore. For already downloaded ZIM files, You can copy
|
||||||
|
them to the `Android/media/org.kiwix.kiwixmobile/` folder, and the application will read them.
|
||||||
|
Before uninstalling the application, please ensure that you move all your ZIM files
|
||||||
|
from this folder, as they will be automatically deleted when the application is uninstalled
|
||||||
|
or if the application data is cleared. To use the full version of Kiwix
|
||||||
and benefit of the ZIM file picker feature, you can download it
|
and benefit of the ZIM file picker feature, you can download it
|
||||||
directly from the [official
|
directly from the [official
|
||||||
repository](https://download.kiwix.org/release/kiwix-android/) or use
|
repository](https://download.kiwix.org/release/kiwix-android/) or use
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
package eu.mhutti1.utils.storage
|
package eu.mhutti1.utils.storage
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.ContextWrapper
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -28,7 +29,8 @@ import java.util.ArrayList
|
|||||||
|
|
||||||
object StorageDeviceUtils {
|
object StorageDeviceUtils {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getWritableStorage(context: Context) = validate(externalFilesDirsDevices(context, true), true)
|
fun getWritableStorage(context: Context) =
|
||||||
|
validate(externalMediaFilesDirsDevices(context), true)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getReadableStorage(context: Context): List<StorageDevice> {
|
fun getReadableStorage(context: Context): List<StorageDevice> {
|
||||||
@ -36,6 +38,7 @@ object StorageDeviceUtils {
|
|||||||
add(environmentDevices(context))
|
add(environmentDevices(context))
|
||||||
addAll(externalMountPointDevices())
|
addAll(externalMountPointDevices())
|
||||||
addAll(externalFilesDirsDevices(context, false))
|
addAll(externalFilesDirsDevices(context, false))
|
||||||
|
addAll(externalMediaFilesDirsDevices(context))
|
||||||
// Scan the app-specific directory as well because we have limitations in scanning
|
// Scan the app-specific directory as well because we have limitations in scanning
|
||||||
// all directories on Android 11 and above in the Play Store variant.
|
// all directories on Android 11 and above in the Play Store variant.
|
||||||
// If a user copies the ZIM file to the app-specific directory on the SD card,
|
// If a user copies the ZIM file to the app-specific directory on the SD card,
|
||||||
@ -55,6 +58,12 @@ object StorageDeviceUtils {
|
|||||||
.filterNotNull()
|
.filterNotNull()
|
||||||
.mapIndexed { index, dir -> StorageDevice(generalisePath(dir.path, writable), index == 0) }
|
.mapIndexed { index, dir -> StorageDevice(generalisePath(dir.path, writable), index == 0) }
|
||||||
|
|
||||||
|
private fun externalMediaFilesDirsDevices(
|
||||||
|
context: Context
|
||||||
|
) = ContextWrapper(context).externalMediaDirs
|
||||||
|
.filterNotNull()
|
||||||
|
.mapIndexed { index, dir -> StorageDevice(generalisePath(dir.path, true), index == 0) }
|
||||||
|
|
||||||
private fun externalMountPointDevices(): Collection<StorageDevice> =
|
private fun externalMountPointDevices(): Collection<StorageDevice> =
|
||||||
ExternalPaths.possiblePaths.fold(mutableListOf(), { acc, path ->
|
ExternalPaths.possiblePaths.fold(mutableListOf(), { acc, path ->
|
||||||
acc.apply {
|
acc.apply {
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package org.kiwix.kiwixmobile.core.utils
|
package org.kiwix.kiwixmobile.core.utils
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.ContextWrapper
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
@ -106,12 +107,12 @@ class SharedPreferenceUtil @Inject constructor(val context: Context) {
|
|||||||
get() {
|
get() {
|
||||||
val storage = sharedPreferences.getString(PREF_STORAGE, null)
|
val storage = sharedPreferences.getString(PREF_STORAGE, null)
|
||||||
return when {
|
return when {
|
||||||
storage == null -> getPublicDirectoryPath(defaultStorage()).also {
|
storage == null -> getPublicDirectoryPath(defaultPublicStorage()).also {
|
||||||
putPrefStorage(it)
|
putPrefStorage(it)
|
||||||
putStoragePosition(0)
|
putStoragePosition(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
!File(storage).isFileExist() -> getPublicDirectoryPath(defaultStorage()).also {
|
!File(storage).isFileExist() -> getPublicDirectoryPath(defaultPublicStorage()).also {
|
||||||
putStoragePosition(0)
|
putStoragePosition(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,6 +127,10 @@ class SharedPreferenceUtil @Inject constructor(val context: Context) {
|
|||||||
getExternalFilesDirs(context, null)[0]?.path
|
getExternalFilesDirs(context, null)[0]?.path
|
||||||
?: context.filesDir.path // a workaround for emulators
|
?: context.filesDir.path // a workaround for emulators
|
||||||
|
|
||||||
|
fun defaultPublicStorage(): String =
|
||||||
|
ContextWrapper(context).externalMediaDirs[0]?.path
|
||||||
|
?: context.filesDir.path // a workaround for emulators
|
||||||
|
|
||||||
fun getPrefStorageTitle(defaultTitle: String): String =
|
fun getPrefStorageTitle(defaultTitle: String): String =
|
||||||
sharedPreferences.getString(PREF_STORAGE_TITLE, defaultTitle) ?: defaultTitle
|
sharedPreferences.getString(PREF_STORAGE_TITLE, defaultTitle) ?: defaultTitle
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
package org.kiwix.kiwixmobile.custom.download.effects
|
package org.kiwix.kiwixmobile.custom.download.effects
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import org.kiwix.kiwixmobile.core.base.SideEffect
|
import org.kiwix.kiwixmobile.core.base.SideEffect
|
||||||
import org.kiwix.kiwixmobile.core.settings.StorageCalculator
|
import org.kiwix.kiwixmobile.core.settings.StorageCalculator
|
||||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||||
@ -30,7 +29,7 @@ class SetPreferredStorageWithMostSpace @Inject constructor(
|
|||||||
private val sharedPreferenceUtil: SharedPreferenceUtil
|
private val sharedPreferenceUtil: SharedPreferenceUtil
|
||||||
) : SideEffect<Unit> {
|
) : SideEffect<Unit> {
|
||||||
override fun invokeWith(activity: AppCompatActivity) {
|
override fun invokeWith(activity: AppCompatActivity) {
|
||||||
ContextCompat.getExternalFilesDirs(activity, null)
|
activity.externalMediaDirs
|
||||||
.filterNotNull()
|
.filterNotNull()
|
||||||
.maxBy(storageCalculator::availableBytes)
|
.maxBy(storageCalculator::availableBytes)
|
||||||
?.let { sharedPreferenceUtil.putPrefStorage(it.path) }
|
?.let { sharedPreferenceUtil.putPrefStorage(it.path) }
|
||||||
|
@ -19,10 +19,8 @@
|
|||||||
package org.kiwix.kiwixmobile.custom.download.effects
|
package org.kiwix.kiwixmobile.custom.download.effects
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import io.mockk.every
|
import io.mockk.every
|
||||||
import io.mockk.mockk
|
import io.mockk.mockk
|
||||||
import io.mockk.mockkStatic
|
|
||||||
import io.mockk.verify
|
import io.mockk.verify
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.kiwix.kiwixmobile.core.settings.StorageCalculator
|
import org.kiwix.kiwixmobile.core.settings.StorageCalculator
|
||||||
@ -36,10 +34,9 @@ internal class SetPreferredStorageWithMostSpaceTest {
|
|||||||
val storageCalculator = mockk<StorageCalculator>()
|
val storageCalculator = mockk<StorageCalculator>()
|
||||||
val sharedPreferenceUtil = mockk<SharedPreferenceUtil>()
|
val sharedPreferenceUtil = mockk<SharedPreferenceUtil>()
|
||||||
val activity = mockk<AppCompatActivity>()
|
val activity = mockk<AppCompatActivity>()
|
||||||
mockkStatic(ContextCompat::class)
|
|
||||||
val directoryWithMoreStorage = mockk<File>()
|
val directoryWithMoreStorage = mockk<File>()
|
||||||
val directoryWithLessStorage = mockk<File>()
|
val directoryWithLessStorage = mockk<File>()
|
||||||
every { ContextCompat.getExternalFilesDirs(activity, null) } returns arrayOf(
|
every { activity.externalMediaDirs } returns arrayOf(
|
||||||
directoryWithMoreStorage, null, directoryWithLessStorage
|
directoryWithMoreStorage, null, directoryWithLessStorage
|
||||||
)
|
)
|
||||||
every { storageCalculator.availableBytes(directoryWithMoreStorage) } returns 1
|
every { storageCalculator.availableBytes(directoryWithMoreStorage) } returns 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user