Skip to content

Commit

Permalink
- Budget sync for Google Drive suffered from 2 problems:
Browse files Browse the repository at this point in the history
1) saveFileContents was buggy since it erroneously used accountFolder instead of baseFolder
2) retrieving budget folder raised exception because property was not defined
- Report failure of retrieving budgets
  • Loading branch information
mtotschnig committed Dec 25, 2024
1 parent e5358af commit b41169d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ class GoogleDriveBackendProvider internal constructor(
maybeEncrypt: Boolean
) {
val base = if (toAccountDir) accountFolder else baseFolder
val driveFolder = if (folder == null) base else {
getResInAccountDir(folder) ?: driveServiceHelper.createFolder(
accountFolder.id,
val driveFolder = if (folder == null) base else {
driveServiceHelper.getFileByNameAndParent(base, folder) ?: driveServiceHelper.createFolder(
base.id,
folder,
null
)
Expand Down Expand Up @@ -387,12 +387,14 @@ class GoogleDriveBackendProvider internal constructor(
private const val LOCK_TOKEN_KEY = KEY_LOCK_TOKEN
private const val IS_BACKUP_FOLDER = "isBackupFolder"
private const val IS_ATTACHMENT_FOLDER = "isAttachmentFolder"
private const val IS_BUDGETS_FOLDER = "isBudgetsFolder"
const val IS_SYNC_FOLDER = "isSyncFolder"

private fun collectionPropertyKey(collectionName: String) =
when (collectionName) {
BACKUP_FOLDER_NAME -> IS_BACKUP_FOLDER
ATTACHMENT_FOLDER_NAME -> IS_ATTACHMENT_FOLDER
BUDGETS_FOLDER_NAME -> IS_BUDGETS_FOLDER
else -> throw NotImplementedError()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.rememberNestedScrollInteropConnection
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.isTraversalGroup
Expand All @@ -57,7 +56,6 @@ import org.totschnig.myexpenses.compose.ChipGroup
import org.totschnig.myexpenses.compose.ColoredAmountText
import org.totschnig.myexpenses.compose.DonutInABox
import org.totschnig.myexpenses.compose.LocalColors
import org.totschnig.myexpenses.compose.TEST_TAG_LIST
import org.totschnig.myexpenses.compose.conditional
import org.totschnig.myexpenses.compose.scrollbar.LazyColumnWithScrollbar
import org.totschnig.myexpenses.compose.simpleStickyHeader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ abstract class AbstractSyncBackendProvider<Res>(protected val context: Context)

override fun writeBudget(uuid: String, budget: BudgetExport): String {
val fileName = "$uuid.$extensionForData"
requireCollection(BUDGETS_FOLDER_NAME)
saveFileContents(
false,
BUDGETS_FOLDER_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import org.totschnig.myexpenses.provider.filter.Criterion
import org.totschnig.myexpenses.provider.filter.FilterPersistence
import org.totschnig.myexpenses.provider.getLong
import org.totschnig.myexpenses.sync.GenericAccountService
import org.totschnig.myexpenses.util.crashreporting.CrashHandler
import org.totschnig.myexpenses.util.enumValueOrDefault
import org.totschnig.myexpenses.viewmodel.BudgetViewModel2.Companion.aggregateNeutralPrefKey
import org.totschnig.myexpenses.viewmodel.data.Budget
Expand Down Expand Up @@ -189,18 +190,21 @@ class BudgetListViewModel(application: Application) : BudgetViewModel(applicatio
GenericAccountService.getSyncBackendProvider(localizedContext, accountName)
.mapCatching { backend ->
val allBudgets = allBudgets
_importInfo.update {
accountName to
backend.budgets.filter { remote ->
allBudgets.none { local -> local.uuid == remote.first }
}.map { (uuid, budget) ->
budget.accountUuid?.let {
repository.findAccountByUuid(it)?.let {
Importable(uuid, budget, it)
} ?: NotImportable(uuid, budget.title)
} ?: Importable(uuid, budget, 0L)
}
}
val budgets = backend.budgets
accountName to
budgets.filter { remote ->
allBudgets.none { local -> local.uuid == remote.first }
}.map { (uuid, budget) ->
budget.accountUuid?.let {
repository.findAccountByUuid(it)?.let {
Importable(uuid, budget, it)
} ?: NotImportable(uuid, budget.title)
} ?: Importable(uuid, budget, 0L)
}
}.onSuccess { result ->
_importInfo.update { result }
}.onFailure {
CrashHandler.report(it)
}
}
}
Expand Down

0 comments on commit b41169d

Please sign in to comment.