Skip to content

Instantly share code, notes, and snippets.

View gs-ts's full-sized avatar

Giannis Tsepas gs-ts

View GitHub Profile
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.VectorConverter
import androidx.compose.animation.core.spring
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.forEachGesture
@ianhanniballake
ianhanniballake / PickImageContracts.kt
Last active September 10, 2022 18:03
Gist showing how to write backward compatible ActivityResultContracts for supporting Android 13's new Photo Picker: https://developer.android.com/about/versions/13/features/photopicker
/**
* Use this [ActivityResultContract] to seamlessly switch between
* the new [MediaStore.ACTION_PICK_IMAGES] and [Intent.ACTION_GET_CONTENT]
* based on the availability of the Photo Picker.
*
* Use [PickMultipleImages] if you'd like the user to be able to select multiple
* photos/videos.
*
* Input: the mimeType you'd like to receive. This should generally be
* either `image/\*` or `video/\*` for requesting only images or only videos
@KlassenKonstantin
KlassenKonstantin / Blocking.kt
Created August 20, 2021 17:14
Blocking access to DataStore<Preferences> with Enum support
private class Blocking<T>(
private val dataStore: DataStore<Preferences>,
private val prefKey: Preferences.Key<T>
) : ReadWriteProperty<Any, T?> {
override fun getValue(thisRef: Any, property: KProperty<*>): T? = runBlocking {
dataStore.data.map {
it[prefKey]
}.firstOrNull()
}
@gmk57
gmk57 / Sending events to UI.kt
Last active March 3, 2025 15:45
Sending events to UI with Channel/Flow + custom collector (see my first comment for reasons behind it)
/**
* Starts collecting a flow when the lifecycle is started, and **cancels** the collection on stop.
* This is different from `lifecycleScope.launchWhenStarted { flow.collect{...} }`, in which case
* the coroutine is just suspended on stop.
*/
inline fun <reified T> Flow<T>.collectWhileStarted(
lifecycleOwner: LifecycleOwner,
noinline action: suspend (T) -> Unit
) {
object : DefaultLifecycleObserver {
@Skyyo
Skyyo / InternetConnectionTracker2.kt
Created August 10, 2020 17:45
Tracker for internet connection updates. #network_connection
object NetworkUtils : ConnectivityManager.NetworkCallback() {
private val networkLiveData: MutableLiveData<Boolean> = MutableLiveData()
override fun onAvailable(network: Network) {
networkLiveData.postValue(true)
}
override fun onLost(network: Network) {
networkLiveData.postValue(false)
@Skyyo
Skyyo / InternetConnectionTracker.kt
Created August 10, 2020 17:43
Simple network tracker. #network_connection
object InternetConnectionTracker : LiveData<Boolean>() {
private val manager: ConnectivityManager by lazy {
Injector.get().appContext()
.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
}
private val netCallback = object : ConnectivityManager.NetworkCallback() {
override fun onAvailable(network: Network) {
postValue(true)
super.onAvailable(network)
@faruktoptas
faruktoptas / debounce.kt
Created March 5, 2020 06:28
Kotlin coroutine debounce for EditText
fun <T> debounce(
waitMs: Long = 300L,
scope: CoroutineScope,
destinationFunction: (T) -> Unit
): (T) -> Unit {
var debounceJob: Job? = null
return { param: T ->
debounceJob?.cancel()
debounceJob = scope.launch {
delay(waitMs)
@objcode
objcode / ConcurrencyHelpers.kt
Last active January 5, 2025 08:26
Helpers to control concurrency for one shot requests using Kotlin coroutines.
/* Copyright 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@florina-muntenescu
florina-muntenescu / Data.kt
Last active February 19, 2025 14:28
Using RoomDatabase#Callback to pre-populate the database - https://medium.com/google-developers/7-pro-tips-for-room-fbadea4bfbd1
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@Pulimet
Pulimet / AdbCommands
Last active April 24, 2025 14:48
Adb useful commands list
Hi All!
I've recently launched a tool that wraps many of the commands here with a user interface. This desktop application is currently available for macOS. There's a roadmap outlining planned features for the near future.
Feel free to request any features you'd like to see, and I'll prioritize them accordingly.
One of the most important aspects of this application is that every command executed behind the scenes is displayed in a special log section. This allows you to see exactly what’s happening and learn from it.
Here's the link to the repository: https://github.com/Pulimet/ADBugger
App Description:
ADBugger is a desktop tool designed for debugging and QA of Android devices and emulators. It simplifies testing, debugging, and performance analysis by offering device management, automated testing, log analysis, and remote control capabilities. This ensures smooth app performance across various setups.