forked from orgzly-revived/orgzly-android-revived
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue orgzly-revived#174: Parse book properties contained in preface
This presupposes orgzly-revived/org-java#6. Linking to notebooks via their "ID" property now works. I did not touch the handling of the preface, so the book properties are visible as part of the preface content. This means they can be shown and edited in Orgzly without changing the current GUI. It feels a bit hacky, but it could be a first, simple implementation of book properties, which I suppose could later be improved by adding a "edit book properties" menu choice, similar to today's "edit preface". Book properties are stored in a separate DB table, just like note properties. They are only parsed and stored when loading books from files and when the preface has been edited.
- Loading branch information
Showing
18 changed files
with
1,748 additions
and
53 deletions.
There are no files selected for viewing
1,533 changes: 1,533 additions & 0 deletions
1,533
app/schemas/com.orgzly.android.db.OrgzlyDatabase/157.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
app/src/main/java/com/orgzly/android/db/dao/BookPropertyDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.orgzly.android.db.dao | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Query | ||
import androidx.room.Transaction | ||
import com.orgzly.android.db.entity.BookProperty | ||
|
||
@Dao | ||
abstract class BookPropertyDao : BaseDao<BookProperty> { | ||
|
||
@Query("SELECT * FROM book_properties WHERE book_id = :bookId") | ||
abstract fun get(bookId: Long): List<BookProperty> | ||
|
||
@Query("SELECT * FROM book_properties WHERE book_id = :bookId AND name = :name") | ||
abstract fun get(bookId: Long, name: String): List<BookProperty> | ||
|
||
@Query("SELECT * FROM book_properties") | ||
abstract fun getAll(): List<BookProperty> | ||
|
||
@Transaction | ||
open fun upsert(bookId: Long, name: String, value: String) { | ||
val properties = get(bookId, name) | ||
|
||
if (properties.isEmpty()) { | ||
// Insert new | ||
insert(BookProperty(bookId, name, value)) | ||
|
||
} else { | ||
// Update first | ||
update(properties.first().copy(value = value)) | ||
|
||
// Delete others | ||
for (i in 1 until properties.size) { | ||
delete(properties[i]) | ||
} | ||
} | ||
} | ||
|
||
@Query("DELETE FROM book_properties WHERE book_id = :bookId") | ||
abstract fun delete(bookId: Long) | ||
} |
34 changes: 34 additions & 0 deletions
34
app/src/main/java/com/orgzly/android/db/entity/BookProperty.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.orgzly.android.db.entity | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.Entity | ||
import androidx.room.ForeignKey | ||
import androidx.room.Index | ||
|
||
@Entity( | ||
tableName = "book_properties", | ||
|
||
primaryKeys = [ "book_id" ], | ||
|
||
foreignKeys = [ | ||
ForeignKey( | ||
entity = Book::class, | ||
parentColumns = arrayOf("id"), | ||
childColumns = arrayOf("book_id"), | ||
onDelete = ForeignKey.CASCADE) | ||
], | ||
|
||
indices = [ | ||
Index("book_id"), | ||
Index("name"), | ||
Index("value") | ||
] | ||
) | ||
data class BookProperty( | ||
@ColumnInfo(name = "book_id") | ||
val bookId: Long, | ||
|
||
val name: String, | ||
|
||
val value: String | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.