Skip to content

Instantly share code, notes, and snippets.

@saurabharora90
Created August 6, 2019 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saurabharora90/61e55bcffc296054133b42528a45c21f to your computer and use it in GitHub Desktop.
Save saurabharora90/61e55bcffc296054133b42528a45c21f to your computer and use it in GitHub Desktop.
Missing Night Color
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