Skip to content

Commit

Permalink
Add djvu translation assets and logic to link it
Browse files Browse the repository at this point in the history
  • Loading branch information
max-kammerer committed Apr 27, 2024
1 parent bb6cdba commit 4f1abd2
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
4 changes: 2 additions & 2 deletions orion-viewer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ android {
srcDirs += "src/analytics/kotlin"
}
}

assets.srcDirs += '../nativeLibs/djvu/share/djvu'
}

androidTest {
java.srcDirs += 'src/androidTest/kotlin'
resources.srcDirs += 'src/androidTest/assets'
assets.srcDirs += 'src/androidTest/assets'
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package universe.constellation.orion.viewer.test.engine.exceptions

import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Assert.fail
import org.junit.Test
import universe.constellation.orion.viewer.android.isAtLeastLollipop
import universe.constellation.orion.viewer.djvu.DjvuDocument
import universe.constellation.orion.viewer.test.framework.BaseTest
import java.io.File
Expand Down Expand Up @@ -30,7 +32,12 @@ class DjvuExceptionTest : BaseTest() {
DjvuDocument(tmpFIle.absolutePath)
} catch (e: Exception) {
e.printStackTrace()
assertTrue(e.message, e.message!!.contains("EOF"))
if (isAtLeastLollipop()) {
assertEquals(e.message, "Unexpected End Of File.")
}
else {
assertTrue(e.message, e.message!!.contains("EOF"))
}
return
}
fail("Expecting exception to be thrown above")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import android.os.Build

fun isAtLeastKitkat() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT

fun isAtLeastLollipop() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP

fun Intent.isContentScheme(): Boolean {
return ContentResolver.SCHEME_CONTENT == scheme
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package universe.constellation.orion.viewer.prefs

import android.content.res.AssetManager
import java.io.File

fun copyResIfNotExists(assets: AssetManager, path: String, targetRoot: File) {
val res = assets.list(path)
res?.forEach {
val relPath = "$path/$it"
if (it.endsWith(".xml")) {
val newFile = File(targetRoot, relPath)
try {
if (newFile.exists()) return
newFile.parentFile?.mkdirs()
assets.open(relPath).use { input ->
newFile.outputStream().use { output ->
println("Copy " + newFile.absolutePath)
input.copyTo(output)
}
}
} catch (e: Throwable) {
e.printStackTrace()
newFile.delete()
}
} else {
copyResIfNotExists(assets, relPath, targetRoot)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ import android.os.Build
import android.os.Build.VERSION.CODENAME
import android.os.Build.VERSION.RELEASE
import android.preference.PreferenceManager
import android.system.Os
import androidx.core.os.ConfigurationCompat
import androidx.core.os.LocaleListCompat
import androidx.multidex.MultiDex
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import universe.constellation.orion.viewer.AndroidLogger
import universe.constellation.orion.viewer.BuildConfig
import universe.constellation.orion.viewer.BuildConfig.DEBUG
Expand All @@ -47,6 +53,7 @@ import universe.constellation.orion.viewer.log
import universe.constellation.orion.viewer.logger
import universe.constellation.orion.viewer.prefs.GlobalOptions.DEFAULT_LANGUAGE
import universe.constellation.orion.viewer.test.IdlingResource
import java.io.File
import java.util.Locale
import kotlin.properties.Delegates

Expand Down Expand Up @@ -107,6 +114,14 @@ class OrionApplication : Application() {
super.onCreate()
setLanguage(options.appLanguage)
logOrionAndDeviceInfo()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
val fileToCopy = File(filesDir, "djvuConf")
val envPath = File(fileToCopy, "osi").absolutePath
CoroutineScope(SupervisorJob() + Dispatchers.Default).launch {
copyResIfNotExists(assets, "osi", fileToCopy)
}
Os.setenv("DJVU_CONFIG_DIR", envPath, true)
}
}

fun setLanguage(langCode: String) {
Expand Down

0 comments on commit 4f1abd2

Please sign in to comment.