Skip to content

Instantly share code, notes, and snippets.

@JvmName("trackForEventType")
fun track(
eventType: AnalyticsEventType,
properties: Map<String, String>? = null
) {
eventType.loggerTypes.forEach { logger ->
when (logger) {
AnalyticsLoggerType.Amplitude -> AmplitudeManager.track(eventType, properties)
AnalyticsLoggerType.Airbridge -> AirbridgeManager.track(eventType, properties)
}
@kimji1
kimji1 / ApiResponse.kt
Created October 20, 2023 01:30
Display image upload progress using Retrofit2 in Android
sealed class ApiResponse<out T> {
data class Success<T>(val data: T) : ApiResponse<T>()
sealed class Failure(val message: String?) : ApiResponse<Nothing>() {
data class HttpError(
val statusCode: Int,
val statusMessage: String?,
val error: ErrorDto?
) : Failure(error?.message ?: statusMessage)
/**
* example (use in fragment) >
* viewLifecycleOwner.lifecycle.addObserver(
* FocusClearLifecycleObserver(binding.root, requireActivity()) {
* binding.editText.clearFocus()
* })
*
* example (use in activity) >
* lifecycle.addObserver(
* FocusClearLifecycleObserver(binding.root, this) {
@kimji1
kimji1 / BaseListAdapter.kt
Last active July 5, 2022 06:47
Files for Sticky Header Implementation
abstract class BaseListAdapter<T: ListItem, VH : DataBindingBaseViewHolder<T>>
: ListAdapter<T, VH>(ListItemDiffUtils()) {
}
fun Fragment.findNavControllerSafety(): NavController? {
try {
val fragmentName = this.javaClass.name
val controller = NavHostFragment.findNavController(this)
val isCurrentDestination = when (val currentDestination = controller.currentDestination) {
is DialogFragmentNavigator.Destination -> currentDestination.className == fragmentName
is FragmentNavigator.Destination -> currentDestination.className == fragmentName
else -> false
}