This repository has been archived by the owner on Jan 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from d4rken/dev
v0.4.0 release
- Loading branch information
Showing
82 changed files
with
1,686 additions
and
842 deletions.
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
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
17 changes: 13 additions & 4 deletions
17
app/src/main/java/subreddit/android/appstore/AppComponent.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 |
---|---|---|
@@ -1,21 +1,30 @@ | ||
package subreddit.android.appstore; | ||
|
||
import android.content.SharedPreferences; | ||
|
||
import dagger.Component; | ||
import subreddit.android.appstore.backend.ScraperModule; | ||
import subreddit.android.appstore.backend.WikiRepositoryModule; | ||
import subreddit.android.appstore.backend.github.SelfUpdater; | ||
import subreddit.android.appstore.backend.github.SelfUpdaterModule; | ||
import subreddit.android.appstore.backend.reddit.wiki.WikiRepository; | ||
import subreddit.android.appstore.backend.reddit.wiki.WikiRepositoryModule; | ||
import subreddit.android.appstore.backend.scrapers.MediaScraper; | ||
import subreddit.android.appstore.backend.wiki.WikiRepository; | ||
import subreddit.android.appstore.backend.scrapers.ScraperModule; | ||
import subreddit.android.appstore.util.dagger.ApplicationScope; | ||
|
||
|
||
@ApplicationScope | ||
@Component(modules = { | ||
AndroidModule.class, | ||
WikiRepositoryModule.class, | ||
ScraperModule.class | ||
ScraperModule.class, | ||
SelfUpdaterModule.class | ||
}) | ||
public interface AppComponent { | ||
SharedPreferences providePreferences(); | ||
|
||
WikiRepository wikiRepository(); | ||
|
||
MediaScraper mediaScraper(); | ||
|
||
SelfUpdater selfUpdater(); | ||
} |
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
25 changes: 25 additions & 0 deletions
25
app/src/main/java/subreddit/android/appstore/backend/DeviceIdentifier.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 subreddit.android.appstore.backend; | ||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import android.preference.PreferenceManager; | ||
|
||
import java.util.UUID; | ||
|
||
public class DeviceIdentifier { | ||
static final String PREF_KEY = "device.uuid"; | ||
final Context context; | ||
|
||
public DeviceIdentifier(Context context) {this.context = context;} | ||
|
||
public String getUUID() { | ||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); | ||
String uuid = prefs.getString(PREF_KEY, null); | ||
if (uuid == null) { | ||
uuid = UUID.randomUUID().toString(); | ||
prefs.edit().putString(PREF_KEY, uuid).apply(); | ||
} | ||
return uuid; | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
app/src/main/java/subreddit/android/appstore/backend/UserAgentInterceptor.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,39 @@ | ||
package subreddit.android.appstore.backend; | ||
|
||
import android.content.Context; | ||
import android.content.pm.PackageInfo; | ||
import android.content.pm.PackageManager; | ||
|
||
import java.io.IOException; | ||
import java.util.Locale; | ||
|
||
import okhttp3.Interceptor; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
import timber.log.Timber; | ||
|
||
|
||
public class UserAgentInterceptor implements Interceptor { | ||
|
||
private final String userAgent; | ||
|
||
public UserAgentInterceptor(Context context) { | ||
PackageInfo packageInfo; | ||
try { | ||
packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); | ||
} catch (PackageManager.NameNotFoundException e) { | ||
Timber.e(e, null); | ||
throw new RuntimeException(e); | ||
} | ||
this.userAgent = String.format(Locale.US, "android:%s:%s", packageInfo.packageName, packageInfo.versionName); | ||
} | ||
|
||
@Override | ||
public Response intercept(Chain chain) throws IOException { | ||
Request originRequest = chain.request(); | ||
Request requestWithUserAgent = originRequest.newBuilder() | ||
.header("User-Agent", userAgent) | ||
.build(); | ||
return chain.proceed(requestWithUserAgent); | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
app/src/main/java/subreddit/android/appstore/backend/github/LiveSelfUpdater.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,47 @@ | ||
package subreddit.android.appstore.backend.github; | ||
|
||
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; | ||
|
||
import io.reactivex.Observable; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.logging.HttpLoggingInterceptor; | ||
import retrofit2.Retrofit; | ||
import retrofit2.converter.gson.GsonConverterFactory; | ||
import retrofit2.http.GET; | ||
import subreddit.android.appstore.BuildConfig; | ||
import subreddit.android.appstore.backend.UserAgentInterceptor; | ||
|
||
public class LiveSelfUpdater implements SelfUpdater { | ||
private static final String BASEURL = "https://api.github.com/"; | ||
private final ReleaseApi releaseApi; | ||
private Observable<Release> latestReleaseCache; | ||
|
||
public LiveSelfUpdater(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); | ||
OkHttpClient client = builder.build(); | ||
Retrofit retrofit = new Retrofit.Builder() | ||
.client(client) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create()) | ||
.baseUrl(BASEURL) | ||
.build(); | ||
releaseApi = retrofit.create(ReleaseApi.class); | ||
} | ||
|
||
interface ReleaseApi { | ||
@GET("repos/d4rken/reddit-android-appstore/releases/latest") | ||
Observable<Release> getLatestRelease(); | ||
} | ||
|
||
@Override | ||
public Observable<Release> getLatestRelease() { | ||
if (latestReleaseCache == null) latestReleaseCache = releaseApi.getLatestRelease().cache(); | ||
return latestReleaseCache; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/subreddit/android/appstore/backend/github/SelfUpdater.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,29 @@ | ||
package subreddit.android.appstore.backend.github; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import io.reactivex.Observable; | ||
|
||
public interface SelfUpdater { | ||
|
||
Observable<Release> getLatestRelease(); | ||
|
||
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; | ||
} | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
app/src/main/java/subreddit/android/appstore/backend/reddit/Token.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 subreddit.android.appstore.backend.reddit; | ||
|
||
|
||
public 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; | ||
} | ||
} |
Oops, something went wrong.