Skip to content

Instantly share code, notes, and snippets.

View majidsa70's full-sized avatar

majid sadeghi majidsa70

View GitHub Profile
@MohammadRezaAlizadeh000
MohammadRezaAlizadeh000 / Kotlin create shape extensions
Last active August 4, 2022 06:42
Instead of use xml file to create shape you can use this extension to create your drawable shape at run time.
import android.graphics.drawable.GradientDrawable
import android.view.View
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.fragment.app.Fragment
fun Fragment.createBackground(
color: Int,
corner: Int = 0,
@MohammadRezaAlizadeh000
MohammadRezaAlizadeh000 / Kotlin flow extension
Created August 3, 2022 20:04
To collect flow in fragment/activity you should write 3 line. I wrote extension that let you collect your flow in fragment/activity in 1 line.
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.launch
fun <T> Fragment.flowLife(flow: Flow<T>, collector: FlowCollector<T>) {
viewLifecycleOwner.lifecycleScope.launch {
lifecycleScope.launchWhenResumed {