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
@Injectable(ExampleModules::class) | |
class ExampleActivity : FragmentActivity() { | |
// Assuming you have set up your Presenter or another class that uses ViewModel (if using MVVM) | |
// This example uses MVP, but MVVM only requires a few more steps | |
val presenter: ExampleViewModel by viewModel() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_quotes) |
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 ExampleRepository(private val exampleDao: ExampleDao) : IExampleRepository { | |
override fun getAll(): Observable<List<Example>> = exampleDao.getAll() | |
} |
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
interface IExampleRepository { | |
fun getAll(): Observable<List<Example>> | |
} |
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
@Database(entities = ExampleEntity::class, version = 1, exportSchema = false) | |
@TypeConverters(Converters::class) | |
abstract class AppDatabase : RoomDatabase() { | |
abstract fun exampleDao(): ExampleDao | |
companion object { | |
// For Singleton instantiation | |
@Volatile private var instance: AppDatabase? = null |
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 ExampleDao { | |
@Query("SELECT * FROM examples") | |
fun getExamples(): LiveData<List<Example>> | |
@Query("SELECT * FROM examples WHERE id = :id)") | |
fun getExampleById(id: String): LiveData<Example> | |
} |
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 = "example") | |
data class ExampleEntity( | |
@PrimaryKey | |
val id: String, | |
val exampleName: String, | |
val exampleAge: Int, | |
val exampleDate: Date | |
) |
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
val myModule = module { | |
// singleton | |
single { DataRepository() } | |
// factory for ExampleUseCase, use get() to resolve the constructor | |
factory { ExampleUseCase(get()) } | |
// Define a singleton of type HttpClient ("properties_url" is in Koin properties) | |
single { HttpClient(getProperty("properties_url")) } | |
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 DataRepository() | |
class ExampleUseCase(val repository : Repository) | |
class ExampleViewModel(val repository : Repository) | |
class HttpClient(val url : 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
class ExampleApplication : Application() { | |
override fun onCreate() { | |
super.onCreate() | |
startKoin { | |
androidLogger() | |
androidContext(this@ExampleApplication) | |
modules(appModule) | |
} |
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
// Koin for Android | |
compile "org.koin:koin-android:$koin_version" | |
// Koin Android Scope feature | |
compile "org.koin:koin-android-scope:$koin_version" | |
// Koin Android ViewModel feature | |
compile "org.koin:koin-android-viewmodel:$koin_version" |
NewerOlder