Skip to content

Instantly share code, notes, and snippets.

Avatar

David Rawson drawers

  • ClearPoint
  • Auckland, New Zealand
View GitHub Profile
View Provider.kt
import com.google.devtools.ksp.symbol.*
class IntSummableProcessorProvider : SymbolProcessorProvider {
override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor {
return IntSummableProcessor(
options = environment.options,
codeGenerator = environment.codeGenerator,
logger = environment.logger
)
View build.gradle.kts
plugins {
kotlin("jvm") version "1.4.32"
}
repositories {
mavenCentral()
google()
}
dependencies {
View GeneratedCode.kt
public fun FooSummable.sumInts(): Int {
val sum = bar + baz
return sum
}
View Foo.kt
@IntSummable
data class Foo(
val bar: Int = 234,
val baz: Int = 123
)
@drawers
drawers / DDDTest.kt
Last active Jan 25, 2021
DDDTest.kt
View DDDTest.kt
class TasksViewModel: ViewModel {
val taskItems: LiveData<List<TaskItem>>
val _tasksItems: MutableLiveData<List<TaskItem>>
fun loadTasks() {
val tasks = tasksRepository.getAllTasks()
_taskItems.value = tasks.map { it.toTaskItem() }
}
}
@drawers
drawers / TaskItem.kt
Last active Jan 25, 2021
TaskItem.kt
View TaskItem.kt
/**
* A presentation-layer item for display in a RecyclerView
*/
class TaskItem(
val id: String,
val title: String,
val description: String,
val color: @ColorRes Int
)
View TaskWithColor.kt
class Task(
/*
* snip
*/
val color: @ColorRes Int
)
@drawers
drawers / DomainLeakingIntoPresentation.kt
Created Jan 21, 2021
DomainLeakingIntoPresentation.kt
View DomainLeakingIntoPresentation.kt
class TasksFragment {
private lateinit var tasksAdapter: TasksAdapter
fun showTasks(tasks: List<Tasks>) {
tasksAdapter.setData(tasks)
}
}
// inside tasks adapter
@drawers
drawers / Separating.kt
Created Jan 21, 2021
Extracting a separate
View Separating.kt
// data layer object
open class RealmTask constructor(
var title: String = "",
var description: String,
var isCompleted: Boolean,
@PrimaryKey var entryId: String
): RealmObject()
fun RealmTask.toDomain() {
return Task(
View Task.kt
// Realm models must be open
open class Task constructor(
var title: String = "",
var description: String,
var isCompleted: Boolean,
@PrimaryKey var entryId: String
): RealmObject()