book-reader/app/src/main/java/com/aryan/reader/epub/EpubXMLFileParser.kt
Aryan c6363f3061
Update readme (#3)
docs: Revamp README and add APK naming convention

This commit introduces a complete overhaul of the `README.md` to improve project presentation. Key changes include:
*   Adds a new header with the app icon and a Google Play badge.
*   Updates the feature graphic and includes a note distinguishing the OSS version from the Play Store version.
*   Refines the "Open Source Libraries" section to be more structured.
*   Moves the main preview image into the `docs` directory.

Additionally, the `app/build.gradle.kts` file is updated to configure a standardized naming convention for output APK files, including flavor, version, and build type.

* refactor copyright headers and fix README icon alignment

This commit introduces two main changes across the codebase:

The `spotless/copyright.kt` template have been updated for consistency:
*   The author name is simplified from "Episteme Authors" to "Episteme".
*   The contact email prefix is shortened from "Electronic mail:" to "mail:".

Second, the `README.md` file is adjusted to correct the vertical alignment of the app icon with the project title.
2026-02-25 21:30:28 +05:30

74 lines
No EOL
2.7 KiB
Kotlin

/*
* Episteme Reader - A native Android document reader.
* Copyright (C) 2026 Episteme
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* mail: epistemereader@gmail.com
*/
package com.aryan.reader.epub
import timber.log.Timber
import org.jsoup.Jsoup
/**
* Parses an XML/HTML file from an EPUB archive, primarily to extract a title
* and determine the effective path for WebView (including fragments).
*
* @property fileRelativePath The relative path of the HTML file within the EPUB's extraction directory.
* @property data The raw data (content) of the HTML file.
* @property fragmentId Optional ID of the fragment to link to within the HTML file.
*/
class EpubXMLFileParser(
val fileRelativePath: String, // e.g., "OEBPS/chapter1.xhtml"
val data: ByteArray,
private val fragmentId: String? = null
) {
companion object {
private const val TAG = "EpubXMLFileParser"
}
/**
* Represents the output of the parsing.
*
* @property title The extracted title of the HTML document (e.g., from h1-h6 tags).
* @property effectiveHtmlPath The relative path to the HTML file, including any fragment identifier.
* This path is relative to the book's extraction base.
*/
data class Output(val title: String?, val effectiveHtmlPath: String)
/**
* Parses the HTML data to extract a title and construct the effective HTML path.
*
* @return [Output] The title and effective HTML path.
*/
fun parseForTitleAndPath(): Output {
Timber.d("Parsing for title and path: $fileRelativePath, fragment: $fragmentId")
val document = Jsoup.parse(data.inputStream(), "UTF-8", "")
val extractedTitle = document.selectFirst("h1, h2, h3, h4, h5, h6")?.text()?.trim()
val pathWithFragment = if (fragmentId != null) {
"$fileRelativePath#$fragmentId"
} else {
fileRelativePath
}
Timber.d("Effective HTML path: $pathWithFragment for file: $fileRelativePath")
return Output(
title = extractedTitle,
effectiveHtmlPath = pathWithFragment
)
}
}