Skip to content

Instantly share code, notes, and snippets.

View davidtcdeveloper's full-sized avatar

David Tiago Conceição davidtcdeveloper

  • Microsoft
  • Florianópolis, SC
View GitHub Profile
public boolean hasProfilePicure() {
return this.profileUrl() != null;
}
@davidtcdeveloper
davidtcdeveloper / Module build.gradle
Last active February 26, 2017 19:02
Adding parcelable extension.
annotationProcessor 'com.ryanharter.auto.value:auto-value-parcel:0.2.2'
@davidtcdeveloper
davidtcdeveloper / PersonData.java
Created May 28, 2016 17:44
Implementing Parcelable
@AutoValue
public abstract class PersonData implements Parcelable {
@davidtcdeveloper
davidtcdeveloper / AutoValue_PersonData.java
Created May 28, 2016 17:45
Parcelable generated implementation.
public static final Parcelable.Creator<AutoValue_PersonData> CREATOR = new Parcelable.Creator<AutoValue_PersonData>() {
@Override
public AutoValue_PersonData createFromParcel(Parcel in) {
return new AutoValue_PersonData(
in.readLong(),
in.readString(),
in.readInt(),
in.readString(),
in.readString(),
in.readInt() == 0 ? in.readString() : null
@davidtcdeveloper
davidtcdeveloper / build.gradle
Last active February 26, 2017 19:02
GSON setup.
annotationProcessor 'com.ryanharter.auto.value:auto-value-gson:0.3.1'
compile 'com.google.code.gson:gson:2.6.2'
@davidtcdeveloper
davidtcdeveloper / PersonData.java
Last active June 5, 2016 17:54
Adding GSON setup in our class.
public static TypeAdapter<PersonData> typeAdapter(Gson gson) {
return new AutoValue_PersonData.GsonTypeAdapter(gson);
}
@davidtcdeveloper
davidtcdeveloper / AutoValueTypeAdapterFactory.java
Last active May 29, 2016 18:27
Creating adapter factory to work with GSON.
public class AutoValueTypeAdapterFactory implements TypeAdapterFactory {
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
Class<? super T> rawType = type.getRawType();
if (PersonData.class.isAssignableFrom(rawType)) {
return (TypeAdapter<T>) PersonData.typeAdapter(gson);
}
return null;
}
}
//...
import com.ryanharter.auto.value.gson.AutoValueGsonTypeAdapterFactory;
//...
Gson gson = new GsonBuilder()
.registerTypeAdapterFactory(new AutoValueGsonTypeAdapterFactory())
.create();
@davidtcdeveloper
davidtcdeveloper / Test.java
Created May 29, 2016 18:12
Creating class with AutoValue builder
PersonData personData = PersonData.builder()
.id(1)
.name("David Tiago Conceição")
.eMail("david@david.com")
.status(0)
.profileUrl("twitter.com/davidtiagocon")
.pictureImageUrl("https://pbs.twimg.com/profile_images/601894402198544384/FJupV0uC.jpg")
.build();
@GsonTypeAdapterFactory
abstract class AutoValueGsonAdapterFactory implements TypeAdapterFactory {
static TypeAdapterFactory create() {
return new AutoValueGson_AutoValueGsonAdapterFactory();
}
}