Skip to content

Commit

Permalink
Bump version (#190)
Browse files Browse the repository at this point in the history
---------
Signed-off-by: starry-shivam <[email protected]>
  • Loading branch information
starry-shivam authored Jun 28, 2024
1 parent 0fbbd0d commit 1268294
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
Expand Down
41 changes: 27 additions & 14 deletions app/src/main/java/com/starry/myne/epub/EpubXMLFileParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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("")


Expand Down Expand Up @@ -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()

Expand All @@ -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()) {
Expand All @@ -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 }
Expand All @@ -177,6 +186,7 @@ class EpubXMLFileParser(
return parseAsImage(absolutePathImage)
}

// Traverses the <p> tag to extract the text content.
private fun getPTraverse(node: Node): String {
fun innerTraverse(node: Node): String =
node.childNodes().joinToString("") { child ->
Expand All @@ -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())
Expand All @@ -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) },
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/starry/myne/helpers/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/391.txt
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 1268294

Please sign in to comment.