diff --git a/src/main/java/com/nilsenlabs/flavormatrix/actions/AndroidModuleHelper.kt b/src/main/java/com/nilsenlabs/flavormatrix/actions/AndroidModuleHelper.kt index 76216d6..8e40b9f 100644 --- a/src/main/java/com/nilsenlabs/flavormatrix/actions/AndroidModuleHelper.kt +++ b/src/main/java/com/nilsenlabs/flavormatrix/actions/AndroidModuleHelper.kt @@ -11,6 +11,7 @@ object AndroidModuleHelper { addBuildTypes(modules, dimensions) dimensions.createOrderedDimensionMaps(androidModules) dimensions.selectFrom(androidModules) + dimensions.deselectDuplicates() return dimensions } diff --git a/src/main/java/com/nilsenlabs/flavormatrix/actions/DimensionList.kt b/src/main/java/com/nilsenlabs/flavormatrix/actions/DimensionList.kt index f93e120..9a3b9e3 100644 --- a/src/main/java/com/nilsenlabs/flavormatrix/actions/DimensionList.kt +++ b/src/main/java/com/nilsenlabs/flavormatrix/actions/DimensionList.kt @@ -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 = 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 @@ -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( diff --git a/src/main/java/com/nilsenlabs/flavormatrix/actions/VariantSelectorDialog.kt b/src/main/java/com/nilsenlabs/flavormatrix/actions/VariantSelectorDialog.kt index e136cef..30bae81 100644 --- a/src/main/java/com/nilsenlabs/flavormatrix/actions/VariantSelectorDialog.kt +++ b/src/main/java/com/nilsenlabs/flavormatrix/actions/VariantSelectorDialog.kt @@ -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 } /** @@ -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 } } \ No newline at end of file