Removed unnecessary file creation.

* Testing loading files from chunks.
* Removed the `PLAY_ASSET_FILE` file tag from BuildConfig file as now we are using chunks for loading zim file from asset folder.
This commit is contained in:
MohitMali 2023-11-07 19:11:20 +05:30
parent 54f8354104
commit d1c84e9555
3 changed files with 16 additions and 8 deletions

View File

@ -46,8 +46,6 @@ 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

@ -34,7 +34,7 @@ android {
createDownloadTask(it)
createPublishApkWithExpansionTask(it, applicationVariants)
}
File("$projectDir/../install_time_asset/src/main/assets", "$name.zim").let {
File("$projectDir/../install_time_asset/src/main/assets").let {
createDownloadTaskForPlayAssetDelivery(it)
createPublishBundleWithAssetPlayDelivery()
}
@ -114,7 +114,7 @@ fun writeZimFileData(responseBody: ResponseBody, file: File, chunkSize: Long = 1
while (inputStream.read(buffer).also { bytesRead = it } != -1) {
if (outputStream == null) {
// Create a new chunk file
val nextChunkFile = File(file.parent, "chunk$chunkNumber.zim")
val nextChunkFile = File(file.path, "chunk$chunkNumber.zim")
nextChunkFile.createNewFile()
outputStream = FileOutputStream(nextChunkFile)
}
@ -151,8 +151,6 @@ fun ProductFlavor.createDownloadTaskForPlayAssetDelivery(
) {
group = "Downloading"
doLast {
if (file.exists()) file.delete()
file.createNewFile()
OkHttpClient().newCall(fetchRequest()).execute().use { response ->
if (response.isSuccessful) {

View File

@ -22,8 +22,11 @@ import android.content.Context
import android.content.pm.PackageManager
import android.content.res.AssetFileDescriptor
import android.content.res.AssetManager
import android.os.ParcelFileDescriptor
import android.util.Log
import androidx.core.content.ContextCompat
import org.kiwix.kiwixmobile.core.extensions.deleteFile
import org.kiwix.kiwixmobile.core.extensions.isFileExist
import org.kiwix.kiwixmobile.core.utils.files.FileUtils
import org.kiwix.kiwixmobile.custom.main.ValidationState.HasBothFiles
import org.kiwix.kiwixmobile.custom.main.ValidationState.HasFile
@ -66,6 +69,9 @@ class CustomFileValidator @Inject constructor(private val context: Context) {
assetFileDescriptorList.add(assetManager.openFd(it))
}
val combinedFilePath = FileUtils.getDemoFilePathForCustomApp(context)
val demoFile = File(combinedFilePath)
if (demoFile.isFileExist()) demoFile.deleteFile()
demoFile.createNewFile()
val combinedFileOutputStream = FileOutputStream(combinedFilePath)
val chunkSize = 100 * 1024 * 1024
@ -87,8 +93,14 @@ class CustomFileValidator @Inject constructor(private val context: Context) {
chunkFileInputStream.close()
}
return assetFileDescriptorList[0]
return AssetFileDescriptor(
ParcelFileDescriptor.open(
demoFile,
ParcelFileDescriptor.MODE_READ_ONLY
),
0L,
demoFile.length()
)
} catch (packageNameNotFoundException: PackageManager.NameNotFoundException) {
Log.w(
"ASSET_PACKAGE_DELIVERY",