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:
MohitMali 2023-10-17 12:28:42 +05:30
parent 4c951de69e
commit 1b87900695
3 changed files with 17 additions and 15 deletions

View File

@ -46,6 +46,8 @@ fun ProductFlavors.create(customApps: List<CustomApp>) {
applicationIdSuffix = ".kiwixcustom${customApp.name}"
buildConfigField("String", "ZIM_URL", "\"${customApp.url}\"")
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_TABS", "${customApp.disableTabs}")
buildConfigField("Boolean", "DISABLE_READ_ALOUD", "${customApp.disableReadAloud}")

View File

@ -129,20 +129,19 @@ fun ProductFlavor.createDownloadTaskForPlayAssetDelivery(
) {
group = "Downloading"
doLast {
if (!file.exists()) {
file.createNewFile()
if (file.exists()) file.delete()
file.createNewFile()
OkHttpClient().newCall(fetchRequest()).execute().use { response ->
if (response.isSuccessful) {
response.body?.let { responseBody ->
writeZimFileData(responseBody, file)
}
} else {
throw RuntimeException(
"Download Failed. Error: ${response.message}\n" +
" Status Code: ${response.code}"
)
OkHttpClient().newCall(fetchRequest()).execute().use { response ->
if (response.isSuccessful) {
response.body?.let { responseBody ->
writeZimFileData(responseBody, file)
}
} 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" }
return tasks.create("publish${capitalizedName}ReleaseBundleWithPlayAssetDelivery") {
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 {
val packageName = "org.kiwix$applicationIdSuffix"
println("packageName $packageName")

View File

@ -22,6 +22,7 @@ import android.content.Context
import android.content.pm.PackageManager
import android.util.Log
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.HasFile
import org.kiwix.kiwixmobile.custom.main.ValidationState.HasNothing
@ -59,9 +60,9 @@ class CustomFileValidator @Inject constructor(private val context: Context) {
try {
val context = context.createPackageContext(context.packageName, 0)
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]
zimFile = File(filePath, "dwds_de_dictionary_nopic_2023-09-12.zim")
zimFile = File(filePath, BuildConfig.PLAY_ASSET_FILE)
FileOutputStream(zimFile).use { outputSteam ->
inputStream.use { inputStream ->
val buffer = ByteArray(1024)