Skip to content

Instantly share code, notes, and snippets.

View hi-manshu's full-sized avatar

Himanshu Singh hi-manshu

View GitHub Profile
class MyUseCase @Inject constructor() {
private val getUserFlow: Flow<Int> = flowOf<Int>(1, 2, 3, 4)
private val getUserSessionFlow: Flow<Int> = flowOf<Int>(5, 6, 7, 8)
operator fun invoke(): Flow<Unit> {
return getUserFlow.zip(getUserSessionFlow) { user, session ->
// Do transformation here
}
}
object RemoteConfigHelper {
private const val REMOTE_KEY_IN_APP_REVIEW_ENABLED =
BuildConfig.REMOTE_CONFIG_KEY_PREFIX + "in_app_review_enabled"
private const val REMOTE_KEY_APP_UPDATES = BuildConfig.REMOTE_CONFIG_KEY_PREFIX + "app_updates"
private const val REMOTE_KEY_WORDS_MANIFEST = BuildConfig.REMOTE_CONFIG_KEY_PREFIX + "words_manifest"
init {
val settings = remoteConfigSettings {
minimumFetchIntervalInSeconds = BuildConfig.REMOTE_CONFIG_MIN_FETCH_INTERVAL_SECONDS
class CalendarController(
val listener: (CalendarEvent) -> Unit
) : TypedEpoxyController<CalendarState.Data>() {
override fun buildModels(data: CalendarState.Data) {
for (row in data.rows) {
calendarRow {
onDaySelectedListener { day -> this@CalendarController.listener(CalendarEvent.OnDaySelectedChanged(day)) }
onDayTouchedListener { day -> this@CalendarController.listener(CalendarEvent.OnDayTouchedChanged(day)) }
}
abstract class BaseAdapter<T : Any, VH : BaseItemViewHolder<T, out BaseItemViewModel<T>>>(
parentLifecycle: Lifecycle,
private val dataList: ArrayList<T>
) : RecyclerView.Adapter<VH>() {
private var recyclerView: RecyclerView? = null
init {
parentLifecycle.addObserver(object : LifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
postCollection.aggregate<Post>(
lookup(
"user",
listOf(Post::likes.variableDefinition()),
User::userId
),
match(
expr(
MongoOperator.and from listOf(
MongoOperator.`in` from listOf(User::userId, Post::likes),
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
class ImageCompressor(context: Context) {
companion object {
private const val maxWidth = 612
private const val maxHeight = 816
private val compressFormat = CompressFormat.JPEG
private const val quality = 50
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Path
import android.graphics.PointF
import android.util.AttributeSet
import android.util.Log
import android.view.View
val compressedFile = ImageCompressor(requireContext()).compressToFile(----the file here----)
class DetailBrowsePeopleAdapter : BaseRecyclerViewAdapter<DetailBrowsePeopleItem>(mutableListOf()) {
override fun registerItemClick(holder: BaseBindingViewHolder, viewType: Int, position: Int) {
}
}
/**
* Created by Himanshu Singh on 27-10-2020.
**/
abstract class IBaseRecyclerViewAdapter<Item : IRecyclerItemViewModel?>(var items: MutableList<Item>) : RecyclerView.Adapter<BaseRecyclerViewAdapter.BaseBindingViewHolder>() {
private var position = 0
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseBindingViewHolder {
// here the viewType is the actual layoutId to make it generic
val layoutInflater = LayoutInflater.from(parent.context)