-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync current page in reader. Closes #124
Upping versionCode to 68
- Loading branch information
1 parent
b3fb421
commit 3f50597
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
app/src/main/java/org/zotero/android/database/requests/StorePageForItemDbRequest.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,39 @@ | ||
package org.zotero.android.database.requests | ||
|
||
import io.realm.Realm | ||
import io.realm.kotlin.createObject | ||
import io.realm.kotlin.where | ||
import org.zotero.android.database.DbRequest | ||
import org.zotero.android.database.objects.RObjectChange | ||
import org.zotero.android.database.objects.RPageIndex | ||
import org.zotero.android.database.objects.RPageIndexChanges | ||
import org.zotero.android.database.objects.UpdatableChangeType | ||
import org.zotero.android.sync.LibraryIdentifier | ||
|
||
class StorePageForItemDbRequest( | ||
private val key: String, | ||
private val libraryId: LibraryIdentifier, | ||
private val page: String, | ||
): DbRequest { | ||
override val needsWrite: Boolean | ||
get() = true | ||
|
||
override fun process(database: Realm) { | ||
val pageIndex: RPageIndex | ||
val existing = database.where<RPageIndex>().key(this.key, this.libraryId).findFirst() | ||
if (existing != null) { | ||
if (existing.index == this.page) { | ||
return | ||
} | ||
pageIndex = existing | ||
} else { | ||
pageIndex = database.createObject<RPageIndex>() | ||
pageIndex.key = this.key | ||
pageIndex.libraryId = this.libraryId | ||
} | ||
|
||
pageIndex.index = this.page | ||
pageIndex.changes.add(RObjectChange.create(listOf(RPageIndexChanges.index))) | ||
pageIndex.changeType = UpdatableChangeType.user.name | ||
} | ||
} |
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