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/nextcloud/utils/extensions/DrawerActivityExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/DrawerActivityExtensions.kt new file mode 100644 index 000000000000..18cef7ab9682 --- /dev/null +++ b/app/src/main/java/com/nextcloud/utils/extensions/DrawerActivityExtensions.kt @@ -0,0 +1,53 @@ +/* + * 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.MainApp +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 -> { + 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/activities/ActivitiesActivity.java b/app/src/main/java/com/owncloud/android/ui/activities/ActivitiesActivity.java index c1e3c45102f7..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) { @@ -77,7 +75,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 +151,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 42991b80590e..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 @@ -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. @@ -133,7 +135,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 +169,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 +201,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. */ @@ -241,6 +231,20 @@ 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 && !isMenuItemChecked) { + Integer menuItemIdFromTitle = getMenuItemIdFromTitle(DrawerActivity.this); + if (menuItemIdFromTitle != null && menuItemIdFromTitle != menuItemId) { + menuItemId = menuItemIdFromTitle; + } + setDrawerMenuItemChecked(); + isMenuItemChecked = true; + } + } /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { @@ -253,6 +257,7 @@ public void onDrawerClosed(View view) { pendingRunnable = null; } + isMenuItemChecked = false; closeDrawer(); } @@ -272,7 +277,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 +371,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 +497,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 +521,6 @@ private void onNavigationItemClicked(final MenuItem menuItem) { } intent.setAction(FileDisplayActivity.ALL_FILES); - intent.putExtra(FileDisplayActivity.DRAWER_MENU_ID, menuItem.getItemId()); startActivity(intent); } @@ -537,7 +546,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 +558,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 +576,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 +651,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 +661,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 +688,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 +821,7 @@ private void unsetAllDrawerMenuItems() { } } - mCheckedMenuItem = Menu.NONE; + menuItemId = Menu.NONE; } private void updateQuotaLink() { @@ -836,7 +842,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 +885,27 @@ 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 */ - protected 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 (mNavigationView == null) { + return; + } + + 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; + } + + Log_OC.d(TAG, "New menu item is: " + menuItemId); + + viewThemeUtils.platform.colorNavigationView(mNavigationView); + menuItem.setChecked(true); } /** @@ -988,8 +1005,6 @@ public void onLoadFailed(Exception e, Drawable errorDrawable) { target, R.drawable.ic_link); } - - setDrawerMenuItemChecked(mCheckedMenuItem); } } @@ -1008,10 +1023,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 +1034,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 +1058,6 @@ protected void onPostCreate(Bundle savedInstanceState) { updateQuotaLink(); } - public int getCheckedMenuItem() { - return mCheckedMenuItem; - } - @Override public void onConfigurationChanged(@NonNull Configuration newConfig) { super.onConfigurationChanged(newConfig); @@ -1080,12 +1081,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..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 @@ -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); @@ -561,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 { @@ -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) { @@ -1169,21 +1158,20 @@ protected void onResume() { Log_OC.v(TAG, "onResume() end"); } - private void setDrawerAllFiles() { if (MainApp.isOnlyPersonFiles()) { - setDrawerMenuItemChecked(R.id.nav_personal_files); - setupHomeSearchToolbarWithSortAndListButtons(); + menuItemId = R.id.nav_personal_files; } else if (MainApp.isOnlyOnDevice()) { - setDrawerMenuItemChecked(R.id.nav_on_device); + menuItemId = R.id.nav_on_device; + } else if (menuItemId == Menu.NONE) { + menuItemId = R.id.nav_all_files; + } + + setDrawerMenuItemChecked(); + + if (MainApp.isOnlyOnDevice()) { setupToolbar(); } else { - int lastMenuItem = getCheckedMenuItem(); - if (lastMenuItem == Menu.NONE) { - lastMenuItem = R.id.nav_all_files; - } - - setDrawerMenuItemChecked(lastMenuItem); 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..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 @@ -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; @@ -173,7 +174,7 @@ public void onCreate(Bundle savedInstanceState) { // Sync setupSyncCategory(); - + // More setupMoreCategory(); @@ -284,7 +285,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); @@ -313,7 +314,15 @@ 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); @@ -557,10 +566,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); @@ -876,20 +885,22 @@ public boolean onOptionsItemSelected(MenuItem item) { private void setupActionBar() { ActionBar actionBar = getDelegate().getSupportActionBar(); - - 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)); - } - } + 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_arrow_back, + null); + + if (menuIcon == null) return; + viewThemeUtils.androidx.themeActionBar(this, + actionBar, + getString(R.string.actionbar_settings), + menuIcon); } private void launchDavDroidLogin() { @@ -1107,7 +1118,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 2370560a907e..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 @@ -93,8 +93,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; @@ -279,7 +279,6 @@ public void onResume() { super.onResume(); } - /** * {@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)