-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #442 from amberin/174-id-links-for-notebooks-dont-…
…work Parse notebook properties and allow linking to notebooks
- Loading branch information
Showing
21 changed files
with
1,842 additions
and
66 deletions.
There are no files selected for viewing
1,534 changes: 1,534 additions & 0 deletions
1,534
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
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 LOWER(name) = LOWER(: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) | ||
} |
Oops, something went wrong.