Skip to content

Commit

Permalink
Added VersionCode in File
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Boulongne <[email protected]>
  • Loading branch information
KevinBoulongne committed Feb 1, 2022
1 parent 2f09633 commit 61cd2cb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
23 changes: 11 additions & 12 deletions app/src/main/java/com/infomaniak/drive/data/cache/FileController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package com.infomaniak.drive.data.cache
import android.content.Context
import androidx.collection.ArrayMap
import androidx.collection.arrayMapOf
import com.infomaniak.drive.BuildConfig
import com.infomaniak.drive.data.api.ApiRepository
import com.infomaniak.drive.data.models.CancellableAction
import com.infomaniak.drive.data.models.File
Expand Down Expand Up @@ -232,12 +233,7 @@ object FileController {
moreTransaction: (() -> Unit)? = null
) {
realm.executeTransaction {
if (oldFile?.isUsable() == true) {
newFile.isComplete = oldFile.isComplete
newFile.children = oldFile.children
newFile.responseAt = oldFile.responseAt
newFile.isOffline = oldFile.isOffline
}
if (oldFile?.isUsable() == true) keepOldLocalFilesData(oldFile, newFile)
moreTransaction?.invoke()
it.insertOrUpdate(newFile)
}
Expand Down Expand Up @@ -593,6 +589,7 @@ object FileController {
|| folderProxy == null
|| folderProxy.children.isNullOrEmpty()
|| !folderProxy.isComplete
|| folderProxy.versionCode < BuildConfig.VERSION_CODE
|| hasDuplicatesFiles
|| minDateToIgnoreCache >= folderProxy.responseAt

Expand Down Expand Up @@ -700,6 +697,7 @@ object FileController {
insertOrUpdateFile(currentRealm, remoteFolder) {
if (childrenSize < ApiRepository.PER_PAGE) remoteFolder.isComplete = true
remoteFolder.responseAt = responseAt
remoteFolder.versionCode = BuildConfig.VERSION_CODE
}
}

Expand Down Expand Up @@ -901,12 +899,13 @@ object FileController {
return ApiRepository.createTeamFolder(okHttpClient, driveId, name, forAllUsers)
}

private fun keepOldLocalFilesData(managedFile: File, remoteFile: File) {
remoteFile.apply {
children = managedFile.children
isComplete = managedFile.isComplete
responseAt = managedFile.responseAt
isOffline = managedFile.isOffline
private fun keepOldLocalFilesData(oldFile: File, newFile: File) {
newFile.apply {
children = oldFile.children
isComplete = oldFile.isComplete
isOffline = oldFile.isOffline
responseAt = oldFile.responseAt
versionCode = oldFile.versionCode
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ class FileMigration : RealmMigration {

// Migrated to version 3:
// - Added new field (Folder Color) in File table
// - Added new field (Version Code) in File table
if (oldVersionTemp == 2L) {
schema.get(File::class.java.simpleName)?.apply {
addField("_color", String::class.java)
addField("versionCode", Int::class.java)
}
oldVersionTemp++
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/infomaniak/drive/data/models/File.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ open class File(
* Local
*/
var isComplete: Boolean = false,
var isOffline: Boolean = false,
var isFromActivities: Boolean = false,
var isFromSearch: Boolean = false,
var isFromUploads: Boolean = false,
var isOffline: Boolean = false,
var versionCode: Int = 0,
) : RealmObject(), Parcelable {

@LinkingObjects("children")
Expand Down

0 comments on commit 61cd2cb

Please sign in to comment.