-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b379cca
commit d413903
Showing
50 changed files
with
2,531 additions
and
127 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1715335209 | ||
1738586822 |
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
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
80 changes: 80 additions & 0 deletions
80
...src/main/java/org/zotero/android/database/requests/LinkAttachmentToParentItemDbRequest.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,80 @@ | ||
package org.zotero.android.database.requests | ||
|
||
import io.realm.Realm | ||
import io.realm.kotlin.where | ||
import org.zotero.android.api.pojo.sync.KeyBaseKeyPair | ||
import org.zotero.android.database.DbRequest | ||
import org.zotero.android.database.objects.FieldKeys | ||
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.database.objects.UpdatableChangeType | ||
import org.zotero.android.sync.DateParser | ||
import org.zotero.android.sync.LibraryIdentifier | ||
import org.zotero.android.sync.SchemaController | ||
import timber.log.Timber | ||
import java.util.Date | ||
|
||
class LinkAttachmentToParentItemDbRequest( | ||
private val schemaController: SchemaController, | ||
private val dateParser: DateParser, | ||
private val libraryId: LibraryIdentifier, | ||
private val itemKey: String, | ||
private val parentItemKey: String | ||
): DbRequest { | ||
override val needsWrite: Boolean | ||
get() = true | ||
|
||
override fun process(database: Realm) { | ||
val item = database | ||
.where<RItem>() | ||
.key(this.itemKey, this.libraryId) | ||
.findFirst()!! | ||
val parentItem = database | ||
.where<RItem>() | ||
.key(this.parentItemKey, this.libraryId) | ||
.findFirst()!! | ||
|
||
item.parent = parentItem | ||
|
||
for (collection in item.collections!! | ||
.where() | ||
.findAll()) { | ||
val index = collection.items.indexOf(item) | ||
if (index == -1) { | ||
continue | ||
} | ||
collection.items.removeAt(index) | ||
} | ||
|
||
val key = this.schemaController.titleKey(item.rawType) | ||
if (key == null) { | ||
Timber.e("LinkAttachmentToParentItemDbRequest: schema controller doesn't contain title key for item type ${item.rawType}") | ||
return | ||
} | ||
|
||
val keyPair = KeyBaseKeyPair( | ||
key = key, | ||
baseKey = (if (key != FieldKeys.Item.title) FieldKeys.Item.title else null) | ||
) | ||
|
||
EditItemFieldsDbRequest( | ||
key = itemKey, | ||
libraryId = libraryId, | ||
fieldValues = mapOf(keyPair to "PDF"), | ||
dateParser = dateParser | ||
).process(database) | ||
|
||
item.changes.add( | ||
RObjectChange.create( | ||
changes = listOf( | ||
RItemChanges.collections, | ||
RItemChanges.parent, | ||
RItemChanges.fields | ||
) | ||
) | ||
) | ||
item.changeType = UpdatableChangeType.user.name | ||
item.dateModified = Date() | ||
} | ||
} |
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.