Skip to content

Instantly share code, notes, and snippets.

internal fun createErrorThemesAndStylesIssue(detectorClass: KClass<out Detector>, scope: EnumSet<Scope>): Issue {
return createThemesAndStylesIssue(detectorClass, Severity.ERROR, scope)
}
internal fun createWarningThemesAndStylesIssue(detectorClass: KClass<out Detector>, scope: EnumSet<Scope>): Issue {
return createThemesAndStylesIssue(detectorClass, Severity.WARNING, scope)
}
private fun createThemesAndStylesIssue(
detectorClass: KClass<out Detector>,
internal class StyleAttrUsesThemeDetector : ResourceXmlDetector() {
companion object {
val ISSUE = createErrorThemesAndStylesIssue(StyleAttrUsesThemeDetector::class, Scope.RESOURCE_FILE_SCOPE)
}
override fun appliesTo(folderType: ResourceFolderType) = folderType == ResourceFolderType.LAYOUT
override fun getApplicableAttributes(): Collection<String> = XmlScannerConstants.ALL
private val DEF_STYLE_ATTR = R.attr.monzoButtonStyle
class MonzoButton(ctx: Context, attrs: AttributeSet) : AppCompatButton(
wrapContext(ctx, attrs),
attrs,
DEF_STYLE_ATTR
) {
companion object {
fun wrapContext(context: Context, attrs: AttributeSet): Context {
<style name="ThemeOverlay.Monzo.MonzoButton.Pill" parent="">
<!-- any value larger than `button.height / 2` -->
<item name="monzoButtonCornerRadius">1000dp</item>
</style>
<shape android:shape="rectangle">
<corners android:radius="?attr/monzoButtonCornerRadius" />
<!-- ... -->
<style name="Widget.Monzo.CompoundButton.CheckBox" parent="Widget.MaterialComponents.CompoundButton.CheckBox">
<item name="android:textColor">?attr/mdsColorPrimaryContent</item>
<item name="materialThemeOverlay">@style/ThemeOverlay.Monzo.CompoundButton</item>
</style>
<style name="Widget.Monzo.CompoundButton.RadioButton" parent="Widget.MaterialComponents.CompoundButton.RadioButton">
<item name="android:textColor">?attr/mdsColorPrimaryContent</item>
<item name="materialThemeOverlay">@style/ThemeOverlay.Monzo.CompoundButton</item>
</style>
<style name="ThemeOverlay.Monzo.CompoundButton" parent="">
<item name="colorSecondary">?attr/mdsColorBlueTint</item>
</style>
<androidx.appcompat.widget.Toolbar
android:id="@+id/loanCalculatorToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.Monzo.Toolbar.LoansNavy" />
<style name="ThemeOverlay.Monzo.Toolbar.Loans" parent="">
<item name="colorPrimary">@color/navy</item>
<item name="colorOnPrimary">@color/white</item>
</style>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Widget.Monzo.CompoundButton.CheckBox.OnLight" />
<style name="Widget.Monzo.CompoundButton.CheckBox.OnDark" />
</resources>