Skip to content
Permalink
Browse files

Replace nullable "static" variables with lateinit

  • Loading branch information
zsmb13 committed Jan 7, 2020
1 parent 2cf3ba9 commit 5c3dca558077a4ca54ad1d78d9eb0f78c459dbc1
@@ -7,8 +7,8 @@ import dev.marcosfarias.pokedex.database.AppDatabase

class App : Application() {
companion object {
var context: Context? = null
var database: AppDatabase? = null
lateinit var context: Context
lateinit var database: AppDatabase
}

override fun onCreate() {
@@ -8,7 +8,7 @@ import dev.marcosfarias.pokedex.model.Pokemon

class DashboardViewModel : ViewModel() {

private val pokemonDAO: PokemonDAO = App.database!!.pokemonDAO()
private val pokemonDAO: PokemonDAO = App.database.pokemonDAO()

fun getPokemonById(id: String?): LiveData<List<Pokemon?>?> {
return pokemonDAO.getById(id)
@@ -15,42 +15,42 @@ class GenerationViewModel : ViewModel() {
listGeneration.value = listOf(
Generation(
1,
App.context!!.resources.getString(R.string.generation_item_1),
App.context.resources.getString(R.string.generation_item_1),
R.drawable.gen1
),
Generation(
1,
App.context!!.resources.getString(R.string.generation_item_2),
App.context.resources.getString(R.string.generation_item_2),
R.drawable.gen2
),
Generation(
1,
App.context!!.resources.getString(R.string.generation_item_3),
App.context.resources.getString(R.string.generation_item_3),
R.drawable.gen3
),
Generation(
1,
App.context!!.resources.getString(R.string.generation_item_4),
App.context.resources.getString(R.string.generation_item_4),
R.drawable.gen4
),
Generation(
1,
App.context!!.resources.getString(R.string.generation_item_5),
App.context.resources.getString(R.string.generation_item_5),
R.drawable.gen5
),
Generation(
1,
App.context!!.resources.getString(R.string.generation_item_6),
App.context.resources.getString(R.string.generation_item_6),
R.drawable.gen6
),
Generation(
1,
App.context!!.resources.getString(R.string.generation_item_7),
App.context.resources.getString(R.string.generation_item_7),
R.drawable.gen7
),
Generation(
1,
App.context!!.resources.getString(R.string.generation_item_8),
App.context.resources.getString(R.string.generation_item_8),
R.drawable.gen8
)
)
@@ -15,12 +15,12 @@ class HomeViewModel : ViewModel() {

fun getListMenu(): LiveData<List<Menu>> {
listMenu.value = listOf(
Menu(1, App.context!!.resources.getString(R.string.menu_item_1), R.color.lightTeal),
Menu(1, App.context!!.resources.getString(R.string.menu_item_2), R.color.lightRed),
Menu(1, App.context!!.resources.getString(R.string.menu_item_3), R.color.lightBlue),
Menu(1, App.context!!.resources.getString(R.string.menu_item_4), R.color.lightYellow),
Menu(1, App.context!!.resources.getString(R.string.menu_item_5), R.color.lightPurple),
Menu(1, App.context!!.resources.getString(R.string.menu_item_6), R.color.lightBrown)
Menu(1, App.context.resources.getString(R.string.menu_item_1), R.color.lightTeal),
Menu(1, App.context.resources.getString(R.string.menu_item_2), R.color.lightRed),
Menu(1, App.context.resources.getString(R.string.menu_item_3), R.color.lightBlue),
Menu(1, App.context.resources.getString(R.string.menu_item_4), R.color.lightYellow),
Menu(1, App.context.resources.getString(R.string.menu_item_5), R.color.lightPurple),
Menu(1, App.context.resources.getString(R.string.menu_item_6), R.color.lightBrown)
)
return listMenu
}
@@ -12,7 +12,7 @@ import retrofit2.Response

class PokedexViewModel : ViewModel() {

private val pokemonDAO: PokemonDAO = App.database!!.pokemonDAO()
private val pokemonDAO: PokemonDAO = App.database.pokemonDAO()

init {
initNetworkRequest()

0 comments on commit 5c3dca5

Please sign in to comment.
You can’t perform that action at this time.