Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ import com.itsaky.androidide.activities.editor.EditorHandlerActivity
import com.itsaky.androidide.analytics.IAnalyticsManager
import com.itsaky.androidide.idetooltips.TooltipTag
import com.itsaky.androidide.lookup.Lookup
import com.itsaky.androidide.projects.IProjectManager
import com.itsaky.androidide.projects.builder.BuildService
import com.itsaky.androidide.projects.isPluginProject
import com.itsaky.androidide.quickbuild.GradleQuickBuildProvisioner
import com.itsaky.androidide.quickbuild.QuickBuildGraphWarmUp
import com.itsaky.androidide.quickbuild.QuickBuildProjectSupport
import com.itsaky.androidide.resources.R
import com.itsaky.androidide.utils.flashError
import com.itsaky.androidide.utils.flashInfoLong
Expand Down Expand Up @@ -91,7 +95,7 @@ class QuickBuildAction(
// long-press dropdown row is one line and "Standard build in progress" was cut off at 2x
// font scale. The full reason stays on the content description and the blocked-tap flash.
val blocked = blockedByStandardBuild(tone, standardBuildInProgress())
enabled = !blocked
enabled = !blocked && unsupportedProjectReason(context) == null
Comment thread
Daniel-ADFA marked this conversation as resolved.
Resolved
// The label moves with the icon: it is what the long-press dropdown and the
// overflow menu read, so leaving it on "Quick Build" while the icon says stop would
// offer the user two different actions for one button.
Expand Down Expand Up @@ -276,6 +280,54 @@ class QuickBuildAction(
*/
fun isBlockedByStandardBuild(): Boolean = blockedByStandardBuild(currentTone(), standardBuildInProgress())

/**
* Why the bolt is greyed out for the open project, or null when Quick Build can run it:
* a plugin project builds no runnable app, and a release variant is not debuggable.
*
* @param tone what the button is presenting; the stop button of a running Quick Build
* stays tappable whatever is selected now.
* @param isPluginProject whether the open project builds a plugin package.
* @param variantName the Build Variants selection, or null while the project model has none.
*/
@StringRes
internal fun unsupportedProjectMessage(
tone: QuickBuildTone,
isPluginProject: Boolean,
variantName: String?,
): Int? =
if (tone == QuickBuildTone.BUILDING) {
null
} else {
QuickBuildProjectSupport.unsupportedProjectTypeMessage(isPluginProject)
?: variantName?.let(QuickBuildProjectSupport::nonDebuggableVariantMessage)
}

/**
* The live reading of [unsupportedProjectMessage] as text, so the toolbar's spoken label
* gives the same reason the button is greyed for.
*/
fun unsupportedProjectReason(context: Context): String? {
val variantName = GradleQuickBuildProvisioner.selectedVariantName()
val message =
unsupportedProjectMessage(
currentTone(),
IProjectManager.getInstance().isPluginProject(),
variantName,
) ?: return null
return context.getString(message, variantName)
}

/**
* Why the bolt is greyed out right now, for the toolbar to show when it is tapped anyway;
* null when the bolt is enabled.
*/
fun disabledReason(context: Context): String? =
if (isBlockedByStandardBuild()) {
context.getString(R.string.quick_build_standard_build_in_progress)
} else {
unsupportedProjectReason(context)
}

/**
* Whether a build the USER started is running - [BuildService.isUserVisibleBuildInProgress],
* not the raw flag, which an internal Quick Build build also sets.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ import com.itsaky.androidide.utils.IntentUtils.openImage
import com.itsaky.androidide.utils.UniqueNameBuilder
import com.itsaky.androidide.utils.capHeightToSpaceBelow
import com.itsaky.androidide.utils.flashError
import com.itsaky.androidide.utils.flashInfoLong
import com.itsaky.androidide.utils.flashSuccess
import com.itsaky.androidide.utils.hasVisibleDialog
import com.itsaky.androidide.utils.isDeepLinkTargetOfOpenProject
Expand Down Expand Up @@ -798,7 +799,13 @@ open class EditorHandlerActivity :
// path's tint and disabled dim here.
icon = toolbarIcon(action.icon, action.createColorFilter(data), action.enabled),
hint = getToolbarContentDescription(action, data),
onClick = { if (action.enabled) registry.executeAction(action, data) },
onClick = {
if (action.enabled) {
registry.executeAction(action, data)
} else if (action.id == QuickBuildAction.ID) {
QuickBuildAction.disabledReason(this)?.let(::flashInfoLong)
}
},
onLongClick = {
// Quick Build is a split button: long-press opens the
// Quick Build / Restart session / Help dropdown instead of the
Expand Down Expand Up @@ -926,6 +933,9 @@ open class EditorHandlerActivity :
if (action.id == QuickRunAction.ID && buildInProgress) {
return getString(string.cd_toolbar_cancel_build)
}
if (action.id == QuickBuildAction.ID && !QuickBuildAction.isBlockedByStandardBuild()) {
QuickBuildAction.unsupportedProjectReason(this)?.let { return it }
}
val resId =
when (action.id) {
QuickRunAction.ID -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,50 @@ class QuickBuildActionPresentationTest {
.isFalse()
}
}

@Test
fun `a release variant greys the bolt out and says why`() {
// ADFA-6574: Quick Build only builds debuggable variants, so the button says so before
// the tap instead of refusing after it.
QuickBuildTone.entries
.filter { it != QuickBuildTone.BUILDING }
.forEach { tone ->
listOf("release", "freeRelease").forEach { variant ->
assertThat(QuickBuildAction.unsupportedProjectMessage(tone, isPluginProject = false, variantName = variant))
.isEqualTo(R.string.quick_build_non_debuggable_variant)
}
}
}

@Test
fun `a plugin project greys the bolt out and says why`() {
assertThat(
QuickBuildAction.unsupportedProjectMessage(QuickBuildTone.READY, isPluginProject = true, variantName = "debug"),
).isEqualTo(R.string.quick_build_unsupported_plugin_project)
}

@Test
fun `a debug variant of an app project leaves the bolt enabled`() {
QuickBuildTone.entries.forEach { tone ->
listOf("debug", "freeDebug").forEach { variant ->
assertThat(QuickBuildAction.unsupportedProjectMessage(tone, isPluginProject = false, variantName = variant))
.isNull()
}
}
}

@Test
fun `an unknown variant leaves the bolt enabled`() {
// Mid-sync the project model has no selection to read; the tap itself waits for the model.
assertThat(
QuickBuildAction.unsupportedProjectMessage(QuickBuildTone.READY, isPluginProject = false, variantName = null),
).isNull()
}

@Test
fun `the stop affordance stays tappable after a switch to release`() {
assertThat(
QuickBuildAction.unsupportedProjectMessage(QuickBuildTone.BUILDING, isPluginProject = false, variantName = "release"),
).isNull()
}
}
Loading