-
Notifications
You must be signed in to change notification settings - Fork 169
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
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
app/src/main/java/org/gdg/frisbee/android/api/PlusApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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=" | ||
+ BuildConfig.IP_SIMPLE_API_ACCESS_KEY) | ||
Person getPerson(@Path("gplusId") String gplusId); | ||
} |
25 changes: 25 additions & 0 deletions
25
app/src/main/java/org/gdg/frisbee/android/api/PlusApiFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
app/src/main/java/org/gdg/frisbee/android/api/PlusImageResizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
87 changes: 0 additions & 87 deletions
87
app/src/main/java/org/gdg/frisbee/android/api/PlusPersonDownloader.java
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
app/src/main/java/org/gdg/frisbee/android/api/model/plus/Cover.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/org/gdg/frisbee/android/api/model/plus/CoverPhoto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/org/gdg/frisbee/android/api/model/plus/Image.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/org/gdg/frisbee/android/api/model/plus/ImageInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
app/src/main/java/org/gdg/frisbee/android/api/model/plus/Person.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
app/src/main/java/org/gdg/frisbee/android/api/model/plus/Urls.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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())) | ||
|
@@ -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; | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.