-
-
Notifications
You must be signed in to change notification settings - Fork 22
Deep Links And PKM integration #196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e70000a
28f1196
d57ed16
83ebc43
16f88a7
59adf48
8eda750
f05375d
0499e09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,12 +31,15 @@ import java.util.UUID | |
| )] | ||
| ) | ||
| data class Page( | ||
| @PrimaryKey val id: String = UUID.randomUUID().toString(), val scroll: Int = 0, | ||
| @PrimaryKey val id: String = UUID.randomUUID().toString(), | ||
| val name: String? = null, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this the only think that changed in db, that requires migration? I don't see exactly why its needed, where its used. For now, I mostly generated page names to contain "quick pages" or page number in notebook. It might be useful to have names for separate pages in notebook, but for now I don't see a need for it.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quick pages don't have names and can pile up without us understanding what's under the hood. Previous logic works quite well and this doesn't change anything for the end user. If they want to rename manually, then they can. Else, it is exactly the same. And doesn't disrupt older database either.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, seems ok. |
||
| val scroll: Int = 0, | ||
| @ColumnInfo(index = true) val notebookId: String? = null, | ||
| @ColumnInfo(defaultValue = "blank") val background: String = "blank", // path or native subtype | ||
| @ColumnInfo(defaultValue = "native") val backgroundType: String = "native", // image, imageRepeating, coverImage, native | ||
| @ColumnInfo(index = true) val parentFolderId: String? = null, | ||
| val createdAt: Date = Date(), val updatedAt: Date = Date() | ||
| val createdAt: Date = Date(), | ||
| val updatedAt: Date = Date() | ||
| ) | ||
|
|
||
| data class PageWithStrokes( | ||
|
|
@@ -58,6 +61,9 @@ interface PageDao { | |
| @Query("SELECT * FROM page WHERE id IN (:ids)") | ||
| fun getByIds(ids: List<String>): List<Page> | ||
|
|
||
| @Query("SELECT * FROM page") | ||
| fun getAll(): List<Page> | ||
|
|
||
| @Query("SELECT * FROM page WHERE id = (:pageId)") | ||
| fun getById(pageId: String): Page? | ||
|
|
||
|
|
@@ -100,6 +106,10 @@ class PageRepository(context: Context) { | |
| return db.updateScroll(id, scroll) | ||
| } | ||
|
|
||
| fun getAll(): List<Page> { | ||
| return db.getAll() | ||
| } | ||
|
|
||
| fun getById(pageId: String): Page? { | ||
| return db.getById(pageId) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,19 +2,34 @@ package com.ethran.notable.editor.ui | |
|
|
||
| import androidx.compose.foundation.background | ||
| import androidx.compose.foundation.border | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Box | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.IntrinsicSize | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.width | ||
| import androidx.compose.foundation.text.BasicTextField | ||
| import androidx.compose.foundation.text.KeyboardActions | ||
| import androidx.compose.foundation.text.KeyboardOptions | ||
| import androidx.compose.material.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.runtime.setValue | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.graphics.Color | ||
| import androidx.compose.ui.graphics.RectangleShape | ||
| import androidx.compose.ui.platform.LocalContext | ||
| import androidx.compose.ui.text.TextStyle | ||
| import androidx.compose.ui.text.font.FontWeight | ||
| import androidx.compose.ui.text.input.ImeAction | ||
| import androidx.compose.ui.unit.dp | ||
| import androidx.compose.ui.unit.sp | ||
| import androidx.compose.ui.window.Dialog | ||
| import androidx.compose.ui.window.Popup | ||
| import androidx.compose.ui.window.PopupProperties | ||
| import com.ethran.notable.data.AppRepository | ||
|
|
@@ -33,6 +48,19 @@ fun PageMenu( | |
| ) { | ||
| val context = LocalContext.current | ||
| val appRepository = AppRepository(context) | ||
| var showRenameDialog by remember { mutableStateOf(false) } | ||
|
|
||
| if (showRenameDialog) { | ||
| PageRenameDialog( | ||
| pageId = pageId, | ||
| appRepository = appRepository, | ||
| onClose = { | ||
| showRenameDialog = false | ||
| onClose() | ||
| } | ||
| ) | ||
| return | ||
| } | ||
| Popup( | ||
| alignment = Alignment.TopStart, | ||
| onDismissRequest = { onClose() }, | ||
|
|
@@ -85,6 +113,15 @@ fun PageMenu( | |
| } | ||
| } | ||
|
|
||
| Box( | ||
| Modifier | ||
| .padding(10.dp) | ||
| .noRippleClickable { | ||
| showRenameDialog = true | ||
| }) { | ||
| Text("Rename") | ||
| } | ||
|
|
||
| Box( | ||
| Modifier | ||
| .padding(10.dp) | ||
|
|
@@ -107,3 +144,84 @@ fun PageMenu( | |
| } | ||
| } | ||
|
|
||
| @Composable | ||
| fun PageRenameDialog( | ||
| pageId: String, | ||
| appRepository: AppRepository, | ||
| onClose: () -> Unit | ||
| ) { | ||
| val page = remember { appRepository.pageRepository.getById(pageId) } | ||
| var pageName by remember { mutableStateOf(page?.name ?: "") } | ||
|
Comment on lines
+153
to
+154
|
||
|
|
||
| Dialog(onDismissRequest = onClose) { | ||
| Column( | ||
| modifier = Modifier | ||
| .background(Color.White) | ||
| .border(1.dp, Color.Black, RectangleShape) | ||
| .padding(24.dp), | ||
| verticalArrangement = Arrangement.spacedBy(12.dp), | ||
| horizontalAlignment = Alignment.CenterHorizontally | ||
| ) { | ||
| Text( | ||
| text = "Rename Page", | ||
| fontWeight = FontWeight.Bold, | ||
| fontSize = 20.sp | ||
| ) | ||
|
|
||
| BasicTextField( | ||
| value = pageName, | ||
| onValueChange = { pageName = it }, | ||
| textStyle = TextStyle(fontSize = 16.sp), | ||
| keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done), | ||
| keyboardActions = KeyboardActions( | ||
| onDone = { | ||
| page?.let { | ||
| appRepository.pageRepository.update(it.copy(name = pageName.ifBlank { null })) | ||
| } | ||
| onClose() | ||
| } | ||
| ), | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| .border(1.dp, Color.Gray, RectangleShape) | ||
| .padding(12.dp), | ||
| decorationBox = { innerTextField -> | ||
| Box { | ||
| if (pageName.isEmpty()) { | ||
| Text("Page name", color = Color.Gray) | ||
| } | ||
| innerTextField() | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| Row( | ||
| horizontalArrangement = Arrangement.spacedBy(16.dp), | ||
| modifier = Modifier.padding(top = 12.dp) | ||
| ) { | ||
| Box( | ||
| Modifier | ||
| .border(1.dp, Color.Black, RectangleShape) | ||
| .padding(horizontal = 16.dp, vertical = 8.dp) | ||
| .noRippleClickable { onClose() } | ||
| ) { | ||
| Text("Cancel") | ||
| } | ||
| Box( | ||
| Modifier | ||
| .border(1.dp, Color.Black, RectangleShape) | ||
| .padding(horizontal = 16.dp, vertical = 8.dp) | ||
| .noRippleClickable { | ||
| page?.let { | ||
| appRepository.pageRepository.update(it.copy(name = pageName.ifBlank { null })) | ||
| } | ||
| onClose() | ||
| } | ||
| ) { | ||
| Text("Save") | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The getByTitle query only returns one folder when multiple folders with the same title can exist. This will cause unpredictable behavior when creating pages in folders via deep links, as the query will arbitrarily select one matching folder. Consider using a combination of folder name and parent path to uniquely identify folders, or document that folder names must be unique in the documentation.