From 1268294b8fca3a5d76131ac9154d1901950d384a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C9=91rry=20Shiv=C9=91m?= Date: Fri, 28 Jun 2024 13:37:20 +0530 Subject: [PATCH] Bump version (#190) --------- Signed-off-by: starry-shivam --- app/build.gradle | 10 ++--- .../com/starry/myne/epub/EpubXMLFileParser.kt | 41 ++++++++++++------- .../java/com/starry/myne/helpers/Utils.kt | 4 ++ .../metadata/android/en-US/changelogs/391.txt | 3 ++ 4 files changed, 39 insertions(+), 19 deletions(-) create mode 100644 fastlane/metadata/android/en-US/changelogs/391.txt diff --git a/app/build.gradle b/app/build.gradle index a937e4a7..5439cae4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -28,8 +28,8 @@ android { applicationId "com.starry.myne" minSdk 26 targetSdk 34 - versionCode 390 - versionName "3.9.0" + versionCode 391 + versionName "3.9.1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { @@ -151,13 +151,13 @@ dependencies { // Testing components. testImplementation 'junit:junit:4.13.2' testImplementation "com.google.truth:truth:1.1.3" - testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.0' + testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.1' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' testImplementation 'org.robolectric:robolectric:4.12.1' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' // Android testing components. - androidTestImplementation 'androidx.test.ext:junit:1.1.5' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' + androidTestImplementation 'androidx.test.ext:junit:1.2.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' androidTestImplementation "androidx.compose.ui:ui-test-junit4" // debug components. debugImplementation "androidx.compose.ui:ui-tooling" diff --git a/app/src/main/java/com/starry/myne/epub/EpubXMLFileParser.kt b/app/src/main/java/com/starry/myne/epub/EpubXMLFileParser.kt index 85b24411..ac03adb4 100644 --- a/app/src/main/java/com/starry/myne/epub/EpubXMLFileParser.kt +++ b/app/src/main/java/com/starry/myne/epub/EpubXMLFileParser.kt @@ -50,6 +50,7 @@ class EpubXMLFileParser( */ data class Output(val title: String?, val body: String) + // The parent folder of the XML file. private val fileParentFolder: File = File(fileAbsolutePath).parentFile ?: File("") @@ -116,6 +117,27 @@ class EpubXMLFileParser( ) } + /** + * Parses the input data as an image and returns the image path and aspect ratio. + * + * @param absolutePathImage The absolute path of the image file. + * @return [String] The image path and aspect ratio. + */ + fun parseAsImage(absolutePathImage: String): String { + // Use run catching so it can be run locally without crash + val bitmap = zipFile[absolutePathImage]?.data?.runCatching { + BitmapFactory.decodeByteArray(this, 0, this.size) + }?.getOrNull() + + val text = BookTextMapper.ImgEntry( + path = absolutePathImage, + yrel = bitmap?.let { it.height.toFloat() / it.width.toFloat() } ?: 1.45f + ).toXMLString() + + return "\n\n$text\n\n" + } + + // Traverses the XML document to find the next sibling node. private fun getNextSibling(currentNode: Node?): Node? { var nextSibling: Node? = currentNode?.nextSibling() @@ -135,6 +157,7 @@ class EpubXMLFileParser( return nextSibling } + // Traverses the descendants of a node to find the next node. private fun traverseDescendants(node: Node): Node? { val children = node.childNodes() if (children.isNotEmpty()) { @@ -149,20 +172,6 @@ class EpubXMLFileParser( return null } - fun parseAsImage(absolutePathImage: String): String { - // Use run catching so it can be run locally without crash - val bitmap = zipFile[absolutePathImage]?.data?.runCatching { - BitmapFactory.decodeByteArray(this, 0, this.size) - }?.getOrNull() - - val text = BookTextMapper.ImgEntry( - path = absolutePathImage, - yrel = bitmap?.let { it.height.toFloat() / it.width.toFloat() } ?: 1.45f - ).toXMLString() - - return "\n\n$text\n\n" - } - // Rewrites the image node to xml for the next stage. private fun declareImgEntry(node: Node): String { val attrs = node.attributes().associate { it.key to it.value } @@ -177,6 +186,7 @@ class EpubXMLFileParser( return parseAsImage(absolutePathImage) } + // Traverses the

tag to extract the text content. private fun getPTraverse(node: Node): String { fun innerTraverse(node: Node): String = node.childNodes().joinToString("") { child -> @@ -193,6 +203,7 @@ class EpubXMLFileParser( return if (paragraph.isNotEmpty()) "$paragraph\n\n" else "" } + // Traverses the node to extract the text content. private fun getNodeTextTraverse(node: Node): String { val children = node.childNodes() if (children.isEmpty()) @@ -215,6 +226,8 @@ class EpubXMLFileParser( } } + // Traverses the node to extract the structured text content + // based on the node type and its children. private fun getNodeStructuredText(node: Node, singleNode: Boolean = false): String { val nodeActions = mapOf( "p" to { n: Node -> getPTraverse(n) }, diff --git a/app/src/main/java/com/starry/myne/helpers/Utils.kt b/app/src/main/java/com/starry/myne/helpers/Utils.kt index f791468f..fc88d667 100644 --- a/app/src/main/java/com/starry/myne/helpers/Utils.kt +++ b/app/src/main/java/com/starry/myne/helpers/Utils.kt @@ -31,7 +31,11 @@ import kotlin.math.floor import kotlin.math.log10 import kotlin.math.pow +/** + * A collection of utility functions. + */ object Utils { + /** * Formats a number into a more readable format with a suffix representing its magnitude. * For example, 1000 becomes "1k", 1000000 becomes "1M", etc. diff --git a/fastlane/metadata/android/en-US/changelogs/391.txt b/fastlane/metadata/android/en-US/changelogs/391.txt new file mode 100644 index 00000000..0df5ea0d --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/391.txt @@ -0,0 +1,3 @@ +- Prevent screen from turning off in ebook reader. +- Make developer email address clickable in about screen. +- Updated dependencies & some other minor improvements. \ No newline at end of file