Skip to content

Instantly share code, notes, and snippets.

View stevdza-san's full-sized avatar
💭
Android Developer/Content Creator/Teacher.

Stefan Jovanovic stevdza-san

💭
Android Developer/Content Creator/Teacher.
View GitHub Profile
@stevdza-san
stevdza-san / RequestState.kt
Last active April 12, 2024 11:10
Useful wrapper class for handling the data in Jetpack Compose
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.togetherWith
import androidx.compose.runtime.Composable
sealed class RequestState<out T> {
data object Idle : RequestState<Nothing>()
data object Loading : RequestState<Nothing>()
@stevdza-san
stevdza-san / MainScreen.kt
Created December 24, 2023 22:33
TabRow with HorizontalPager - Jetpack Compose
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Favorite
@stevdza-san
stevdza-san / RichTextEditor.kt
Created October 14, 2023 14:08
Demo project of a Compose-Rich-Editor library
import android.annotation.SuppressLint
import android.util.Log
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
@stevdza-san
stevdza-san / AnimatedBorderCard.kt
Last active April 3, 2024 14:01
Card with Animated Border built with Jetpack Compose.
@Composable
fun AnimatedBorderCard(
modifier: Modifier = Modifier,
shape: Shape = RoundedCornerShape(size = 0.dp),
borderWidth: Dp = 2.dp,
gradient: Brush = Brush.sweepGradient(listOf(Color.Gray, Color.White)),
animationDuration: Int = 10000,
onCardClick: () -> Unit = {},
content: @Composable () -> Unit
) {
@stevdza-san
stevdza-san / MainScreen.kt
Created October 20, 2022 06:31
New Photo Picker on Android 13/API Level 33 - Backwards Compatible
// Coil
// implementation("io.coil-kt:coil-compose:2.2.2")
import android.util.Log
import android.widget.Toast
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.PickVisualMediaRequest
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
@stevdza-san
stevdza-san / MainScreen.kt
Created September 16, 2022 09:18
Disappearing and Animated Top Bar - Jetpack Compose
import android.annotation.SuppressLint
import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
@stevdza-san
stevdza-san / HomeScreen.kt
Created September 8, 2022 12:08
isScrolled extension property for the LazyListState
import android.annotation.SuppressLint
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.ContentAlpha
import androidx.compose.material.MaterialTheme
@stevdza-san
stevdza-san / Game.kt
Last active March 26, 2024 21:47
Tic-Tac-Toe Game with Kotlin
import kotlin.system.exitProcess
class Game {
private val board = MutableList<Cell>(size = 9) { Cell.Empty }
private var status: Status = Status.Idle
private lateinit var player: Player
fun start() {
status = Status.Running
println(" ------------------------------ ")
@stevdza-san
stevdza-san / MainActivity.kt
Created July 2, 2022 06:32
collectAsStateWithLifecycle() example
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.lifecycle.ViewModel
import androidx.lifecycle.compose.ExperimentalLifecycleComposeApi
@stevdza-san
stevdza-san / StopwatchAnimation.kt
Created June 29, 2022 18:54
Create a Stopwatch Animation on a Text with Jetpack Compose
import androidx.compose.animation.*
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue