Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added VersionCode in File #491

Merged
merged 1 commit into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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