Skip to content

Commit

Permalink
Submit logic for Share Screen,
Browse files Browse the repository at this point in the history
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
Dima-Android committed Mar 29, 2024
1 parent 0ccff46 commit ddd7f65
Show file tree
Hide file tree
Showing 11 changed files with 660 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,16 @@ data class CreatorResponse(
val firstName: String?,
val lastName: String?,
val name: String?,
)
) {
val summaryName: String? get() {
val name = this.name
if (name != null) {
return name
}
val lastName = this.lastName
if (lastName != null) {
return lastName
}
return this.firstName
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.zotero.android.database.objects.ItemTypes
import org.zotero.android.helpers.formatter.iso8601DateFormat
import org.zotero.android.ktx.rounded
import org.zotero.android.ktx.unmarshalList
import org.zotero.android.sync.LibraryIdentifier
import org.zotero.android.sync.LinkMode
import org.zotero.android.sync.SchemaController
import org.zotero.android.sync.SchemaError
Expand Down Expand Up @@ -309,8 +310,35 @@ data class ItemResponse(

return rects to paths
}
}


fun copy(
libraryId: LibraryIdentifier,
collectionKeys: Set<String>,
tags: List<TagResponse>
): ItemResponse {
return ItemResponse(
rawType = this.rawType,
key = this.key,
library = LibraryResponse.init(libraryId = libraryId),
parentKey = this.parentKey,
collectionKeys = collectionKeys,
links = this.links,
parsedDate = this.parsedDate,
isTrash = this.isTrash,
version = this.version,
dateModified = this.dateModified,
dateAdded = this.dateAdded,
fields = this.fields,
tags = tags,
creators = this.creators,
relations = this.relations,
createdBy = this.createdBy,
lastModifiedBy = this.lastModifiedBy,
rects = this.rects,
paths = this.paths,
inPublications = false,
)
}

val copyWithAutomaticTags: ItemResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,29 @@ data class LibraryResponse(
val links: LinksResponse?
) {

companion object {
fun init(libraryId: LibraryIdentifier): LibraryResponse {
val id: Int
val type: String
when (libraryId) {
is LibraryIdentifier.custom -> {
id = 0
type = "user"
}
is LibraryIdentifier.group -> {
id = libraryId.groupId
type = "group"
}
}
return LibraryResponse(
name = "",
links = null,
id = id,
type = type,
)
}
}

val libraryId: LibraryIdentifier?
get() {
return when (this.type) {
Expand Down
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

}

}
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()
}
}
Loading

0 comments on commit ddd7f65

Please sign in to comment.