Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

483/Replace plus person downloader #588

Closed
wants to merge 3 commits into from
Closed
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
18 changes: 18 additions & 0 deletions app/src/main/java/org/gdg/frisbee/android/api/PlusApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.gdg.frisbee.android.api;

import org.gdg.frisbee.android.BuildConfig;
import org.gdg.frisbee.android.api.model.plus.ImageInfo;
import org.gdg.frisbee.android.api.model.plus.Person;

import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Path;

public interface PlusApi {
@GET("people/{gplusId}?fields=image&key=" + BuildConfig.IP_SIMPLE_API_ACCESS_KEY)
Call<ImageInfo> getImageInfo(@Path("gplusId") String gplusId);

@GET("people/{gplusId}?fields=image,aboutMe,tagline,urls,url,cover,displayName&key="
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I realized this duplication, this key can be added through OkHttp interceptors.

+ BuildConfig.IP_SIMPLE_API_ACCESS_KEY)
Person getPerson(@Path("gplusId") String gplusId);
}
25 changes: 25 additions & 0 deletions app/src/main/java/org/gdg/frisbee/android/api/PlusApiFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.gdg.frisbee.android.api;

import org.gdg.frisbee.android.app.App;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class PlusApiFactory {
private static final String API_URL = "https://www.googleapis.com/plus/v1/";

private PlusApiFactory() {
}

private static Retrofit provideRestAdapter() {
return new Retrofit.Builder()
.baseUrl(API_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(OkClientFactory.okHttpClientWithIdlingResources(App.getInstance().getOkHttpClient()))
.build();
}

public static PlusApi providePlusApi() {
return provideRestAdapter().create(PlusApi.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.gdg.frisbee.android.api;

import org.gdg.frisbee.android.api.model.plus.ImageInfo;
import org.gdg.frisbee.android.app.App;

import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

public class PlusImageResizer implements Interceptor {

private static final Pattern mPlusPattern
= Pattern.compile("http[s]?:\\/\\/plus\\..*google\\.com.*(\\+[a-zA-Z] +|[0-9]{21}).*");

@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();

Matcher matcher = mPlusPattern.matcher(request.url().toString());
if (!matcher.matches()) {
return chain.proceed(request);
}

String gplusId = matcher.group(1);
retrofit2.Response<ImageInfo> imageInfoResponse
= App.getInstance().getPlusApi().getImageInfo(gplusId).execute();
if (imageInfoResponse.isSuccessful()) {
ImageInfo imageInfo = imageInfoResponse.body();
if (imageInfo.getImage() != null && imageInfo.getImage().getUrl() != null) {
String imageUrl = imageInfo.getImage().getUrl().replace("sz=50", "sz=196");
return chain.proceed(request.newBuilder().url(imageUrl).build());
}
}

return null;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.gdg.frisbee.android.api.model.plus;

public class Cover {
CoverPhoto coverPhoto;

public CoverPhoto getCoverPhoto() {
return coverPhoto;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.gdg.frisbee.android.api.model.plus;

public class CoverPhoto {
String url;

public String getUrl() {
return url;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.gdg.frisbee.android.api.model.plus;

public class Image {
private String url;
private boolean isDefault;

public String getUrl() {
return url;
}

public boolean isDefault() {
return isDefault;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.gdg.frisbee.android.api.model.plus;

public class ImageInfo {
private Image image;

public Image getImage() {
return image;
}

public String getUrl() {
return image.getUrl();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.gdg.frisbee.android.api.model.plus;

import java.util.List;

public class Person {
private String url;
private String tagline;
private String aboutMe;
private ImageInfo image;
private Cover cover;
private List<Urls> urls;
private String displayName;

public String getUrl() {
return url;
}

public String getTagline() {
return tagline;
}

public String getAboutMe() {
return aboutMe;
}

public ImageInfo getImage() {
return image;
}

public Cover getCover() {
return cover;
}

public List<Urls> getUrls() {
return urls;
}

public String getDisplayName() {
return displayName;
}
}
19 changes: 19 additions & 0 deletions app/src/main/java/org/gdg/frisbee/android/api/model/plus/Urls.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.gdg.frisbee.android.api.model.plus;

public class Urls {
String label;
String type;
String value;

public String getLabel() {
return label;
}

public String getType() {
return type;
}

public String getValue() {
return value;
}
}
14 changes: 12 additions & 2 deletions app/src/main/java/org/gdg/frisbee/android/app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
import org.gdg.frisbee.android.api.GroupDirectory;
import org.gdg.frisbee.android.api.GroupDirectoryFactory;
import org.gdg.frisbee.android.api.OkClientFactory;
import org.gdg.frisbee.android.api.PlusPersonDownloader;
import org.gdg.frisbee.android.api.PlusApi;
import org.gdg.frisbee.android.api.PlusApiFactory;
import org.gdg.frisbee.android.api.PlusImageResizer;
import org.gdg.frisbee.android.cache.ModelCache;
import org.gdg.frisbee.android.eventseries.TaggedEventSeries;
import org.gdg.frisbee.android.utils.CrashlyticsTree;
Expand Down Expand Up @@ -85,6 +87,7 @@ public class App extends BaseApp implements LocationListener {
private ArrayList<TaggedEventSeries> mTaggedEventSeriesList;
private RefWatcher refWatcher;
private Plus plusClient;
private PlusApi plusApiInstance;

public static App getInstance() {
return mInstance;
Expand Down Expand Up @@ -140,7 +143,7 @@ public void onCreate() {
// Only the interceptors will be different.
// We shouldn't have the below interceptor in other instances.
OkHttpClient.Builder picassoClient = mOkHttpClient.newBuilder();
picassoClient.addInterceptor(new PlusPersonDownloader(plusClient));
picassoClient.addInterceptor(new PlusImageResizer());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the name. Does it resize the images?


mPicasso = new Picasso.Builder(this)
.downloader(new OkHttp3Downloader(picassoClient.build()))
Expand Down Expand Up @@ -342,6 +345,13 @@ public GitHub getGithub() {
return gitHubInstance;
}

public PlusApi getPlusApi() {
if (plusApiInstance == null) {
plusApiInstance = PlusApiFactory.providePlusApi();
}
return plusApiInstance;
}

public OkHttpClient getOkHttpClient() {
return mOkHttpClient;
}
Expand Down
Loading