-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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:
Plain:
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):
- Static Booleans in
MainApp.java:
private static boolean mOnlyOnDevice;
private static boolean mOnlyPersonalFiles;
- 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;
}
- Static
menuItemIdfromDrawerActivity:
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
}