Skip to content

Instantly share code, notes, and snippets.

View mo0rti's full-sized avatar
🧨
Making cool stuffs

Morteza Taghdisi mo0rti

🧨
Making cool stuffs
View GitHub Profile
fun rendezvousChannel(
coroutineScope: CoroutineScope
) {
// create a rendezvous channel with capacity 0
val channel = Channel<Int>()
// get the starting time to display the time difference in the logs
val startTime = System.currentTimeMillis()
// launch the producer coroutine
import android.util.Log
const val TAG = "Channel"
@OptIn(ExperimentalCoroutinesApi::class)
fun bufferedChannel(
coroutineScope: CoroutineScope
) {
// create a buffered channel with capacity of 2
val channel = Channel<Int>(capacity = 2)
@Composable
fun LocationDisplay(activity: ComponentActivity) {
// Create a conflated channel for location updates
val locationChannel = remember { Channel<Location>(Channel.CONFLATED) }
// Create a mutable state for the location text
val locationState = remember { mutableStateOf("") }
// Receive location updates from the channel using a coroutine
LaunchedEffect(locationChannel) {
val scope = CoroutineScope(Dispatchers.Default)
@mo0rti
mo0rti / previewAnnotations.kt
Last active August 21, 2023 19:53
Custom list item to display in different previews
import android.content.res.Configuration
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size