Skip to content

Instantly share code, notes, and snippets.

@SEAbdulbasit
SEAbdulbasit / Moving Gradient
Last active November 18, 2024 16:04
Moving Mesh Gradient
@Composable
fun FluidMeshGradient(
modifier: Modifier = Modifier
) {
val infiniteTransition = rememberInfiniteTransition(label = "gradient")
// Angle animations for smoother movement
val angle1 = infiniteTransition.animateFloat(
initialValue = 0f,
@Composable
fun CardGradient(modifier: Modifier = Modifier) {
Card(
modifier = Modifier.padding(16.dp).fillMaxWidth().aspectRatio(600 / 400f)
.clip(RoundedCornerShape(16.dp))
) {
Gradient()
}
}
@Composable
fun AgeCalculator() {
var startDate by remember { mutableStateOf(LocalDate.now()) }
var endDate by remember { mutableStateOf(LocalDate.now()) }
var showDialogStartDate by remember { mutableStateOf(false) }
var showDialogEndDate by remember { mutableStateOf(false) }
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
@SEAbdulbasit
SEAbdulbasit / Bouncing Ball
Created February 4, 2024 11:59
Bouncing ball animation
@Composable
fun BouncingBall() {
val scope = rememberCoroutineScope()
val animatable = remember { Animatable(0f) }
var targetHeight by remember { mutableStateOf(1f) }
LaunchedEffect(key1 = true) {
scope.launch {
while (targetHeight > 0.01f) { // the animation will stop when the height is less than 1% of maxHeight
@HiltViewModel
class MusicDetailViewModel @Inject constructor(
private val savedStateHandle: SavedStateHandle, private val repository: MusicRepository
) : ViewModel() {
val state: StateFlow<MusicDetailScreenState>
init {
val musicDetails = savedStateHandle.getStateFlow<Long>(MUSIC_ID, -1).filter { it != -1L }
.flatMapLatest { getMusicDetails(it) }
class MusicDetailViewModelTest {
private lateinit var SUT: MusicDetailViewModel
private val repository: MusicRepository = mockk()
private val savedInstanceStateHandle: SavedStateHandle = SavedStateHandle()
@Before
fun setUp() {
Dispatchers.setMain(Dispatchers.Unconfined)
@SEAbdulbasit
SEAbdulbasit / MusicDetailViewModel.kt
Created September 24, 2022 17:02
Music Details View Model
@HiltViewModel
class MusicDetailViewModel @Inject constructor(
private val savedStateHandle: SavedStateHandle, private val repository: MusicRepository,
) : ViewModel() {
val state: StateFlow<MusicDetailScreenState>
init {
val musicDetails = savedStateHandle.getStateFlow<Long>(MUSIC_ID, -1).filter { it != -1L }
.flatMapLatest { getMusicDetails(it) }
@SEAbdulbasit
SEAbdulbasit / MusicDetailViewModelTest.kt
Created September 24, 2022 17:01
Music Details Unit test
class MusicDetailViewModelTest {
lateinit var SUT: MusicDetailViewModel
@MockK
val repo = mockk<MusicRepository>()
@MockK
val savedInstanceStateHandle = mockk<SavedStateHandle>(relaxed = true)