Skip to content

Instantly share code, notes, and snippets.

View pablichjenkov's full-sized avatar

pablichjenkov pablichjenkov

View GitHub Profile
@Preview(showBackground = true, showSystemUi = true)
@Composable
fun App() {
Column {
MarxistRow {
Text("Left Text", Modifier.background(Color.Red))
Text("Right Text", Modifier.background(Color.Blue))
}
MarxistRow {
@zach-klippenstein
zach-klippenstein / SegmentedControl.kt
Last active August 24, 2023 09:31
iOS-style segmented control in Compose
import android.annotation.SuppressLint
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.forEachGesture
import androidx.compose.foundation.gestures.horizontalDrag
import androidx.compose.foundation.layout.Arrangement.spacedBy
import androidx.compose.foundation.layout.Box
/* Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
fun animateVisibility(view: View, visible: Boolean) {
val targetAlpha = if (visible) 1f else 0f
if (view.alpha == targetAlpha) return
view.visibility = View.VISIBLE
val spring = view.spring(SpringAnimation.ALPHA)
(view.getTag(R.id.tag_pending_end_listener) as?
DynamicAnimation.OnAnimationEndListener)?.let {
@RBusarow
RBusarow / TestCoroutineExtension.kt
Last active November 20, 2023 19:03
A JUnit 4 Rule and JUnit 5 Extension for utilizing TestCoroutineDispatcher and TestCoroutineScope from kotlinx.coroutines-test
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.TestCoroutineScope
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import org.junit.jupiter.api.extension.AfterAllCallback
import org.junit.jupiter.api.extension.AfterEachCallback
import org.junit.jupiter.api.extension.BeforeAllCallback
import org.junit.jupiter.api.extension.ExtendWith
import org.junit.jupiter.api.extension.ExtensionContext
@vemilyus
vemilyus / ActorState.kt
Created December 30, 2018 14:48
Sample implementation of ActorState with read-write separation
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.ObsoleteCoroutinesApi
import kotlinx.coroutines.channels.actor
import kotlinx.coroutines.isActive
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlin.coroutines.CoroutineContext
interface ActorState<T : Any> : CoroutineScope {
@y-polek
y-polek / doze_mode_adb_commands.sh
Last active April 20, 2024 09:36
adb commands to test Doze mode
#! /bin/zsh
# Buttery powered state
adb shell dumpsys battery | grep powered
# Unplug battery
adb shell dumpsys battery unplug
# Reset battery
adb shell dumpsys battery reset
@gpeal
gpeal / SimpleDemo.kt
Last active August 28, 2018 17:54
Airbnb MvRx Early Look
data class SimpleDemoState(val listing: Async<Listing> = Uninitialized)
class SimpleDemoViewModel(override val initialState: SimpleDemoState) : MvRxViewModel<SimpleDemoState>() {
init {
fetchListing()
}
private fun fetchListing() {
// This automatically fires off a request and maps its response to Async<Listing>
// which is a sealed class and can be: Unitialized, Loading, Success, and Fail.
@ericwindmill
ericwindmill / form_page.dart
Created April 14, 2018 19:25
Flutter Simple inherited Widget Example
import 'package:flutter/material.dart';
import 'package:simple_inherit/state_container.dart';
class UpdateUserScreen extends StatelessWidget {
static final GlobalKey<FormState> formKey = new GlobalKey<FormState>();
static final GlobalKey<FormFieldState<String>> firstNameKey =
new GlobalKey<FormFieldState<String>>();
static final GlobalKey<FormFieldState<String>> lastNameKey =
new GlobalKey<FormFieldState<String>>();
static final GlobalKey<FormFieldState<String>> emailKey =
@hameno
hameno / ExtendedFileProvider
Last active January 12, 2022 10:47
"Enhanced" FileProvider with support for external secondary paths (based on 27.0.2)
/*
* Copyright (C) 2013 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
@FavoRiteKK
FavoRiteKK / EndlessRecyclerScrollListener
Created October 27, 2017 04:55
[Android] Endless load more for RecyclerView
package com.estate.mrnx.tb.custom.refresharticle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
public abstract class EndlessRecyclerScrollListener extends RecyclerView.OnScrollListener {
// The minimum amount of items to have below your current scroll position
// before loading more.