Skip to content

Commit 92c01b7

Browse files
ADFA-1179: Display editor toolbar menu items in a scroll view (#322)
* WIP(ADFA-307): create custom toolbar * fix (ADFA-307): remove duplicate menu items * feat(ADFA-307): Add arrows to the start and end of the scrollview * feat(ADFA-307): Replace extended toolbar with custom toolbar * feat(ADFA-1179): Remove app name from editor toolbar Remove "Code on the Go" from editor toolbar and display just the current project's name * feat(ADFA-1179): Replace double arrows with single arrows * feat(ADFA-1179): Handle find action * Show a dialog when "Find" menu is clicked * Implement "FindInFile" and "FindInProject" actions * fix(ADFA-1179): UI fixes in toolbar menu * refactor(ADFA-1179): Remove hardcoded text * refactor(ADFA-1179): Remove unnecessary context addition * refactor(ADFA-1179): Rename variable name Change "shouldMarkInvisible" to "shouldHideFindInFileAction" * refactor(ADFA-1179): Remove redundant variable declaration * refactor(ADFA-1179): Remove usages of ExtendedMenuToolbar * fix(ADFA-1179): Set image color tint based on device theme * refactor(ADFA-1179): Reorder editor toolbar menu items * feat(ADFA-1179): Update menu items when app state changes * fix(ADFA-1179): Always show chevrons * fix(ADFA-1179): Remove end margin from last action item * fix(ADFA-1179): Use cancel build icon while build is in progress only for quick run action Both QuickRunAction and DebugAction implement AbstractCancellableRunAction which sets the action item icon to "stop_daemons" icon. This is not needed for DebugAction. * fix(ADFA-1179): Disable debug action when build is in progress * feat(ADFA-1179): Remove git icons from toolbar * fix(ADFA-1179): Resolve issue with project name's text color in dark mode * refactor(ADFA-1179): Remove manual action execution * refactor(ADFA-1179): Replace findViewById with view binding * refactor(ADFA-1179): Use current theme attributes * fix(ADFA-1179): Prevent project title from overlapping toolbar actions * fix(ADFA-1179): Disable find action if build is in progress * fix(ADFA-1179): Execute actions only when item is enabled * fix(ADFA-1179): Fix issue with quick run action * refactor(ADFA-1179): Rename find action item location * refactor(ADFA-1179): Use theme-defined colors * fix: extract action IDs to constants Signed-off-by: Akash Yadav <akashyadav@appdevforall.org> --------- Signed-off-by: Akash Yadav <akashyadav@appdevforall.org> Co-authored-by: Akash Yadav <akashyadav@appdevforall.org>
1 parent 7910fa9 commit 92c01b7

26 files changed

Lines changed: 2558 additions & 2446 deletions

‎actions/src/main/java/com/itsaky/androidide/actions/ActionItem.kt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ interface ActionItem {
158158
/** Location marker for action items shown in editor activity's toolbar. */
159159
EDITOR_TOOLBAR("ide.editor.toolbar"),
160160

161+
/** Location marker for action items shown in editor activity's toolbar submenu.
162+
* FindInFileAction and FindInProjectAction will use this location so
163+
* they don't show in the editor activity's toolbar*/
164+
EDITOR_FIND_ACTION_MENU("ide.editor.toolbar.find.menu"),
165+
161166
/**
162167
* Location marker for action items shown in editor activity's sidebar (navigation rail in the drawer).
163168
*/

‎app/src/main/java/com/itsaky/androidide/actions/build/AbstractCancellableRunAction.kt‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ abstract class AbstractCancellableRunAction(
4040
return
4141
}
4242

43-
if (data.getActivity().isBuildInProgress()) {
43+
if (data.getActivity()
44+
.isBuildInProgress() && id == QuickRunAction.ID
45+
) {
4446
label = context.getString(R.string.title_cancel_build)
4547
icon = ContextCompat.getDrawable(context, R.drawable.ic_stop_daemons)
4648
} else {
@@ -94,7 +96,8 @@ abstract class AbstractCancellableRunAction(
9496

9597
companion object {
9698
@JvmStatic
97-
protected val log: Logger = LoggerFactory.getLogger(AbstractCancellableRunAction::class.java)
99+
protected val log: Logger =
100+
LoggerFactory.getLogger(AbstractCancellableRunAction::class.java)
98101

99102
fun EditorHandlerActivity?.isBuildInProgress(): Boolean {
100103
val buildService = Lookup.getDefault().lookup(BuildService.KEY_BUILD_SERVICE)

‎app/src/main/java/com/itsaky/androidide/actions/build/DebugAction.kt‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,8 @@ class DebugAction(
3737

3838
override fun prepare(data: ActionData) {
3939
super.prepare(data)
40-
if (data.getActivity().isBuildInProgress()) {
41-
// if a build is in progress, then the 'Quick run' action will be used to
42-
// show the cancellation button
43-
visible = false
44-
}
45-
enabled = JdwpOptions.JDWP_ENABLED
40+
val buildIsInProgress = data.getActivity().isBuildInProgress()
41+
enabled = JdwpOptions.JDWP_ENABLED && !buildIsInProgress
4642
}
4743

4844
override fun onCreateTaskExecMessage(

‎app/src/main/java/com/itsaky/androidide/actions/build/ProjectSyncAction.kt‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@ import com.itsaky.androidide.resources.R.string
3131
*/
3232
class ProjectSyncAction(context: Context, override val order: Int) : BaseBuildAction() {
3333

34-
override val id: String = "ide.editor.syncProject"
34+
override val id: String = ID
3535
override var requiresUIThread = false
3636

37+
companion object {
38+
const val ID = "ide.editor.syncProject"
39+
}
40+
3741
init {
3842
label = context.getString(string.title_sync_project)
3943
icon = ContextCompat.getDrawable(context, R.drawable.ic_sync)

‎app/src/main/java/com/itsaky/androidide/actions/build/QuickRunAction.kt‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ class QuickRunAction(context: Context, override val order: Int) :
4646
iconRes = R.drawable.ic_run_outline
4747
) {
4848

49-
override val id: String = "ide.editor.build.quickRun"
49+
override val id: String = ID
50+
51+
companion object {
52+
const val ID = "ide.editor.build.quickRun"
53+
}
5054

5155
override fun onCreateTaskExecMessage(
5256
data: ActionData,

‎app/src/main/java/com/itsaky/androidide/actions/build/RunTasksAction.kt‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ import com.itsaky.androidide.resources.R
2626

2727
/** @author Akash Yadav */
2828
class RunTasksAction(context: Context, override val order: Int) : BaseBuildAction() {
29-
override val id: String = "ide.editor.build.runTasks"
29+
override val id: String = ID
3030
private var dialog: RunTasksDialogFragment? = null
3131

32+
companion object {
33+
const val ID = "ide.editor.build.runTasks"
34+
}
35+
3236
init {
3337
label = context.getString(R.string.title_run_tasks)
3438
icon = ContextCompat.getDrawable(context, R.drawable.ic_run_tasks)

app/src/main/java/com/itsaky/androidide/actions/etc/FindActionMenu.kt renamed to app/src/main/java/com/itsaky/androidide/actions/etc/FindAction.kt

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,36 @@ package com.itsaky.androidide.actions.etc
2020
import android.content.Context
2121
import androidx.core.content.ContextCompat
2222
import com.itsaky.androidide.actions.ActionData
23-
import com.itsaky.androidide.actions.ActionItem
24-
import com.itsaky.androidide.actions.ActionMenu
2523
import com.itsaky.androidide.actions.EditorActivityAction
24+
import com.itsaky.androidide.actions.build.AbstractCancellableRunAction.Companion.isBuildInProgress
2625
import com.itsaky.androidide.resources.R
2726

2827
/** @author Akash Yadav */
29-
class FindActionMenu(context: Context, override val order: Int) : EditorActivityAction(),
30-
ActionMenu {
28+
class FindAction() : EditorActivityAction() {
3129

32-
override val children: MutableSet<ActionItem> = mutableSetOf()
33-
override val id: String = "ide.editor.find"
30+
override var requiresUIThread: Boolean = true
31+
override var order: Int = 0
3432

35-
init {
36-
label = context.getString(R.string.menu_find)
37-
icon = ContextCompat.getDrawable(context, R.drawable.ic_search)
33+
constructor(context: Context, order: Int) : this() {
34+
this.label = context.getString(R.string.menu_find)
35+
this.icon = ContextCompat.getDrawable(context, R.drawable.ic_search)
36+
this.order = order
37+
}
3838

39-
addAction(FindInFileAction(context, 0))
40-
addAction(FindInProjectAction(context, 1))
41-
}
39+
override val id: String = "ide.editor.find"
4240

43-
override fun prepare(data: ActionData) {
44-
super<EditorActivityAction>.prepare(data)
45-
super<ActionMenu>.prepare(data)
46-
}
41+
override fun prepare(data: ActionData) {
42+
super.prepare(data)
43+
enabled = data.getActivity().isBuildInProgress().not()
44+
}
45+
46+
override suspend fun execAction(data: ActionData): Boolean {
47+
val context = data.getActivity() ?: return false
48+
val dialog = context.findActionDialog(data)
49+
50+
return run {
51+
dialog.show()
52+
true
53+
}
54+
}
4755
}

‎app/src/main/java/com/itsaky/androidide/actions/etc/FindInFileAction.kt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package com.itsaky.androidide.actions.etc
2020
import android.content.Context
2121
import androidx.core.content.ContextCompat
2222
import com.itsaky.androidide.actions.ActionData
23+
import com.itsaky.androidide.actions.ActionItem
2324
import com.itsaky.androidide.actions.EditorRelatedAction
2425
import com.itsaky.androidide.resources.R
2526

@@ -28,6 +29,7 @@ class FindInFileAction() : EditorRelatedAction() {
2829

2930
override val id: String = "ide.editor.find.inFile"
3031
override var requiresUIThread: Boolean = true
32+
override var location: ActionItem.Location = ActionItem.Location.EDITOR_FIND_ACTION_MENU
3133

3234
override var order: Int = 0
3335

‎app/src/main/java/com/itsaky/androidide/actions/etc/FindInProjectAction.kt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package com.itsaky.androidide.actions.etc
2020
import android.content.Context
2121
import androidx.core.content.ContextCompat
2222
import com.itsaky.androidide.actions.ActionData
23+
import com.itsaky.androidide.actions.ActionItem
2324
import com.itsaky.androidide.actions.EditorActivityAction
2425
import com.itsaky.androidide.actions.markInvisible
2526
import com.itsaky.androidide.projects.IProjectManager
@@ -30,6 +31,7 @@ class FindInProjectAction() : EditorActivityAction() {
3031

3132
override var requiresUIThread: Boolean = true
3233
override var order: Int = 0
34+
override var location: ActionItem.Location = ActionItem.Location.EDITOR_FIND_ACTION_MENU
3335

3436
constructor(context: Context, order: Int) : this() {
3537
this.label = context.getString(R.string.menu_find_project)

0 commit comments

Comments
 (0)