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 e725b1b commit 8799185
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
applicationId "com.infomaniak.drive"
minSdkVersion 21
targetSdkVersion 31
versionCode 40100002
versionCode 4_01_000_02
versionName "4.1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
27 changes: 15 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 @@ -50,6 +51,10 @@ object FileController {
private const val REALM_DB_FILE = "kDrive-%s-%s.realm"
private const val REALM_DB_SHARES_WITH_ME = "kDrive-%s-%s-shares.realm"

// Bump this when we want to force-refresh files that are too old.
// Example: We did it when we added Categories & Colored folders, to automatically display them when updating the app.
private const val MIN_VERSION_CODE = 4_01_000_02

const val FAVORITES_FILE_ID = -1
const val MY_SHARES_FILE_ID = -2
const val RECENT_CHANGES_FILE_ID = -4
Expand Down Expand Up @@ -232,12 +237,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 +593,7 @@ object FileController {
|| folderProxy == null
|| folderProxy.children.isNullOrEmpty()
|| !folderProxy.isComplete
|| folderProxy.versionCode < MIN_VERSION_CODE
|| hasDuplicatesFiles
|| minDateToIgnoreCache >= folderProxy.responseAt

Expand Down Expand Up @@ -700,6 +701,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 +903,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 8799185

Please sign in to comment.