Skip to content

Instantly share code, notes, and snippets.

@sdetilly
sdetilly / AnimatedVisibilityWithNull
Created October 3, 2025 18:42
How to use Animated visibility with null values
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.AnimatedVisibilityScope
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.expandIn
import androidx.compose.animation.fadeIn
@sdetilly
sdetilly / MainActivity.kt
Created October 1, 2025 13:06
Shared Element Demo
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.AnimatedVisibilityScope
import androidx.compose.animation.ExperimentalSharedTransitionApi
import androidx.compose.animation.SharedTransitionLayout
import androidx.compose.animation.SharedTransitionScope
import androidx.compose.animation.core.tween
@sdetilly
sdetilly / KoinServiceSetup.kt
Created July 31, 2023 19:28
Koin Service Setup
// Common Code
interface Bootstrap {
val gpsService: GPSService
}
class KoinBootstrap : KoinComponent {
fun initDependencies(bootstrap: Bootstrap) = startKoin {
configureKoin(bootstrap)
}
}
@sdetilly
sdetilly / RestaurantFinder.kt
Last active July 31, 2023 18:59
RestaurantFinder
fun restaurantsNearUser(): Flow<List<Restaurant>> =
flow {
emit(null)
gpsService.currentUserLocation().also { location ->
emit(location)
}
}
.map { userLocation ->
buildRestaurantList(userLocation)
}
class IOSGPSService: GPSService {
private let asyncLocationManager = AsyncLocationManager(desiredAccuracy: .threeKilometersAccuracy)
func userGPSCoordinates() async throws -> GPSCoordinates? {
switch asyncLocationManager.getAuthorizationStatus() {
case .authorizedAlways, .authorizedWhenInUse:
let locationUpdate = try? await asyncLocationManager.requestLocation()
switch locationUpdate {
case .didUpdateLocations(let locations):
@sdetilly
sdetilly / AndroidGPSService.kt
Created July 28, 2023 01:57
AndroidGPSService
class AndroidGPSService(
private val context: Context
) : GPSService {
// withContext is necessary here because location queries need to be done in the UI Thread
override suspend fun userGPSCoordinates() = withContext(Dispatchers.Main.immediate) {
suspendCancellableCoroutine { continuation ->
// PermissionUtils checks permission using ContextCompat.checkSelfPermission(...) and returns true if granted
if (PermissionUtils.hasPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION)) {
val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
@sdetilly
sdetilly / GPSService.kt
Created July 25, 2023 18:16
Common code GPSService
interface GPSService {
suspend fun userGPSCoordinates(): GPSCoordinates?
}
data class GPSCoordinates(
val latitude: Double,
val longitude: Double
)