From 8ae06de780793251392bcc69a4f7d491604ef6b5 Mon Sep 17 00:00:00 2001 From: Joris Bodin Date: Tue, 19 Jul 2022 17:03:00 +0200 Subject: [PATCH] Fix remove category --- .../java/com/infomaniak/drive/ApiRepositoryTest.kt | 6 +++--- .../java/com/infomaniak/drive/data/api/ApiRepository.kt | 2 +- .../ui/fileList/fileDetails/SelectCategoriesFragment.kt | 2 +- .../ui/fileList/fileDetails/SelectCategoriesViewModel.kt | 2 +- app/src/main/res/layout/fragment_file_details_infos.xml | 4 +++- 5 files changed, 9 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 f1f9c93b48..a522409753 100644 --- a/app/src/androidTest/java/com/infomaniak/drive/ApiRepositoryTest.kt +++ b/app/src/androidTest/java/com/infomaniak/drive/ApiRepositoryTest.kt @@ -496,13 +496,13 @@ class ApiRepositoryTest : KDriveTest() { val category = createCategory(userDrive.driveId, "testRemoveCategory-$randomSuffix", "#000").data assertNotNull(category, "Category should not be null") // Add the category to the test file - addCategory(testFile, category!!.id) + assertApiResponseData(addCategory(testFile, category!!.id)) // Remove the category - removeCategory(testFile, category.id) + assertApiResponseData(removeCategory(testFile, category.id)) // Make sure the category is removed with(getFileDetails(testFile)) { assertApiResponseData(this) - assertTrue(data!!.categories.isNullOrEmpty(), "The test file should not have a category") + assertTrue(data!!.categories.isEmpty(), "The test file should not have a category") } // Delete the test category deleteCategory(userDrive.driveId, category.id) 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 2799f05b5d..3265a1ad04 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 @@ -335,7 +335,7 @@ object ApiRepository : ApiRepositoryCore() { return callApi(ApiRoutes.fileCategory(driveId, categoryId), POST, mapOf("file_ids" to fileIds)) } - fun removeCategory(file: File, categoryId: Int): ApiResponse { + fun removeCategory(file: File, categoryId: Int): ApiResponse { return callApi(ApiRoutes.fileCategory(file, categoryId), DELETE) } diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/SelectCategoriesFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/SelectCategoriesFragment.kt index 689fed3de2..6ca1d0549c 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/SelectCategoriesFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/SelectCategoriesFragment.kt @@ -280,7 +280,7 @@ class SelectCategoriesFragment : Fragment() { } } - private fun updateAdapterAfterAddingOrRemovingCategory(id: Int, apiResponse: ApiResponse, isAdding: Boolean) { + private fun updateAdapterAfterAddingOrRemovingCategory(id: Int, apiResponse: ApiResponse<*>, isAdding: Boolean) { val isSelected = if (apiResponse.isSuccess()) { isAdding } else { diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/SelectCategoriesViewModel.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/SelectCategoriesViewModel.kt index 628c18bc16..1916882481 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/SelectCategoriesViewModel.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/SelectCategoriesViewModel.kt @@ -45,7 +45,7 @@ class SelectCategoriesViewModel : ViewModel() { } } - fun removeCategory(file: File, categoryId: Int): LiveData> { + fun removeCategory(file: File, categoryId: Int): LiveData> { return liveData(Dispatchers.IO) { with(ApiRepository.removeCategory(file, categoryId)) { if (isSuccess()) { diff --git a/app/src/main/res/layout/fragment_file_details_infos.xml b/app/src/main/res/layout/fragment_file_details_infos.xml index 295e2da237..00595554fb 100644 --- a/app/src/main/res/layout/fragment_file_details_infos.xml +++ b/app/src/main/res/layout/fragment_file_details_infos.xml @@ -133,7 +133,9 @@ android:layout_width="match_parent" android:layout_height="1dp" android:layout_marginTop="@dimen/marginStandardMedium" - android:background="@color/divider" /> + android:background="@color/divider" + android:visibility="gone" + tools:visibility="visible" />