Skip to content

Instantly share code, notes, and snippets.

View ibrahimsn98's full-sized avatar
🐙

İbrahim Süren ibrahimsn98

🐙
View GitHub Profile
@ibrahimsn98
ibrahimsn98 / MealDemeterEventDispatcher.kt
Last active September 19, 2022 09:26
ty-demeter-blog-7
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) {
@ibrahimsn98
ibrahimsn98 / DemeterResultReporter.kt
Last active September 19, 2022 07:51
ty-demeter-blog-6
demeter.addEventResultReporter(DemeterResultReporter())
...
class DemeterResultReporter : EventResultReporter {
override fun report(result: Result<String>) {
if (result.isFailure) {
// Report the result
}
@ibrahimsn98
ibrahimsn98 / BatchEventOperation.kt
Last active October 2, 2022 10:25
ty-demeter-blog-6
internal class BatchEventOperation : Operation {
override suspend fun operate(demeter: Demeter) {
val events = demeter.eventDataProvider.fetchAwaitingEvents(FETCH_EVENT_SIZE)
...
demeter.eventDataProvider.updateEventStatus(
events = events,
eventStatus = EventStatus.PROCESSING,
@ibrahimsn98
ibrahimsn98 / sample_payload.json
Last active September 18, 2022 13:21
ty-demeter-blog-5
{
"session_id": "...",
"platform": "...",
"timestamp": "...",
"os_version": "...",
"app_version": "...",
"domain": "...",
"channel": "...",
"parameters": {
"event_param1": "...",
@ibrahimsn98
ibrahimsn98 / BatchEventDispatcher.kt
Created September 17, 2022 20:05
ty-demeter-blog-4
LifecycleAwareTimer.Builder()
.interval(DISPATCHER_TIMER_INTERVAL)
.scope(dispatcherScope)
.lifecycleOwner(ProcessLifecycleOwner.get())
.onInterval(this::onInterval)
.build()
@ibrahimsn98
ibrahimsn98 / DemeterInitializer.kt
Created September 17, 2022 19:23
ty-demeter-blog-4
internal class DemeterInitializer : Initializer {
override suspend fun initialize(demeter: Demeter) {
demeter.eventDataProvider.updateEventStatus(EventStatus.AWAITING)
}
}
@ibrahimsn98
ibrahimsn98 / OperationQueue.kt
Created September 17, 2022 18:34
ty-demeter-blog-3
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 September 17, 2022 14:54
ty-demeter-blog-2
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)
}
@ibrahimsn98
ibrahimsn98 / MealDemeterIncerceptor.kt
Last active September 17, 2022 15:48
ty-demeter-blog-1
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 July 7, 2021 14:03
Android Appending Sticky Bottom Sheet View
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)