forked from nextcloud/android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawerActivityExtensions.kt
More file actions
84 lines (74 loc) · 3.15 KB
/
DrawerActivityExtensions.kt
File metadata and controls
84 lines (74 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2024 Alper Ozturk <alper.ozturk@nextcloud.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
package com.nextcloud.utils.extensions
import android.content.Intent
import com.owncloud.android.MainApp
import com.owncloud.android.R
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.ui.activity.DrawerActivity
import com.owncloud.android.ui.activity.FileDisplayActivity
/**
* 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_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
getString(R.string.drawer_item_album) -> R.id.nav_album
else -> {
if (MainApp.isOnlyPersonFiles()) {
R.id.nav_personal_files
} else if (MainApp.isOnlyOnDevice()) {
R.id.nav_on_device
} else {
DrawerActivity.menuItemId
}
}
}
}
@Suppress("ReturnCount")
fun DrawerActivity.handleBackButtonEvent(currentDir: OCFile): Boolean {
if (DrawerActivity.menuItemId == R.id.nav_all_files && currentDir.isRootDirectory) {
moveTaskToBack(true)
return true
}
val isParentDirExists = (storageManager.getFileById(currentDir.parentId) != null)
if (isParentDirExists) {
return false
}
DrawerActivity.menuItemId = R.id.nav_all_files
setNavigationViewItemChecked()
MainApp.showOnlyFilesOnDevice(false)
MainApp.showOnlyPersonalFiles(false)
Intent(applicationContext, FileDisplayActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
action = FileDisplayActivity.ALL_FILES
}.run {
startActivity(this)
}
return true
}