Skip to content

Commit

Permalink
Use DrawerState instead static menuItemId
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Sep 23, 2024
1 parent 8ccee61 commit 616cbb0
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package com.owncloud.android.ui.fragment

import androidx.test.espresso.intent.rule.IntentsTestRule
import com.nextcloud.model.DrawerState
import com.nextcloud.test.GrantStoragePermissionRule
import com.nextcloud.test.TestActivity
import com.owncloud.android.AbstractIT
Expand Down Expand Up @@ -373,12 +374,12 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {

testFolder.richWorkspace = " "
activity.storageManager.saveFile(testFolder)
sut.adapter.swapDirectory(user, testFolder, activity.storageManager, false, "")
sut.adapter.swapDirectory(user, testFolder, activity.storageManager, false, "", DrawerState.AllFiles)
Assert.assertFalse(sut.adapter.shouldShowHeader())

testFolder.richWorkspace = null
activity.storageManager.saveFile(testFolder)
sut.adapter.swapDirectory(user, testFolder, activity.storageManager, false, "")
sut.adapter.swapDirectory(user, testFolder, activity.storageManager, false, "", DrawerState.AllFiles)
Assert.assertFalse(sut.adapter.shouldShowHeader())

testFolder.richWorkspace = "1"
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/com/nextcloud/model/DrawerState.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2024 Alper Ozturk <[email protected]>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

package com.nextcloud.model

@Suppress("ForbiddenComment")
enum class DrawerState {
// TODO: Refactor drawer navigation to use DrawerState instead of static menuItemId.
AllFiles,
Favorite,
Shared
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import com.nextcloud.client.onboarding.FirstRunActivity;
import com.nextcloud.client.preferences.AppPreferences;
import com.nextcloud.common.NextcloudClient;
import com.nextcloud.model.DrawerState;
import com.nextcloud.ui.ChooseAccountDialogFragment;
import com.nextcloud.ui.composeActivity.ComposeActivity;
import com.nextcloud.ui.composeActivity.ComposeDestination;
Expand Down Expand Up @@ -1319,4 +1320,15 @@ private void handleNavItemClickEvent(@IdRes int menuItemId) {
Menu navMenu = mNavigationView.getMenu();
onNavigationItemClicked(navMenu.findItem(menuItemId));
}

// TODO Implement rest of states
public static DrawerState getDrawerState() {
if (menuItemId == R.id.nav_favorites) {
return DrawerState.Favorite;
} else if (menuItemId == R.id.nav_shared) {
return DrawerState.Shared;
} else {
return DrawerState.AllFiles;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.owncloud.android.ui.adapter

import com.nextcloud.client.account.User
import com.nextcloud.model.DrawerState
import com.owncloud.android.datamodel.FileDataStorageManager
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.utils.FileSortOrder
Expand All @@ -21,7 +22,8 @@ interface CommonOCFileListAdapterInterface {
directory: OCFile,
storageManager: FileDataStorageManager,
onlyOnDevice: Boolean,
mLimitToMimeType: String
mLimitToMimeType: String,
drawerState: DrawerState
)

fun setHighlightedItem(file: OCFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.afollestad.sectionedrecyclerview.SectionedRecyclerViewAdapter
import com.afollestad.sectionedrecyclerview.SectionedViewHolder
import com.nextcloud.client.account.User
import com.nextcloud.client.preferences.AppPreferences
import com.nextcloud.model.DrawerState
import com.owncloud.android.databinding.GalleryHeaderBinding
import com.owncloud.android.databinding.GalleryRowBinding
import com.owncloud.android.datamodel.FileDataStorageManager
Expand Down Expand Up @@ -262,7 +263,8 @@ class GalleryAdapter(
directory: OCFile,
storageManager: FileDataStorageManager,
onlyOnDevice: Boolean,
mLimitToMimeType: String
mLimitToMimeType: String,
drawerState: DrawerState
) {
TODO("Not yet implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.nextcloud.client.account.User;
import com.nextcloud.client.jobs.upload.FileUploadHelper;
import com.nextcloud.client.preferences.AppPreferences;
import com.nextcloud.model.DrawerState;
import com.nextcloud.utils.extensions.ViewExtensionsKt;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
Expand Down Expand Up @@ -771,7 +772,8 @@ public void swapDirectory(
@NonNull OCFile directory,
@NonNull FileDataStorageManager updatedStorageManager,
boolean onlyOnDevice,
@NonNull String limitToMimeType) {
@NonNull String limitToMimeType,
@NonNull DrawerState drawerState) {
this.onlyOnDevice = onlyOnDevice;

if (!updatedStorageManager.equals(mStorageManager)) {
Expand All @@ -790,10 +792,10 @@ public void swapDirectory(
if (OCFile.ROOT_PATH.equals(directory.getRemotePath()) && MainApp.isOnlyPersonFiles()) {
mFiles = limitToPersonalFiles(mFiles);
}
if (DrawerActivity.menuItemId == R.id.nav_shared && currentDirectory.isRootDirectory()) {
if (drawerState == DrawerState.Shared && currentDirectory.isRootDirectory()) {
mFiles = filterSharedFiles(mFiles);
}
if (DrawerActivity.menuItemId == R.id.nav_favorites && currentDirectory.isRootDirectory()) {
if (drawerState == DrawerState.Favorite && currentDirectory.isRootDirectory()) {
mFiles = filterFavoriteFiles(mFiles);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,8 @@ public void listDirectory(OCFile directory, OCFile file, boolean onlyOnDevice) {
directory,
storageManager,
onlyOnDevice,
mLimitToMimeType);
mLimitToMimeType,
DrawerActivity.getDrawerState());

OCFile previousDirectory = mFile;
mFile = directory;
Expand Down

0 comments on commit 616cbb0

Please sign in to comment.