Skip to content

Instantly share code, notes, and snippets.

View FireZenk's full-sized avatar
🌍
Improving the world

Jorge Garrido FireZenk

🌍
Improving the world
View GitHub Profile
@kafri8889
kafri8889 / DateTextField.kt
Last active May 30, 2023 08:33
Date format in TextField Jetpack Compose
@Composable
fun Screen() {
var date by remember {
mutableStateOf(
TextFieldValue(
text = "dd-MM-yyyy"
)
)
}
@hvisser
hvisser / KeepScreenOn.kt
Created January 21, 2022 09:16
LocalView.current can be useful if you need to tap into a view function like keepScreenOn or haptics from Compose
@Composable
fun KeepScreenOn() {
val currentView = LocalView.current
DisposableEffect(Unit) {
currentView.keepScreenOn = true
onDispose {
currentView.keepScreenOn = false
}
}
@cgruber
cgruber / constrain_desktop_window.kt
Last active April 11, 2023 09:48
Constrain Compose Desktop Window to a minimum size.
//
// Copyright (c) Christian Gruber, All Rights Reserved
//
// Licensed for use under any of simplified BSD 2-clause, BSD, MIT, or Apache licenses,
// at the licensee's discretion.
//
// I'd release it to the public domain, except that prevents its use in some commercial
// environments due to the US having a broken copyright system. So there it is. Liberally
// licensed as I can make it.
@pedrovgs
pedrovgs / ComposeViewModel.kt
Created April 28, 2021 16:58
Example of a base view model for Jetpack Compose
import androidx.lifecycle.*
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
abstract class ComposeViewModel<C, E> : ViewModel(), LifecycleObserver {
@handstandsam
handstandsam / MyLifecycleOwner.kt
Last active March 30, 2024 16:59
Jetpack Compose OverlayService. You have to have all the correct permissions granted and in your manifest, but if you do, this this will show a green box with "Hello" in it!
import android.os.Bundle
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleRegistry
import androidx.savedstate.SavedStateRegistry
import androidx.savedstate.SavedStateRegistryController
import androidx.savedstate.SavedStateRegistryOwner
internal class MyLifecycleOwner : SavedStateRegistryOwner {
private var mLifecycleRegistry: LifecycleRegistry = LifecycleRegistry(this)
private var mSavedStateRegistryController: SavedStateRegistryController = SavedStateRegistryController.create(this)
@motorro
motorro / prepopulate-MainActivityModel.kt
Created March 12, 2020 15:40
New database instance
val db = Room
.databaseBuilder(getApplication(), CitiesDb::class.java, "cities.db")
.createFromAsset("databases/cities.db")
.fallbackToDestructiveMigration() // On version update - just copy over
.build()
@pablisco
pablisco / Coroutine_scope_functions.kt
Last active January 11, 2024 16:42
Simple way to jump into a separate context
suspend fun <T, R> T.letOn(
context: CoroutineContext,
block: suspend CoroutineScope.(T) -> R
): R = withContext(context) { block(this@letOn) }
suspend fun <T> T.alsoOn(
context: CoroutineContext,
block: suspend CoroutineScope.(T) -> Unit
): T = also { withContext(context) { block(this@alsoOn) } }
@sergiocasero
sergiocasero / DaoGenerator.kt
Created April 25, 2019 09:39
DaoGenerator code template for IntelliJ/AS
package ${PACKAGE_NAME}
#parse("File Header.java")
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Update
import androidx.room.Query
@Dao
package com.geekorum.geekdroid.navigation
import android.content.Context
import android.os.Bundle
import android.util.AttributeSet
import androidx.core.content.res.use
import androidx.core.os.bundleOf
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
@alvr
alvr / packages.md
Last active April 14, 2024 10:51
Available Packages

Available Packages:

Path Version Description
add-ons;addon-google_apis-google-15 3 Google APIs
add-ons;addon-google_apis-google-16 4 Google APIs
add-ons;addon-google_apis-google-17 4 Google APIs
add-ons;addon-google_apis-google-18 4 Googl