Skip to content

Instantly share code, notes, and snippets.

Avatar

İbrahim Süren ibrahimsn98

View GitHub Profile
View MealDemeterEventDispatcher.kt
class MealDemeterEventDispatcher @Inject constructor(
@MealDemeter private val demeter: Demeter,
) : EventDispatcher {
override fun report(event: Event) {
val eventData = event.getData().analyticsMap[MealEvent.DEMETER] ?: return
...
when (eventGroup) {
View DemeterResultReporter.kt
demeter.addEventResultReporter(DemeterResultReporter())
...
class DemeterResultReporter : EventResultReporter {
override fun report(result: Result<String>) {
if (result.isFailure) {
// Report the result
}
View BatchEventOperation.kt
internal class BatchEventOperation : Operation {
override suspend fun operate(demeter: Analytics) {
val events = demeter.eventDataProvider.fetchAwaitingEvents(FETCH_EVENT_SIZE)
...
demeter.eventDataProvider.updateEventStatus(
events = events,
eventStatus = EventStatus.PROCESSING,
View sample_payload.json
{
"session_id": "...",
"platform": "...",
"timestamp": "...",
"os_version": "...",
"app_version": "...",
"domain": "...",
"channel": "...",
"parameters": {
"event_param1": "...",
View BatchEventDispatcher.kt
LifecycleAwareTimer.Builder()
.interval(DISPATCHER_TIMER_INTERVAL)
.scope(dispatcherScope)
.lifecycleOwner(ProcessLifecycleOwner.get())
.onInterval(this::onInterval)
.build()
View DemeterInitializer.kt
internal class DemeterInitializer : Initializer {
override suspend fun initialize(demeter: Demeter) {
demeter.eventDataProvider.updateEventStatus(EventStatus.AWAITING)
}
}
View OperationQueue.kt
internal class OperationQueue(demeter: Demeter, coroutineScope: CoroutineScope) {
private val queue = Channel<Operation>(BUFFER_SIZE)
init {
queue.receiveAsFlow()
.onEach { operation ->
runCatching {
operation.operate(demeter)
}.onFailure {
@ibrahimsn98
ibrahimsn98 / Demeter.kt
Created Sep 17, 2022
ty-demeter-blog-2
View Demeter.kt
fun sendEvent(name: String, group: String, screen: String, parameters: Map<String, String>) {
singleEventDispatcher.dispatch(name, group, screen, parameters)
}
fun enqueueEvent(name: String, group: String, screen: String, parameters: Map<String, String>) {
batchEventDispatcher.dispatch(name, group, screen, parameters)
}
View MealDemeterIncerceptor.kt
class MealDemeterInterceptor @Inject constructor(
private val buildConfigProvider: BuildConfigProvider,
private val buildModelProvider: BuildModelProvider,
) : Demeter.Interceptor {
override suspend fun intercept(parameters: Parameters): Parameters {
val mutableParameters = parameters.toMutableMap()
mutableParameters["os_version"] = buildModelProvider.getBuildVersion()
mutableParameters["app_version"] = buildConfigProvider.getAppVersionName()
mutableParameters["domain"] = DOMAIN
@ibrahimsn98
ibrahimsn98 / bottomsheet.kt
Created Jul 7, 2021
Android Appending Sticky Bottom Sheet View
View bottomsheet.kt
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val bottomSheetDialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
bottomSheetDialog.setOnShowListener {
val containerLayout = dialog?.findViewById(
com.google.android.material.R.id.container
) as? FrameLayout
val buttonLayout = LayoutInflater.from(dialog?.context)
.inflate(R.layout.layout_delivery_bottom_sheet_buttons, null)
.findViewById<LinearLayout>(R.id.layoutButtons)