Skip to content

Commit

Permalink
applied pmd rules, updated realm, removed bintray plugin, cleaned up …
Browse files Browse the repository at this point in the history
…gradle files, progress in integration test
  • Loading branch information
Zeyad-37 committed Jul 3, 2017
1 parent 25e1c2c commit a19f682
Show file tree
Hide file tree
Showing 28 changed files with 478 additions and 753 deletions.
9 changes: 4 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:3.0.0'
classpath 'io.realm:realm-gradle-plugin:3.3.1'
// classpath 'com.google.gms:google-services:3.1.0'
classpath 'io.realm:realm-gradle-plugin:3.4.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
classpath "com.uber:infer-plugin:0.7.4"
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
// classpath "com.uber:infer-plugin:0.7.4"
}
}

Expand Down
17 changes: 8 additions & 9 deletions sampleApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ android {
minifyEnabled false
shrinkResources false
debuggable true
proguardFiles getDefaultProguardFile('proguard-android.txt'), "$project.rootDir/tools/rules-proguard-debug.pro"
// proguardFiles getDefaultProguardFile('proguard-android.txt'), "$project.rootDir/tools/rules-proguard-debug.pro"
// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debugConfig
}
Expand Down Expand Up @@ -100,6 +100,7 @@ android {
splits.density.enable = false
aaptOptions.cruncherEnabled = false
}

sourceSets {
main {
assets.srcDirs = ['src/main/assets', 'src/androidTest/java/com/zeyad/usecases/app/assets/']
Expand All @@ -109,7 +110,6 @@ android {

ext {
supportLibraryVersion = '25.3.1'
googlePlayVersion = '10.0.1'
butterKnifeVersion = '8.6.0'
rxbindingVersion = '2.0.0'
rxLifeCycle = '2.0.1'
Expand All @@ -135,7 +135,7 @@ dependencies {

// Bootstrap
compile 'com.github.Zeyad-37:GenericRecyclerViewAdapter:1.1.0'
compile 'com.github.Zeyad-37:RxRedux:1.2.0'
compile 'com.github.Zeyad-37:RxRedux:1.3.0'

// compile "android.arch.lifecycle:runtime:$archCompVersion"
compile "android.arch.lifecycle:extensions:$archCompVersion"
Expand All @@ -158,9 +158,9 @@ dependencies {
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
compile "org.parceler:parceler-api:$parcelerVersion"
annotationProcessor "org.parceler:parceler:$parcelerVersion"
compile("io.flowup:android-sdk:0.2.4") {
exclude group: 'com.google.android.gms'
}
// compile("io.flowup:android-sdk:0.2.4") {
// exclude group: 'com.google.android.gms'
// }
testCompile 'io.flowup:android-sdk-no-op:0.2.4'
// Testing
androidTestCompile "com.android.support.test:runner:$androidSupportTest"
Expand All @@ -180,12 +180,11 @@ dependencies {

testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
// testCompile 'org.mockito:mockito-core:2.0.57-beta'
}

//apply from: "$project.rootDir/tools/script-git-version.gradle"
apply from: "$project.rootDir/tools/script-findbugs.gradle"
apply from: "$project.rootDir/tools/script-pmd.gradle"
//apply from: "$project.rootDir/tools/script-pmd.gradle"
//apply from: "$project.rootDir/tools/script-java-code-coverage.gradle"
apply from: "$project.rootDir/tools/script-infer.gradle"
//apply from: "$project.rootDir/tools/script-infer.gradle"
//apply from: "$project.rootDir/tools/script-check-style.gradle"
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.os.StrictMode;
import android.support.annotation.NonNull;
import android.util.Base64;
import android.util.Log;
Expand All @@ -17,14 +16,14 @@
import com.zeyad.usecases.api.DataServiceConfig;
import com.zeyad.usecases.api.DataServiceFactory;

import java.lang.reflect.InvocationTargetException;
import java.security.MessageDigest;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.X509TrustManager;

import io.flowup.FlowUp;
import io.reactivex.Completable;
import io.reactivex.schedulers.Schedulers;
import io.realm.Realm;
Expand Down Expand Up @@ -85,7 +84,9 @@ private static boolean checkEmulator() {
return false;
}

private static String getSystemProperty(String name) throws Exception {
private static String getSystemProperty(String name)
throws NoSuchMethodException, ClassNotFoundException, InvocationTargetException,
IllegalAccessException {
Class systemPropertyClazz = Class.forName("android.os.SystemProperties");
return (String) systemPropertyClazz.getMethod("get", new Class[]{String.class})
.invoke(systemPropertyClazz, name);
Expand All @@ -97,7 +98,7 @@ private static boolean checkDebuggable(Context context) {

@Override
public void onCreate() {
// initializeStrictMode();
initializeStrictMode();
super.onCreate();
if (LeakCanary.isInAnalyzerProcess(this)) {
// This process is dedicated to LeakCanary for heap analysis.
Expand All @@ -106,8 +107,10 @@ public void onCreate() {
}
LeakCanary.install(this);
Completable.fromAction(() -> {
// checkAppTampering(this);
initializeFlowUp();
if (!checkAppTampering(this)) {
throw new IllegalAccessException("App might be tampered with!");
}
// initializeFlowUp();
Rollbar.init(this, "c8c8b4cb1d4f4650a77ae1558865ca87", BuildConfig.DEBUG ? "debug" : "production");
}).subscribeOn(Schedulers.io())
.subscribe(() -> {
Expand Down Expand Up @@ -140,8 +143,9 @@ OkHttpClient.Builder getOkHttpBuilder() {
.build())
.connectionSpecs(Arrays.asList(ConnectionSpec.MODERN_TLS,
ConnectionSpec.COMPATIBLE_TLS));
if (getSSlSocketFactory() != null && getX509TrustManager() != null)
if (getSSlSocketFactory() != null && getX509TrustManager() != null) {
builder.sslSocketFactory(getSSlSocketFactory(), getX509TrustManager());
}
return builder;
}

Expand All @@ -151,12 +155,12 @@ String getApiBaseUrl() {
}

private void initializeStrictMode() {
if (BuildConfig.DEBUG) {
StrictMode.setThreadPolicy(
new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
StrictMode.setVmPolicy(
new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
}
// if (BuildConfig.DEBUG) {
// StrictMode.setThreadPolicy(
// new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
// StrictMode.setVmPolicy(
// new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
// }
}

private void initializeRealm() {
Expand All @@ -170,17 +174,18 @@ private void initializeRealm() {
}

private void initializeFlowUp() {
FlowUp.Builder.with(this)
.apiKey(getString(R.string.flow_up_api_key))
.forceReports(BuildConfig.DEBUG)
.start();
// FlowUp.Builder.with(this)
// .apiKey(getString(R.string.flow_up_api_key))
// .forceReports(BuildConfig.DEBUG)
// .start();
}

private boolean checkAppTampering(Context context) {
return checkAppSignature(context)
&& verifyInstaller(context)
&& checkEmulator()
&& checkDebuggable(context);
return true;
// return checkAppSignature(context)
// && verifyInstaller(context)
// && checkEmulator()
// && checkDebuggable(context);
}

X509TrustManager getX509TrustManager() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,33 @@
import io.reactivex.MaybeTransformer;
import io.reactivex.ObservableTransformer;
import io.reactivex.SingleTransformer;
import io.reactivex.annotations.NonNull;

/**
* @author by ZIaDo on 6/14/17.
*/
public class LifecycleRxJavaBinder {
public static <T> FlowableTransformer<T, T> applyFlowable(LifecycleOwner lifecycleOwner) {

private LifecycleRxJavaBinder() {
}

public static <T> FlowableTransformer<T, T> applyFlowable(@NonNull final LifecycleOwner lifecycleOwner) {
return flowable -> {
LiveData<T> liveData = LiveDataReactiveStreams.fromPublisher(flowable);
return Flowable.fromPublisher(LiveDataReactiveStreams.toPublisher(lifecycleOwner, liveData));
};
}

public static <T> ObservableTransformer<T, T> applyObservable(LifecycleOwner lifecycleOwner,
BackpressureStrategy strategy) {
public static <T> ObservableTransformer<T, T> applyObservable(@NonNull final LifecycleOwner lifecycleOwner,
final BackpressureStrategy strategy) {
return observable -> {
LiveData<T> liveData = LiveDataReactiveStreams.fromPublisher(observable.toFlowable(strategy));
return Flowable.fromPublisher(LiveDataReactiveStreams
.toPublisher(lifecycleOwner, liveData)).toObservable();
};
}

public static <T> ObservableTransformer<T, T> applyObservable(LifecycleOwner lifecycleOwner) {
public static <T> ObservableTransformer<T, T> applyObservable(@NonNull final LifecycleOwner lifecycleOwner) {
return observable -> {
LiveData<T> liveData = LiveDataReactiveStreams.fromPublisher(observable
.toFlowable(BackpressureStrategy.BUFFER));
Expand All @@ -40,19 +45,19 @@ public static <T> ObservableTransformer<T, T> applyObservable(LifecycleOwner lif
};
}

public static <T> SingleTransformer<T, T> applySingle(LifecycleOwner lifecycleOwner) {
public static <T> SingleTransformer<T, T> applySingle(@NonNull final LifecycleOwner lifecycleOwner) {
return single -> {
LiveData<T> liveData = LiveDataReactiveStreams.fromPublisher(single.toFlowable());
return Flowable.fromPublisher(LiveDataReactiveStreams
.toPublisher(lifecycleOwner, liveData)).singleOrError();
};
}

public static <T> MaybeTransformer<T, T> applyMaybe(LifecycleOwner lifecycleOwner) {
public static <T> MaybeTransformer<T, T> applyMaybe(@NonNull final LifecycleOwner lifecycleOwner) {
return maybe -> {
LiveData<T> liveData = LiveDataReactiveStreams.fromPublisher(maybe.toFlowable());
return Flowable.fromPublisher(LiveDataReactiveStreams
.toPublisher(lifecycleOwner, liveData)).firstElement();
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class MyGlideModule implements GlideModule {
@Override
public void applyOptions(Context context, GlideBuilder builder) {
// builder.setDiskCache(new DiskCacheFactory(context, “.”, IMAGE_CACHE_SIZE));
// builder.setDiskCache(new DiskCacheFactory(context, ".", IMAGE_CACHE_SIZE));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,23 @@ public void initialize() {
// protected void onResume() {
// super.onResume();
// viewModel.getUser()
// .compose(bindToLifecycle())
// .subscribe(user -> Log.d("Test", user.toString()),
// throwable -> {
// });
// .compose(bindToLifecycle())
// .doOnCancel(() -> Log.d("Test", "Cancelled"))
// .subscribe(user -> Log.d("Test", user.toString()),
// throwable -> {
// });
// }

@Override
public void setupUI() {
setContentView(R.layout.activity_user_list);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
toolbar.setTitle(getTitle());
setupRecyclerView();
twoPane = findViewById(R.id.user_detail_container) != null;
}

@NonNull
private SuccessStateAccumulator<UserListState> getUserListStateSuccessStateAccumulator() {
return (newResult, event, currentStateBundle) -> {
Expand All @@ -137,6 +148,8 @@ private SuccessStateAccumulator<UserListState> getUserListStateSuccessStateAccum
.toList()
.blockingGet();
break;
default:
break;
}
int lastId = users.get(users.size() - 1).getId();
users = new ArrayList<>(new HashSet<>(users));
Expand All @@ -146,16 +159,6 @@ private SuccessStateAccumulator<UserListState> getUserListStateSuccessStateAccum
};
}

@Override
public void setupUI() {
setContentView(R.layout.activity_user_list);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
toolbar.setTitle(getTitle());
setupRecyclerView();
twoPane = findViewById(R.id.user_detail_container) != null;
}

@Override
public void renderState(UserListState state) {
viewState = state;
Expand All @@ -172,6 +175,17 @@ public void renderState(UserListState state) {
}
}

@Override
public void toggleViews(boolean toggle) {
loaderLayout.bringToFront();
loaderLayout.setVisibility(toggle ? View.VISIBLE : View.GONE);
}

@Override
public void showError(String message) {
showErrorSnackBar(message, userRecycler, Snackbar.LENGTH_LONG);
}

private void setupRecyclerView() {
usersAdapter = new GenericRecyclerViewAdapter(
(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE), new ArrayList<>()) {
Expand Down Expand Up @@ -260,17 +274,6 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
.doOnNext(searchUsersEvent -> Log.d("NextPageEvent", "fired!"))));
}

@Override
public void toggleViews(boolean toggle) {
loaderLayout.bringToFront();
loaderLayout.setVisibility(toggle ? View.VISIBLE : View.GONE);
}

@Override
public void showError(String message) {
showErrorSnackBar(message, userRecycler, Snackbar.LENGTH_LONG);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.list_menu, menu);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
/** @author by ZIaDo on 10/1/16. */
public class Utils {

private Utils() {
}

public static boolean isNotEmpty(String text) {
return text != null && !text.isEmpty() && !text.equalsIgnoreCase("null");
}
Expand Down
26 changes: 13 additions & 13 deletions tools/script-infer.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.uber.infer.android'
check.dependsOn 'inferDebug'
check.dependsOn 'eradicateDebug'
inferPlugin {
infer {
include = project.files("src/main")
exclude = project.files("build/")
}
eradicate {
include = project.files("src/main")
exclude = project.files("build/")
}
}
//apply plugin: 'com.uber.infer.android'
//check.dependsOn 'inferDebug'
//check.dependsOn 'eradicateDebug'
//inferPlugin {
// infer {
// include = project.files("src/main")
// exclude = project.files("build/")
// }
// eradicate {
// include = project.files("src/main")
// exclude = project.files("build/")
// }
//}
Loading

0 comments on commit a19f682

Please sign in to comment.