Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ We also use the following open-source libraries.
* [Butterknife](https://github.com/JakeWharton/butterknife)
* [RxJava](https://github.com/ReactiveX/RxJava)
* [Otto](https://github.com/square/otto)
* [Retrolambda](https://github.com/evant/gradle-retrolambda)

Before contributing, please be sure your are familiar with the design patterns and libraries.
Feel free to reach out on Slack if you have questions!
Expand All @@ -48,6 +49,8 @@ key.facebookid=...
```
Please contact the current app devs for the `debug.keystore` and `debug_keys.properties` files

[Retrolambda](https://github.com/evant/gradle-retrolambda) is used to give us access to Java 8's lambdas, so you will need to [install the Java 8 JDK](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html). Then go to Android Studio -> Preferences -> Path Variables and add a new JAVA8_HOME variable with the value set to your jdk8 path.

##Mortar and Flow

A quick primer on how we're using mortar and flow.
Expand Down
19 changes: 19 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ repositories {
}

apply plugin: 'com.neenbedankt.android-apt'
buildscript {
repositories {
mavenCentral()
}

dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.3.0-beta4'
}
}

repositories {
mavenCentral()
}

android {
compileSdkVersion 23
Expand Down Expand Up @@ -45,6 +58,12 @@ android {
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

buildTypes {

def ftbSigningConfig = signingConfigs.ftb
Expand Down
23 changes: 5 additions & 18 deletions app/src/main/java/com/berniesanders/fieldthebern/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,9 @@ private void handleOptionsMenu(Menu menu) {
} else {
menu.add(actionBarMenuAction.label())
.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS)
.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
actionBarMenuAction.action().call();
return true;
}
.setOnMenuItemClickListener(menuItem -> {
actionBarMenuAction.action().call();
return true;
});
}
// // Inflate the options menu from XML
Expand Down Expand Up @@ -467,12 +464,7 @@ private void showPage(String title) {
if (item.getTitle().equals(title)) {
final Page searchItem = (Page) item;
Timber.v("Showing page from search: %s", searchItem.getTitle());
container.post(new Runnable() {
@Override
public void run() {
Flow.get(MainActivity.this).set(new PageScreen(searchItem));
}
});
container.post(() -> Flow.get(MainActivity.this).set(new PageScreen(searchItem)));
break;
}
}
Expand All @@ -486,12 +478,7 @@ private void showCollection(String title) {
if (item.getTitle().equals(title)) {
final Collection searchItem = (Collection) item;
Timber.v("Showing Collection from search: %s", item.getTitle());
container.post(new Runnable() {
@Override
public void run() {
Flow.get(MainActivity.this).set(new CollectionScreen(searchItem));
}
});
container.post(() -> Flow.get(MainActivity.this).set(new CollectionScreen(searchItem)));
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,20 @@ public int getItemViewType(final int position) {
return layoutAnnotation.value();
}

MultiAdapter.ClickListener onGridItemClick = new MultiAdapter.ClickListener() {
MultiAdapter.ClickListener onGridItemClick = (model, v) -> {
animateClick(v);

@Override
public void onClick(Object model, View v) {
animateClick(v);
ApiItem apiItem = (ApiItem) model;

ApiItem apiItem = (ApiItem) model;
Timber.v("onGridItemClick: %s %s", apiItem.getClass().getSimpleName(), apiItem.getTitle());

Timber.v("onGridItemClick: %s %s", apiItem.getClass().getSimpleName(), apiItem.getTitle());

if (apiItem instanceof Page) {
Flow.get(v).set(new PageScreen((Page) apiItem));
} else if (apiItem instanceof Collection) {
Flow.get(v).set(new CollectionScreen((Collection) apiItem));
}

Timber.v("Flow.get v= %s", Flow.get(v).toString());
if (apiItem instanceof Page) {
Flow.get(v).set(new PageScreen((Page) apiItem));
} else if (apiItem instanceof Collection) {
Flow.get(v).set(new CollectionScreen((Collection) apiItem));
}

Timber.v("Flow.get v= %s", Flow.get(v).toString());
};

void animateClick(View v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,10 @@ public void onDismiss(DialogInterface dialog) {
}

DialogInterface.OnClickListener createClickListener(final int actionIndex) {
return new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (dialogConfig != null) {
dialogConfig.actions[actionIndex].action().call();
dialogConfig = null;
}
return (dialog, which) -> {
if (dialogConfig != null) {
dialogConfig.actions[actionIndex].action().call();
dialogConfig = null;
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,9 @@ public void dispatch(Flow.Traversal traversal, final Flow.TraversalCallback call

//TODO add a method to container to hold a ref to the traversal, then we can get
//TODO a view for a SceneAction and for trying to use the Transitions framework
container.executeTraversal(this, traversal, new Flow.TraversalCallback() {
@Override
public void onTraversalCompleted() {
callback.onTraversalCompleted();
disabled = false;
}
container.executeTraversal(this, traversal, () -> {
callback.onTraversalCompleted();
disabled = false;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,16 @@ protected void performTraversal(final ViewGroup containerView,
} else {
containerView.addView(newView);
final View finalFromView = fromView;
Utils.waitForMeasure(newView, new Utils.OnMeasuredCallback() {
@Override
public void onMeasured(View view, int width, int height) {
runAnimation(containerView, finalFromView, view, direction, new Flow.TraversalCallback() {
@Override
public void onTraversalCompleted() {
containerView.removeView(finalFromView);
oldPath.destroyNotIn(context, contextFactory);
callback.onTraversalCompleted();
}
});
}
});
Utils.waitForMeasure(newView,
(view, width, height) -> runAnimation(containerView,
finalFromView,
view,
direction,
() -> {
containerView.removeView(finalFromView);
oldPath.destroyNotIn(context, contextFactory);
callback.onTraversalCompleted();
}));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@ public AddressRepo(Gson gson, TokenRepo tokenRepo, RxSharedPreferences rxPrefs,
this.config = config;
this.context = context;

HttpLoggingInterceptor.Logger logger = new HttpLoggingInterceptor.Logger() {
@Override
public void log(String message) {
Timber.v(message);
}
};
HttpLoggingInterceptor.Logger logger = message -> Timber.v(message);
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(logger);
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.io.Reader;
import javax.inject.Inject;
import javax.inject.Singleton;
import okhttp3.Interceptor;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Response;
Expand All @@ -48,7 +47,6 @@
import retrofit2.RxJavaCallAdapterFactory;
import rx.Observable;
import rx.Subscriber;
import rx.functions.Func1;
import timber.log.Timber;

/**
Expand Down Expand Up @@ -91,13 +89,9 @@ public Observable<Collection> get(final CollectionSpec spec) {
return getFromFile();
}

return getFromHttp(spec.url()).map(new Func1<Collection, Collection>() {

@Override
public Collection call(Collection collection) {
collectionMemCache = collection;
return collectionMemCache;
}
return getFromHttp(spec.url()).map(collection -> {
collectionMemCache = collection;
return collectionMemCache;
});
}

Expand Down Expand Up @@ -143,28 +137,20 @@ private Observable<Collection> getFromHttp(final String urlStub) {
return Observable.error(new NetworkUnavailableException("No internet available"));
}

HttpLoggingInterceptor.Logger logger = new HttpLoggingInterceptor.Logger() {
@Override
public void log(String message) {
Timber.v(message);
}
};
HttpLoggingInterceptor.Logger logger = message -> Timber.v(message);
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(logger);
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

OkHttpClient client =
new OkHttpClient.Builder().addInterceptor(new UserAgentInterceptor(config.getUserAgent()))
.addInterceptor(new Interceptor() {
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
Response response = chain.proceed(chain.request());
MediaType contentType = response.body().contentType();
String bodyString = response.body().string();
ResponseBody body = ResponseBody.create(contentType, bodyString);
ResponseBody body2 = ResponseBody.create(contentType, bodyString);
write(response.newBuilder().body(body2).build());
return response.newBuilder().body(body).build();
}
.addInterceptor(chain -> {
Response response = chain.proceed(chain.request());
MediaType contentType = response.body().contentType();
String bodyString = response.body().string();
ResponseBody body = ResponseBody.create(contentType, bodyString);
ResponseBody body2 = ResponseBody.create(contentType, bodyString);
write(response.newBuilder().body(body2).build());
return response.newBuilder().body(body).build();
})
.addInterceptor(loggingInterceptor)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@ public RankingsRepo(Gson gson, TokenRepo tokenRepo, RxSharedPreferences rxPrefs,
this.config = config;
this.context = context;

HttpLoggingInterceptor.Logger logger = new HttpLoggingInterceptor.Logger() {
@Override
public void log(String message) {
Timber.v(message);
}
};
HttpLoggingInterceptor.Logger logger = message -> Timber.v(message);
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(logger);
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import retrofit2.Retrofit;
import retrofit2.RxJavaCallAdapterFactory;
import rx.Observable;
import rx.functions.Func1;
import timber.log.Timber;

/**
Expand All @@ -63,12 +62,7 @@ public TokenRepo(Gson gson, RxSharedPreferences rxPrefs, Config config, Context
this.config = config;
this.context = context;

HttpLoggingInterceptor.Logger logger = new HttpLoggingInterceptor.Logger() {
@Override
public void log(String message) {
Timber.v(message);
}
};
HttpLoggingInterceptor.Logger logger = message -> Timber.v(message);
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(logger);
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

Expand Down Expand Up @@ -109,14 +103,11 @@ public Observable<Token> loginEmail(final TokenSpec spec) {
return Observable.error(new NetworkUnavailableException("No internet available"));
}

return loginEmail(spec.getEmail()).map(new Func1<Token, Token>() {
@Override
public Token call(Token token) {
Timber.v("loginEmail() saving token");
Preference<String> tokenPref = rxPrefs.getString(Token.PREF_NAME);
tokenPref.set(gson.toJson(token));
return token;
}
return loginEmail(spec.getEmail()).map(token -> {
Timber.v("loginEmail() saving token");
Preference<String> tokenPref = rxPrefs.getString(Token.PREF_NAME);
tokenPref.set(gson.toJson(token));
return token;
});
}

Expand All @@ -129,14 +120,11 @@ public Observable<Token> loginFacebook(final TokenSpec spec) {
return Observable.error(new NetworkUnavailableException("No internet available"));
}

return loginFacebook(spec.getFacebook()).map(new Func1<Token, Token>() {
@Override
public Token call(Token token) {
Timber.v("loginFacebook() saving token");
Preference<String> tokenPref = rxPrefs.getString(Token.PREF_NAME);
tokenPref.set(gson.toJson(token));
return token;
}
return loginFacebook(spec.getFacebook()).map(token -> {
Timber.v("loginFacebook() saving token");
Preference<String> tokenPref = rxPrefs.getString(Token.PREF_NAME);
tokenPref.set(gson.toJson(token));
return token;
});
}

Expand Down Expand Up @@ -178,14 +166,11 @@ public Observable<Token> refresh() {
}

return endpoint.refresh(Token.GRANT_REFRESH, config.getClientId(), config.getClientSecret(),
refreshToken).map(new Func1<Token, Token>() {
@Override
public Token call(Token token) {

Preference<String> tokenPref = rxPrefs.getString(Token.PREF_NAME);
tokenPref.set(gson.toJson(token));
return token;
}
refreshToken).map(token -> {

Preference<String> tokenPref = rxPrefs.getString(Token.PREF_NAME);
tokenPref.set(gson.toJson(token));
return token;
});
}

Expand Down
Loading