Skip to content

Instantly share code, notes, and snippets.

View HugoMatilla's full-sized avatar
🏠
Working from home

Hugo Matilla HugoMatilla

🏠
Working from home
View GitHub Profile
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.SOURCE)
/**
* Friendly reminder that this might not be the best place to do major changes. Or any changes at all.
* Use the [reason] arg to point your teammates and your future-self to some documentation.
*/
annotation class HereBeDragons(val reason: String)
@RubyLichtenstein
RubyLichtenstein / PainlessFragmentArguments.md
Last active February 11, 2021 00:40
Painless android fragments with Kotlin

Starting new fragments with Kotlin is easy

Example

val user = User(id = "id", name = "Ruby")
val userFragment: UserFragment = newFragment<User, UserFragment>(user)

How this magic works

interface TasksRepository {
suspend fun tasks(user: User): Either<RepositoryError, List<Task>>
}
fun tasks(tasksRepository: TasksRepository, userRepository: UserRepository):
() -> Either<RepositoryError, List<Task>> = {
runBlocking { tasksRepository.tasks(userRepository.currentUser()) } // This is b
}
UseCase<RepositoryError, List<Task>>().bg(tasks(tasksRepository, userRepository))
@pablisco
pablisco / Logger.kt
Last active May 17, 2018 10:35
Fluent Logging with Kotlin
inline fun <A> A.logWith(logger: Logger, block: Logger.(A) -> Unit) : A =
this.also { logger.block(it) }
// With interface injection
interface HasLog {
val log: Logger
fun <A> A.log(block: Logger.(A) -> Unit) : A =
logWith(logger, block)
}
@Sloy
Sloy / LiveDataExtensions.kt
Created February 6, 2018 11:08
Kotlin extensions for LiveData
package com.sloydev.macookbuk.infrastructure.extensions
import android.arch.lifecycle.*
fun <T, R> LiveData<T>.map(transformation: (T) -> R): LiveData<R> {
return Transformations.map(this, transformation)
}
fun <A, B, C> LiveData<A>.zipWith(other: LiveData<B>, zipFunc: (A, B) -> C): LiveData<C> {
return ZippedLiveData<A, B, C>(this, other, zipFunc)
@pablisco
pablisco / gist:da25563d57559dd1d18f165272269b57
Last active April 15, 2022 03:23
ResourcesExceptions.kt
import android.content.Context
import android.content.res.Resources
import android.graphics.drawable.Drawable
import android.support.annotation.AnyRes
import android.support.v4.app.Fragment
import android.support.v4.content.res.ResourcesCompat.*
import android.view.View
val Context.animations
get() = ResourceMapper { resources.getAnimation(it) }
@rharter
rharter / SharedPreferenceLiveData.kt
Last active March 19, 2023 08:15
Creates LiveData objects that observe a value in SharedPreferences while they have active listeners.
import android.arch.lifecycle.LiveData
import android.content.SharedPreferences
abstract class SharedPreferenceLiveData<T>(val sharedPrefs: SharedPreferences,
val key: String,
val defValue: T) : LiveData<T>() {
private val preferenceChangeListener = SharedPreferences.OnSharedPreferenceChangeListener { sharedPreferences, key ->
if (key == this.key) {
value = getValueFromPreferences(key, defValue)
@yanngx
yanngx / FragmentArgumentDelegate.kt
Last active January 19, 2023 09:26
Fragment arguments without hassle !
package be.brol
import android.os.Binder
import android.os.Bundle
import android.support.v4.app.BundleCompat
import android.support.v4.app.Fragment
/**
* Eases the Fragment.newInstance ceremony by marking the fragment's args with this delegate
* Just write the property in newInstance and read it like any other property after the fragment has been created
@JosiasSena
JosiasSena / DeCryptor.java
Last active September 12, 2023 12:40
Encryptor and Decryptor for data encryption.decryption using the Android KeyStore.
/**
_____ _____ _
| __ \ / ____| | |
| | | | ___| | _ __ _ _ _ __ | |_ ___ _ __
| | | |/ _ \ | | '__| | | | '_ \| __/ _ \| '__|
| |__| | __/ |____| | | |_| | |_) | || (_) | |
|_____/ \___|\_____|_| \__, | .__/ \__\___/|_|
__/ | |
|___/|_|
*/
@cutiko
cutiko / LoginActivity.java
Last active August 29, 2022 14:53
How to customize firebase-ui-auth for Android
public class LoginActivity extends AppCompatActivity {
private static final int RC_SIGN_IN = 343;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);