Skip to content

Instantly share code, notes, and snippets.

View zakrodionov's full-sized avatar
🇺🇦
Peace For Ukraine

Zakhar Rodionov zakrodionov

🇺🇦
Peace For Ukraine
View GitHub Profile
@inidamleader
inidamleader / AutoSizeText.kt
Last active April 25, 2025 11:23
AutoSizeText: Composable function that automatically adjusts the text size to fit within given constraints with optimal performance by using a binary search algorithm
/*
MIT License
Copyright (c) 2024 Reda El Madini
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
@ExperimentalMaterialApi
@Composable
fun OverlayBottomSheetScaffold(
sheetContent: @Composable ColumnScope.() -> Unit,
scaffoldState: BottomSheetScaffoldState = rememberBottomSheetScaffoldState(),
sheetPeekHeight: Dp = 0.dp,
maxOverlayAlpha: Float = 0.7f,
overlayColor: Color = Color.Black,
cancelable: Boolean = true,
content: @Composable (PaddingValues) -> Unit,
@antonshilov
antonshilov / SwipeButton.kt
Created January 15, 2022 13:04
Swipeable Button created with Jetpack Compose
package com.antonshilov.swipebutton
import androidx.compose.animation.Crossfade
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
@XanderZhu
XanderZhu / Calendar.kt
Created October 3, 2021 08:20
Jetpack compose calendar.
@OptIn(ExperimentalPagerApi::class)
@Composable
fun Calendar(
startDate: LocalDate,
months: List<YearMonth>,
selectedDates: Set<LocalDate>,
focusedDate: LocalDate?,
isNewDateSelectionEnabled: Boolean,
onDateClick: (LocalDate) -> Unit,
horizontalPadding: Dp,
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Paint
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
@Composable
fun HomeList(taskViewModel: ListViewModel = viewModel()) {
val coroutineScope = rememberCoroutineScope()
val scaffoldState = rememberScaffoldState()
val onShowSnackbar: (Task) -> Unit = { task ->
coroutineScope.launch {
val snackbarResult = scaffoldState.snackbarHostState.showSnackbar(
message = "${task.title} completed",
actionLabel = "Undo"
@JorgeCastilloPrz
JorgeCastilloPrz / RatingStars.kt
Last active August 29, 2021 23:43
Composable to show rating stars. Noninteractive.
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ColorFilter
class FragmentViewBindingDelegate<T : ViewBinding>(private val factory: (View) -> T) : ReadOnlyProperty<Fragment, T> {
private var backingValue: T? = null
override operator fun getValue(thisRef: Fragment, property: KProperty<*>): T = when (val binding = backingValue) {
null -> {
thisRef.parentFragmentManager.registerFragmentLifecycleCallbacks(object : FragmentManager.FragmentLifecycleCallbacks() {
override fun onFragmentViewDestroyed(fm: FragmentManager, fragment: Fragment) {
if (fragment != thisRef) return
backingValue = null
fm.unregisterFragmentLifecycleCallbacks(this)
@morenodoug
morenodoug / utilsAndroid.java
Created June 27, 2020 18:37
Adding an image to mediaStore(see in phone gallery) on Android
public static void notifyMediaStoreScanner(Context mContext, Uri cacheImageUri) throws IOException {
Uri newImageUri = createImageInMediaStore(mContext, cacheImageUri);
ContentResolver resolver = mContext
.getContentResolver();
FileInputStream input ;
FileOutputStream outputStream ;
try (ParcelFileDescriptor pfd = resolver
.openFileDescriptor(newImageUri, "w", null)) {
// Write data into the pending image.
@Zhuinden
Zhuinden / FragmentViewBindingDelegate.kt
Last active February 11, 2025 09:25
Fragment view binding delegate
// https://github.com/Zhuinden/fragmentviewbindingdelegate-kt
import android.view.View
import androidx.fragment.app.Fragment
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import androidx.viewbinding.ViewBinding
import kotlin.properties.ReadOnlyProperty