Skip to content

Commit

Permalink
Handle incomplete selections
Browse files Browse the repository at this point in the history
  • Loading branch information
RuterFrode committed Dec 18, 2020
1 parent 096d188 commit 628cfb0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ object AndroidModuleHelper {
addBuildTypes(modules, dimensions)
dimensions.createOrderedDimensionMaps(androidModules)
dimensions.selectFrom(androidModules)
dimensions.deselectDuplicates()
return dimensions
}

Expand Down
22 changes: 17 additions & 5 deletions src/main/java/com/nilsenlabs/flavormatrix/actions/DimensionList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@ class DimensionList {
/** Generates a selectable variant string for the given module based on the selected items */
fun getSelectedVariantFor(moduleName: String): String? {
val dimensionList: MutableList<Dimension> = moduleOrderedDimensionMap[moduleName] ?: return null
val variantString = dimensionList.joinToString("") {
it.flavors
try {
val variantString = dimensionList.joinToString("") {
it.flavors
.first { it.isSelected }
.title.capitalize()
.title.capitalize() // Lowercase first char
}
return variantString[0].toLowerCase().toString() + variantString.subSequence(1, variantString.length)
} catch (ex: NoSuchElementException) {
return null
}
// Lowercase first char
return variantString[0].toLowerCase().toString() + variantString.subSequence(1, variantString.length)
}

/** Make a map of Module => Ordered List Of Dimensions, where order
Expand Down Expand Up @@ -88,6 +91,15 @@ class DimensionList {
.flatMap { it.flavors }
.firstOrNull { it.title == name }
}

fun deselectDuplicates() {
for (dimension in dimensions) {
val selectedFlavors = dimension.flavors.count { it.isSelected }
if (selectedFlavors > 1) {
dimension.flavors.forEach { it.isSelected = false }
}
}
}
}

data class Dimension(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,24 @@ class VariantSelectorDialog(
}
}
}
populateVariantResult(moduleListTextArea)
val allFlavorsSelected = populateVariantResult(moduleListTextArea)
enableButtons(allFlavorsSelected)
container.add(moduleListTextArea)

selectorContainer.doLayout()
return container
}

private fun populateVariantResult(variantResultList: JTextArea) {
private fun populateVariantResult(variantResultList: JTextArea): Boolean {
var text = ""
var anyNull = false
for (module in androidModules) {
val variantName = dimensions.getSelectedVariantFor(module.moduleName)
if (variantName == null) anyNull = true
text += "${module.moduleName}: $variantName\n"
}
variantResultList.text = text
return !anyNull
}

/**
Expand All @@ -104,6 +108,11 @@ class VariantSelectorDialog(
if (button.isSelected) {
dimension.selectUniqueFlavor(button.text)
}
populateVariantResult(variantResultList)
val allFlavorsSelected = populateVariantResult(variantResultList)
enableButtons(allFlavorsSelected)
}

fun enableButtons(allFlavorsSelected: Boolean) {
isOKActionEnabled = allFlavorsSelected
}
}

0 comments on commit 628cfb0

Please sign in to comment.