Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. private const val COLOR = "color"
  2.  
  3. class MissingNightColorDetector : ResourceXmlDetector() {
  4.  
  5. private val nightModeColors = mutableListOf<String>()
  6. private val regularColors = mutableMapOf<String, Location>()
  7.  
  8. override fun appliesTo(folderType: ResourceFolderType): Boolean {
  9. return folderType == ResourceFolderType.VALUES
  10. }
  11.  
  12. override fun getApplicableElements(): Collection<String>? {
  13. return listOf(COLOR)
  14. }
  15.  
  16. override fun afterCheckEachProject(context: Context) {
  17. regularColors.forEach { (color, location) ->
  18. if (!nightModeColors.contains(color))
  19. context.report(
  20. MissingNightColorIssue.ISSUE,
  21. location,
  22. MissingNightColorIssue.EXPLANATION
  23. )
  24. }
  25. }
  26.  
  27. override fun visitElement(context: XmlContext, element: Element) {
  28. if (context.getFolderConfiguration()!!.isDefault)
  29. regularColors[element.getAttribute("name")] = context.getLocation(element)
  30. else if (context.getFolderConfiguration()!!.nightModeQualifier.isValid)
  31. nightModeColors.add(element.getAttribute("name"))
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement