From e065127ad24c185b2e65cb8e009d730697498309 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 29 Aug 2024 14:37:52 +0200 Subject: [PATCH 01/14] Fix Signed-off-by: alperozturk --- .../android/ui/activity/DrawerActivity.java | 2 +- .../android/ui/fragment/OCFileListFragment.java | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index 42991b80590e..b7005143fa2d 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -881,7 +881,7 @@ public void onLoadFailed(Exception e, Drawable errorDrawable) { * * @param menuItemId the menu item to be highlighted */ - protected void setDrawerMenuItemChecked(int menuItemId) { + public void setDrawerMenuItemChecked(int menuItemId) { if (mNavigationView != null && mNavigationView.getMenu().findItem(menuItemId) != null) { viewThemeUtils.platform.colorNavigationView(mNavigationView); mCheckedMenuItem = menuItemId; diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java index 2370560a907e..dc708ad6c4f5 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -80,6 +80,7 @@ import com.owncloud.android.lib.resources.files.ToggleFavoriteRemoteOperation; import com.owncloud.android.lib.resources.status.E2EVersion; import com.owncloud.android.lib.resources.status.OCCapability; +import com.owncloud.android.ui.activity.DrawerActivity; import com.owncloud.android.ui.activity.FileActivity; import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.ui.activity.FolderPickerActivity; @@ -93,8 +94,8 @@ import com.owncloud.android.ui.dialog.CreateFolderDialogFragment; import com.owncloud.android.ui.dialog.RemoveFilesDialogFragment; import com.owncloud.android.ui.dialog.RenameFileDialogFragment; -import com.owncloud.android.ui.dialog.setupEncryption.SetupEncryptionDialogFragment; import com.owncloud.android.ui.dialog.SyncFileNotEnoughSpaceDialogFragment; +import com.owncloud.android.ui.dialog.setupEncryption.SetupEncryptionDialogFragment; import com.owncloud.android.ui.events.ChangeMenuEvent; import com.owncloud.android.ui.events.CommentsEvent; import com.owncloud.android.ui.events.EncryptionEvent; @@ -276,9 +277,19 @@ public void onResume() { handleSearchEvent(searchEvent); } + setDrawerMenuItemChecked(); + super.onResume(); } + private void setDrawerMenuItemChecked() { + if (searchEvent != null && searchEvent.getSearchType() == SearchRemoteOperation.SearchType.FAVORITE_SEARCH) { + if (requireActivity() instanceof DrawerActivity activity) { + activity.setDrawerMenuItemChecked(R.id.nav_favorites); + } + } + } + /** * {@inheritDoc} From 9f9f89b2f33eb343823c75594bc4a7fa3dee4651 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 4 Sep 2024 11:37:24 +0200 Subject: [PATCH 02/14] Remove duplicated logic Signed-off-by: alperozturk --- .../ui/composeActivity/ComposeActivity.kt | 10 +-- .../ui/activities/ActivitiesActivity.java | 6 +- .../android/ui/activity/CommunityActivity.kt | 7 +- .../android/ui/activity/DrawerActivity.java | 85 ++++++------------- .../ui/activity/ExternalSiteWebView.java | 12 +-- .../ui/activity/FileDisplayActivity.java | 28 ++---- .../ui/activity/NotificationsActivity.kt | 7 +- .../android/ui/activity/SettingsActivity.java | 4 +- .../ui/activity/UploadListActivity.java | 4 +- .../ui/fragment/OCFileListFragment.java | 11 --- .../android/ui/trashbin/TrashbinActivity.kt | 8 +- 11 files changed, 46 insertions(+), 136 deletions(-) diff --git a/app/src/main/java/com/nextcloud/ui/composeActivity/ComposeActivity.kt b/app/src/main/java/com/nextcloud/ui/composeActivity/ComposeActivity.kt index e3eba394ea05..d341769208f0 100644 --- a/app/src/main/java/com/nextcloud/ui/composeActivity/ComposeActivity.kt +++ b/app/src/main/java/com/nextcloud/ui/composeActivity/ComposeActivity.kt @@ -36,12 +36,10 @@ import java.lang.ref.WeakReference class ComposeActivity : DrawerActivity() { lateinit var binding: ActivityComposeBinding - private var menuItemId: Int = R.id.nav_all_files companion object { const val DESTINATION = "DESTINATION" const val TITLE = "TITLE" - const val MENU_ITEM = "MENU_ITEM" } override fun onCreate(savedInstanceState: Bundle?) { @@ -51,9 +49,8 @@ class ComposeActivity : DrawerActivity() { val destination = intent.getSerializableArgument(DESTINATION, ComposeDestination::class.java) val titleId = intent.getIntExtra(TITLE, R.string.empty) - menuItemId = intent.getIntExtra(MENU_ITEM, R.id.nav_all_files) - setupDrawer(menuItemId) + setupDrawer() setupToolbarShowOnlyMenuButtonAndTitle(getString(titleId)) { openDrawer() @@ -69,11 +66,6 @@ class ComposeActivity : DrawerActivity() { } } - override fun onResume() { - super.onResume() - setDrawerMenuItemChecked(menuItemId) - } - override fun onOptionsItemSelected(item: MenuItem): Boolean { return when (item.itemId) { android.R.id.home -> { diff --git a/app/src/main/java/com/owncloud/android/ui/activities/ActivitiesActivity.java b/app/src/main/java/com/owncloud/android/ui/activities/ActivitiesActivity.java index c1e3c45102f7..47f51b83249f 100644 --- a/app/src/main/java/com/owncloud/android/ui/activities/ActivitiesActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activities/ActivitiesActivity.java @@ -77,7 +77,7 @@ protected void onCreate(Bundle savedInstanceState) { viewThemeUtils.androidx.themeSwipeRefreshLayout(binding.swipeContainingList); // setup drawer - setupDrawer(R.id.nav_activity); + setupDrawer(); updateActionBarTitleAndHomeButtonByString(getString(R.string.drawer_item_activities)); binding.swipeContainingList.setOnRefreshListener(() -> { @@ -153,11 +153,7 @@ public boolean onOptionsItemSelected(MenuItem item) { @Override protected void onResume() { super.onResume(); - actionListener.onResume(); - - setDrawerMenuItemChecked(R.id.nav_activity); - setupContent(); } diff --git a/app/src/main/java/com/owncloud/android/ui/activity/CommunityActivity.kt b/app/src/main/java/com/owncloud/android/ui/activity/CommunityActivity.kt index b507103c18b2..308d7eb99340 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/CommunityActivity.kt +++ b/app/src/main/java/com/owncloud/android/ui/activity/CommunityActivity.kt @@ -30,7 +30,7 @@ open class CommunityActivity : DrawerActivity() { setupToolbar() updateActionBarTitleAndHomeButtonByString(getString(R.string.drawer_community)) - setupDrawer(R.id.nav_community) + setupDrawer() binding.communityReleaseCandidateText.movementMethod = LinkMovementMethod.getInstance() setupContributeForumView() setupContributeTranslationView() @@ -125,9 +125,4 @@ open class CommunityActivity : DrawerActivity() { } return retval } - - override fun onResume() { - super.onResume() - setDrawerMenuItemChecked(R.id.nav_community) - } } diff --git a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index b7005143fa2d..c7b5b75ddd46 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -133,7 +133,6 @@ public abstract class DrawerActivity extends ToolbarActivity private static final String TAG = DrawerActivity.class.getSimpleName(); private static final String KEY_IS_ACCOUNT_CHOOSER_ACTIVE = "IS_ACCOUNT_CHOOSER_ACTIVE"; - private static final String KEY_CHECKED_MENU_ITEM = "CHECKED_MENU_ITEM"; private static final int ACTION_MANAGE_ACCOUNTS = 101; private static final int MENU_ORDER_EXTERNAL_LINKS = 3; private static final int MENU_ITEM_EXTERNAL_LINK = 111; @@ -168,7 +167,7 @@ public abstract class DrawerActivity extends ToolbarActivity /** * Id of the checked menu item. */ - private int mCheckedMenuItem = Menu.NONE; + public static int menuItemId = Menu.NONE; /** * container layout of the quota view. @@ -200,17 +199,6 @@ public abstract class DrawerActivity extends ToolbarActivity @Inject ClientFactory clientFactory; - /** - * Initializes the drawer, its content and highlights the menu item with the given id. This method needs to be - * called after the content view has been set. - * - * @param menuItemId the menu item to be checked/highlighted - */ - protected void setupDrawer(int menuItemId) { - setupDrawer(); - setDrawerMenuItemChecked(menuItemId); - } - /** * Initializes the drawer and its content. This method needs to be called after the content view has been set. */ @@ -261,6 +249,7 @@ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); mDrawerToggle.setDrawerIndicatorEnabled(true); supportInvalidateOptionsMenu(); + setDrawerMenuItemChecked(); } }; @@ -272,7 +261,9 @@ public void onDrawerOpened(View drawerView) { R.drawable.ic_arrow_back, null); - viewThemeUtils.platform.tintToolbarArrowDrawable(this, mDrawerToggle, backArrow); + if (backArrow != null) { + viewThemeUtils.platform.tintToolbarArrowDrawable(this, mDrawerToggle, backArrow); + } } /** @@ -364,7 +355,10 @@ private void showTopBanner(LinearLayout banner, int primaryColor) { notesView.setOnClickListener(v -> openAppOrStore("it.niedermann.owncloud.notes")); talkView.setOnClickListener(v -> openAppOrStore("com.nextcloud.talk2")); moreView.setOnClickListener(v -> openAppStore("Nextcloud", true)); - assistantView.setOnClickListener(v -> startComposeActivity(ComposeDestination.AssistantScreen, R.string.assistant_screen_top_bar_title, -1)); + assistantView.setOnClickListener(v -> { + DrawerActivity.menuItemId = Menu.NONE; + startComposeActivity(ComposeDestination.AssistantScreen, R.string.assistant_screen_top_bar_title); + }); if (getCapabilities() != null && getCapabilities().getAssistant().isTrue()) { assistantView.setVisibility(View.VISIBLE); } else { @@ -487,9 +481,9 @@ public void onMessageEvent(DummyDrawerEvent event) { } private void onNavigationItemClicked(final MenuItem menuItem) { - setDrawerMenuItemChecked(menuItem.getItemId()); - int itemId = menuItem.getItemId(); + menuItemId = itemId; + setDrawerMenuItemChecked(); if (itemId == R.id.nav_all_files || itemId == R.id.nav_personal_files) { if (this instanceof FileDisplayActivity && @@ -511,7 +505,6 @@ private void onNavigationItemClicked(final MenuItem menuItem) { } intent.setAction(FileDisplayActivity.ALL_FILES); - intent.putExtra(FileDisplayActivity.DRAWER_MENU_ID, menuItem.getItemId()); startActivity(intent); } @@ -537,7 +530,7 @@ private void onNavigationItemClicked(final MenuItem menuItem) { } else if (itemId == R.id.nav_community) { startActivity(CommunityActivity.class); } else if (itemId == R.id.nav_logout) { - mCheckedMenuItem = -1; + menuItemId = Menu.NONE; MenuItem isNewMenuItemChecked = menuItem.setChecked(false); Log_OC.d(TAG,"onNavigationItemClicked nav_logout setChecked " + isNewMenuItemChecked); final Optional optionalUser = getUser(); @@ -549,13 +542,12 @@ private void onNavigationItemClicked(final MenuItem menuItem) { } else if (itemId == R.id.nav_recently_modified) { startRecentlyModifiedSearch(menuItem); } else if (itemId == R.id.nav_assistant) { - startComposeActivity(ComposeDestination.AssistantScreen, R.string.assistant_screen_top_bar_title, itemId); + startComposeActivity(ComposeDestination.AssistantScreen, R.string.assistant_screen_top_bar_title); } else if (itemId == R.id.nav_groupfolders) { MainApp.showOnlyFilesOnDevice(false); Intent intent = new Intent(getApplicationContext(), FileDisplayActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.setAction(FileDisplayActivity.LIST_GROUPFOLDERS); - intent.putExtra(FileDisplayActivity.DRAWER_MENU_ID, menuItem.getItemId()); startActivity(intent); } else { if (menuItem.getItemId() >= MENU_ITEM_EXTERNAL_LINK && @@ -568,11 +560,10 @@ private void onNavigationItemClicked(final MenuItem menuItem) { } } - private void startComposeActivity(ComposeDestination destination, int titleId, int menuItemId) { + private void startComposeActivity(ComposeDestination destination, int titleId) { Intent composeActivity = new Intent(getApplicationContext(), ComposeActivity.class); composeActivity.putExtra(ComposeActivity.DESTINATION, destination); composeActivity.putExtra(ComposeActivity.TITLE, titleId); - composeActivity.putExtra(ComposeActivity.MENU_ITEM, menuItemId); startActivity(composeActivity); } @@ -644,6 +635,7 @@ private void handleSearchEvents(SearchEvent searchEvent, int menuItemId) { } private void launchActivityForSearch(SearchEvent searchEvent, int menuItemId) { + DrawerActivity.menuItemId = menuItemId; Intent intent = new Intent(getApplicationContext(), FileDisplayActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); @@ -653,7 +645,6 @@ private void launchActivityForSearch(SearchEvent searchEvent, int menuItemId) { intent.setAction(Intent.ACTION_SEARCH); intent.putExtra(OCFileListFragment.SEARCH_EVENT, searchEvent); - intent.putExtra(FileDisplayActivity.DRAWER_MENU_ID, menuItemId); startActivity(intent); } @@ -681,7 +672,6 @@ private void externalLinkClicked(MenuItem menuItem) { externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_TITLE, link.getName()); externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_URL, link.getUrl()); externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_SHOW_SIDEBAR, true); - externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_MENU_ITEM_ID, menuItem.getItemId()); startActivity(externalWebViewIntent); } } @@ -815,7 +805,7 @@ private void unsetAllDrawerMenuItems() { } } - mCheckedMenuItem = Menu.NONE; + menuItemId = Menu.NONE; } private void updateQuotaLink() { @@ -836,7 +826,7 @@ private void updateQuotaLink() { externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_TITLE, firstQuota.getName()); externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_URL, firstQuota.getUrl()); externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_SHOW_SIDEBAR, true); - externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_MENU_ITEM_ID, -1); + menuItemId = Menu.NONE; startActivity(externalWebViewIntent); }); @@ -879,16 +869,19 @@ public void onLoadFailed(Exception e, Drawable errorDrawable) { /** * checks/highlights the provided menu item if the drawer has been initialized and the menu item exists. * - * @param menuItemId the menu item to be highlighted */ - public void setDrawerMenuItemChecked(int menuItemId) { - if (mNavigationView != null && mNavigationView.getMenu().findItem(menuItemId) != null) { - viewThemeUtils.platform.colorNavigationView(mNavigationView); - mCheckedMenuItem = menuItemId; - mNavigationView.getMenu().findItem(menuItemId).setChecked(true); - } else { + public void setDrawerMenuItemChecked() { + if (menuItemId == Menu.NONE || mNavigationView == null) { + return; + } + + if (mNavigationView.getMenu().findItem(menuItemId) == null) { Log_OC.w(TAG, "setDrawerMenuItemChecked has been called with invalid menu-item-ID"); + return; } + + viewThemeUtils.platform.colorNavigationView(mNavigationView); + mNavigationView.getMenu().findItem(menuItemId).setChecked(true); } /** @@ -988,8 +981,6 @@ public void onLoadFailed(Exception e, Drawable errorDrawable) { target, R.drawable.ic_link); } - - setDrawerMenuItemChecked(mCheckedMenuItem); } } @@ -1008,10 +999,8 @@ private void setExternalLinkIcon(int id, Drawable drawable, int greyColor) { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (savedInstanceState != null) { mIsAccountChooserActive = savedInstanceState.getBoolean(KEY_IS_ACCOUNT_CHOOSER_ACTIVE, false); - mCheckedMenuItem = savedInstanceState.getInt(KEY_CHECKED_MENU_ITEM, Menu.NONE); } externalLinksProvider = new ExternalLinksProvider(getContentResolver()); @@ -1021,22 +1010,14 @@ protected void onCreate(Bundle savedInstanceState) { @Override protected void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); - outState.putBoolean(KEY_IS_ACCOUNT_CHOOSER_ACTIVE, mIsAccountChooserActive); - outState.putInt(KEY_CHECKED_MENU_ITEM, mCheckedMenuItem); } @Override public void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); - mIsAccountChooserActive = savedInstanceState.getBoolean(KEY_IS_ACCOUNT_CHOOSER_ACTIVE, false); - mCheckedMenuItem = savedInstanceState.getInt(KEY_CHECKED_MENU_ITEM, Menu.NONE); - - // check/highlight the menu item if present - if (mCheckedMenuItem > Menu.NONE || mCheckedMenuItem < Menu.NONE) { - setDrawerMenuItemChecked(mCheckedMenuItem); - } + setDrawerMenuItemChecked(); } @Override @@ -1053,10 +1034,6 @@ protected void onPostCreate(Bundle savedInstanceState) { updateQuotaLink(); } - public int getCheckedMenuItem() { - return mCheckedMenuItem; - } - @Override public void onConfigurationChanged(@NonNull Configuration newConfig) { super.onConfigurationChanged(newConfig); @@ -1080,12 +1057,6 @@ public void onBackPressed() { } } - @Override - protected void onResume() { - super.onResume(); - setDrawerMenuItemChecked(mCheckedMenuItem); - } - @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); diff --git a/app/src/main/java/com/owncloud/android/ui/activity/ExternalSiteWebView.java b/app/src/main/java/com/owncloud/android/ui/activity/ExternalSiteWebView.java index fb917e19d553..d7c529334c3c 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/ExternalSiteWebView.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/ExternalSiteWebView.java @@ -44,14 +44,12 @@ public class ExternalSiteWebView extends FileActivity { public static final String EXTRA_URL = "URL"; public static final String EXTRA_SHOW_SIDEBAR = "SHOW_SIDEBAR"; public static final String EXTRA_SHOW_TOOLBAR = "SHOW_TOOLBAR"; - public static final String EXTRA_MENU_ITEM_ID = "MENU_ITEM_ID"; public static final String EXTRA_TEMPLATE = "TEMPLATE"; private static final String TAG = ExternalSiteWebView.class.getSimpleName(); protected boolean showToolbar = true; private ExternalsiteWebviewBinding binding; - private int menuItemId; private boolean showSidebar; String url; @@ -67,7 +65,6 @@ protected final void onCreate(Bundle savedInstanceState) { showToolbar = extras.getBoolean(EXTRA_SHOW_TOOLBAR); } - menuItemId = extras.getInt(EXTRA_MENU_ITEM_ID); showSidebar = extras.getBoolean(EXTRA_SHOW_SIDEBAR); // show progress @@ -107,8 +104,7 @@ protected void postOnCreate() { } } - // setup drawer - setupDrawer(menuItemId); + setupDrawer(); if (!showSidebar) { setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); @@ -235,12 +231,6 @@ public boolean onOptionsItemSelected(MenuItem item) { } } - @Override - protected void onPostCreate(Bundle savedInstanceState) { - super.onPostCreate(savedInstanceState); - setDrawerMenuItemChecked(menuItemId); - } - protected WebView getWebView() { return binding.webView; } diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index 9f4726d402ad..a1029ff35328 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -196,8 +196,6 @@ public class FileDisplayActivity extends FileActivity public static final String ACTION_DETAILS = "com.owncloud.android.ui.activity.action.DETAILS"; - public static final String DRAWER_MENU_ID = "DRAWER_MENU_ID"; - public static final int REQUEST_CODE__SELECT_CONTENT_FROM_APPS = REQUEST_CODE__LAST_SHARED + 1; public static final int REQUEST_CODE__SELECT_FILES_FROM_FILE_SYSTEM = REQUEST_CODE__LAST_SHARED + 2; public static final int REQUEST_CODE__MOVE_OR_COPY_FILES = REQUEST_CODE__LAST_SHARED + 3; @@ -231,7 +229,6 @@ public class FileDisplayActivity extends FileActivity private SearchView searchView; private PlayerServiceConnection mPlayerConnection; private Optional lastDisplayedUser = Optional.empty(); - private int menuItemId = -1; @Inject AppPreferences preferences; @@ -382,11 +379,7 @@ protected void onPostCreate(Bundle savedInstanceState) { if (IntentExtensionsKt.getParcelableArgument(getIntent(), OCFileListFragment.SEARCH_EVENT, SearchEvent.class) != null) { switchToSearchFragment(savedInstanceState); - - int menuId = getIntent().getIntExtra(DRAWER_MENU_ID, -1); - if (menuId != -1) { - setupDrawer(menuId); - } + setupDrawer(); } else { createMinFragments(savedInstanceState); syncAndUpdateFolder(true); @@ -1147,10 +1140,7 @@ protected void onResume() { mDownloadFinishReceiver = new DownloadFinishReceiver(); localBroadcastManager.registerReceiver(mDownloadFinishReceiver, downloadIntentFilter); - // setup drawer - menuItemId = getIntent().getIntExtra(FileDisplayActivity.DRAWER_MENU_ID, -1); - - if (menuItemId == -1) { + if (menuItemId == Menu.NONE) { setDrawerAllFiles(); } else { if (menuItemId == R.id.nav_all_files || menuItemId == R.id.nav_personal_files) { @@ -1158,7 +1148,6 @@ protected void onResume() { } else { setupToolbar(); } - setDrawerMenuItemChecked(menuItemId); } if (ocFileListFragment instanceof GalleryFragment) { @@ -1172,18 +1161,19 @@ protected void onResume() { private void setDrawerAllFiles() { if (MainApp.isOnlyPersonFiles()) { - setDrawerMenuItemChecked(R.id.nav_personal_files); + menuItemId = R.id.nav_personal_files; + setDrawerMenuItemChecked(); setupHomeSearchToolbarWithSortAndListButtons(); } else if (MainApp.isOnlyOnDevice()) { - setDrawerMenuItemChecked(R.id.nav_on_device); + menuItemId = R.id.nav_on_device; + setDrawerMenuItemChecked(); setupToolbar(); } else { - int lastMenuItem = getCheckedMenuItem(); - if (lastMenuItem == Menu.NONE) { - lastMenuItem = R.id.nav_all_files; + if (menuItemId == Menu.NONE) { + menuItemId = R.id.nav_all_files; } - setDrawerMenuItemChecked(lastMenuItem); + setDrawerMenuItemChecked(); setupHomeSearchToolbarWithSortAndListButtons(); } } diff --git a/app/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.kt b/app/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.kt index 671efe8492b0..18862e5a9dca 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.kt +++ b/app/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.kt @@ -65,7 +65,7 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View { setupToolbar() updateActionBarTitleAndHomeButtonByString(getString(R.string.drawer_item_notifications)) - setupDrawer(R.id.nav_notifications) + setupDrawer() if (optionalUser?.isPresent == false) { showError() @@ -303,11 +303,6 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View { binding.emptyList.emptyListIcon.visibility = View.VISIBLE } - override fun onResume() { - super.onResume() - setDrawerMenuItemChecked(R.id.nav_notifications) - } - override fun onRemovedNotification(isSuccess: Boolean) { if (!isSuccess) { DisplayUtils.showSnackMessage(this, getString(R.string.remove_notification_failed)) diff --git a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java index 0dbf9ca99e92..9916a5b415f3 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java @@ -284,7 +284,7 @@ private void setupAboutCategory(String appVersion) { getResources().getString(R.string.privacy)); intent.putExtra(ExternalSiteWebView.EXTRA_URL, privacyUrl.toString()); intent.putExtra(ExternalSiteWebView.EXTRA_SHOW_SIDEBAR, false); - intent.putExtra(ExternalSiteWebView.EXTRA_MENU_ITEM_ID, -1); + DrawerActivity.menuItemId = Menu.NONE; } startActivity(intent); @@ -1107,7 +1107,7 @@ private void loadExternalSettingLinks(PreferenceCategory preferenceCategory) { externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_TITLE, link.getName()); externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_URL, link.getUrl()); externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_SHOW_SIDEBAR, false); - externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_MENU_ITEM_ID, link.getId()); + DrawerActivity.menuItemId = link.getId(); startActivity(externalWebViewIntent); return true; diff --git a/app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java index e8c136908e57..a9f8d631c29a 100755 --- a/app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java @@ -131,7 +131,7 @@ protected void onCreate(Bundle savedInstanceState) { updateActionBarTitleAndHomeButtonByString(getString(R.string.uploads_view_title)); // setup drawer - setupDrawer(R.id.nav_uploads); + setupDrawer(); setupContent(); observeWorkerState(); @@ -232,8 +232,6 @@ protected void onResume() { Log_OC.v(TAG, "onResume() start"); super.onResume(); - setDrawerMenuItemChecked(R.id.nav_uploads); - // Listen for upload messages uploadMessagesReceiver = new UploadMessagesReceiver(); IntentFilter uploadIntentFilter = new IntentFilter(); diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java index dc708ad6c4f5..b2c2edf976a1 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -277,20 +277,9 @@ public void onResume() { handleSearchEvent(searchEvent); } - setDrawerMenuItemChecked(); - super.onResume(); } - private void setDrawerMenuItemChecked() { - if (searchEvent != null && searchEvent.getSearchType() == SearchRemoteOperation.SearchType.FAVORITE_SEARCH) { - if (requireActivity() instanceof DrawerActivity activity) { - activity.setDrawerMenuItemChecked(R.id.nav_favorites); - } - } - } - - /** * {@inheritDoc} */ diff --git a/app/src/main/java/com/owncloud/android/ui/trashbin/TrashbinActivity.kt b/app/src/main/java/com/owncloud/android/ui/trashbin/TrashbinActivity.kt index 9097b149611d..04adff7f668e 100644 --- a/app/src/main/java/com/owncloud/android/ui/trashbin/TrashbinActivity.kt +++ b/app/src/main/java/com/owncloud/android/ui/trashbin/TrashbinActivity.kt @@ -109,7 +109,7 @@ class TrashbinActivity : View.GONE updateActionBarTitleAndHomeButtonByString(getString(R.string.trashbin_activity_title)) - setupDrawer(R.id.nav_trashbin) + setupDrawer() } override fun onStart() { @@ -119,12 +119,6 @@ class TrashbinActivity : setupContent() } - override fun onResume() { - super.onResume() - - setDrawerMenuItemChecked(R.id.nav_trashbin) - } - private fun setupContent() { val recyclerView = binding.list recyclerView.setEmptyView(binding.emptyList.emptyListView) From 5cb2e3a41015ee1eb1d300cc5d6965523ed909b6 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 4 Sep 2024 11:52:35 +0200 Subject: [PATCH 03/14] Only highlight new menu item Signed-off-by: alperozturk --- .../owncloud/android/ui/activity/DrawerActivity.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index c7b5b75ddd46..0b33a34adf40 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -875,13 +875,19 @@ public void setDrawerMenuItemChecked() { return; } - if (mNavigationView.getMenu().findItem(menuItemId) == null) { + MenuItem menuItem = mNavigationView.getMenu().findItem(menuItemId); + + if (menuItem == null) { Log_OC.w(TAG, "setDrawerMenuItemChecked has been called with invalid menu-item-ID"); return; } + if (menuItem.isChecked()) { + return; + } + viewThemeUtils.platform.colorNavigationView(mNavigationView); - mNavigationView.getMenu().findItem(menuItemId).setChecked(true); + menuItem.setChecked(true); } /** From 06ad7d023908c11b59b7ad60c505f9e67b347f09 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 4 Sep 2024 12:07:09 +0200 Subject: [PATCH 04/14] Allow to set Menu.NONE Signed-off-by: alperozturk --- .../android/ui/activity/DrawerActivity.java | 2 +- .../android/ui/activity/FileDisplayActivity.java | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index 0b33a34adf40..cf14fb8ca343 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -871,7 +871,7 @@ public void onLoadFailed(Exception e, Drawable errorDrawable) { * */ public void setDrawerMenuItemChecked() { - if (menuItemId == Menu.NONE || mNavigationView == null) { + if (mNavigationView == null) { return; } diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index a1029ff35328..e35d5526220c 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -1158,22 +1158,20 @@ protected void onResume() { Log_OC.v(TAG, "onResume() end"); } - private void setDrawerAllFiles() { if (MainApp.isOnlyPersonFiles()) { menuItemId = R.id.nav_personal_files; - setDrawerMenuItemChecked(); - setupHomeSearchToolbarWithSortAndListButtons(); } else if (MainApp.isOnlyOnDevice()) { menuItemId = R.id.nav_on_device; - setDrawerMenuItemChecked(); + } else if (menuItemId == Menu.NONE) { + menuItemId = R.id.nav_all_files; + } + + setDrawerMenuItemChecked(); + + if (MainApp.isOnlyOnDevice()) { setupToolbar(); } else { - if (menuItemId == Menu.NONE) { - menuItemId = R.id.nav_all_files; - } - - setDrawerMenuItemChecked(); setupHomeSearchToolbarWithSortAndListButtons(); } } From 403b34e8cf3a7e8ee13182e94f62a34894db5f9f Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 4 Sep 2024 12:09:26 +0200 Subject: [PATCH 05/14] Reduce lint Signed-off-by: alperozturk --- .../com/owncloud/android/ui/activities/ActivitiesActivity.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/activities/ActivitiesActivity.java b/app/src/main/java/com/owncloud/android/ui/activities/ActivitiesActivity.java index 47f51b83249f..53aeb637f0cb 100644 --- a/app/src/main/java/com/owncloud/android/ui/activities/ActivitiesActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activities/ActivitiesActivity.java @@ -29,7 +29,6 @@ import com.owncloud.android.ui.preview.PreviewImageActivity; import com.owncloud.android.ui.preview.PreviewImageFragment; import com.owncloud.android.utils.DisplayUtils; -import com.owncloud.android.utils.theme.ViewThemeUtils; import java.util.List; @@ -59,7 +58,6 @@ public class ActivitiesActivity extends DrawerActivity implements ActivityListIn @Inject ActivitiesRepository activitiesRepository; @Inject FilesRepository filesRepository; @Inject ClientFactory clientFactory; - @Inject ViewThemeUtils viewThemeUtils; @Override protected void onCreate(Bundle savedInstanceState) { From 1543685b5c408a5a9ae035439bc4720d7925425f Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 4 Sep 2024 13:18:58 +0200 Subject: [PATCH 06/14] Better flow and menu item selection before opening Signed-off-by: alperozturk --- .../utils/extensions/ContextExtensions.kt | 7 ++++ .../android/ui/activity/DrawerActivity.java | 42 ++++++++++++++++--- .../android/ui/activity/SettingsActivity.java | 36 ++++++++++------ 3 files changed, 67 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt index f3e4d89abcc2..813589411d60 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt @@ -16,8 +16,10 @@ import android.os.Build import android.os.Handler import android.os.Looper import android.widget.Toast +import androidx.localbroadcastmanager.content.LocalBroadcastManager import com.google.common.io.Resources import com.owncloud.android.datamodel.ReceiverFlag +import com.owncloud.android.ui.activity.DrawerActivity @SuppressLint("UnspecifiedRegisterReceiverFlag") fun Context.registerBroadcastReceiver(receiver: BroadcastReceiver?, filter: IntentFilter, flag: ReceiverFlag): Intent? { @@ -53,3 +55,8 @@ fun Context.showToast(message: String) { } fun Context.showToast(messageId: Int) = showToast(getString(messageId)) + +fun Context.sendOpenDrawerEvent() { + val intent = Intent(DrawerActivity.OPEN_DRAWER_MENU) + LocalBroadcastManager.getInstance(this).sendBroadcast(intent) +} diff --git a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index cf14fb8ca343..a76020e38c83 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -15,8 +15,10 @@ import android.accounts.AuthenticatorException; import android.accounts.OperationCanceledException; import android.app.Activity; +import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.content.res.ColorStateList; import android.content.res.Configuration; import android.graphics.Bitmap; @@ -122,6 +124,7 @@ import androidx.core.view.GravityCompat; import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.Fragment; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; import hct.Hct; /** @@ -138,6 +141,7 @@ public abstract class DrawerActivity extends ToolbarActivity private static final int MENU_ITEM_EXTERNAL_LINK = 111; private static final int MAX_LOGO_SIZE_PX = 1000; private static final int RELATIVE_THRESHOLD_WARNING = 80; + public static final String OPEN_DRAWER_MENU = "OPEN_DRAWER_MENU"; /** * Reference to the drawer layout. @@ -230,6 +234,14 @@ protected void setupDrawer() { private void setupDrawerToggle() { mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) { + @Override + public void onDrawerSlide(View drawerView, float slideOffset) { + super.onDrawerSlide(drawerView, slideOffset); + if (slideOffset > 0) { + setDrawerMenuItemChecked(); + } + } + /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); @@ -249,7 +261,6 @@ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); mDrawerToggle.setDrawerIndicatorEnabled(true); supportInvalidateOptionsMenu(); - setDrawerMenuItemChecked(); } }; @@ -866,6 +877,30 @@ public void onLoadFailed(Exception e, Drawable errorDrawable) { } } + @Override + protected void onDestroy() { + super.onDestroy(); + try { + LocalBroadcastManager.getInstance(this).unregisterReceiver(openDrawerReceiver); + } catch (IllegalArgumentException e) { + Log_OC.d(TAG, "drawerMenuUpdateReceiver not registered"); + } + } + + private void registerOpenDrawerReceiver() { + IntentFilter filter = new IntentFilter(OPEN_DRAWER_MENU); + LocalBroadcastManager.getInstance(this).registerReceiver(openDrawerReceiver, filter); + } + + private final BroadcastReceiver openDrawerReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (!isDrawerOpen()) { + openDrawer(); + } + } + }; + /** * checks/highlights the provided menu item if the drawer has been initialized and the menu item exists. * @@ -882,10 +917,6 @@ public void setDrawerMenuItemChecked() { return; } - if (menuItem.isChecked()) { - return; - } - viewThemeUtils.platform.colorNavigationView(mNavigationView); menuItem.setChecked(true); } @@ -1011,6 +1042,7 @@ protected void onCreate(Bundle savedInstanceState) { externalLinksProvider = new ExternalLinksProvider(getContentResolver()); arbitraryDataProvider = new ArbitraryDataProviderImpl(this); + registerOpenDrawerReceiver(); } @Override diff --git a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java index 9916a5b415f3..2fa492c97001 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java @@ -21,6 +21,7 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Configuration; +import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.preference.ListPreference; @@ -49,6 +50,7 @@ import com.nextcloud.client.preferences.AppPreferences; import com.nextcloud.client.preferences.AppPreferencesImpl; import com.nextcloud.client.preferences.DarkMode; +import com.nextcloud.utils.extensions.ContextExtensionsKt; import com.owncloud.android.BuildConfig; import com.owncloud.android.MainApp; import com.owncloud.android.R; @@ -876,20 +878,28 @@ public boolean onOptionsItemSelected(MenuItem item) { private void setupActionBar() { ActionBar actionBar = getDelegate().getSupportActionBar(); + if (actionBar == null) return; + + viewThemeUtils.platform.themeStatusBar(this); + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setDisplayShowTitleEnabled(true); + + if (getResources() == null) return; + Drawable menuIcon = ResourcesCompat.getDrawable(getResources(), + R.drawable.ic_menu, + null); + + if (menuIcon == null) return; + viewThemeUtils.androidx.themeActionBar(this, + actionBar, + getString(R.string.actionbar_settings), + menuIcon); + } - if (actionBar != null) { - viewThemeUtils.platform.themeStatusBar(this); - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setDisplayShowTitleEnabled(true); - if (this.getResources() != null) { - viewThemeUtils.androidx.themeActionBar(this, - actionBar, - getString(R.string.actionbar_settings), - ResourcesCompat.getDrawable(this.getResources(), - R.drawable.ic_arrow_back, - null)); - } - } + @Override + public void onBackPressed() { + ContextExtensionsKt.sendOpenDrawerEvent(this); + // super.onBackPressed(); } private void launchDavDroidLogin() { From cb0e8baf609e5628ead5c05051180b9e5094db54 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 4 Sep 2024 14:02:54 +0200 Subject: [PATCH 07/14] Use getMenuItemIdFromTitle Signed-off-by: alperozturk --- .../extensions/DrawerActivityExtensions.kt | 43 +++++++++++++++++++ .../android/ui/activity/DrawerActivity.java | 6 +++ 2 files changed, 49 insertions(+) create mode 100644 app/src/main/java/com/nextcloud/utils/extensions/DrawerActivityExtensions.kt diff --git a/app/src/main/java/com/nextcloud/utils/extensions/DrawerActivityExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/DrawerActivityExtensions.kt new file mode 100644 index 000000000000..c6e1a0f79a8a --- /dev/null +++ b/app/src/main/java/com/nextcloud/utils/extensions/DrawerActivityExtensions.kt @@ -0,0 +1,43 @@ +/* + * Nextcloud - Android Client + * + * SPDX-FileCopyrightText: 2024 Alper Ozturk + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +package com.nextcloud.utils.extensions + +import com.owncloud.android.R +import com.owncloud.android.ui.activity.DrawerActivity + +/** + * Determines the appropriate menu item ID based on the current ActionBar title. + * + * This function serves as a workaround solution because not all drawer menu item + * navigations extend from DrawerActivity. As a result, the content and highlighted + * menu item may not always match. This function helps maintain consistency between + * the displayed content and the highlighted menu item. + * + * @return The menu item ID corresponding to the current ActionBar title, or null if + * the ActionBar is not available. + */ +fun DrawerActivity.getMenuItemIdFromTitle(): Int? { + val actionBar = supportActionBar ?: return null + + return when (actionBar.title) { + getString(R.string.drawer_item_all_files) -> R.id.nav_all_files + getString(R.string.drawer_item_personal_files) -> R.id.nav_personal_files + getString(R.string.drawer_item_activities) -> R.id.nav_activity + getString(R.string.drawer_item_favorites) -> R.id.nav_favorites + getString(R.string.drawer_item_gallery) -> R.id.nav_gallery + getString(R.string.drawer_item_shared) -> R.id.nav_shared + getString(R.string.drawer_item_groupfolders) -> R.id.nav_groupfolders + getString(R.string.drawer_item_on_device) -> R.id.nav_on_device + getString(R.string.drawer_item_recently_modified) -> R.id.nav_recently_modified + getString(R.string.drawer_item_notifications) -> R.id.nav_notifications + getString(R.string.drawer_item_assistant) -> R.id.nav_assistant + getString(R.string.drawer_item_uploads_list) -> R.id.nav_uploads + getString(R.string.drawer_item_trashbin) -> R.id.nav_trashbin + else -> DrawerActivity.menuItemId + } +} diff --git a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index a76020e38c83..023bc9ee9f51 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -127,6 +127,8 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager; import hct.Hct; +import static com.nextcloud.utils.extensions.DrawerActivityExtensionsKt.getMenuItemIdFromTitle; + /** * Base class to handle setup of the drawer implementation including user switching and avatar fetching and fallback * generation. @@ -238,6 +240,10 @@ private void setupDrawerToggle() { public void onDrawerSlide(View drawerView, float slideOffset) { super.onDrawerSlide(drawerView, slideOffset); if (slideOffset > 0) { + Integer menuItemIdFromTitle = getMenuItemIdFromTitle(DrawerActivity.this); + if (menuItemIdFromTitle != null && menuItemIdFromTitle != menuItemId) { + menuItemId = menuItemIdFromTitle; + } setDrawerMenuItemChecked(); } } From ae5cee70569db4047014315dba35478b8235bfac Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 4 Sep 2024 14:22:00 +0200 Subject: [PATCH 08/14] Remove drawer open event Signed-off-by: alperozturk --- .../utils/extensions/ContextExtensions.kt | 5 ---- .../android/ui/activity/DrawerActivity.java | 30 +++---------------- .../android/ui/activity/SettingsActivity.java | 16 ++++------ 3 files changed, 9 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt index 813589411d60..246c8b47f4df 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt @@ -55,8 +55,3 @@ fun Context.showToast(message: String) { } fun Context.showToast(messageId: Int) = showToast(getString(messageId)) - -fun Context.sendOpenDrawerEvent() { - val intent = Intent(DrawerActivity.OPEN_DRAWER_MENU) - LocalBroadcastManager.getInstance(this).sendBroadcast(intent) -} diff --git a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index 023bc9ee9f51..45b5867db05f 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -143,7 +143,6 @@ public abstract class DrawerActivity extends ToolbarActivity private static final int MENU_ITEM_EXTERNAL_LINK = 111; private static final int MAX_LOGO_SIZE_PX = 1000; private static final int RELATIVE_THRESHOLD_WARNING = 80; - public static final String OPEN_DRAWER_MENU = "OPEN_DRAWER_MENU"; /** * Reference to the drawer layout. @@ -883,30 +882,6 @@ public void onLoadFailed(Exception e, Drawable errorDrawable) { } } - @Override - protected void onDestroy() { - super.onDestroy(); - try { - LocalBroadcastManager.getInstance(this).unregisterReceiver(openDrawerReceiver); - } catch (IllegalArgumentException e) { - Log_OC.d(TAG, "drawerMenuUpdateReceiver not registered"); - } - } - - private void registerOpenDrawerReceiver() { - IntentFilter filter = new IntentFilter(OPEN_DRAWER_MENU); - LocalBroadcastManager.getInstance(this).registerReceiver(openDrawerReceiver, filter); - } - - private final BroadcastReceiver openDrawerReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - if (!isDrawerOpen()) { - openDrawer(); - } - } - }; - /** * checks/highlights the provided menu item if the drawer has been initialized and the menu item exists. * @@ -923,6 +898,10 @@ public void setDrawerMenuItemChecked() { return; } + if (menuItem.isChecked()) { + return; + } + viewThemeUtils.platform.colorNavigationView(mNavigationView); menuItem.setChecked(true); } @@ -1048,7 +1027,6 @@ protected void onCreate(Bundle savedInstanceState) { externalLinksProvider = new ExternalLinksProvider(getContentResolver()); arbitraryDataProvider = new ArbitraryDataProviderImpl(this); - registerOpenDrawerReceiver(); } @Override diff --git a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java index 2fa492c97001..84a33f1c4bfe 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java @@ -175,7 +175,7 @@ public void onCreate(Bundle savedInstanceState) { // Sync setupSyncCategory(); - + // More setupMoreCategory(); @@ -315,7 +315,7 @@ private void setupAboutCategory(String appVersion) { } } } - + private void setupSyncCategory() { final PreferenceCategory preferenceCategorySync = (PreferenceCategory) findPreference("sync"); viewThemeUtils.files.themePreferenceCategory(preferenceCategorySync); @@ -559,10 +559,10 @@ private void setupAutoUploadPreference(PreferenceCategory preferenceCategoryMore }); } } - + private void setupInternalTwoWaySyncPreference(PreferenceCategory preferenceCategorySync) { Preference twoWaySync = findPreference("internal_two_way_sync"); - + twoWaySync.setOnPreferenceClickListener(preference -> { Intent intent = new Intent(this, InternalTwoWaySyncActivity.class); startActivity(intent); @@ -886,7 +886,7 @@ private void setupActionBar() { if (getResources() == null) return; Drawable menuIcon = ResourcesCompat.getDrawable(getResources(), - R.drawable.ic_menu, + R.drawable.ic_arrow_back, null); if (menuIcon == null) return; @@ -896,12 +896,6 @@ private void setupActionBar() { menuIcon); } - @Override - public void onBackPressed() { - ContextExtensionsKt.sendOpenDrawerEvent(this); - // super.onBackPressed(); - } - private void launchDavDroidLogin() { Intent davDroidLoginIntent = new Intent(); davDroidLoginIntent.setClassName("at.bitfire.davdroid", "at.bitfire.davdroid.ui.setup.LoginActivity"); From 92c720e49f1619d1420ef90da9a7bd0f2dbc4b7a Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 4 Sep 2024 14:30:41 +0200 Subject: [PATCH 09/14] Change back behaviour of SettingsActivity due to not extending from DrawerActivity Signed-off-by: alperozturk --- .../android/ui/activity/FileDisplayActivity.java | 4 ++-- .../owncloud/android/ui/activity/SettingsActivity.java | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index e35d5526220c..bcc065ee0256 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -554,13 +554,13 @@ protected void onNewIntent(Intent intent) { } } else if (ALL_FILES.equals(intent.getAction())) { Log_OC.d(this, "Switch to oc file fragment"); - + DrawerActivity.menuItemId = R.id.nav_all_files; setLeftFragment(new OCFileListFragment()); getSupportFragmentManager().executePendingTransactions(); browseToRoot(); } else if (LIST_GROUPFOLDERS.equals(intent.getAction())) { Log_OC.d(this, "Switch to list groupfolders fragment"); - + DrawerActivity.menuItemId = R.id.nav_groupfolders; setLeftFragment(new GroupfolderListFragment()); getSupportFragmentManager().executePendingTransactions(); } else { diff --git a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java index 84a33f1c4bfe..54eb81f2a795 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java @@ -50,7 +50,6 @@ import com.nextcloud.client.preferences.AppPreferences; import com.nextcloud.client.preferences.AppPreferencesImpl; import com.nextcloud.client.preferences.DarkMode; -import com.nextcloud.utils.extensions.ContextExtensionsKt; import com.owncloud.android.BuildConfig; import com.owncloud.android.MainApp; import com.owncloud.android.R; @@ -316,6 +315,14 @@ private void setupAboutCategory(String appVersion) { } } + @Override + public void onBackPressed() { + Intent i = new Intent(this, FileDisplayActivity.class); + i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + i.setAction(FileDisplayActivity.ALL_FILES); + startActivity(i); + } + private void setupSyncCategory() { final PreferenceCategory preferenceCategorySync = (PreferenceCategory) findPreference("sync"); viewThemeUtils.files.themePreferenceCategory(preferenceCategorySync); From 45d363a417d4e6d6147927a897442b60437d2761 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 4 Sep 2024 14:38:34 +0200 Subject: [PATCH 10/14] Remove workaround Signed-off-by: alperozturk --- .../extensions/DrawerActivityExtensions.kt | 43 ------------------- .../android/ui/activity/DrawerActivity.java | 14 ++---- 2 files changed, 4 insertions(+), 53 deletions(-) delete mode 100644 app/src/main/java/com/nextcloud/utils/extensions/DrawerActivityExtensions.kt diff --git a/app/src/main/java/com/nextcloud/utils/extensions/DrawerActivityExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/DrawerActivityExtensions.kt deleted file mode 100644 index c6e1a0f79a8a..000000000000 --- a/app/src/main/java/com/nextcloud/utils/extensions/DrawerActivityExtensions.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Nextcloud - Android Client - * - * SPDX-FileCopyrightText: 2024 Alper Ozturk - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -package com.nextcloud.utils.extensions - -import com.owncloud.android.R -import com.owncloud.android.ui.activity.DrawerActivity - -/** - * Determines the appropriate menu item ID based on the current ActionBar title. - * - * This function serves as a workaround solution because not all drawer menu item - * navigations extend from DrawerActivity. As a result, the content and highlighted - * menu item may not always match. This function helps maintain consistency between - * the displayed content and the highlighted menu item. - * - * @return The menu item ID corresponding to the current ActionBar title, or null if - * the ActionBar is not available. - */ -fun DrawerActivity.getMenuItemIdFromTitle(): Int? { - val actionBar = supportActionBar ?: return null - - return when (actionBar.title) { - getString(R.string.drawer_item_all_files) -> R.id.nav_all_files - getString(R.string.drawer_item_personal_files) -> R.id.nav_personal_files - getString(R.string.drawer_item_activities) -> R.id.nav_activity - getString(R.string.drawer_item_favorites) -> R.id.nav_favorites - getString(R.string.drawer_item_gallery) -> R.id.nav_gallery - getString(R.string.drawer_item_shared) -> R.id.nav_shared - getString(R.string.drawer_item_groupfolders) -> R.id.nav_groupfolders - getString(R.string.drawer_item_on_device) -> R.id.nav_on_device - getString(R.string.drawer_item_recently_modified) -> R.id.nav_recently_modified - getString(R.string.drawer_item_notifications) -> R.id.nav_notifications - getString(R.string.drawer_item_assistant) -> R.id.nav_assistant - getString(R.string.drawer_item_uploads_list) -> R.id.nav_uploads - getString(R.string.drawer_item_trashbin) -> R.id.nav_trashbin - else -> DrawerActivity.menuItemId - } -} diff --git a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index 45b5867db05f..3be597c57d14 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -15,10 +15,8 @@ import android.accounts.AuthenticatorException; import android.accounts.OperationCanceledException; import android.app.Activity; -import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.content.IntentFilter; import android.content.res.ColorStateList; import android.content.res.Configuration; import android.graphics.Bitmap; @@ -124,11 +122,8 @@ import androidx.core.view.GravityCompat; import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.Fragment; -import androidx.localbroadcastmanager.content.LocalBroadcastManager; import hct.Hct; -import static com.nextcloud.utils.extensions.DrawerActivityExtensionsKt.getMenuItemIdFromTitle; - /** * Base class to handle setup of the drawer implementation including user switching and avatar fetching and fallback * generation. @@ -234,16 +229,14 @@ protected void setupDrawer() { */ private void setupDrawerToggle() { mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) { + private boolean isMenuItemChecked = false; @Override public void onDrawerSlide(View drawerView, float slideOffset) { super.onDrawerSlide(drawerView, slideOffset); - if (slideOffset > 0) { - Integer menuItemIdFromTitle = getMenuItemIdFromTitle(DrawerActivity.this); - if (menuItemIdFromTitle != null && menuItemIdFromTitle != menuItemId) { - menuItemId = menuItemIdFromTitle; - } + if (slideOffset > 0 && !isMenuItemChecked) { setDrawerMenuItemChecked(); + isMenuItemChecked = true; } } @@ -258,6 +251,7 @@ public void onDrawerClosed(View view) { pendingRunnable = null; } + isMenuItemChecked = false; closeDrawer(); } From 79d6c7ca4168452af3eb474a44006364bae78449 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 4 Sep 2024 14:39:09 +0200 Subject: [PATCH 11/14] Fix kotlin spotless check Signed-off-by: alperozturk --- .../java/com/nextcloud/utils/extensions/ContextExtensions.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt index 246c8b47f4df..f3e4d89abcc2 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt @@ -16,10 +16,8 @@ import android.os.Build import android.os.Handler import android.os.Looper import android.widget.Toast -import androidx.localbroadcastmanager.content.LocalBroadcastManager import com.google.common.io.Resources import com.owncloud.android.datamodel.ReceiverFlag -import com.owncloud.android.ui.activity.DrawerActivity @SuppressLint("UnspecifiedRegisterReceiverFlag") fun Context.registerBroadcastReceiver(receiver: BroadcastReceiver?, filter: IntentFilter, flag: ReceiverFlag): Intent? { From cab8c790ef6022c91f43f2268f6326ab34aa94a0 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 4 Sep 2024 14:40:46 +0200 Subject: [PATCH 12/14] Optimize imports Signed-off-by: alperozturk --- .../com/owncloud/android/ui/fragment/OCFileListFragment.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java index b2c2edf976a1..23215455668a 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -80,7 +80,6 @@ import com.owncloud.android.lib.resources.files.ToggleFavoriteRemoteOperation; import com.owncloud.android.lib.resources.status.E2EVersion; import com.owncloud.android.lib.resources.status.OCCapability; -import com.owncloud.android.ui.activity.DrawerActivity; import com.owncloud.android.ui.activity.FileActivity; import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.ui.activity.FolderPickerActivity; From 530ea26cde8d9009c0d4074fc06a2086b9609257 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 4 Sep 2024 16:42:45 +0200 Subject: [PATCH 13/14] Compare content and selected drawer menu item Signed-off-by: alperozturk --- .../extensions/DrawerActivityExtensions.kt | 44 +++++++++++++++++++ .../android/ui/activity/DrawerActivity.java | 6 +++ 2 files changed, 50 insertions(+) create mode 100644 app/src/main/java/com/nextcloud/utils/extensions/DrawerActivityExtensions.kt diff --git a/app/src/main/java/com/nextcloud/utils/extensions/DrawerActivityExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/DrawerActivityExtensions.kt new file mode 100644 index 000000000000..3b5d7dd8cc0d --- /dev/null +++ b/app/src/main/java/com/nextcloud/utils/extensions/DrawerActivityExtensions.kt @@ -0,0 +1,44 @@ +/* + * Nextcloud - Android Client + * + * SPDX-FileCopyrightText: 2024 Alper Ozturk + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +package com.nextcloud.utils.extensions + +import com.owncloud.android.R +import com.owncloud.android.ui.activity.DrawerActivity + +/** + * Determines the appropriate menu item ID based on the current ActionBar title. + * + * This function serves as a workaround solution because not all drawer menu item + * navigations extend from DrawerActivity and back button changes content but not the drawer menu item. + * As a result, the content and highlighted + * menu item may not always match. This function helps maintain consistency between + * the displayed content and the highlighted menu item. + * + * @return The menu item ID corresponding to the current ActionBar title, or null if + * the ActionBar is not available. + */ +fun DrawerActivity.getMenuItemIdFromTitle(): Int? { + val actionBar = supportActionBar ?: return null + + return when (actionBar.title.toString()) { + getString(R.string.drawer_item_all_files) -> R.id.nav_all_files + getString(R.string.drawer_item_personal_files) -> R.id.nav_personal_files + getString(R.string.drawer_item_activities) -> R.id.nav_activity + getString(R.string.drawer_item_favorites) -> R.id.nav_favorites + getString(R.string.drawer_item_gallery) -> R.id.nav_gallery + getString(R.string.drawer_item_shared) -> R.id.nav_shared + getString(R.string.drawer_item_groupfolders) -> R.id.nav_groupfolders + getString(R.string.drawer_item_on_device) -> R.id.nav_on_device + getString(R.string.drawer_item_recently_modified) -> R.id.nav_recently_modified + getString(R.string.drawer_item_notifications) -> R.id.nav_notifications + getString(R.string.drawer_item_assistant) -> R.id.nav_assistant + getString(R.string.drawer_item_uploads_list) -> R.id.nav_uploads + getString(R.string.drawer_item_trashbin) -> R.id.nav_trashbin + else -> DrawerActivity.menuItemId + } +} diff --git a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index 3be597c57d14..520bbeeec907 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -124,6 +124,8 @@ import androidx.fragment.app.Fragment; import hct.Hct; +import static com.nextcloud.utils.extensions.DrawerActivityExtensionsKt.getMenuItemIdFromTitle; + /** * Base class to handle setup of the drawer implementation including user switching and avatar fetching and fallback * generation. @@ -235,6 +237,10 @@ private void setupDrawerToggle() { public void onDrawerSlide(View drawerView, float slideOffset) { super.onDrawerSlide(drawerView, slideOffset); if (slideOffset > 0 && !isMenuItemChecked) { + Integer menuItemIdFromTitle = getMenuItemIdFromTitle(DrawerActivity.this); + if (menuItemIdFromTitle != null && menuItemIdFromTitle != menuItemId) { + menuItemId = menuItemIdFromTitle; + } setDrawerMenuItemChecked(); isMenuItemChecked = true; } From 5f03caeac5692e8d16a096b368a6b9c06d3b0274 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 10 Sep 2024 14:21:32 +0200 Subject: [PATCH 14/14] Fix for AOSP version Signed-off-by: alperozturk --- .../utils/extensions/DrawerActivityExtensions.kt | 11 ++++++++++- .../owncloud/android/ui/activity/DrawerActivity.java | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/nextcloud/utils/extensions/DrawerActivityExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/DrawerActivityExtensions.kt index 3b5d7dd8cc0d..18cef7ab9682 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/DrawerActivityExtensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/DrawerActivityExtensions.kt @@ -7,6 +7,7 @@ package com.nextcloud.utils.extensions +import com.owncloud.android.MainApp import com.owncloud.android.R import com.owncloud.android.ui.activity.DrawerActivity @@ -39,6 +40,14 @@ fun DrawerActivity.getMenuItemIdFromTitle(): Int? { getString(R.string.drawer_item_assistant) -> R.id.nav_assistant getString(R.string.drawer_item_uploads_list) -> R.id.nav_uploads getString(R.string.drawer_item_trashbin) -> R.id.nav_trashbin - else -> DrawerActivity.menuItemId + else -> { + if (MainApp.isOnlyPersonFiles()) { + R.id.nav_personal_files + } else if (MainApp.isOnlyOnDevice()) { + R.id.nav_on_device + } else { + DrawerActivity.menuItemId + } + } } } diff --git a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index 520bbeeec907..2bfaf8ce8636 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -902,6 +902,8 @@ public void setDrawerMenuItemChecked() { return; } + Log_OC.d(TAG, "New menu item is: " + menuItemId); + viewThemeUtils.platform.colorNavigationView(mNavigationView); menuItem.setChecked(true); }