This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
allprojects { | |
apply(plugin = "io.gitlab.arturbosch.detekt") // Version should be inherited from parent | |
repositories { | |
google() | |
mavenCentral() | |
} | |
/** | |
* Step 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Step 1 | |
* */ | |
plugins { | |
id("io.gitlab.arturbosch.detekt") version ("1.18.1") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
allprojects { | |
apply(plugin = "org.jlleitschuh.gradle.ktlint") // Version should be inherited from parent | |
repositories { | |
google() | |
mavenCentral() | |
} | |
/** | |
* Step 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Step 1 | |
* */ | |
plugins { | |
id("org.jlleitschuh.gradle.ktlint") version "10.2.0" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun getAllCat() { | |
viewModelScope.launch { | |
catDao.getCats().collect { catEntities -> | |
val catList = catEntities.map { catEntity -> | |
Cat.from(catEntity) | |
} | |
_cats.postValue(catList) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Dao | |
interface CatDao { | |
@Query("SELECT * FROM $DATABASE_TABLE_NAME") | |
fun getCats(): Flow<List<CatEntity>> | |
@Insert(onConflict = OnConflictStrategy.IGNORE) | |
suspend fun addCat(catEntity: CatEntity) | |
@Delete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Repository(): KoinComponent { | |
private val propertyA: ClassA = get() | |
//Lazy injection | |
private val propertyA: ClassA by inject() | |
} |
NewerOlder