nextcloud / nextcloud/android

Navigation and Toolbar State Management into a Unified Enum-Based Approach

Open
#14,149 0 comments 0 reactions 2 assignees Assigned to @tobiasKaminsky View on GitHub
bug navigation technical debt ux-enhancement
Dominant language
Kotlin
Stars
5.6k
Forks
2k
Avg merge
2d 18h
Merged PRs (30d)
92

Description

### Context

Our current implementation involves managing navigation state, toolbar configuration, and menu item highlighting using multiple independent sources. This fragmented approach introduces significant complexity and fragility, especially when states override one another or are not persisted properly.

**Toolbar Variants:**

With search:

Image

Plain:

Image

### Current Implementation Issues

We currently rely on three separate mechanisms to determine and control the toolbar type, screen title, and the selected menu item (in both bottom navigation and drawer):

1. Static Booleans in `MainApp.java`:

```
private static boolean mOnlyOnDevice;
private static boolean mOnlyPersonalFiles;
```

2. SearchEvent in `com.owncloud.android.ui.events`:

Various search types are used to define the current context in fragments such as `OCFileListFragment`, `GalleryFragment`, and `SharedListFragment`, all managed by `FileDisplayActivity`:

```
public static enum SearchType {
FILE_SEARCH,
FAVORITE_SEARCH,
RECENTLY_MODIFIED_SEARCH,
PHOTO_SEARCH,
SHARED_SEARCH,
GALLERY_SEARCH,
FILE_ID_SEARCH,
CONTENT_TYPE_SEARCH,
RECENTLY_ADDED_SEARCH,
SHARED_FILTER;
}
```

3. Static `menuItemId` from `DrawerActivity`:

Tracks user interaction from UI components within `DrawerActivity`. These mechanisms are not synchronized and often override one another, making state management brittle and error-prone.

### Problem Scenarios

Scenario 1:

A user navigates to the Media tab. The `SearchEvent` and `menuItemId` are correctly set. However, when the user backgrounds the app and later returns, the "All Files" are shown while the "Media" menu item remains highlighted. This occurs because `FileDisplayActivity` must handle all search types and ensure the toolbar and active menu item reflect the current state, but it often fails due to fragmented state checks.

Scenario 2:

The user opens the Shared Files view. The static flags in `MainApp` are set. Even if the user navigates using the drawer or bottom navigation afterward, the `menuItemId` updates correctly, but the outdated static flags still influence the toolbar and highlighted menu, resulting in inconsistent UI behavior.

### Suggestion

To eliminate these inconsistencies, I recommend consolidating all related state management into a single, unified enum class. This would act as a single source of truth for determining the current screen state, toolbar configuration, and navigation highlighting:

```
enum class States(val titleId: Int, val toolbarType: ToolbarType) {
ALL_FILES(titleId = R.string.all_files, toolbarType = ToolbarType.SEARCH_BAR),
FAVORITE(titleId = R.string.favorite, toolbarType = ToolbarType.PLAIN),
...
...
}

enum class ToolbarType {
SEARCH_BAR,
PLAIN
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.