Skip to content

Instantly share code, notes, and snippets.

View dladukedev's full-sized avatar

Donovan LaDuke dladukedev

View GitHub Profile
@dladukedev
dladukedev / UseCaseAsInterface.kt
Created August 15, 2024 02:35
An example of using Use Case interfaces without backing Use Case classes
package com.example.counterapplication
import android.app.Application
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
@dladukedev
dladukedev / 0 - Compose Previews.kt
Last active May 1, 2024 15:15
Approaches to Compose Previews
package com.dladukedev.composepreviews.base
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Card
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
@dladukedev
dladukedev / exhaustive-if.kt
Created December 20, 2023 20:02
Exhaustive if blocks in Kotlin
import kotlin.random.Random
val myInt = Random.nextInt()
val myBool = Random.nextBoolean()
// Expression - Exhaustive Required
val result = if (myInt == 1) {
"I'm #1"
} else {
"I'm something else"
@dladukedev
dladukedev / FunctionReferenceAmbiguity.kt
Last active December 19, 2023 02:48
Kotlin Function Reference Ambiguity
data class AdditionClass(val str: String, val num: Int) {
fun add(addStr: String): String {
return str + addStr
}
fun add(addNum: Int): Int {
return num + addNum
}
}
@dladukedev
dladukedev / 1_StartingPoint.kt
Last active December 25, 2023 09:32
Passive UI in Jetpack Compose
package com.dladukedev.passiveui
import android.util.Log
import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Checkbox
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@dladukedev
dladukedev / img_star_background.png
Last active December 26, 2023 04:01
Tilling Image Background with ShaderBrush and ImageShader
img_star_background.png
@dladukedev
dladukedev / AlignmentExample.kt
Created November 13, 2023 21:28
Alignment vs Absolute Alignment
package com.dladukedev.alignment
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.AbsoluteAlignment
@dladukedev
dladukedev / functional-reactive-programming.kt
Last active October 12, 2023 01:38
Examples of Procedural vs Functional and Reactive styles of Programming
fun procedural() {
val numbers = (1..10).shuffled().toMutableList()
// Remove Even Numbers
var index = 0
while(index < numbers.count()) {
if(numbers[index] % 2 == 0) {
numbers.removeAt(index)
} else {
index += 1
@dladukedev
dladukedev / SemanticMatchersDemo.kt
Created August 26, 2023 03:18
Show how to use the different modifying functions for SemanticMatchers
package com.dladukedev.semanticsmatchertest
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Text
import androidx.compose.ui.test.assertCountEquals
import androidx.compose.ui.test.hasAnyAncestor
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.isDialog
import androidx.compose.ui.test.isRoot
@dladukedev
dladukedev / colors.kt
Created August 3, 2023 15:38
Use Compose Preview to Show your Theme
package com.dladukedev.themetest.ui.theme
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier