-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Displaying selected collection or library in the list of collections available to choose from. UploadData for generating and containing all the info necessary for uploading file attachments FilenameFormatter for generating valid filename based on ItemResponse. New DBRequests: CreateBackendItemDbRequest UpdateCollectionLastUsedDbRequest
- Loading branch information
1 parent
0ccff46
commit ddd7f65
Showing
11 changed files
with
660 additions
and
19 deletions.
There are no files selected for viewing
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
52 changes: 52 additions & 0 deletions
52
app/src/main/java/org/zotero/android/database/requests/CreateBackendItemDbRequest.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,52 @@ | ||
package org.zotero.android.database.requests | ||
|
||
import io.realm.Realm | ||
import io.realm.kotlin.where | ||
import org.zotero.android.api.pojo.sync.ItemResponse | ||
import org.zotero.android.database.DbError | ||
import org.zotero.android.database.DbResponseRequest | ||
import org.zotero.android.database.objects.RItem | ||
import org.zotero.android.database.objects.RItemChanges | ||
import org.zotero.android.database.objects.RObjectChange | ||
import org.zotero.android.sync.DateParser | ||
import org.zotero.android.sync.SchemaController | ||
|
||
class CreateBackendItemDbRequest( | ||
private val item: ItemResponse, | ||
private val schemaController: SchemaController, | ||
private val dateParser: DateParser, | ||
) : DbResponseRequest<RItem> { | ||
override val needsWrite: Boolean | ||
get() = true | ||
|
||
override fun process(database: Realm): RItem { | ||
val libraryId = this.item.library.libraryId ?: throw DbError.objectNotFound | ||
|
||
StoreItemsDbResponseRequest( | ||
responses = listOf(this.item), | ||
schemaController = this.schemaController, | ||
dateParser = this.dateParser, | ||
preferResponseData = true, | ||
denyIncorrectCreator = false | ||
) | ||
.process(database) | ||
val item = database.where<RItem>().key(this.item.key, libraryId).findFirst() | ||
if (item == null) { | ||
throw DbError.objectNotFound | ||
} | ||
val changes = listOf( | ||
RItemChanges.type, | ||
RItemChanges.trash, | ||
RItemChanges.collections, | ||
RItemChanges.fields, | ||
RItemChanges.tags, | ||
RItemChanges.creators | ||
) | ||
item.changes.add(RObjectChange.create(changes = changes)) | ||
item.fields.forEach { it.changed = true } | ||
|
||
return item | ||
|
||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
app/src/main/java/org/zotero/android/database/requests/UpdateCollectionLastUsedDbRequest.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,21 @@ | ||
package org.zotero.android.database.requests | ||
|
||
import io.realm.Realm | ||
import io.realm.kotlin.where | ||
import org.zotero.android.database.DbRequest | ||
import org.zotero.android.database.objects.RCollection | ||
import org.zotero.android.sync.LibraryIdentifier | ||
import java.util.Date | ||
|
||
class UpdateCollectionLastUsedDbRequest( | ||
private val key: String, | ||
private val libraryId: LibraryIdentifier, | ||
): DbRequest { | ||
override val needsWrite: Boolean | ||
get() = true | ||
|
||
override fun process(database: Realm) { | ||
val collection = database.where<RCollection>().key(this.key, this.libraryId).findFirst() ?: return | ||
collection.lastUsed = Date() | ||
} | ||
} |
Oops, something went wrong.