mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-08 06:42:21 -04:00
Fixed zim file not found when we try to retrieve it from Play asset delivery
to our application.
* We are now storing the zim file name in buildConfig file which we will use when we try to retrieve it later. * Improved downloading functionality.
This commit is contained in:
parent
4c951de69e
commit
1b87900695
@ -46,6 +46,8 @@ fun ProductFlavors.create(customApps: List<CustomApp>) {
|
|||||||
applicationIdSuffix = ".kiwixcustom${customApp.name}"
|
applicationIdSuffix = ".kiwixcustom${customApp.name}"
|
||||||
buildConfigField("String", "ZIM_URL", "\"${customApp.url}\"")
|
buildConfigField("String", "ZIM_URL", "\"${customApp.url}\"")
|
||||||
buildConfigField("String", "ENFORCED_LANG", "\"${customApp.enforcedLanguage}\"")
|
buildConfigField("String", "ENFORCED_LANG", "\"${customApp.enforcedLanguage}\"")
|
||||||
|
// Add asset file name in buildConfig file, we will use later to receive the zim file.
|
||||||
|
buildConfigField("String", "PLAY_ASSET_FILE", "\"${customApp.name}.zim\"")
|
||||||
buildConfigField("Boolean", "DISABLE_SIDEBAR", "${customApp.disableSideBar}")
|
buildConfigField("Boolean", "DISABLE_SIDEBAR", "${customApp.disableSideBar}")
|
||||||
buildConfigField("Boolean", "DISABLE_TABS", "${customApp.disableTabs}")
|
buildConfigField("Boolean", "DISABLE_TABS", "${customApp.disableTabs}")
|
||||||
buildConfigField("Boolean", "DISABLE_READ_ALOUD", "${customApp.disableReadAloud}")
|
buildConfigField("Boolean", "DISABLE_READ_ALOUD", "${customApp.disableReadAloud}")
|
||||||
|
@ -129,20 +129,19 @@ fun ProductFlavor.createDownloadTaskForPlayAssetDelivery(
|
|||||||
) {
|
) {
|
||||||
group = "Downloading"
|
group = "Downloading"
|
||||||
doLast {
|
doLast {
|
||||||
if (!file.exists()) {
|
if (file.exists()) file.delete()
|
||||||
file.createNewFile()
|
file.createNewFile()
|
||||||
|
|
||||||
OkHttpClient().newCall(fetchRequest()).execute().use { response ->
|
OkHttpClient().newCall(fetchRequest()).execute().use { response ->
|
||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
response.body?.let { responseBody ->
|
response.body?.let { responseBody ->
|
||||||
writeZimFileData(responseBody, file)
|
writeZimFileData(responseBody, file)
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw RuntimeException(
|
|
||||||
"Download Failed. Error: ${response.message}\n" +
|
|
||||||
" Status Code: ${response.code}"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
throw RuntimeException(
|
||||||
|
"Download Failed. Error: ${response.message}\n" +
|
||||||
|
" Status Code: ${response.code}"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,7 +199,7 @@ fun ProductFlavor.createPublishBundleWithAssetPlayDelivery(
|
|||||||
name.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else "$it" }
|
name.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else "$it" }
|
||||||
return tasks.create("publish${capitalizedName}ReleaseBundleWithPlayAssetDelivery") {
|
return tasks.create("publish${capitalizedName}ReleaseBundleWithPlayAssetDelivery") {
|
||||||
group = "publishing"
|
group = "publishing"
|
||||||
description = "Uploads $capitalizedName to the Play Console with an Expansion file"
|
description = "Uploads $capitalizedName to the Play Console with an Play Asset delivery mode"
|
||||||
doLast {
|
doLast {
|
||||||
val packageName = "org.kiwix$applicationIdSuffix"
|
val packageName = "org.kiwix$applicationIdSuffix"
|
||||||
println("packageName $packageName")
|
println("packageName $packageName")
|
||||||
|
@ -22,6 +22,7 @@ import android.content.Context
|
|||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import org.kiwix.kiwixmobile.custom.BuildConfig
|
||||||
import org.kiwix.kiwixmobile.custom.main.ValidationState.HasBothFiles
|
import org.kiwix.kiwixmobile.custom.main.ValidationState.HasBothFiles
|
||||||
import org.kiwix.kiwixmobile.custom.main.ValidationState.HasFile
|
import org.kiwix.kiwixmobile.custom.main.ValidationState.HasFile
|
||||||
import org.kiwix.kiwixmobile.custom.main.ValidationState.HasNothing
|
import org.kiwix.kiwixmobile.custom.main.ValidationState.HasNothing
|
||||||
@ -59,9 +60,9 @@ class CustomFileValidator @Inject constructor(private val context: Context) {
|
|||||||
try {
|
try {
|
||||||
val context = context.createPackageContext(context.packageName, 0)
|
val context = context.createPackageContext(context.packageName, 0)
|
||||||
val assetManager = context.assets
|
val assetManager = context.assets
|
||||||
val inputStream = assetManager.open("dwds_de_dictionary_nopic_2023-09-12.zim")
|
val inputStream = assetManager.open(BuildConfig.PLAY_ASSET_FILE)
|
||||||
val filePath = ContextCompat.getExternalFilesDirs(context, null)[0]
|
val filePath = ContextCompat.getExternalFilesDirs(context, null)[0]
|
||||||
zimFile = File(filePath, "dwds_de_dictionary_nopic_2023-09-12.zim")
|
zimFile = File(filePath, BuildConfig.PLAY_ASSET_FILE)
|
||||||
FileOutputStream(zimFile).use { outputSteam ->
|
FileOutputStream(zimFile).use { outputSteam ->
|
||||||
inputStream.use { inputStream ->
|
inputStream.use { inputStream ->
|
||||||
val buffer = ByteArray(1024)
|
val buffer = ByteArray(1024)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user