Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
* Provide OkHttpClient, Retrofit and Gson instances from Dagger * Separate APIs and response types into their own classes * Minor refactor missed in #100
- Loading branch information
Showing
with
307 additions
and 271 deletions.
- +4 −2 app/src/main/java/subreddit/android/appstore/AppComponent.java
- +35 −0 app/src/main/java/subreddit/android/appstore/backend/HttpModule.java
- +38 −0 app/src/main/java/subreddit/android/appstore/backend/github/GithubApi.java
- +2 −24 app/src/main/java/subreddit/android/appstore/backend/github/GithubRepository.java
- +6 −38 app/src/main/java/subreddit/android/appstore/backend/github/LiveGithubRepository.java
- +0 −19 app/src/main/java/subreddit/android/appstore/backend/reddit/Token.java
- +35 −0 app/src/main/java/subreddit/android/appstore/backend/reddit/TokenApi.java
- +14 −54 app/src/main/java/subreddit/android/appstore/backend/reddit/TokenRepository.java
- +3 −85 app/src/main/java/subreddit/android/appstore/backend/reddit/wiki/LiveWikiRepository.java
- +66 −0 app/src/main/java/subreddit/android/appstore/backend/reddit/wiki/WikiApi.java
- +4 −3 app/src/main/java/subreddit/android/appstore/backend/scrapers/LiveMediaScraper.java
- +6 −6 app/src/main/java/subreddit/android/appstore/backend/scrapers/gplay/GPlayScraper.java
- +6 −6 app/src/main/java/subreddit/android/appstore/screens/navigation/NavigationContract.java
- +4 −4 app/src/main/java/subreddit/android/appstore/screens/navigation/NavigationFragment.java
- +6 −5 app/src/main/java/subreddit/android/appstore/screens/navigation/NavigationPresenter.java
- +3 −2 app/src/main/java/subreddit/android/appstore/screens/settings/AboutActivity.java
- +1 −2 app/src/main/java/subreddit/android/appstore/util/ui/glide/IconRequestModelLoader.java
- +7 −7 app/src/mock/java/subreddit/android/appstore/backend/github/FakeGithubRepository.java
- +22 −4 app/src/prod/java/subreddit/android/appstore/backend/github/GithubRepositoryModule.java
- +42 −8 app/src/prod/java/subreddit/android/appstore/backend/reddit/wiki/WikiRepositoryModule.java
- +3 −2 app/src/prod/java/subreddit/android/appstore/backend/scrapers/ScraperModule.java
There are no files selected for viewing
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
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
@@ -0,0 +1,35 @@ | ||
package subreddit.android.appstore.backend; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
|
||
import dagger.Module; | ||
import dagger.Provides; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.logging.HttpLoggingInterceptor; | ||
import subreddit.android.appstore.BuildConfig; | ||
import subreddit.android.appstore.util.dagger.ApplicationScope; | ||
|
||
@Module | ||
public class HttpModule { | ||
|
||
@Provides | ||
@ApplicationScope | ||
Gson provideGson() { | ||
return new GsonBuilder().create(); | ||
} | ||
|
||
@Provides | ||
@ApplicationScope | ||
OkHttpClient provideOkHttpClient(UserAgentInterceptor userAgent) { | ||
OkHttpClient.Builder builder = new OkHttpClient.Builder(); | ||
if (BuildConfig.DEBUG) { | ||
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); | ||
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); | ||
builder.addInterceptor(interceptor); | ||
} | ||
builder.addInterceptor(userAgent); | ||
return builder.build(); | ||
} | ||
|
||
} |
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
@@ -0,0 +1,38 @@ | ||
package subreddit.android.appstore.backend.github; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import io.reactivex.Observable; | ||
import retrofit2.http.GET; | ||
|
||
public interface GithubApi { | ||
String BASEURL = "https://api.github.com/"; | ||
|
||
@GET("repos/d4rken/reddit-android-appstore/releases/latest") | ||
Observable<Release> getLatestRelease(); | ||
|
||
@GET("repos/d4rken/reddit-android-appstore/contributors") | ||
Observable<List<Contributor>> getContributors(); | ||
|
||
class Release { | ||
@SerializedName("url") public String releaseUrl; | ||
@SerializedName("tag_name") public String tagName; | ||
@SerializedName("name") public String releaseName; | ||
@SerializedName("body") public String releaseDescription; | ||
public boolean prerelease; | ||
@SerializedName("published_at") public Date publishDate; | ||
public List<Assets> assets; | ||
|
||
public static class Assets { | ||
@SerializedName("browser_download_url") public String downloadUrl; | ||
public long size; | ||
} | ||
} | ||
|
||
class Contributor { | ||
@SerializedName("login") public String username; | ||
} | ||
} |
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
@@ -1,34 +1,12 @@ | ||
package subreddit.android.appstore.backend.github; | ||
|
||
import java.util.List; | ||
|
||
import io.reactivex.Observable; | ||
|
||
public interface GithubRepository { | ||
|
||
Observable<GithubApi.Release> getLatestRelease(); | ||
Observable<List<GithubApi.Contributor>> getContributors(); | ||
|
||
} |
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
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
@@ -0,0 +1,35 @@ | ||
package subreddit.android.appstore.backend.reddit; | ||
|
||
|
||
import io.reactivex.Observable; | ||
import retrofit2.http.Field; | ||
import retrofit2.http.FormUrlEncoded; | ||
import retrofit2.http.Header; | ||
import retrofit2.http.POST; | ||
|
||
public interface TokenApi { | ||
String BASEURL = "https://www.reddit.com/"; | ||
|
||
@FormUrlEncoded | ||
@POST("api/v1/access_token") | ||
Observable<TokenApi.Token> getUserlessAuthToken(@Header("Authorization") String authentication, | ||
@Field("device_id") String deviceId, | ||
@Field("grant_type") String grant_type, | ||
@Field("scope") String scope); | ||
|
||
class Token { | ||
String access_token; | ||
String token_type; | ||
long expires_in; | ||
String scope; | ||
final long issuedTime = System.currentTimeMillis(); | ||
|
||
public boolean isExpired() { | ||
return System.currentTimeMillis() > issuedTime + expires_in * 1000; | ||
} | ||
|
||
public String getAuthorizationString() { | ||
return token_type + " " + access_token; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.