This file contains 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 App : Application() | |
override fun onCreate() { | |
super.onCreate() | |
registerActivityLifecycleCallbacks(analyticsCallbacks) | |
registerActivityLifecycleCallbacks(pushCallbacks) | |
} | |
// other App code | |
} |
This file contains 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 App : Application() | |
override fun onCreate() { | |
super.onCreate() | |
appComponent.callbacks().forEach { registerActivityLifecycleCallbacks(it) } | |
} | |
// ... other App code | |
} |
This file contains 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
@Module | |
class AnalyticsModule { | |
@Provides | |
@IntoSet | |
fun analyticsCallbacks(callbacks: AnalyticsCallbacks): ActivityLifecycleCallbacks = callbacks | |
} | |
@Module | |
class PushModule { |
This file contains 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 PushCallbacks( | |
val pushStream: PushStream | |
) : Application.ActivityLifecycleCallbacks, PushStream.OnPush { | |
private var foregroundActivity: Activity? = null | |
override fun onActivityResumed(activity: Activity) { | |
foregroundActivity = activity | |
pushStream.register(this) | |
} |
This file contains 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 PushStream { | |
fun register(onPush: OnPush) | |
fun unregister(onPush: OnPush) | |
interface OnPush { | |
fun onPush(push: PushMessage) | |
} | |
} |
This file contains 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 App : Application() | |
override fun onCreate() { | |
super.onCreate() | |
registerActivityLifecycleCallbacks(analyticsCallbacks) | |
} | |
// ... other App code | |
} |
This file contains 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 Analytics { | |
fun activityCreated(activity: Activity) | |
fun activityResumed(activity: Activity) | |
fun activityPaused(activity: Activity) | |
fun activityDestroyed(activity: Activity) | |
} |
This file contains 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 AnalyticsCallbacks( | |
val analytics: Analytics | |
) : Application.ActivityLifecycleCallbacks { | |
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) = analytics.activityCreated(activity) | |
override fun onActivityResumed(activity: Activity) = analytics.activityResumed(activity) | |
override fun onActivityPaused(activity: Activity) = analytics.activityPaused(activity) |
This file contains 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 ContactsViewModel(val getContactsUseCase: GetContactsUseCase, parameters: Parameters) : ViewModel() { | |
private val contactsLiveData: LiveData<Contacts> by lazy { | |
val liveData = MutableLiveData<Contacts>() | |
getContactsUseCase.loadContacts(parameters) { liveData.value = it } | |
return@lazy liveData | |
} | |
fun contacts(parameters: Parameters): LiveData<Contacts> = contactsLiveData | |
} |