Skip to content

Instantly share code, notes, and snippets.

View stevdza-san's full-sized avatar
💭
Kotlin Multiplatform Developer/Content Creator

Stefan Jovanovic stevdza-san

💭
Kotlin Multiplatform Developer/Content Creator
View GitHub Profile
@stevdza-san
stevdza-san / HyperlinkText.kt
Last active May 6, 2024 11:14
Embedd a Hyperlink within a Text using Jetpack Compose.
import androidx.compose.foundation.text.ClickableText
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.TextUnit
@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 / 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 / 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 / SelectableItem.kt
Last active April 2, 2024 01:58
Custom Animated Selectable Item - Jetpack Compose
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
import androidx.compose.animation.core.tween
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
@stevdza-san
stevdza-san / Converters.kt
Last active March 31, 2024 10:09
@TypeConverter
class Converters {
@TypeConverter
fun fromBitmap(bitmap: Bitmap): ByteArray {
val outputStream = ByteArrayOutputStream()
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream)
return outputStream.toByteArray()
}
@TypeConverter
@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 / 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 / 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