From b55b17ad13c6fc20c2457b7ba2c4790bb53bdaaf Mon Sep 17 00:00:00 2001 From: Fabian Devel Date: Tue, 22 Feb 2022 11:41:48 +0100 Subject: [PATCH 1/4] rebase branch to only get changes Add the changes of branch android-ui-test to delete useless function --- .../java/com/infomaniak/drive/ApiRepositoryTest.kt | 12 +++++++++++- .../com/infomaniak/drive/data/api/ApiRepository.kt | 5 ----- .../ui/fileList/fileDetails/FileDetailsViewModel.kt | 6 +++++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/src/androidTest/java/com/infomaniak/drive/ApiRepositoryTest.kt b/app/src/androidTest/java/com/infomaniak/drive/ApiRepositoryTest.kt index c1c737bc74..ea87b25b8a 100644 --- a/app/src/androidTest/java/com/infomaniak/drive/ApiRepositoryTest.kt +++ b/app/src/androidTest/java/com/infomaniak/drive/ApiRepositoryTest.kt @@ -17,6 +17,7 @@ */ package com.infomaniak.drive +import android.util.Log import androidx.collection.arrayMapOf import androidx.test.ext.junit.runners.AndroidJUnit4 import com.google.gson.JsonObject @@ -68,7 +69,9 @@ import com.infomaniak.drive.utils.ApiTestUtils.createFileForTest import com.infomaniak.drive.utils.ApiTestUtils.deleteTestFile import com.infomaniak.drive.utils.ApiTestUtils.getCategory import com.infomaniak.drive.utils.ApiTestUtils.getShareLink +import com.infomaniak.drive.utils.KDriveHttpClient import com.infomaniak.drive.utils.Utils.ROOT_ID +import kotlinx.coroutines.runBlocking import org.junit.* import org.junit.runner.RunWith @@ -126,7 +129,14 @@ class ApiRepositoryTest : KDriveTest() { @Test fun getFileActivities() { - assertApiResponse(getFileActivities(testFile, 1)) + val okHttpClientWithTimeout = runBlocking { KDriveHttpClient.getHttpClient(user.id, 30) } + with(getFileActivities(okHttpClientWithTimeout, testFile, 1)) { + if (isSuccess()) { + assertApiResponse(this) + } else { + Log.e("getFileActivityTest", "api response error : ${context.getString(translatedError)}") + } + } } @Test diff --git a/app/src/main/java/com/infomaniak/drive/data/api/ApiRepository.kt b/app/src/main/java/com/infomaniak/drive/data/api/ApiRepository.kt index dd3ffe8300..75819719fd 100644 --- a/app/src/main/java/com/infomaniak/drive/data/api/ApiRepository.kt +++ b/app/src/main/java/com/infomaniak/drive/data/api/ApiRepository.kt @@ -197,11 +197,6 @@ object ApiRepository { return callApi(ApiRoutes.getFileCount(file), GET) } - fun getFileActivities(file: File, page: Int): ApiResponse> { - val url = "${ApiRoutes.getFileActivities(file)}?with=user&${pagination(page, 25)}" + ACTIONS - return callApi(url, GET) - } - fun getFileComments(file: File, page: Int): ApiResponse> { val url = "${ApiRoutes.commentFile(file)}?with=like,response&${pagination(page)}" return callApi(url, GET) diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsViewModel.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsViewModel.kt index f0ad9f0668..e76a13392c 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsViewModel.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsViewModel.kt @@ -26,6 +26,8 @@ import com.infomaniak.drive.data.models.File import com.infomaniak.drive.data.models.FileActivity import com.infomaniak.drive.data.models.FileComment import com.infomaniak.drive.data.models.Share +import com.infomaniak.drive.utils.AccountUtils +import com.infomaniak.drive.utils.KDriveHttpClient import com.infomaniak.lib.core.models.ApiResponse import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -44,7 +46,9 @@ class FileDetailsViewModel : ViewModel() { return liveData(Dispatchers.IO + getFileActivitiesJob) { suspend fun recursive(page: Int) { - val apiRepository = ApiRepository.getFileActivities(file, page) + // Increase timeout for this api call because it can take more than 10s to process data + val okHttpClient = KDriveHttpClient.getHttpClient(AccountUtils.currentUserId, 30) + val apiRepository = ApiRepository.getFileActivities(okHttpClient, file, page) if (apiRepository.isSuccess()) { when { apiRepository.data?.isNullOrEmpty() == true -> emit(null) From 8fe139c097718f4be7877880f2866a9f662fc69c Mon Sep 17 00:00:00 2001 From: Fabian Devel Date: Tue, 22 Feb 2022 17:14:46 +0100 Subject: [PATCH 2/4] refactor timeout fix --- .../com/infomaniak/drive/ApiRepositoryTest.kt | 5 +---- .../infomaniak/drive/data/api/ApiRepository.kt | 15 ++++++++++++--- .../infomaniak/drive/data/cache/FileController.kt | 5 +---- .../fileList/fileDetails/FileDetailsViewModel.kt | 6 +----- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/app/src/androidTest/java/com/infomaniak/drive/ApiRepositoryTest.kt b/app/src/androidTest/java/com/infomaniak/drive/ApiRepositoryTest.kt index ea87b25b8a..46ebfbdd25 100644 --- a/app/src/androidTest/java/com/infomaniak/drive/ApiRepositoryTest.kt +++ b/app/src/androidTest/java/com/infomaniak/drive/ApiRepositoryTest.kt @@ -69,9 +69,7 @@ import com.infomaniak.drive.utils.ApiTestUtils.createFileForTest import com.infomaniak.drive.utils.ApiTestUtils.deleteTestFile import com.infomaniak.drive.utils.ApiTestUtils.getCategory import com.infomaniak.drive.utils.ApiTestUtils.getShareLink -import com.infomaniak.drive.utils.KDriveHttpClient import com.infomaniak.drive.utils.Utils.ROOT_ID -import kotlinx.coroutines.runBlocking import org.junit.* import org.junit.runner.RunWith @@ -129,8 +127,7 @@ class ApiRepositoryTest : KDriveTest() { @Test fun getFileActivities() { - val okHttpClientWithTimeout = runBlocking { KDriveHttpClient.getHttpClient(user.id, 30) } - with(getFileActivities(okHttpClientWithTimeout, testFile, 1)) { + with(getFileActivities(testFile, 1, false)) { if (isSuccess()) { assertApiResponse(this) } else { diff --git a/app/src/main/java/com/infomaniak/drive/data/api/ApiRepository.kt b/app/src/main/java/com/infomaniak/drive/data/api/ApiRepository.kt index 75819719fd..5856ba25ac 100644 --- a/app/src/main/java/com/infomaniak/drive/data/api/ApiRepository.kt +++ b/app/src/main/java/com/infomaniak/drive/data/api/ApiRepository.kt @@ -22,11 +22,14 @@ import com.google.gson.JsonElement import com.infomaniak.drive.data.models.* import com.infomaniak.drive.data.models.drive.Category import com.infomaniak.drive.data.models.drive.DriveInfo +import com.infomaniak.drive.utils.AccountUtils +import com.infomaniak.drive.utils.KDriveHttpClient import com.infomaniak.lib.core.models.ApiResponse import com.infomaniak.lib.core.models.User import com.infomaniak.lib.core.networking.HttpClient import com.infomaniak.lib.core.utils.ApiController.ApiMethod.* import com.infomaniak.lib.core.utils.ApiController.callApi +import kotlinx.coroutines.runBlocking import okhttp3.OkHttpClient object ApiRepository { @@ -90,9 +93,15 @@ object ApiRepository { return callApi(url, GET, okHttpClient = okHttpClient) } - fun getFileActivities(okHttpClient: OkHttpClient, file: File, page: Int): ApiResponse> { - val url = "${ApiRoutes.getFileActivities(file)}?${pagination(page)}&depth=children&from_date=${file.responseAt}" + - "&with=file,rights,collaborative_folder,favorite,share_link,mobile,categories" + ACTIONS + fun getFileActivities(file: File, page: Int, forFileList: Boolean): ApiResponse> { + val queries = if (forFileList) { + "&depth=children&from_date=${file.responseAt}&with=file,rights,collaborative_folder,favorite,share_link,mobile,categories" + } else { + "&with=user" + } + val url = "${ApiRoutes.getFileActivities(file)}?${pagination(page)}$queries$ACTIONS" + // Increase timeout for this api call because it can take more than 10s to process data + val okHttpClient = runBlocking { KDriveHttpClient.getHttpClient(AccountUtils.currentUserId, 30) } return callApi(url, GET, okHttpClient = okHttpClient) } diff --git a/app/src/main/java/com/infomaniak/drive/data/cache/FileController.kt b/app/src/main/java/com/infomaniak/drive/data/cache/FileController.kt index a8def1d076..a5e1ab339b 100644 --- a/app/src/main/java/com/infomaniak/drive/data/cache/FileController.kt +++ b/app/src/main/java/com/infomaniak/drive/data/cache/FileController.kt @@ -748,11 +748,8 @@ object FileController { page: Int, userDrive: UserDrive? = null ): Map { - val okHttpClient = runBlocking { - userDrive?.userId?.let { KDriveHttpClient.getHttpClient(it) } ?: HttpClient.okHttpClient - } val returnResponse = arrayMapOf() - val apiResponse = ApiRepository.getFileActivities(okHttpClient, folder, page) + val apiResponse = ApiRepository.getFileActivities(folder, page, true) if (!apiResponse.isSuccess()) return returnResponse return if (apiResponse.data?.isNotEmpty() == true) { diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsViewModel.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsViewModel.kt index e76a13392c..e17fbf92a6 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsViewModel.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsViewModel.kt @@ -26,8 +26,6 @@ import com.infomaniak.drive.data.models.File import com.infomaniak.drive.data.models.FileActivity import com.infomaniak.drive.data.models.FileComment import com.infomaniak.drive.data.models.Share -import com.infomaniak.drive.utils.AccountUtils -import com.infomaniak.drive.utils.KDriveHttpClient import com.infomaniak.lib.core.models.ApiResponse import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -46,9 +44,7 @@ class FileDetailsViewModel : ViewModel() { return liveData(Dispatchers.IO + getFileActivitiesJob) { suspend fun recursive(page: Int) { - // Increase timeout for this api call because it can take more than 10s to process data - val okHttpClient = KDriveHttpClient.getHttpClient(AccountUtils.currentUserId, 30) - val apiRepository = ApiRepository.getFileActivities(okHttpClient, file, page) + val apiRepository = ApiRepository.getFileActivities(file, page, false) if (apiRepository.isSuccess()) { when { apiRepository.data?.isNullOrEmpty() == true -> emit(null) From 120e1b67e8f7ddfef2c17fe28c1b0f4b6194f790 Mon Sep 17 00:00:00 2001 From: Joris Bodin Date: Tue, 22 Feb 2022 18:11:59 +0100 Subject: [PATCH 3/4] Refactor and fix okHttpClient --- Core | 2 +- .../drive/data/api/ApiRepository.kt | 20 +++++++++---------- .../infomaniak/drive/data/api/ApiRoutes.kt | 7 +++++-- .../drive/data/cache/FileController.kt | 5 ++++- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Core b/Core index 79c51bb239..0c70f45581 160000 --- a/Core +++ b/Core @@ -1 +1 @@ -Subproject commit 79c51bb2395d07ccd34437c0902c007d5e9b9b5f +Subproject commit 0c70f4558112a55fd25628d4b0d9662395c9e4b1 diff --git a/app/src/main/java/com/infomaniak/drive/data/api/ApiRepository.kt b/app/src/main/java/com/infomaniak/drive/data/api/ApiRepository.kt index 5856ba25ac..9dad069207 100644 --- a/app/src/main/java/com/infomaniak/drive/data/api/ApiRepository.kt +++ b/app/src/main/java/com/infomaniak/drive/data/api/ApiRepository.kt @@ -19,17 +19,15 @@ package com.infomaniak.drive.data.api import androidx.collection.arrayMapOf import com.google.gson.JsonElement +import com.infomaniak.drive.data.api.ApiRoutes.withFile import com.infomaniak.drive.data.models.* import com.infomaniak.drive.data.models.drive.Category import com.infomaniak.drive.data.models.drive.DriveInfo -import com.infomaniak.drive.utils.AccountUtils -import com.infomaniak.drive.utils.KDriveHttpClient import com.infomaniak.lib.core.models.ApiResponse import com.infomaniak.lib.core.models.User import com.infomaniak.lib.core.networking.HttpClient import com.infomaniak.lib.core.utils.ApiController.ApiMethod.* import com.infomaniak.lib.core.utils.ApiController.callApi -import kotlinx.coroutines.runBlocking import okhttp3.OkHttpClient object ApiRepository { @@ -93,15 +91,15 @@ object ApiRepository { return callApi(url, GET, okHttpClient = okHttpClient) } - fun getFileActivities(file: File, page: Int, forFileList: Boolean): ApiResponse> { - val queries = if (forFileList) { - "&depth=children&from_date=${file.responseAt}&with=file,rights,collaborative_folder,favorite,share_link,mobile,categories" - } else { - "&with=user" - } + // Increase timeout for this api call because it can take more than 10s to process data + fun getFileActivities( + file: File, + page: Int, + forFileList: Boolean, + okHttpClient: OkHttpClient = HttpClient.okHttpClientLongTimeout, + ): ApiResponse> { + val queries = if (forFileList) "&depth=children&from_date=${file.responseAt}&$withFile" else "&with=user" val url = "${ApiRoutes.getFileActivities(file)}?${pagination(page)}$queries$ACTIONS" - // Increase timeout for this api call because it can take more than 10s to process data - val okHttpClient = runBlocking { KDriveHttpClient.getHttpClient(AccountUtils.currentUserId, 30) } return callApi(url, GET, okHttpClient = okHttpClient) } diff --git a/app/src/main/java/com/infomaniak/drive/data/api/ApiRoutes.kt b/app/src/main/java/com/infomaniak/drive/data/api/ApiRoutes.kt index 3ef5d3adc1..116271c497 100644 --- a/app/src/main/java/com/infomaniak/drive/data/api/ApiRoutes.kt +++ b/app/src/main/java/com/infomaniak/drive/data/api/ApiRoutes.kt @@ -25,7 +25,10 @@ import com.infomaniak.drive.data.models.Team object ApiRoutes { - private const val with = "with=children,rights,collaborative_folder,favorite,mobile,share_link,categories" + private val with = with("children") + val withFile = with("file") + + private fun with(target: String) = "with=$target,rights,collaborative_folder,favorite,mobile,share_link,categories" private fun fileURL(file: File) = "${DRIVE_API}${file.driveId}/file/${file.id}" @@ -111,7 +114,7 @@ object ApiRoutes { fun dropBox(file: File) = "${fileURL(file)}/collaborate" fun getLastActivities(driveId: Int) = - "${DRIVE_API}$driveId/file/activity?with=file,rights,collaborative_folder,favorite,mobile,share_link,categories" + + "${DRIVE_API}$driveId/file/activity?$withFile" + "&depth=unlimited" + "&actions[]=file_create" + "&actions[]=file_update" + diff --git a/app/src/main/java/com/infomaniak/drive/data/cache/FileController.kt b/app/src/main/java/com/infomaniak/drive/data/cache/FileController.kt index a5e1ab339b..1ed7828009 100644 --- a/app/src/main/java/com/infomaniak/drive/data/cache/FileController.kt +++ b/app/src/main/java/com/infomaniak/drive/data/cache/FileController.kt @@ -748,8 +748,11 @@ object FileController { page: Int, userDrive: UserDrive? = null ): Map { + val okHttpClient = runBlocking { + userDrive?.userId?.let { KDriveHttpClient.getHttpClient(it, 30) } ?: HttpClient.okHttpClientLongTimeout + } val returnResponse = arrayMapOf() - val apiResponse = ApiRepository.getFileActivities(folder, page, true) + val apiResponse = ApiRepository.getFileActivities(folder, page, true, okHttpClient) if (!apiResponse.isSuccess()) return returnResponse return if (apiResponse.data?.isNotEmpty() == true) { From 3df97f490bf2ae2f01b8bfb085cdb8f287080822 Mon Sep 17 00:00:00 2001 From: Fabian Devel Date: Wed, 23 Feb 2022 09:10:57 +0100 Subject: [PATCH 4/4] Remove httpClient from getFileTest --- .../java/com/infomaniak/drive/ApiRepositoryTest.kt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/src/androidTest/java/com/infomaniak/drive/ApiRepositoryTest.kt b/app/src/androidTest/java/com/infomaniak/drive/ApiRepositoryTest.kt index 586499df3e..33f58172cf 100644 --- a/app/src/androidTest/java/com/infomaniak/drive/ApiRepositoryTest.kt +++ b/app/src/androidTest/java/com/infomaniak/drive/ApiRepositoryTest.kt @@ -56,7 +56,6 @@ import com.infomaniak.drive.data.api.ApiRepository.putFileShareLink import com.infomaniak.drive.data.api.ApiRepository.removeCategory import com.infomaniak.drive.data.api.ApiRepository.updateDropBox import com.infomaniak.drive.data.api.ApiRoutes.postFileShare -import com.infomaniak.drive.data.api.ErrorCode.Companion.translateError import com.infomaniak.drive.data.models.File import com.infomaniak.drive.utils.ApiTestUtils.assertApiResponseData import com.infomaniak.drive.utils.ApiTestUtils.createDropBoxForTest @@ -66,9 +65,7 @@ import com.infomaniak.drive.utils.ApiTestUtils.deleteTestFile import com.infomaniak.drive.utils.ApiTestUtils.getCategory import com.infomaniak.drive.utils.ApiTestUtils.getShareLink import com.infomaniak.drive.utils.ApiTestUtils.putNewFileInTrash -import com.infomaniak.drive.utils.KDriveHttpClient import com.infomaniak.drive.utils.Utils.ROOT_ID -import kotlinx.coroutines.runBlocking import org.junit.jupiter.api.* import org.junit.jupiter.api.Assertions.* import java.util.* @@ -277,8 +274,7 @@ class ApiRepositoryTest : KDriveTest() { @Test @DisplayName("Check if the file activities are correctly retrieved") fun getFileActivities() { - val okHttpClientWithTimeout = runBlocking { KDriveHttpClient.getHttpClient(user.id, 30) } - with(getFileActivities(okHttpClientWithTimeout, testFile, 1)) { + with(getFileActivities(testFile, 1, false)) { if (isSuccess()) { assertApiResponseData(this) } else {