Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #63 from d4rken/dev
Browse files Browse the repository at this point in the history
v0.4.0 release
  • Loading branch information
d4rken authored Sep 21, 2016
2 parents e5ded03 + caa727f commit 6397443
Show file tree
Hide file tree
Showing 82 changed files with 1,686 additions and 842 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
notifications:
email: false
language: android
jdk:
- oraclejdk8
Expand All @@ -10,12 +12,11 @@ android:

- android-24

- extra-google-google_play_services
- extra-google-m2repository
- extra-android-m2repository

- sys-img-armeabi-v7a-android-24
- sys-img-x86-android-24

before_install:
- chmod +x gradlew

script:
- ./gradlew clean assemble test
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# /r/Android App Store
[![Project License](https://img.shields.io/badge/license-Apache--2.0-blue.svg?style=flat-square)](LICENSE)
[![Build Status](https://travis-ci.org/d4rken/reddit-android-appstore.svg?branch=dev)](https://travis-ci.org/d4rken/reddit-android-appstore)

App inspired by [this reddit post](https://redd.it/50rafp)

Simply pulls the curated app list from the [/r/Android wiki](https://www.reddit.com/r/android/wiki/apps) and displays.
Pulls the curated app list from the [/r/Android wiki](https://www.reddit.com/r/android/wiki/apps) and displays.

## How to Contribute
* Make sure there is an issue for what you are working on __(create one if necessary)__
Expand Down
28 changes: 24 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
apply plugin: 'realm-android'
apply plugin: 'me.tatarka.retrolambda'

def gitSha() {
def p = 'git rev-parse --short HEAD'.execute([], project.rootDir)
Expand Down Expand Up @@ -37,6 +38,9 @@ android {
versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
}
lintOptions {
abortOnError false
}
buildTypes {
debug {
minifyEnabled false
Expand Down Expand Up @@ -85,18 +89,27 @@ android {
showStandardStreams = true
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

tasks.withType(Test) {
systemProperty "robolectric.logging", "stdout"
}
ext {
supportLibVersion = '24.2.0'
supportLibVersion = '24.2.1'
}
//noinspection GroovyAssignabilityCheck
configurations.all {
//noinspection GroovyAssignabilityCheck
resolutionStrategy.force "com.android.support:recyclerview-v7:${supportLibVersion}"
resolutionStrategy.force "com.android.support:support-annotations:${supportLibVersion}"
resolutionStrategy.force "com.android.support:support-v4:${supportLibVersion}"
resolutionStrategy.force "com.android.support:appcompat-v7:${supportLibVersion}"
resolutionStrategy.force "com.android.support:design:${supportLibVersion}"
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
dependencies {
Expand All @@ -108,12 +121,19 @@ dependencies {
compile "com.android.support:customtabs:${supportLibVersion}"
compile "com.android.support:design:${supportLibVersion}"
compile "com.android.support:cardview-v7:${supportLibVersion}"
compile "com.android.support:preference-v14:${supportLibVersion}"

// Recyclerview fast scroller
compile 'com.futuremind.recyclerfastscroll:fastscroll:0.2.4'

// OKHttp
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.squareup.okhttp3:logging-interceptor:3.5.0-SNAPSHOT'

// Retrofit
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0-RC2'

// Glide
compile 'com.github.bumptech.glide:glide:4.0.0-SNAPSHOT'
Expand Down Expand Up @@ -146,11 +166,11 @@ dependencies {
testCompile 'org.mockito:mockito-core:2.0.62-beta'

//Intrumentation tests (UI tests)
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2'

//Resolve conflicts with depdencies
androidTestCompile 'com.android.support:support-annotations:24.2.0'
androidTestCompile "com.android.support:support-annotations:${supportLibVersion}"

//Leakcanary
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Context provideContext() {

@Provides
@ApplicationScope
SharedPreferences providePreferences(Context context) {
public SharedPreferences providePreferences(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context);
}

Expand Down
17 changes: 13 additions & 4 deletions app/src/main/java/subreddit/android/appstore/AppComponent.java
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();
}
10 changes: 9 additions & 1 deletion app/src/main/java/subreddit/android/appstore/AppStoreApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ public static RefWatcher getRefWatcher() {
@Override
public void onCreate() {
super.onCreate();
if (BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree());
if (BuildConfig.DEBUG) {
Timber.plant(new Timber.DebugTree() {
@Override
protected void log(final int priority, final String tag, final String message,
final Throwable t) {
super.log(priority, LOGPREFIX + tag, message, t);
}
});
}
refWatcher = LeakCanary.install(this);
Injector.INSTANCE.init(this);
theme = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(this).getString("theme", "0"));
Expand Down
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;
}

}
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@
import java.util.Collection;
import java.util.LinkedHashSet;

import subreddit.android.appstore.AppStoreApp;
import timber.log.Timber;


public class AppInfo implements Comparable<AppInfo> {
final static String TAG = AppStoreApp.LOGPREFIX + "AppInfo";

final Collection<AppTags> appTagsCollection = new LinkedHashSet<>();
final Collection<Contact> contacts = new ArrayList<>();
final Collection<Download> downloads = new ArrayList<>();
Expand Down Expand Up @@ -92,7 +89,7 @@ public static AppInfo fromJson(Gson gson, String jsonString) {
try {
return gson.fromJson(jsonString, AppInfo.class);
} catch (JsonSyntaxException e) {
Timber.tag(TAG).e(e, "Failed to create AppInfo from: %s", jsonString);
Timber.e(e, "Failed to create AppInfo from: %s", jsonString);
return null;
}
}
Expand Down
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;
}
}
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;
}
}

}
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;
}
}
Loading

0 comments on commit 6397443

Please sign in to comment.