Skip to content

Instantly share code, notes, and snippets.

Avatar

Saurabh saurabharora90

View GitHub Profile
View Application.kt
var completableList: MutableList<Completable> = ArrayList<Completable>()
for (initializer in appComponent.getInitializers()) {
completableList.add(initializer.initialize(context))
}
Completable.mergeDelayError(completableList)
View AllModulesInitializer.kt
private val initializedModules = HashSet<Class<out ModuleInitializer>>()
fun getInitializerCompletable(): Completable {
val completableList = mutableListOf<Completable>()
map.forEach { (clazz, moduleInitializer) ->
completableList.addAll(getCompletableForModule(clazz, moduleInitializer))
}
return Completable.concat(completableList)
}
@saurabharora90
saurabharora90 / AppComponent.kt
Last active Jun 15, 2020
Updated Dagger Module
View AppComponent.kt
interface AppComponent {
@Component.Factory
interface Factory {
fun create(@BindsInstance context: Context): AppComponent
}
.....
View CustomerCareInitializer.kt
class CustomerCareInitializer @Inject constructor(
private val session: UserSession,
private val apiService: ApiService
) : ModuleInitializer {
override fun initialize(context: Context): Completable {
....
}
override fun dependencies(): List<Class<out ModuleInitializer>> {
View ModuleInitializer.kt
interface ModuleInitializer {
fun initialize(context: Context): Completable
fun dependencies(): List<Class<out ModuleInitializer>> {
return emptyList()
}
}
View AppComponent.kt
interface AppComponent {
@Component.Factory
interface Factory {
fun create(@BindsInstance context: Context): AppComponent
}
.....
View CustomerCareInitializer.kt
class CustomerCareInitializer @Inject constructor(
private val session: UserSession,
private val apiService: ApiService
) : ModuleInitializer {
override fun initialize(context: Context): Completable {
return apiService.execute( ... )
.flatMap {
Zendesk.init(...)
}
View ModuleInitializer.kt
interface ModuleInitializer {
/** Initializes a module given the application Context
*
* @return A Completable if the module needs the app to wait for its setup to complete before proceeding.
* If the module setup doesn't need an asynchronous setup, then it can simply return Completable.complete()
*/
fun initialize(context: Context): Completable
}
@saurabharora90
saurabharora90 / checkstyle-as.xml
Created Feb 25, 2020
CodeStyle Configuration to match Android Studio Defaults
View checkstyle-as.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<property name="severity" value="warning" />
<property name="charset" value="UTF-8" />
<module name="FileTabCharacter">
View DarkThemeLintRegistry.kt
class DarkThemeLintRegistry : IssueRegistry() {
override val issues: List<Issue>
get() = listOf(
DirectColorUseIssue.ISSUE,
MissingNightColorIssue.ISSUE
)
}