Created
August 6, 2019 14:34
-
-
Save saurabharora90/61e55bcffc296054133b42528a45c21f to your computer and use it in GitHub Desktop.
Missing Night Color
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private const val COLOR = "color" | |
class MissingNightColorDetector : ResourceXmlDetector() { | |
private val nightModeColors = mutableListOf<String>() | |
private val regularColors = mutableMapOf<String, Location>() | |
override fun appliesTo(folderType: ResourceFolderType): Boolean { | |
return folderType == ResourceFolderType.VALUES | |
} | |
override fun getApplicableElements(): Collection<String>? { | |
return listOf(COLOR) | |
} | |
override fun afterCheckEachProject(context: Context) { | |
regularColors.forEach { (color, location) -> | |
if (!nightModeColors.contains(color)) | |
context.report( | |
MissingNightColorIssue.ISSUE, | |
location, | |
MissingNightColorIssue.EXPLANATION | |
) | |
} | |
} | |
override fun visitElement(context: XmlContext, element: Element) { | |
if (context.getFolderConfiguration()!!.isDefault) | |
regularColors[element.getAttribute("name")] = context.getLocation(element) | |
else if (context.getFolderConfiguration()!!.nightModeQualifier.isValid) | |
nightModeColors.add(element.getAttribute("name")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment