Skip to content

Commit

Permalink
Converted remaining models to use AutoValue
Browse files Browse the repository at this point in the history
  • Loading branch information
codebutler committed Aug 29, 2016
1 parent 782df15 commit 70bf4dd
Show file tree
Hide file tree
Showing 67 changed files with 2,617 additions and 3,908 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Expand Up @@ -4,7 +4,7 @@ buildscript {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0-alpha6'
classpath 'com.android.tools.build:gradle:2.2.0-beta3'
classpath 'io.fabric.tools:gradle:1.21.6'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
Expand Down Expand Up @@ -46,7 +46,7 @@ dependencies {

provided 'com.google.auto.value:auto-value:1.3-rc1'
apt 'com.google.auto.value:auto-value:1.3-rc1'
apt 'com.ryanharter.auto.value:auto-value-parcel:0.2.3-rc2'
apt 'com.ryanharter.auto.value:auto-value-parcel:0.2.3-SNAPSHOT'
apt 'com.ryanharter.auto.value:auto-value-gson:0.4.0'
}

Expand Down
1 change: 1 addition & 0 deletions config/checkstyle/checkstyle.xml
Expand Up @@ -351,6 +351,7 @@ Description: https://source.android.com/source/code-style.html
<!-- Forbid interfaces with no methods -->
<module name="InterfaceIsType"/>

<module name="VisibilityModifier"/>
</module>

<!--################################################-->
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
#Mon May 30 13:44:55 PDT 2016
#Sat Aug 27 17:57:28 PDT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
Expand Up @@ -105,7 +105,7 @@ protected void onCreate(final Bundle savedInstanceState) {

new AsyncTask<Void, Void, Void>() {

boolean mSpeakBalanceEnabled;
private boolean mSpeakBalanceEnabled;

private Exception mException;

Expand Down
Expand Up @@ -70,7 +70,7 @@ public TransitIdentity parseTransitIdentity() {
@Override
public TransitData parseTransitData() {
if (EZLinkTransitData.check(this)) {
return new EZLinkTransitData(this);
return EZLinkTransitData.create(this);
}
return null;
}
Expand Down
Expand Up @@ -92,18 +92,18 @@ public TransitIdentity parseTransitIdentity() {
@Override
public TransitData parseTransitData() {
if (OVChipTransitData.check(this)) {
return new OVChipTransitData(this);
return OVChipTransitData.create(this);
} else if (BilheteUnicoSPTransitData.check(this)) {
return new BilheteUnicoSPTransitData(this);
return BilheteUnicoSPTransitData.create(this);
} else if (ManlyFastFerryTransitData.check(this)) {
return new ManlyFastFerryTransitData(this);
return ManlyFastFerryTransitData.create(this);
} else if (SeqGoTransitData.check(this)) {
return new SeqGoTransitData(this);
return SeqGoTransitData.create(this);
} else if (UnauthorizedClassicTransitData.check(this)) {
// This check must be LAST.
//
// This is to throw up a warning whenever there is a card with all locked sectors
return new UnauthorizedClassicTransitData();
return UnauthorizedClassicTransitData.create();
}

// The card could not be identified, but has some open sectors.
Expand Down
Expand Up @@ -69,27 +69,27 @@ public CardType getCardType() {
@Nullable
public TransitData parseTransitData() {
if (OrcaTransitData.check(this)) {
return new OrcaTransitData(this);
return OrcaTransitData.create(this);
}
if (ClipperTransitData.check(this)) {
return new ClipperTransitData(this);
return ClipperTransitData.parse(this);
}
if (HSLTransitData.check(this)) {
return new HSLTransitData(this);
return HSLTransitData.create(this);
}
if (OpalTransitData.check(this)) {
return new OpalTransitData(this);
return OpalTransitData.create(this);
}
if (MykiTransitData.check(this)) {
return new MykiTransitData(this);
return MykiTransitData.create(this);
}

// Stub card types go last
if (AdelaideMetrocardStubTransitData.check(this)) {
return new AdelaideMetrocardStubTransitData(this);
return AdelaideMetrocardStubTransitData.create(this);
}
if (AtHopStubTransitData.check(this)) {
return new AtHopStubTransitData(this);
return AtHopStubTransitData.create(this);
}
return null;
}
Expand Down
Expand Up @@ -108,9 +108,9 @@ public TransitIdentity parseTransitIdentity() {
@Nullable
public TransitData parseTransitData() {
if (SuicaTransitData.check(this)) {
return new SuicaTransitData(this);
return SuicaTransitData.create(this);
} else if (EdyTransitData.check(this)) {
return new EdyTransitData(this);
return EdyTransitData.create(this);
}
return null;
}
Expand Down
Expand Up @@ -39,6 +39,7 @@

import java.text.DateFormat;
import java.util.Date;
import java.util.List;

public class CardRefillsFragment extends ListFragment {
@Override
Expand All @@ -50,7 +51,7 @@ public void onCreate(Bundle savedInstanceState) {
}

private static class RefillsListAdapter extends ArrayAdapter<Refill> {
RefillsListAdapter(Context context, Refill[] refills) {
RefillsListAdapter(Context context, List<Refill> refills) {
super(context, 0, refills);
}

Expand Down
Expand Up @@ -39,6 +39,8 @@
import com.codebutler.farebot.transit.TransitData;
import com.codebutler.farebot.util.Utils;

import java.util.List;

public class CardSubscriptionsFragment extends ListFragment {
private Card mCard;
private TransitData mTransitData;
Expand All @@ -57,7 +59,7 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
}

private class SubscriptionsAdapter extends ArrayAdapter<Subscription> {
SubscriptionsAdapter(Context context, Subscription[] subscriptions) {
SubscriptionsAdapter(Context context, List<Subscription> subscriptions) {
super(context, 0, subscriptions);
}

Expand Down
Expand Up @@ -73,16 +73,16 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
View view = inflater.inflate(R.layout.fragment_card_trips, null);

List<Trip> trips = new ArrayList<>();
if (mTransitData.getTrips() != null && mTransitData.getTrips().length > 0) {
if (mTransitData.getTrips() != null && mTransitData.getTrips().size() > 0) {
for (Trip t : mTransitData.getTrips()) {
trips.add(t);
}
}

// This is for "legacy" implementations which have a separate list of refills.
if (mTransitData.getRefills() != null && mTransitData.getRefills().length > 0) {
if (mTransitData.getRefills() != null && mTransitData.getRefills().size() > 0) {
for (Refill r : mTransitData.getRefills()) {
trips.add(new RefillTrip(r));
trips.add(RefillTrip.create(r));
}
}

Expand Down
6 changes: 1 addition & 5 deletions src/main/java/com/codebutler/farebot/transit/Refill.java
Expand Up @@ -25,6 +25,7 @@
import android.os.Parcelable;

public abstract class Refill implements Parcelable {

public abstract long getTimestamp();

public abstract String getAgencyName();
Expand All @@ -35,11 +36,6 @@ public abstract class Refill implements Parcelable {

public abstract String getAmountString();

@Override
public final int describeContents() {
return 0;
}

public static class Comparator implements java.util.Comparator<Refill> {
@Override
public int compare(Refill lhs, Refill rhs) {
Expand Down
50 changes: 14 additions & 36 deletions src/main/java/com/codebutler/farebot/transit/RefillTrip.java
Expand Up @@ -19,39 +19,25 @@

package com.codebutler.farebot.transit;

import android.os.Parcel;
import android.support.annotation.NonNull;

import com.google.auto.value.AutoValue;

/**
* Wrapper around Refills to make them like Trips, so Trips become like history. This is similar
* to what the Japanese cards (Edy, Suica) already had implemented for themselves.
*/
public class RefillTrip extends Trip {

public static final Creator<RefillTrip> CREATOR = new Creator<RefillTrip>() {
@Override
public RefillTrip createFromParcel(Parcel source) {
return new RefillTrip(source);
}

@Override
public RefillTrip[] newArray(int size) {
return new RefillTrip[size];
}
};

private final Refill mRefill;
@AutoValue
public abstract class RefillTrip extends Trip {

public RefillTrip(Refill refill) {
mRefill = refill;
}

private RefillTrip(Parcel source) {
mRefill = source.readParcelable(Refill.class.getClassLoader());
@NonNull
public static RefillTrip create(@NonNull Refill refill) {
return new AutoValue_RefillTrip(refill);
}

@Override
public long getTimestamp() {
return mRefill.getTimestamp();
return getRefill().getTimestamp();
}

@Override
Expand All @@ -66,17 +52,17 @@ public String getRouteName() {

@Override
public String getAgencyName() {
return mRefill.getAgencyName();
return getRefill().getAgencyName();
}

@Override
public String getShortAgencyName() {
return mRefill.getShortAgencyName();
return getRefill().getShortAgencyName();
}

@Override
public String getFareString() {
return mRefill.getAmountString();
return getRefill().getAmountString();
}

@Override
Expand Down Expand Up @@ -119,14 +105,6 @@ public boolean hasTime() {
return true;
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
mRefill.writeToParcel(dest, flags);
}

@NonNull
abstract Refill getRefill();
}

0 comments on commit 70bf4dd

Please sign in to comment.