Skip to content

Commit

Permalink
Remaining logic for updating translator items from bundle,
Browse files Browse the repository at this point in the history
Updating android.yml to support recursive checkout, set up Python, execute bundle_translators.py
Fixing ItemResponseMapper not correctly handling CURRENT_DATE date coming from translator items.
Fixing translator JS code not being loaded due to translator being moved from assets to internal folder hence requiring WebView to have a few settings adjustments.
Adding a new Database to save Translators and later Styles.
Adding a way to find a named group in a Matcher when parsing translator items for OS older than Android 7.
Uncommenting parts of AndroidManifest & RootViewModel to make ShareScreen accessible for share actions.
Color improvements for ShareScreen
Upping versionCode to 56
  • Loading branch information
Dima-Android committed Apr 19, 2024
1 parent e694dd7 commit 3422d92
Show file tree
Hide file tree
Showing 22 changed files with 409 additions and 58 deletions.
19 changes: 16 additions & 3 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: recursive
- name: set up JDK
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'zulu'
cache: gradle

- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Writing PSPDFKIT's key into a file to be then picked up by gradle.
run: echo ${{secrets.PSPDFKIT_KEY}} | sed 's/./& /g' > pspdfkit-key.txt
Expand All @@ -35,6 +39,15 @@ jobs:
- name: Decrypt Keystore secrets
run: openssl aes-256-cbc -d -in .github/keystore-secrets.cipher -k ${{secrets.SIGNING_KEY}} -md sha256 > keystore-secrets.txt

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

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

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

- name: Download Android dependencies
run: ./gradlew androidDependencies --no-configuration-cache

Expand Down
28 changes: 15 additions & 13 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,21 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.VIEW" />-->
<!-- <category android:name="android.intent.category.DEFAULT" />-->
<!-- <category android:name="android.intent.category.BROWSABLE" />-->

<!-- &lt;!&ndash; <data android:scheme="http" />&ndash;&gt;-->
<!-- <data android:scheme="https" android:host="*"/>-->
<!-- </intent-filter>-->
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.SEND" />-->
<!-- <category android:name="android.intent.category.DEFAULT" />-->
<!-- <data android:mimeType="*/*" />-->
<!-- </intent-filter>-->
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="*"
android:scheme="https" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
</activity>

<activity
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/org/zotero/android/api/BundleDataDb.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.zotero.android.api;

import static java.lang.annotation.RetentionPolicy.CLASS;

import java.lang.annotation.Retention;

import javax.inject.Qualifier;

@Qualifier
@Retention(CLASS)
public @interface BundleDataDb {
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ class ItemResponseMapper @Inject constructor(
val key = KeyGenerator.newKey()
val rawType = response["itemType"].asString
val accessDate =
response["accessDate"]?.asString?.let { iso8601DateFormatV2.parse(it) } ?: Date()
response["accessDate"]?.asString?.let {
try {
iso8601DateFormatV2.parse(it)
} catch (e: Exception) {
Date()
}
} ?: Date()
val tags = response["tags"]?.asJsonArray ?: JsonArray()
val creators = response["creators"]?.asJsonArray ?: JsonArray()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import dagger.Module
import dagger.Provides
import dagger.hilt.migration.DisableInstallInCheck
import kotlinx.serialization.json.Json
import org.zotero.android.api.BundleDataDb
import org.zotero.android.api.ForGsonWithRoundedDecimals
import org.zotero.android.api.network.InternetConnectionStatusManager
import org.zotero.android.api.network.internetConnectionStatus
Expand Down Expand Up @@ -84,4 +85,12 @@ object GeneralModule {
): DbWrapper {
return DbWrapper()
}

@Provides
@Singleton
@BundleDataDb
fun provideBundleDataDbWrapper(
): DbWrapper {
return DbWrapper()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.google.gson.JsonObject
import org.zotero.android.database.objects.AnnotationType
import org.zotero.android.database.objects.FieldKeys
import org.zotero.android.database.objects.ItemTypes
import org.zotero.android.helpers.formatter.iso8601DateFormat
import org.zotero.android.helpers.formatter.iso8601DateFormatV2
import org.zotero.android.ktx.rounded
import org.zotero.android.ktx.unmarshalList
import org.zotero.android.sync.LibraryIdentifier
Expand Down Expand Up @@ -98,7 +98,7 @@ data class ItemResponse(

FieldKeys.Item.accessDate -> {
if (value == "CURRENT_TIMESTAMP") {
value = iso8601DateFormat.format(Date())
value = iso8601DateFormatV2.format(Date())
}
fields[KeyBaseKeyPair(key = objectS.key, baseKey = null)] = value

Expand Down
37 changes: 37 additions & 0 deletions app/src/main/java/org/zotero/android/architecture/Defaults.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ open class Defaults @Inject constructor(
private val shareExtensionIncludeTags = "shareExtensionIncludeTags"
private val shouldUpdateTranslator = "shouldUpdateTranslator"

private val lastTimestamp = "lastTimestamp"
private val lastTranslatorCommitHash = "lastTranslatorCommitHash"
private val lastTranslatorDeleted = "lastTranslatorDeleted"
private val lastStylesCommitHash = "lastStylesCommitHash"

private val sharedPreferences: SharedPreferences by lazy {
context.getSharedPreferences(
sharedPrefsFile,
Expand Down Expand Up @@ -260,6 +265,38 @@ open class Defaults @Inject constructor(
return sharedPreferences.getBoolean(shouldUpdateTranslator, true)
}

fun setLastTimestamp(newValue: Long) {
sharedPreferences.edit { putLong(lastTimestamp, newValue) }
}

fun getLastTimestamp(): Long {
return sharedPreferences.getLong(lastTimestamp, 0L)
}

fun setLastTranslatorCommitHash(newValue: String) {
sharedPreferences.edit { putString(lastTranslatorCommitHash, newValue) }
}

fun getLastTranslatorCommitHash(): String {
return sharedPreferences.getString(lastTranslatorCommitHash, "") ?: ""
}

fun getLastTranslatorDeleted(): Long {
return sharedPreferences.getLong(lastTranslatorDeleted, 0L)
}

fun setLastTranslatorDeleted(newValue: Long) {
sharedPreferences.edit { putLong(lastTranslatorDeleted, newValue) }
}

fun setLastStylesCommitHash(newValue: String) {
sharedPreferences.edit { putString(lastStylesCommitHash, newValue) }
}

fun getLastStylesCommitHash(): String {
return sharedPreferences.getString(lastStylesCommitHash, "") ?: ""
}

fun reset() {
setUsername("")
setDisplayName("")
Expand Down
18 changes: 14 additions & 4 deletions app/src/main/java/org/zotero/android/database/Database.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
package org.zotero.android.database

import android.content.Context
import io.realm.Realm
import io.realm.RealmConfiguration
import org.zotero.android.files.FileStore
import java.io.File

class Database {
companion object {
private const val schemaVersion = 1L //From now on must only increase by 1 whenever db schema changes

fun mainConfiguration(dbFile: File, context: Context): RealmConfiguration {
Realm.init(context)
fun mainConfiguration(dbFile: File): RealmConfiguration {
val builder = RealmConfiguration.Builder()
.directory(dbFile.parentFile!!)
.name(dbFile.name)
.schemaVersion(schemaVersion)
.allowWritesOnUiThread(true)
.deleteRealmIfMigrationNeeded()

return builder.build()
}

fun bundledDataConfiguration(fileStorage: FileStore): RealmConfiguration {
val dbFile = fileStorage.bundledDataDbFile()
val builder = RealmConfiguration.Builder()
.directory(dbFile.parentFile!!)
.name(dbFile.name)
Expand Down
12 changes: 9 additions & 3 deletions app/src/main/java/org/zotero/android/database/DbWrapper.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.zotero.android.database

import android.content.Context
import io.realm.Realm
import io.realm.RealmConfiguration
import org.zotero.android.files.FileStore
import java.io.File

class DbWrapper constructor() {
Expand All @@ -11,8 +11,14 @@ class DbWrapper constructor() {
lateinit var config: RealmConfiguration
var isInitialized = false

fun initWithMainConfiguration(context: Context, dbFile: File) {
config = Database.mainConfiguration(dbFile = dbFile, context = context)
fun initWithMainConfiguration(dbFile: File) {
config = Database.mainConfiguration(dbFile = dbFile)
realmDbStorage = RealmDbStorage(config = config)
isInitialized = true
}

fun initBundleDataConfiguration(fileStorage: FileStore) {
config = Database.bundledDataConfiguration(fileStorage)
realmDbStorage = RealmDbStorage(config = config)
isInitialized = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SyncTranslatorsDbRequest(
if (existing != null) {
if (
this.forceUpdate
|| existing.lastUpdated < metadata.lastUpdated
|| existing.lastUpdated < metadata.lastUpdatedDate
|| !fileStore.translator(
metadata.id
).exists()
Expand All @@ -49,7 +49,7 @@ class SyncTranslatorsDbRequest(
} else {
rMetadata = database.createObject<RTranslatorMetadata>(metadata.id)
}
rMetadata.lastUpdated = metadata.lastUpdated
rMetadata.lastUpdated = metadata.lastUpdatedDate
update.add(metadata.id to metadata.fileName)
}
return update
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/org/zotero/android/files/FileStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ class FileStore @Inject constructor (
return File(dbDir, "maindb_$userId.realm")
}

fun bundledDataDbFile(): File {
val dbDir = File(getRootDirectory(), "database")
dbDir.mkdirs()
return File(dbDir, "translators.realm")
}

private fun initializeDirectories() {
val filesDir = context.filesDir
rootDirectory = filesDir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class RootViewModel @Inject constructor(
fun init() {
if (!sessionController.isLoggedIn) {
triggerEffect(RootViewEffect.NavigateToSignIn)
// } else if (stateHandle.keys().isNotEmpty()) {
// triggerEffect(RootViewEffect.NavigateToShare)
} else if (stateHandle.keys().isNotEmpty()) {
triggerEffect(RootViewEffect.NavigateToShare)
} else {
triggerEffect(RootViewEffect.NavigateToDashboard)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private fun BoxScope.ShareBottomProgressContainer(message: String, showActivityI
if (showActivityIndicator) {
CircularProgressIndicator(
modifier = Modifier.size(24.dp),
color = CustomPalette.DarkGrayColor,
color = CustomTheme.colors.secondaryContent,
strokeWidth = 2.dp,
)
Spacer(modifier = Modifier.width(16.dp))
Expand All @@ -98,7 +98,7 @@ private fun BoxScope.ShareBottomProgressContainer(message: String, showActivityI
modifier = Modifier,
text = message,
style = CustomTheme.typography.newBody,
color = CustomPalette.DarkGrayColor,
color = CustomTheme.colors.secondaryContent,
)
}

Expand All @@ -122,17 +122,19 @@ private fun ShareFailureLabel(
AttachmentState.Error.downloadedFileNotPdf, AttachmentState.Error.apiFailure -> {
textAlignment = TextAlign.Center
}

is AttachmentState.Error.quotaLimit -> {
textAlignment = TextAlign.Left
}

else -> {
if (!hasItem) {
message += "\n" + stringResource(id = Strings.errors_shareext_failed_additional)
}
textAlignment = TextAlign.Center
}
}
textColor = CustomPalette.DarkGrayColor
textColor = CustomTheme.colors.secondaryContent
}

Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,6 @@ internal class ShareViewModel @Inject constructor(
}
}
}

//TODO implement download
}

private fun processDownload(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package org.zotero.android.screens.share.data

import org.zotero.android.helpers.formatter.sqlFormat
import java.util.Date

data class TranslatorMetadata(
val id: String,
val lastUpdated: Date,
val lastUpdated: String,
val fileName: String
)
) {
val lastUpdatedDate: Date
get() {
return sqlFormat.parse(lastUpdated)!!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ package org.zotero.android.screens.share.navigation
import androidx.activity.compose.LocalOnBackPressedDispatcherOwner
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavHostController
import com.google.accompanist.insets.navigationBarsPadding
Expand All @@ -31,15 +27,14 @@ internal fun ShareRootNavigation(
val navigation = remember(navController) {
ZoteroNavigation(navController, dispatcher)
}
val context = LocalContext.current
val layoutType = CustomLayoutSize.calculateLayoutType()
if (layoutType.isTablet()) {
Box(modifier = Modifier.fillMaxSize()) {
Column(
modifier = Modifier
.fillMaxWidth(0.7f)
.fillMaxHeight(0.6f)
.align(Alignment.Center)
// .fillMaxWidth(0.7f)
// .fillMaxHeight(0.6f)
// .align(Alignment.Center)
) {
ShareRootNavHost(navController, navigation)
}
Expand Down
Loading

0 comments on commit 3422d92

Please sign in to comment.