Skip to content

Instantly share code, notes, and snippets.

@surajsau
surajsau / ParallaxScreen.kt
Last active January 24, 2025 13:55
Parallax effect with Jetpack Compose
@Composable
fun ParallaxScreen(modifier: Modifier = Modifier) {
val context = LocalContext.current
val scope = rememberCoroutineScope()
var data by remember { mutableStateOf<SensorData?>(null) }
DisposableEffect(Unit) {
val dataManager = SensorDataManager(context)
dataManager.init()
@mahdi13
mahdi13 / cafebazaar_rollout.py
Last active August 30, 2023 15:41
Release (deploy) new versions of android app (apk file) to cafebazaar automatically. Great to be used on CI/CD pipelines
import hashlib
import json
import os
import requests
import urllib3
class CafeBazaarClient:
@micer
micer / NestedScrollableHost
Created August 24, 2020 11:24
Fixes issue with nested scrolling elements with the same scroll direction inside ViewPager2. https://issuetracker.google.com/issues/123006042
package com.betvictor.casino.presentation.views
/*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
@jamiesanson
jamiesanson / ViewLifecycleLazy.kt
Last active January 20, 2025 02:41
A Kotlin lazy implementation which automatically clears itself at appropriate times in the View Lifecycle, with a Fragment example
import androidx.fragment.app.Fragment
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
fun <T> Fragment.viewLifecycleLazy(initialise: () -> T): ReadOnlyProperty<Fragment, T> =
object : ReadOnlyProperty<Fragment, T>, DefaultLifecycleObserver {
@MRezaNasirloo
MRezaNasirloo / Ganjeh.kt
Last active October 9, 2021 13:17
Share ViewModels across LifecycleOwners
package com.mrezanasirloo.ganjeh
import android.util.SparseArray
import androidx.activity.ComponentActivity
import androidx.annotation.MainThread
import androidx.fragment.app.Fragment
import androidx.fragment.app.createViewModelLazy
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelLazy
@filipkowicz
filipkowicz / HeaderItemDecoration.kt
Last active February 26, 2025 18:20
Item Decorator for sticky headers in Kotlin
package com.filipkowicz.headeritemdecorator
/*
solution based on - based on Sevastyan answer on StackOverflow
changes:
- take to account views offsets
- transformed to Kotlin
- now works on viewHolders
@humblehacker
humblehacker / mutablelivedata.md
Last active October 4, 2024 19:17
Don't expose MutableLiveData
@vahid-m
vahid-m / BaseRecyclerAdapter.java
Created October 1, 2018 07:34 — forked from EStepiuk/BaseRecyclerAdapter.java
Abstract RecyclerView.Adapter
//T is a type of items
//when inheriting, just create constructor matching super,
//and override viewHolder() method that will return ViewHolder for given item type
public abstract class BaseRecyclerAdapter<T> extends RecyclerView.Adapter<BaseRecyclerAdapter.BaseViewHolder> {
public interface OnItemClickListener<T> {
void onClick(T item);
}
@radoyankov
radoyankov / Example.kt
Last active January 27, 2023 08:59
Easy Spannable on Kotlin
val spanned = spannable{ bold("some") + italic(" formatted") + color(Color.RED, " text") }
val nested = spannable{ bold(italic("nested ")) + url("www.google.com", "text") }
val noWrapping = bold("no ") + sub("wrapping ) + sup("also ") + "works"
text_view.text = spanned + nested + noWrapping
@Jasonlhy
Jasonlhy / LocaleManager.java
Last active June 26, 2021 20:54
LocaleManager for handling android language switch at runtime
public class LocaleManager {
private static final String LANGUAGE_KEY = "CHOOSE_LANGUAGE";
public static Context setLocale(Context c) {
String savedLanguage = getLanguage(c);
return savedLanguage == null ? c : updateResources(c, savedLanguage);
}
public static Context setNewLocale(Context c, String language) {
persistLanguage(c, language);