
android:name=".MyApp"
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 MyApp : Application(){ | |
init { | |
instance = this | |
} | |
companion object { | |
private var instance: MyApp? = null | |
fun context() : Context { | |
return instance!!.applicationContext | |
} | |
} | |
} |
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 { | |
private val context = MyApp.context() | |
private val db = MyDatabase.getDatabase(context) | |
fun create(numberEntity: NumberEntity) = db.numberDao().create(numberEntity) | |
fun read() = db.numberDao().read() | |
fun update(numberEntity: NumberEntity) = db.numberDao().update(numberEntity) | |
fun delete(numberEntity: NumberEntity) = db.numberDao().delete(numberEntity) | |
} |
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 MainViewModel : ViewModel() { | |
private val repository = Repository() | |
fun create() { | |
} | |
fun read() { | |
} | |
fun update(){ | |
} | |
fun delete(){ | |
} | |
} |
'Android Jetpack' 카테고리의 다른 글
Room Advanced - 5 (Adapter) (0) | 2023.02.02 |
---|---|
Room Advanced - 4 (Create / Read) (0) | 2023.02.02 |
Room Advanced - 2 (DB) (0) | 2023.02.02 |
Room Advanced - 1 (XML) (0) | 2023.02.02 |
ROOM + Coroutine Flow - 7 (Room + Flow + ListAdapter CRUD) (0) | 2023.01.29 |