Skip to content

Instantly share code, notes, and snippets.

@bobbyirawan09
bobbyirawan09 / build.gradle.kts
Created January 20, 2022 07:33
Step 2 when adding Detekt to project, add the configuration
allprojects {
apply(plugin = "io.gitlab.arturbosch.detekt") // Version should be inherited from parent
repositories {
google()
mavenCentral()
}
/**
* Step 2
@bobbyirawan09
bobbyirawan09 / build.gradle.kts
Created January 20, 2022 07:31
Step 1 when adding Detekt to Android project, add the plugin
/**
* Step 1
* */
plugins {
id("io.gitlab.arturbosch.detekt") version ("1.18.1")
}
@bobbyirawan09
bobbyirawan09 / build.gradle.kts
Created January 20, 2022 07:27
Step 2 when adding Ktlint to project, add the configuration
allprojects {
apply(plugin = "org.jlleitschuh.gradle.ktlint") // Version should be inherited from parent
repositories {
google()
mavenCentral()
}
/**
* Step 2
@bobbyirawan09
bobbyirawan09 / build.gradle.kts
Created January 20, 2022 07:25
Step 1 when adding Ktlint to your Android project
/**
* Step 1
* */
plugins {
id("org.jlleitschuh.gradle.ktlint") version "10.2.0"
}
@bobbyirawan09
bobbyirawan09 / CatViewModel.kt
Last active August 6, 2020 16:03
Part of the full CatViewModel
private var _cats = MutableLiveData<List<Cat>>()
val cats = _cats as LiveData<List<Cat>>
fun getAllCat() {
viewModelScope.launch {
catDao.getCats().collect { catEntities ->
val catList = catEntities.map { catEntity ->
Cat.from(catEntity)
}
_cats.postValue(catList)
@bobbyirawan09
bobbyirawan09 / CatViewModel.kt
Created August 6, 2020 15:53
Part of the full CatViewModel
fun getAllCat() {
viewModelScope.launch {
catDao.getCats().collect { catEntities ->
val catList = catEntities.map { catEntity ->
Cat.from(catEntity)
}
_cats.postValue(catList)
}
}
}
@bobbyirawan09
bobbyirawan09 / build.gradle
Last active August 6, 2020 08:33
Build gradle file for RoomFlow project
//Room library
implementation "androidx.room:room-runtime:2.2.5"
kapt "androidx.room:room-compiler:2.2.5"
implementation "androidx.room:room-ktx:2.2.5"
//Coroutines library
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.7'
@Dao
interface CatDao {
@Query("SELECT * FROM $DATABASE_TABLE_NAME")
fun getCats(): Flow<List<CatEntity>>
@Insert(onConflict = OnConflictStrategy.IGNORE)
suspend fun addCat(catEntity: CatEntity)
@Delete
@Entity(tableName = DATABASE_TABLE_NAME)
data class CatEntity(
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = COLUMN_ID)
var id: Int = 0,
@ColumnInfo(name = COLUMN_BREED)
var breed: String = ""
) {
companion object {
const val DATABASE_TABLE_NAME = "cat"
class Repository(): KoinComponent {
private val propertyA: ClassA = get()
//Lazy injection
private val propertyA: ClassA by inject()
}