Skip to content

Instantly share code, notes, and snippets.

Avatar

Saurabh saurabharora90

View GitHub Profile
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)
}
View Application.kt
var completableList: MutableList<Completable> = ArrayList<Completable>()
for (initializer in appComponent.getInitializers()) {
completableList.add(initializer.initialize(context))
}
Completable.mergeDelayError(completableList)
View AppComponent.kt
interface AppComponent {
@Component.Factory
interface Factory {
fun create(@BindsInstance context: Context): AppComponent
}
.....
@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 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 / FullScreenPendingIntent.kt
Created Jul 9, 2019
Beginning with Android Q, Background Activity Starts should be done by notification triggered activities.
View FullScreenPendingIntent.kt
val fullScreenIntent = Intent(this, CallActivity::class.java)
val fullScreenPendingIntent = PendingIntent.getActivity(this, 0,
fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT)
val notificationBuilder = NotificationCompat.Builder(this, CHANNEL_ID)
....
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_CALL)
.setFullScreenIntent(fullScreenPendingIntent, true)
@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">