Skip to content

Instantly share code, notes, and snippets.

View Aracem's full-sized avatar
👨‍🚀
Jobandtalent and Storybeat

Marcos Trujillo Aracem

👨‍🚀
Jobandtalent and Storybeat
View GitHub Profile
@Aracem
Aracem / GsonKotlinAdapterFactory
Last active November 30, 2018 10:25
Gson adapter to add kotlin optionals check to gson deserializer
private val TAG: String = "GsonKotlinAdapter"
/**
* GsonKotlinAdapterFactory inspired by https://github.com/sargunv/gson-kotlin
*/
internal class GsonKotlinAdapterFactory : TypeAdapterFactory {
private val Class<*>.isKotlinClass: Boolean
get() = declaredAnnotations.find { it.annotationClass.java.name == "kotlin.Metadata" } != null
@Aracem
Aracem / OptionalExtension.kt
Last active October 18, 2018 10:21
Elvis operator could not contains lambdas or several method calls, only 1 expresion. if var != null could not ensure unwrapping i.e. if var is a class property. These function extensions resolve these problems
package com.aracem.android
inline fun <T, K> T?.ifPresent(block: (T) -> K): K? {
return this?.let { block.invoke(it) }
}
inline fun <K> K?.orElse(block: () -> K): K {
return this?.let { it } ?: block.invoke()
}
@Aracem
Aracem / OnPageChangeListenerAdapter
Created May 23, 2018 17:04
OnPageChangeListenerAdapter to easily implement this listener
open class OnPageChangeListenerAdapter : OnPageChangeListener {
override fun onPageScrollStateChanged(state: Int) {
}
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
}
override fun onPageSelected(position: Int) {
}
}
@Aracem
Aracem / LaunchTestFromTerminal.txt
Last active January 31, 2020 12:24
Launch an unit test using a terminal
// Launch a test from a terminal
./gradlew :module:testFlavourBuildType --tests "*ClassNameTest"
./gradlew :module:testFlavourBuildType --tests "com.aracem.android.ClasNameTest"
// To attach Android Studio debugger
./gradlew :module:testFlavourBuildType --tests "*ClassNameTest" --debug-jvm
// Then wait until the compilation finished and attach a debuger. In Android studio use CTRL + SHIFT + A,
// search for "Debugger" and select attach to local source
@Aracem
Aracem / TextColorMatcher
Created March 28, 2017 10:03
TextColorMatcher for your Espresso test
package com.homerthebulldog.android.matcher;
import android.content.res.Resources;
import android.support.annotation.ColorRes;
import android.support.test.espresso.matcher.BoundedMatcher;
import android.view.View;
import android.widget.TextView;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
@Aracem
Aracem / MasterTrackingHelper.java
Created July 21, 2015 21:23
Aspect Oriented Development with a Tracking Sample
package com.aracem.sample.tracking;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.aracem.sample.tracking.trackingservice.MixpanelTrackingHelper;
import com.aracem.sample.tracking.trackingservice.GoogleAnalyticsTrackingHelper;
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/panavtec/Documents/android-sdk-macosx/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
@Aracem
Aracem / AndroidManifest.xml
Last active March 22, 2016 14:51
Speedup Compile time in debug enabling vmSafeMode. USe this Manifest in your debug folder
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2015 Upclose.me All rights reserved.
~
~ 0000000 xx
~ 00000000 xxxx
~ 0000000000 xxl
~ 00000000000000
~ 000000000000
~ 00000000
@Aracem
Aracem / AnimationViewUtils
Created March 19, 2015 15:40
Tada Animation from Cyrill Mottier
package com.aracem.utils.animation;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.Keyframe;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
package com.fewlaps.android.quitnow.base.customview;
import android.os.Handler;
import android.view.View;
/**
* A simple way to call the common new Handler().postDelayed(..., time);
* to show the Ripple animation completely and then run a Runnable. This class
* have to be used like a {@link android.view.View.OnClickListener}
*