Skip to content

Instantly share code, notes, and snippets.

View Tgo1014's full-sized avatar
💻

Tiago Araujo Tgo1014

💻
  • Barcelona, Spain
  • 20:31 (UTC +02:00)
  • X @Tgo1014
View GitHub Profile
@KlassenKonstantin
KlassenKonstantin / Pull2Refresh.kt
Created March 26, 2024 11:23
Fitbit style Pull 2 Refresh
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
WindowCompat.setDecorFitsSystemWindows(window, false)
super.onCreate(savedInstanceState)
setContent {
P2RTheme {
// A surface container using the 'background' color from the theme
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
CompositionLocalProvider(
LocalOverscrollConfiguration provides null // Disable overscroll otherwise it consumes the drag before we get the chance
@surajsau
surajsau / ParallaxScreen.kt
Last active April 16, 2024 13:53
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()
@mxalbert1996
mxalbert1996 / Scrollbar.kt
Last active February 1, 2024 12:44
Modifiers to draw scrollbars in Jetpack Compose
/*
* MIT License
*
* Copyright (c) 2022 Albert Chang
*
* 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
@gotev
gotev / NavigationBottomBarSectionsStateKeeperWorkaround.kt
Last active June 12, 2023 16:08
JetPack Bottom Bar Navigation with Sections State
package jetpack.navigation.workaround
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.navigation.NavController
import androidx.navigation.ui.setupActionBarWithNavController
import com.google.android.material.bottomnavigation.BottomNavigationView
import java.lang.ref.WeakReference
@russell-shizhen
russell-shizhen / Memos for building an Android Library project.md
Created October 17, 2018 09:24
Memos for building an Android Library project

Library build variants

Consider what features/functionalities

  • Debug
  • Release

Public API

Only expose the ones necessary

This can leave more flexibility to future API changes without breaking the APIs exposed in earlier versions.

Initial verification using code snippets to illustrate the API flow.

@Jeevuz
Jeevuz / Extensions.kt
Last active January 3, 2023 10:25
Here I collect some of my most useful Kotlin extensions
inline fun SharedPreferences.edit(changes: SharedPreferences.Editor.() -> SharedPreferences.Editor) {
edit().changes().apply()
}
fun ImageView.tintSrc(@ColorRes colorRes: Int) {
val drawable = DrawableCompat.wrap(drawable)
DrawableCompat.setTint(drawable, ContextCompat.getColor(context, colorRes))
setImageDrawable(drawable)
if (drawable is TintAwareDrawable) invalidate() // Because in this case setImageDrawable will not call invalidate()
}
@recoverrelax
recoverrelax / BaseSharedPreferences.kt
Last active January 4, 2021 10:19
Base SharedPreferences usage for Kotlin (with dagger2 bonus)
abstract class BaseSharedPreferences(
val preferences: SharedPreferences,
val moshi: Moshi
) {
protected fun get(key: String, default: String): String = preferences.getString(key, default)
protected fun get(key: String, default: Int): Int = preferences.getInt(key, default)
protected fun get(key: String, default: Float): Float = preferences.getFloat(key, default)
protected fun get(key: String, default: Long): Long = preferences.getLong(key, default)
protected fun get(key: String, default: Boolean): Boolean = preferences.getBoolean(key, default)
@passsy
passsy / KIntent.kt
Last active March 28, 2023 06:51
Kotlin extension functions to start a generic Activity
package com.pascalwelsch.extensions
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
/**
* Extensions for simpler launching of Activities
@kibotu
kibotu / ViewExtensions.kt
Last active September 13, 2023 05:45
Kotlin extension method to set margin.
fun View.setMargins(
left: Int? = null,
top: Int? = null,
right: Int? = null,
bottom: Int? = null
) {
val lp = layoutParams as? ViewGroup.MarginLayoutParams
?: return
lp.setMargins(