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 32
versionName '0.1.10'
versionCode 33
versionName '0.1.11'
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
39 changes: 39 additions & 0 deletions app/src/main/java/com/ethran/notable/data/AppRepository.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package com.ethran.notable.data

import android.content.Context
import com.ethran.notable.data.datastore.GlobalAppSettings
import com.ethran.notable.data.db.BookRepository
import com.ethran.notable.data.db.FolderRepository
import com.ethran.notable.data.db.ImageRepository
import com.ethran.notable.data.db.KvProxy
import com.ethran.notable.data.db.KvRepository
import com.ethran.notable.data.db.Page
import com.ethran.notable.data.db.PageRepository
import com.ethran.notable.data.db.StrokeRepository
import com.ethran.notable.data.db.getPageIndex
import com.ethran.notable.data.db.newPage
import com.ethran.notable.data.model.BackgroundType
import com.ethran.notable.ui.SnackState.Companion.logAndShowError
import com.onyx.android.sdk.extension.isNotNull
import java.util.Date
import java.util.UUID
Expand Down Expand Up @@ -122,4 +125,40 @@ class AppRepository(val context: Context) {
return book.getPageIndex(pageId)
}

fun createNewQuickPage(parentFolderId: String? = null) : String? {
val page = Page(
notebookId = null,
background = GlobalAppSettings.current.defaultNativeTemplate,
backgroundType = BackgroundType.Native.key,
parentFolderId = parentFolderId
)
try {
pageRepository.create(page)
} catch (e: android.database.sqlite.SQLiteConstraintException) {
logAndShowError(
"createNewPAge",
"failed to create page ${e.message}"
)
return null
}
return page.id
}

fun newPageInBook(notebookId: String, index: Int = 0): String? {
try {
val book = bookRepository.getById(notebookId)
?: return null
val page = book.newPage()
pageRepository.create(page)
bookRepository.addPage(notebookId, page.id, index)
return page.id
} catch (e: Exception) {
logAndShowError(
"newPageInBook",
"failed to create page ${e.message}"
)
return null
}
}

}
7 changes: 1 addition & 6 deletions app/src/main/java/com/ethran/notable/editor/ui/PageMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Popup
import androidx.compose.ui.window.PopupProperties
import com.ethran.notable.data.AppRepository
import com.ethran.notable.data.db.newPage
import com.ethran.notable.data.deletePage
import com.ethran.notable.ui.noRippleClickable

Expand Down Expand Up @@ -76,11 +75,7 @@ fun PageMenu(
Modifier
.padding(10.dp)
.noRippleClickable {
val book = appRepository.bookRepository.getById(notebookId)
?: return@noRippleClickable
val page = book.newPage()
appRepository.pageRepository.create(page)
appRepository.bookRepository.addPage(notebookId, page.id, index + 1)
appRepository.newPageInBook(notebookId, index + 1)
}) {
Text("Insert after")
}
Expand Down
36 changes: 24 additions & 12 deletions app/src/main/java/com/ethran/notable/io/ImportEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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.model.BackgroundType
import com.ethran.notable.ui.SnackState.Companion.logAndShowError
import io.shipbook.shipbooksdk.ShipBook


Expand Down Expand Up @@ -131,11 +132,17 @@ class ImportEngine(
val strokeRepo = AppDatabase.getDatabase(context).strokeDao()
val imageRepo = AppDatabase.getDatabase(context).ImageDao()
XoppFile(context).importBook(uri) { pageData ->
// TODO: handle conflict with existing pages, make sure that we won't insert the same strokes that already exist.
pageRepo.create(pageData.page.copy(notebookId = book.id))
strokeRepo.create(pageData.strokes)
imageRepo.create(pageData.images)
bookRepo.addPage(book.id, pageData.page.id)
try {
// TODO: handle conflict with existing pages, make sure that we won't insert the same strokes that already exist.
pageRepo.create(pageData.page.copy(notebookId = book.id))
strokeRepo.create(pageData.strokes)
imageRepo.create(pageData.images)
bookRepo.addPage(book.id, pageData.page.id)
} catch (e: Exception) {
logAndShowError(
"importBook", "failed import book ${e.message}"
)
}

}
return "Imported Xopp file"
Expand All @@ -161,13 +168,18 @@ class ImportEngine(
val strokeRepo = AppDatabase.getDatabase(context).strokeDao()
val imageRepo = AppDatabase.getDatabase(context).ImageDao()
importPdf(fileToSave, options) { pageData ->
pageRepo.create(pageData.page.copy(notebookId = book.id))
if (pageData.strokes.isNotEmpty())
strokeRepo.create(pageData.strokes)
if (pageData.images.isNotEmpty())
imageRepo.create(pageData.images)

bookRepo.addPage(book.id, pageData.page.id)
try {
pageRepo.create(pageData.page.copy(notebookId = book.id))
if (pageData.strokes.isNotEmpty())
strokeRepo.create(pageData.strokes)
if (pageData.images.isNotEmpty())
imageRepo.create(pageData.images)
bookRepo.addPage(book.id, pageData.page.id)
} catch (e: Exception) {
logAndShowError(
"importBook", "failed import book ${e.message}"
)
}

}
return "Imported Pdf file"
Expand Down
16 changes: 4 additions & 12 deletions app/src/main/java/com/ethran/notable/ui/components/ShowPagesRow.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.ethran.notable.ui.components

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.border
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Arrangement
Expand All @@ -27,9 +26,7 @@ import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import com.ethran.notable.data.AppRepository
import com.ethran.notable.data.datastore.GlobalAppSettings
import com.ethran.notable.data.db.Page
import com.ethran.notable.data.model.BackgroundType
import com.ethran.notable.editor.ui.PageMenu
import com.ethran.notable.editor.utils.autoEInkAnimationOnScroll
import com.ethran.notable.ui.noRippleClickable
Expand All @@ -40,7 +37,6 @@ import io.shipbook.shipbooksdk.ShipBook

private val logPagesRow = ShipBook.getLogger("QuickNav")

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun ShowPagesRow(
singlePages: List<Page>?,
Expand Down Expand Up @@ -93,14 +89,10 @@ fun ShowPagesRow(
.aspectRatio(3f / 4f)
.border(1.dp, Color.Gray, RectangleShape)
.noRippleClickable {
val page = Page(
notebookId = null,
background = GlobalAppSettings.current.defaultNativeTemplate,
backgroundType = BackgroundType.Native.key,
parentFolderId = folderId
)
appRepository.pageRepository.create(page)
navController.navigate("pages/${page.id}")
val pageId =
appRepository.createNewQuickPage(parentFolderId = folderId)
?: return@noRippleClickable
navController.navigate("pages/${pageId}")
}) {
Icon(
imageVector = FeatherIcons.FilePlus,
Expand Down
10 changes: 1 addition & 9 deletions app/src/main/java/com/ethran/notable/ui/views/PagesView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,7 @@ fun PagesView(navController: NavController, bookId: String) {
onDelete = { pendingDeletePageId = pageId },
onDuplicate = { appRepository.duplicatePage(pageId) },
onAddAfter = {
val bookNow =
appRepository.bookRepository.getById(bookId) ?: return@PageCard
val newPg = bookNow.newPage()
appRepository.pageRepository.create(newPg)
appRepository.bookRepository.addPage(
bookId,
newPg.id,
pageIndex + 1
)
appRepository.newPageInBook(bookId, pageIndex + 1)
}
)
}
Expand Down
Loading