Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ android {
minSdk 29
targetSdk 35

versionCode 31
versionName '0.1.9'
versionCode 32
versionName '0.1.10'
if (project.hasProperty('IS_NEXT') && project.IS_NEXT.toBoolean()) {
def timestamp = new Date().format('dd.MM.YYYY-HH:mm')
versionName = "${versionName}-next-${timestamp}"
Expand Down
12 changes: 3 additions & 9 deletions app/src/main/java/com/ethran/notable/data/AppRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,16 @@ class AppRepository(val context: Context) {
/**
* Retrieves the 0-based index of a page within a notebook.
*
* @param notebookId The ID of the notebook containing the page.
* @param notebookId The ID of the notebook containing the page (must not be null).
* @param pageId The ID of the page to find.
* @return The 0-based index of the page within the notebook's page list. Returns -1 if the page is not found.
* @throws IllegalArgumentException if the `notebookId` is null.
* @throws NoSuchElementException if the notebook with the given `notebookId` is not found.
* @throws NoSuchElementException if the notebook with the given notebookId is not found.
*/
// TODO: Improve handling errors. current function is not easily usable
fun getPageNumber(notebookId: String?, pageId: String): Int {
// Validate that notebookId is not null.
requireNotNull(notebookId) { "Notebook ID cannot be null." }

fun getPageNumber(notebookId: String, pageId: String): Int {
// Fetch the book or throw an exception if it doesn't exist.
val book = bookRepository.getById(notebookId)
?: throw NoSuchElementException("Notebook with ID '$notebookId' not found.")

// Return the index of the page. indexOf() returns -1 if the element is not found, which is a standard convention.
return book.getPageIndex(pageId)
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/ethran/notable/editor/DrawCanvas.kt
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ class DrawCanvas(
coroutineScope.launch {
previewPage.debounce(50).collectLatest { pageId ->
val pageNumber =
AppRepository(context).getPageNumber(page.pageFromDb?.notebookId, pageId)
AppRepository(context).getPageNumber(page.pageFromDb?.notebookId!!, pageId)
Log.d("QuickNav", "Previewing page($pageNumber): $pageId")
// Load and prepare a preview bitmap sized for the visible view area (IO thread)
val previewBitmap = withContext(Dispatchers.IO) {
Expand Down
15 changes: 5 additions & 10 deletions app/src/main/java/com/ethran/notable/editor/PageView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,11 @@ class PageView(
private var dbImages = AppDatabase.getDatabase(context).ImageDao()

val currentPageNumber: Int
get() = try {
appRepository.getPageNumber(pageFromDb?.notebookId, currentPageId)
} catch (e: Exception) {
logAndShowError(
"PageView.currentPageNumber",
"Error getting page number: ${e.message}"
)
-1
}

get() = pageFromDb?.notebookId
?.let { notebookId ->
appRepository.getPageNumber(notebookId, currentPageId)
}
?: -1

/*
If pageNumber is -1, its assumed that the background is image type.
Expand Down
27 changes: 16 additions & 11 deletions app/src/main/java/com/ethran/notable/io/ExportEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import com.ethran.notable.data.db.Page
import com.ethran.notable.data.db.PageRepository
import com.ethran.notable.data.db.Stroke
import com.ethran.notable.data.db.getBackgroundType
import com.ethran.notable.data.model.BackgroundType.Native
import com.ethran.notable.editor.drawing.drawBg
import com.ethran.notable.editor.drawing.drawImage
import com.ethran.notable.editor.drawing.drawStroke
import com.ethran.notable.ui.SnackState.Companion.logAndShowError
import com.ethran.notable.ui.components.getFolderList
import com.ethran.notable.utils.ensureNotMainThread
import io.shipbook.shipbooksdk.Log
Expand Down Expand Up @@ -335,7 +335,7 @@ class ExportEngine(
if (book != null) {
// Page inside a book
val bookTitle = sanitizeFileName(book.title)
val pageNumber = getPageNumber(page.notebookId, page.id)?.plus(1)
val pageNumber = getPageNumber(book.id, page.id).plus(1)
val pageToken = if ((pageNumber ?: 0) >= 1) "p$pageNumber" else "p_"
"$bookTitle-$pageToken"
} else {
Expand Down Expand Up @@ -404,11 +404,20 @@ class ExportEngine(
) {
canvas.scale(scaleFactor, scaleFactor)
val scaledScroll = scroll / scaleFactor
val backgroundType =
data.page.notebookId?.let {
data.page.getBackgroundType()
.resolveForExport(
getPageNumber(
it,
data.page.id
)
)
} ?: Native
drawBg(
context,
canvas,
data.page.getBackgroundType()
.resolveForExport(getPageNumber(data.page.notebookId, data.page.id)),
backgroundType,
data.page.background,
scaledScroll,
scaleFactor
Expand Down Expand Up @@ -772,13 +781,9 @@ class ExportEngine(
parts.filter { it.isNotBlank() }

// Retrieves the 0-based page number of a specific page within a book.
fun getPageNumber(bookId: String?, id: String): Int? {
return try {
AppRepository(context).getPageNumber(bookId, id)
} catch (e: Exception) {
logAndShowError("getPageNumber", "${e.message}")
0
}
fun getPageNumber(bookId: String, id: String): Int {
return AppRepository(context).getPageNumber(bookId, id)

}

}
31 changes: 16 additions & 15 deletions app/src/main/java/com/ethran/notable/io/XoppFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ class XoppFile(

boundingBox.inset(-strokeSize, -strokeSize)
val toolName = strokeElement.getAttribute("tool")
val tool = Pen.Companion.fromString(toolName)
val tool = Pen.fromString(toolName)

val stroke = Stroke(
size = strokeSize,
Expand Down Expand Up @@ -438,20 +438,21 @@ class XoppFile(
*/
private fun parseColor(colorString: String): Color {
return when (colorString.lowercase()) {
"black" -> Color.Companion.Black
"blue" -> Color.Companion.Blue
"red" -> Color.Companion.Red
"green" -> Color.Companion.Green
"magenta" -> Color.Companion.Magenta
"yellow" -> Color.Companion.Yellow
"black" -> Color.Black
"blue" -> Color.Blue
"red" -> Color.Red
"green" -> Color.Green
"magenta" -> Color.Magenta
"yellow" -> Color.Yellow
"gray" -> Color.Gray
// Convert "#RRGGBBAA" → "#AARRGGBB" → Android Color
else -> {
if (colorString.startsWith("#") && colorString.length == 9) Color(
("#" + colorString.substring(7, 9) + colorString.substring(1, 7)).toColorInt()
)
else {
log.e("Unknown color: $colorString")
Color.Companion.Black
Color.Black
}
}
}
Expand All @@ -465,13 +466,13 @@ class XoppFile(
*/
private fun getColorName(color: Color): String {
return when (color) {
Color.Companion.Black -> "black"
Color.Companion.Blue -> "blue"
Color.Companion.Red -> "red"
Color.Companion.Green -> "green"
Color.Companion.Magenta -> "magenta"
Color.Companion.Yellow -> "yellow"
Color.Companion.DarkGray, Color.Companion.Gray -> "gray"
Color.Black -> "black"
Color.Blue -> "blue"
Color.Red -> "red"
Color.Green -> "green"
Color.Magenta -> "magenta"
Color.Yellow -> "yellow"
Color.DarkGray, Color.Gray -> "gray"
else -> {
val argb = color.toArgb()
// Convert ARGB (Android default) → RGBA
Expand Down
Loading