This file contains hidden or 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 MyActivity() : AppCompatActivity(){ | |
| val myModel by viewModel<MyViewModel>() | |
| } |
This file contains hidden or 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 MyActivity() : AppCompatActivity(){ | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| //... | |
| // Direct/Eager inject | |
| val presenter = get<MyPresenter>() | |
| } | |
This file contains hidden or 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 Component : KoinComponent { | |
| // just add parameter map in Lambda | |
| val compA: ComponentA by inject { mapOf(PARAM_URL to URL1) } | |
| } |
This file contains hidden or 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 ComponentA(val componentC: ComponentC) | |
| class ComponentB(val componentA: ComponentA) | |
| class ComponentC : KoinComponent { | |
| // push parameters values | |
| val componentB: ComponentB by inject { mapOf("this" to this) } | |
| } |
This file contains hidden or 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 = "weather") | |
| data class WeatherEntity( | |
| @PrimaryKey | |
| val id: String, | |
| val location: String, | |
| val day: String, | |
| val temp_low: String, | |
| val temp_high: String, | |
| val wind_kph: Int, | |
| val wind_dir: String, |
This file contains hidden or 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 WeatherDAO { | |
| /** | |
| * Save entities | |
| */ | |
| @Insert | |
| fun saveAll(entities: List<WeatherEntity>) | |
| /** |
This file contains hidden or 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 Database instance | |
| bean { | |
| Room.databaseBuilder(androidApplication(), WeatherDatabase::class.java, "weather-db") | |
| .build() | |
| } | |
| // WeatherDAO instance (get instance from WeatherDatabase) | |
| bean { get<WeatherDatabase>().weatherDAO() } |
This file contains hidden or 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
| /** | |
| * In-Memory Room Database definition | |
| */ | |
| val roomTestModule = applicationContext { | |
| bean { | |
| // In-Memory database config | |
| Room.inMemoryDatabaseBuilder(get(), WeatherDatabase::class.java) | |
| .allowMainThreadQueries() | |
| .build() | |
| } |
This file contains hidden or 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
| /** | |
| * WeatherDAOTest is a KoinTest with AndroidJUnit4 runner | |
| * | |
| * KoinTest help inject Koin components from actual runtime | |
| */ | |
| @RunWith(AndroidJUnit4::class) | |
| class WeatherDAOTest : KoinTest { | |
| /* | |
| * Inject needed components from Koin |
This file contains hidden or 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
| // WeatherRepository contract | |
| interface WeatherRepository{ ... } | |
| // WeatherRepository implementation using WeatherDAO | |
| class WeatherRepositoryImpl(private val weatherDAO: WeatherDAO) : WeatherRepository { ... } |