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

fix: Don't trigger NullPointErexception when executing activities action #1551

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.infomaniak.drive.data.services.MqttClientWrapper
import com.infomaniak.drive.utils.AccountUtils
import com.infomaniak.drive.utils.FileId
import com.infomaniak.drive.utils.Utils.ROOT_ID
import com.infomaniak.lib.core.utils.SentryLog
import io.realm.Realm
import io.realm.RealmQuery
import io.sentry.Sentry
Expand All @@ -43,6 +44,8 @@ import java.util.Calendar

object FolderFilesProvider {

private val TAG = FolderFilesProvider::class.java.simpleName

// 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 = 5_00_010_01
Expand Down Expand Up @@ -396,7 +399,7 @@ object FolderFilesProvider {
) {
val actionFile = actionFiles[fileId]

when (action) {
when (actionType) {
FileActivityType.FILE_DELETE,
FileActivityType.FILE_MOVE_OUT,
FileActivityType.FILE_TRASH -> {
Expand All @@ -408,6 +411,9 @@ object FolderFilesProvider {
}
}
else -> {
if (actionType == FileActivityType.UNKNOWN) {
SentryLog.e(TAG, "The action with value '$actionType' is unknown")
}
// The file has not yet been managed and is not the parent folder.
if (returnResponse[fileId] == null && actionFile?.id != currentFolder.id) {
upsertAction(realm, currentFolder, actionFile)
Expand All @@ -421,7 +427,7 @@ object FolderFilesProvider {
FileController.getParentFile(fileId = fileId, realm = realm)?.let { localFolder ->
if (localFolder.id != currentFolder.id) return@let

if (action == FileActivityType.FILE_MOVE_OUT) {
if (actionType == FileActivityType.FILE_MOVE_OUT) {
FileController.updateFile(localFolder.id, realm) { it.children.remove(actionFile) }
} else {
FileController.removeFile(fileId, customRealm = realm, recursive = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ package com.infomaniak.drive.data.models

import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import com.infomaniak.core.utils.enumValueOfOrNull
import kotlinx.parcelize.Parcelize

@Parcelize
data class FileAction(
val action: FileActivityType,
@SerializedName("action")
val actionString: String,
@SerializedName("file_id")
val fileId: Int,
@SerializedName("parent_id")
val parentId: Int,
val path: String,
) : Parcelable
) : Parcelable {
val actionType get() = enumValueOfOrNull<FileActivityType>(actionString) ?: FileActivityType.UNKNOWN
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ open class FileActivity(
FileActivityType.FILE_UNCATEGORIZE -> R.string.fileDetailsActivityFileUncategorize
FileActivityType.FILE_COLOR_UPDATE -> R.string.fileDetailsActivityFileColorUpdate
FileActivityType.FILE_COLOR_DELETE -> R.string.fileDetailsActivityFileColorDelete
null -> null
else -> null
}

fun getDay(context: Context): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ enum class FileActivityType {
COLLABORATIVE_FOLDER_UPDATE,
@SerializedName("collaborative_folder_delete")
COLLABORATIVE_FOLDER_DELETE,
UNKNOWN,
}