Skip to content

Instantly share code, notes, and snippets.

class EnableEdgeToEdgeRule(config: Config) : Rule(config) {
override val issue = Issue(
javaClass.simpleName,
Severity.Defect,
EDGE_TO_EDGE_MESSAGE,
Debt.TWENTY_MINS
)
override fun visitKtFile(file: KtFile) {
plugins {
kotlin
id("io.gitlab.arturbosch.detekt")
}
dependencies {
compileOnly(libs.kotlin)
compileOnly("io.gitlab.arturbosch.detekt:detekt-api:<version>")
}
class JetRuleSetProvider : RuleSetProvider {
override val ruleSetId: String = "JetRuleSet"
override fun instance(config: Config): RuleSet {
return RuleSet(
ruleSetId,
listOf(
EnableEdgeToEdgeRule(config)
),
)
com.jet.detektcustomrules.JetRuleSetProvider
dependencies {
detektPlugins(project(":detekt-custom-rules"))
}
detekt {
config.setFrom(file("config/detekt/detekt.yml"))
}
JetRuleSet:
EnableEdgeToEdgeRule:
active: true
class EnableEdgeToEdgeRuleTest {
@Test
fun `should report when edgeToEdge is not used`() {
val code = """
class A : AppCompatActivity() {
fun foo() {
}
}
"""
fun NotificationCompat.Builder.progressStyleNotification(context: Context) {
val segmentColor = ContextCompat.getColor(context, R.color.jet_brand)
val segments = List(4) { NotificationCompat.ProgressStyle.Segment(25).setColor(segmentColor) }
setStyle(
NotificationCompat
.ProgressStyle()
.setStyledByProgress(true)
.setProgressSegments(segments)
.setProgress(25)
)
NotificationCompat
.Builder(...)
.apply {
setOngoing(true)
setRequestPromotedOngoing(true)
setShowWhen(true)
setWhen(... future ETA in long format ...)
}
internal class LiveUpdateWorker(..) : CoroutineWorker(..) {
override suspend fun doWork(): Result {
// ..
repository.orderStatusFlow.collect { orderStatus ->
setForeground(
ForegroundInfo(
"notificationId",
buildNotification(orderStatus),
ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE,
)