Skip to content

Commit

Permalink
Merge branch 'zotero:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
jjcoffee authored May 16, 2024
2 parents 320f7d6 + 986f049 commit 2b61aa1
Show file tree
Hide file tree
Showing 51 changed files with 3,601 additions and 215 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ jobs:
- name: Execute bundle_translators.py
run: python3 scripts/bundle_translators.py

- name: Grant execute permission for bundle_translation.py
run: chmod +x scripts/bundle_translation.py

- name: Execute bundle_translation.py
run: python3 scripts/bundle_translation.py

- name: Grant execute permission for gradlew
run: chmod +x gradlew

Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,8 @@ pspdfkit-key.txt
.externalNativeBuild
app/prod/release/
buildSrc/gradle/

#translaton and translator items generated files:
app/src/main/assets/translators/
app/src/main/assets/translation_commit_hash.txt
app/src/main/assets/translator.zip
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "translators"]
path = translators
url = https://github.com/zotero/translators.git
[submodule "translation/translate"]
path = translation/translate
url = https://github.com/zotero/translate.git
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ dependencies {
implementation(Libs.jodaTime)
implementation(Libs.eventBus)
implementation(Libs.keyboardVisibility)
implementation("com.google.android.gms:play-services-code-scanner:16.1.0")

}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/assets/timestamp.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1713182643
1715335209
Binary file removed app/src/main/assets/translator.zip
Binary file not shown.
18 changes: 9 additions & 9 deletions app/src/main/java/org/zotero/android/architecture/Defaults.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ open class Defaults @Inject constructor(
private val activeLineWidth = "activeLineWidth"
private val activeEraserSize = "activeEraserSize"
private val shareExtensionIncludeTags = "shareExtensionIncludeTags"
private val shouldUpdateTranslator = "shouldUpdateTranslator"

private val lastTimestamp = "lastTimestamp"
private val lastTranslationCommitHash = "lastTranslationCommitHash"
private val lastTranslatorCommitHash = "lastTranslatorCommitHash"
private val lastTranslatorDeleted = "lastTranslatorDeleted"
private val lastStylesCommitHash = "lastStylesCommitHash"
Expand Down Expand Up @@ -257,14 +257,6 @@ open class Defaults @Inject constructor(
return sharedPreferences.getBoolean(wasPspdfkitInitialized, false)
}

fun setShouldUpdateTranslator(newValue: Boolean) {
sharedPreferences.edit { putBoolean(shouldUpdateTranslator, newValue) }
}

fun shouldUpdateTranslator(): Boolean {
return sharedPreferences.getBoolean(shouldUpdateTranslator, true)
}

fun setLastTimestamp(newValue: Long) {
sharedPreferences.edit { putLong(lastTimestamp, newValue) }
}
Expand All @@ -281,6 +273,14 @@ open class Defaults @Inject constructor(
return sharedPreferences.getString(lastTranslatorCommitHash, "") ?: ""
}

fun setLastTranslationCommitHash(newValue: String) {
sharedPreferences.edit { putString(lastTranslationCommitHash, newValue) }
}

fun getLastTranslationCommitHash(): String {
return sharedPreferences.getString(lastTranslationCommitHash, "") ?: ""
}

fun getLastTranslatorDeleted(): Long {
return sharedPreferences.getLong(lastTranslatorDeleted, 0L)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.zotero.android.screens.mediaviewer.video.VideoPlayerArgs
import org.zotero.android.screens.share.sharecollectionpicker.data.ShareCollectionPickerArgs
import org.zotero.android.screens.sortpicker.data.SortPickerArgs
import org.zotero.android.screens.tagpicker.data.TagPickerArgs
import org.zotero.android.uicomponents.addbyidentifier.data.AddByIdentifierPickerArgs
import org.zotero.android.uicomponents.singlepicker.SinglePickerArgs

object ScreenArguments {
Expand All @@ -42,4 +43,5 @@ object ScreenArguments {
lateinit var pdfAnnotationEditPageArgs: PdfAnnotationEditPageArgs
lateinit var pdfReaderColorPickerArgs: PdfReaderColorPickerArgs
lateinit var shareCollectionPickerArgs: ShareCollectionPickerArgs
lateinit var addByIdentifierPickerArgs: AddByIdentifierPickerArgs
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import org.zotero.android.screens.settings.toSettingsScreen
import org.zotero.android.screens.sortpicker.sortPickerNavScreens
import org.zotero.android.screens.sortpicker.toSortPicker
import org.zotero.android.screens.tagpicker.TagPickerScreen
import org.zotero.android.uicomponents.addbyidentifier.AddByIdentifierScreen
import org.zotero.android.uicomponents.addbyidentifier.ui.AddByIdentifierScreen
import org.zotero.android.uicomponents.navigation.ZoteroNavHost
import org.zotero.android.uicomponents.singlepicker.SinglePickerScreen
import org.zotero.android.uicomponents.theme.CustomTheme
Expand Down Expand Up @@ -176,7 +176,7 @@ internal fun DashboardRootPhoneNavigation(
arguments = listOf(),
) {
AddByIdentifierScreen(
onCancel = navigation::onBack,
onClose = navigation::onBack,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.zotero.android.screens.collectionpicker.CollectionPickerScreen
import org.zotero.android.screens.creatoredit.CreatorEditNavigation
import org.zotero.android.screens.sortpicker.SortPickerNavigation
import org.zotero.android.screens.tagpicker.TagPickerScreen
import org.zotero.android.uicomponents.addbyidentifier.AddByIdentifierScreen
import org.zotero.android.uicomponents.addbyidentifier.ui.AddByIdentifierScreen
import org.zotero.android.uicomponents.navigation.ZoteroNavHost
import org.zotero.android.uicomponents.singlepicker.SinglePickerScreen
import java.io.File
Expand Down Expand Up @@ -113,7 +113,7 @@ internal fun TabletRightPaneNavigation(
route = TabletRightPaneDestinations.ADD_BY_IDENTIFIER_DIALOG,
) {
AddByIdentifierScreen(
onCancel = {
onClose = {
navController.popBackStack()
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ class RemoteAttachmentDownloader @Inject constructor(
private var operations = mutableMapOf<Download, RemoteAttachmentDownloadOperation>()
private var errors = mutableMapOf<Download, Throwable>()
private var coroutineScope = CoroutineScope(dispatcher)
private var batchProgress: AttachmentBatchProgress = AttachmentBatchProgress()
private var totalBatchCount: Int = 0

val batchData: Triple<Int?, Int, Int>
get() {
val progress = this.batchProgress.currentProgress
val remainingBatchCount = this.operations.size
val totalBatchCount = this.totalBatchCount
return Triple(progress, remainingBatchCount, totalBatchCount)
}

fun data(key: String, parentKey: String, libraryId: LibraryIdentifier): Pair<Int?, Throwable?> {
val download = Download(key = key, parentKey = parentKey, libraryId = libraryId)
Expand Down Expand Up @@ -97,6 +107,7 @@ class RemoteAttachmentDownloader @Inject constructor(

operation.onDownloadProgressUpdated = object : OnDownloadProgressUpdated {
override fun onProgressUpdated(progressInHundreds: Int) {
batchProgress.updateProgress(attachment.key, progressInHundreds)
attachmentDownloaderEventStream.emitAsync(
Update(
download = download, kind = Update.Kind.progress(
Expand All @@ -113,7 +124,10 @@ class RemoteAttachmentDownloader @Inject constructor(
result = result
)
}
this.errors.remove(download)
this.operations[download] = operation
this.totalBatchCount += 1

return operation
}

Expand All @@ -140,6 +154,7 @@ class RemoteAttachmentDownloader @Inject constructor(
result: CustomResult<Unit>
) {
this.operations.remove(download)
resetBatchDataIfNeeded()
when (result) {
is CustomResult.GeneralError.CodeError -> {
Timber.e(
Expand Down Expand Up @@ -170,6 +185,20 @@ class RemoteAttachmentDownloader @Inject constructor(
)
}
}
is CustomResult.GeneralError.NetworkError -> {
this.errors[download] = Exception(result.stringResponse)
Timber.e(
result.stringResponse,
"RemoteAttachmentDownloader: failed to download attachment ${download.key}, ${download.libraryId}"
)
attachmentDownloaderEventStream.emitAsync(
Update(
download = download,
kind = Update.Kind.failed
)
)
}

is CustomResult.GeneralSuccess -> {
Timber.i("RemoteAttachmentDownloader: finished downloading ${download.key}")

Expand All @@ -182,4 +211,17 @@ class RemoteAttachmentDownloader @Inject constructor(
}
}

private fun resetBatchDataIfNeeded() {
if (this.operations.isEmpty()) {
this.batchProgress = AttachmentBatchProgress()
this.totalBatchCount = 0
}
}

fun stop() {
operations.forEach {
it.value.cancel()
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.zotero.android.database.requests

import io.realm.Realm
import org.zotero.android.api.pojo.sync.ItemResponse
import org.zotero.android.database.DbRequest
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.SchemaController

class CreateTranslatedItemsDbRequest(
private val responses: List<ItemResponse>,
private val schemaController: SchemaController,
private val dateParser: DateParser,
) : DbRequest {

override val needsWrite: Boolean
get() = true

override fun process(database: Realm) {
for (response in this.responses) {
val (item, _) = StoreItemDbRequest(
response = response,
schemaController = this.schemaController,
dateParser = this.dateParser,
preferRemoteData = true,
denyIncorrectCreator = false
)
.process(database)

item.changeType = UpdatableChangeType.user.name
for (field in item.fields) {
field.changed = true
}

val changes: MutableList<RItemChanges> = mutableListOf(
RItemChanges.type,
RItemChanges.fields,
RItemChanges.trash,
RItemChanges.tags
)
if (!item.collections!!.isEmpty()) {
changes.add(RItemChanges.collections)
}
if (!item.relations.isEmpty()) {
changes.add(RItemChanges.relations)
}
if (!item.creators.isEmpty()) {
changes.add(RItemChanges.creators)
}
if (!item.tags!!.isEmpty()) {
changes.add(RItemChanges.tags)
}
item.changes.add(RObjectChange.create(changes = changes))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import org.zotero.android.architecture.ui.CustomLayoutSize
import org.zotero.android.screens.downloadedfiles.DownloadedFilesPopup
import org.zotero.android.uicomponents.Drawables
import org.zotero.android.uicomponents.icon.IconWithPadding
import org.zotero.android.uicomponents.misc.NewDivider
Expand Down Expand Up @@ -134,20 +135,30 @@ private fun BottomPanel(
viewModel.showSortPicker()
}
)
val filterDrawable =
if (viewState.filters.isEmpty()) {
Drawables.filter_list_off_24px
} else {
Drawables.filter_list_24px
}
IconWithPadding(
modifier = Modifier
.padding(start = 20.dp)
.align(Alignment.CenterStart),
drawableRes = filterDrawable,
onClick = {
viewModel.showFilters()
Box {
if (viewState.showDownloadedFilesPopup) {
DownloadedFilesPopup(
viewState = viewState,
viewModel = viewModel,
)
}
)

val filterDrawable =
if (viewState.filters.isEmpty()) {
Drawables.filter_list_off_24px
} else {
Drawables.filter_list_24px
}
IconWithPadding(
modifier = Modifier
.padding(start = 20.dp)
.align(Alignment.CenterStart),
drawableRes = filterDrawable,
onClick = {
viewModel.showFilters()
}
)
}

}
}
Loading

0 comments on commit 2b61aa1

Please sign in to comment.