Skip to content

Commit

Permalink
Merge pull request #13513 from nextcloud/bugfix/unify-drawer-menu-ite…
Browse files Browse the repository at this point in the history
…m-handling

BugFix - Unify Drawer Menu Item Handling
  • Loading branch information
alperozturk96 committed Sep 12, 2024
2 parents 295814b + 5f03cae commit af3b19d
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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?) {
Expand All @@ -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()
Expand All @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2024 Alper Ozturk <[email protected]>
* 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
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand All @@ -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(() -> {
Expand Down Expand Up @@ -153,11 +151,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
protected void onResume() {
super.onResume();

actionListener.onResume();

setDrawerMenuItemChecked(R.id.nav_activity);

setupContent();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -125,9 +125,4 @@ open class CommunityActivity : DrawerActivity() {
}
return retval
}

override fun onResume() {
super.onResume()
setDrawerMenuItemChecked(R.id.nav_community)
}
}
Loading

0 comments on commit af3b19d

Please sign in to comment.