diff --git a/.gitignore b/.gitignore
index 9997f3b..c113071 100644
--- a/.gitignore
+++ b/.gitignore
@@ -46,3 +46,5 @@ captures/
# Keystore files
*.jks
+
+/.idea/sonarlint
diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml
new file mode 100644
index 0000000..25a8b87
--- /dev/null
+++ b/.idea/codeStyleSettings.xml
@@ -0,0 +1,229 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/eclipseCodeFormatter.xml b/.idea/eclipseCodeFormatter.xml
new file mode 100644
index 0000000..046b942
--- /dev/null
+++ b/.idea/eclipseCodeFormatter.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/findbugs-idea.xml b/.idea/findbugs-idea.xml
new file mode 100644
index 0000000..6039420
--- /dev/null
+++ b/.idea/findbugs-idea.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 4490e9d..deec648 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -35,7 +35,7 @@
-
+
diff --git a/build.gradle b/build.gradle
index 98d0555..87f16da 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,16 +1,57 @@
+project.ext {
+ supportLibrary = '26.1.0'
+ butterKnife = '8.8.1'
+ rxbinding = '2.0.0'
+ okhttpVersion = '3.9.1'
+ archComp = '1.0.0'
+ rxjava = '2.1.7'
+ rxAndroid = '2.0.1'
+ genericRecyclerViewAdapter = '1.6.2'
+ rxredux = '2.0.0'
+ glide = '4.0.0'
+ lottie = '2.2.0'
+ retrofit = '2.3.0'
+
+ rxlint = '1.6'
+ leakCanary = '1.5.4'
+ androidSupportTest = '1.0.1'
+ espressoCore = '3.0.1'
+ powerMock = '1.7.3'
+ robolectric = '3.3.2'
+// robolectric = '3.5.1'
+ okhttpIdelingResource = '1.0.0'
+ mockito = '1.10.19'
+// mockito = '2.10.0'
+ mockitoKotlin = '1.5.0'
+ restMock = '0.2.2'
+ junit = '4.12'
+}
+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
+ ext.kotlin_version = '1.2.0'
repositories {
jcenter()
+ google()
+ mavenCentral()
+ maven {
+ url "https://plugins.gradle.org/m2/" // error-prone
+ }
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.3.3'
+ classpath 'com.android.tools.build:gradle:3.0.1'
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// classpath 'com.google.gms:google-services:3.1.0'
- classpath 'io.realm:realm-gradle-plugin:3.4.0'
+ classpath 'io.realm:realm-gradle-plugin:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
-// classpath "com.uber:infer-plugin:0.7.4"
+ classpath "com.uber:infer-plugin:0.7.4"
+ classpath "net.ltgt.gradle:gradle-errorprone-plugin:0.0.13"
+ classpath 'pl.droidsonroids.gradle:gradle-pitest-plugin:0.1.4'
+ classpath 'com.dicedmelon.gradle:jacoco-android:0.1.2'
+ classpath "gradle.plugin.org.jmailen.gradle:kotlinter-gradle:1.5.1"
+ classpath "gradle.plugin.io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.0.0.RC5-5"
}
}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index a2be7ed..27b8ec9 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Thu Jul 27 15:41:02 COT 2017
+#Mon Dec 11 16:14:29 CET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
diff --git a/usecases/build.gradle b/usecases/build.gradle
index 9355f6f..0e674ed 100644
--- a/usecases/build.gradle
+++ b/usecases/build.gradle
@@ -1,36 +1,36 @@
apply plugin: 'com.android.library'
-apply plugin: 'me.tatarka.retrolambda'
-apply plugin: 'android-apt' // remove
+//apply plugin: 'me.tatarka.retrolambda'
+//apply plugin: 'android-apt' // remove
apply plugin: 'maven'
apply plugin: 'realm-android'
apply plugin: 'com.github.dcendents.android-maven'
-apply plugin: "net.ltgt.errorprone"
+//apply plugin: "net.ltgt.errorprone"
version = "1.0.1"
group = "com.github.zeyad-37"
-buildscript {
- repositories {
- maven {
- url "https://plugins.gradle.org/m2/"
- }
- }
-
- dependencies {
- classpath 'me.tatarka:gradle-retrolambda:3.7.0'
- classpath "net.ltgt.gradle:gradle-errorprone-plugin:0.0.10"
- }
-}
-
-repositories {
- mavenCentral()
-}
+//buildscript {
+// repositories {
+// maven {
+// url "https://plugins.gradle.org/m2/"
+// }
+// }
+//
+// dependencies {
+//// classpath 'me.tatarka:gradle-retrolambda:3.7.0'
+//// classpath "net.ltgt.gradle:gradle-errorprone-plugin:0.0.13"
+// }
+//}
+//
+//repositories {
+// mavenCentral()
+//}
android {
compileSdkVersion 26
- buildToolsVersion '25.0.3'
+ buildToolsVersion '26.0.2'
defaultConfig {
minSdkVersion 17
targetSdkVersion 26
@@ -61,6 +61,7 @@ android {
testOptions {
unitTests.returnDefaultValues = true
+ unitTests.includeAndroidResources = true
unitTests.all {
// All the usual Gradle options.
jvmArgs '-XX:MaxPermSize=256m'
@@ -91,17 +92,6 @@ android {
}
}
-ext {
- supportLibrary = '25.4.0'
- retrofit = '2.3.0'
- okhttpVersion = '3.8.0'
- androidSupportTest = '0.5'
- espressoCore = '2.2.2'
- powerMock = '1.6.6'
- robolectric = '3.3.2'
- okhttpIdelingResource = '1.0.0'
-}
-
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//Job Dispatcher
@@ -115,29 +105,27 @@ dependencies {
compile "com.android.support:support-annotations:$supportLibrary"
// Rx
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
- compile 'io.reactivex.rxjava2:rxjava:2.1.1'
+ compile 'io.reactivex.rxjava2:rxjava:2.1.7'
testCompile 'io.reactivex:rxandroid:1.2.1'
// Cache
-// compile('com.github.lowlevel-studios:storo:1.1.0') {
-// transitive = true
-// }
compile('com.github.Zeyad-37:Storo:2.1.0') {
transitive = true
}
compile 'com.rollbar:rollbar-android:0.2.1'
+ compile 'nl.littlerobots.rxlint:rxlint:1.6'
// Testing
testCompile 'junit:junit:4.12'
testCompile "com.android.support:support-annotations:$supportLibrary"
- testCompile "org.mockito:mockito-core:1.10.19"
+ testCompile "org.mockito:mockito-core:$mockito"
testCompile "org.robolectric:robolectric:$robolectric"
- testCompile "org.robolectric:shadows-support-v4:$robolectric"
+// testCompile "org.robolectric:shadows-support-v4:$robolectric"
testCompile "org.powermock:powermock-module-junit4:$powerMock"
testCompile "org.powermock:powermock-module-junit4-rule:$powerMock"
testCompile "org.powermock:powermock-api-mockito:$powerMock"
testCompile "org.powermock:powermock-classloading-xstream:$powerMock"
- testCompile "com.squareup.okhttp3:mockwebserver:$okhttpVersion"
+// testCompile "com.squareup.okhttp3:mockwebserver:$okhttpVersion"
testCompile 'com.github.andrzejchm.RESTMock:android:0.2.2'
//required to resolve robolectric test problems
testCompile("com.jakewharton.espresso:okhttp3-idling-resource:$okhttpIdelingResource") {
diff --git a/usecases/src/main/java/com/zeyad/usecases/api/DataService.java b/usecases/src/main/java/com/zeyad/usecases/api/DataService.java
index 19a2c91..d27d32e 100644
--- a/usecases/src/main/java/com/zeyad/usecases/api/DataService.java
+++ b/usecases/src/main/java/com/zeyad/usecases/api/DataService.java
@@ -42,14 +42,14 @@ class DataService implements IDataService {
}
@Override
- public Flowable> getList(@NonNull GetRequest getListRequest) {
+ public Flowable> getList(@NonNull final GetRequest getListRequest) {
Flowable> result;
try {
- Class dataClass = getListRequest.getDataClass();
- String url = getListRequest.getUrl();
- String simpleName = dataClass.getSimpleName();
- boolean shouldCache = getListRequest.isShouldCache();
- Flowable> dynamicGetList = mDataStoreFactory.dynamically(url, dataClass)
+ final Class dataClass = getListRequest.getDataClass();
+ final String url = getListRequest.getUrl();
+ final String simpleName = dataClass.getSimpleName();
+ final boolean shouldCache = getListRequest.isShouldCache();
+ final Flowable> dynamicGetList = mDataStoreFactory.dynamically(url, dataClass)
.dynamicGetList(url, getListRequest.getIdColumnName(), dataClass,
getListRequest.isPersist(), shouldCache);
if (Utils.getInstance().withCache(shouldCache)) {
@@ -61,22 +61,22 @@ public Flowable> getList(@NonNull GetRequest getListRequest) {
} else {
result = dynamicGetList;
}
- } catch (IllegalAccessException e) {
+ } catch (final IllegalAccessException e) {
result = Flowable.error(e);
}
return result.compose(applySchedulers());
}
@Override
- public Flowable getObject(@NonNull GetRequest getRequest) {
+ public Flowable getObject(@NonNull final GetRequest getRequest) {
Flowable result;
try {
- Object itemId = getRequest.getItemId();
- Class dataClass = getRequest.getDataClass();
- boolean shouldCache = getRequest.isShouldCache();
- String url = getRequest.getUrl();
- String simpleName = dataClass.getSimpleName();
- Flowable dynamicGetObject = mDataStoreFactory.dynamically(url, dataClass)
+ final Object itemId = getRequest.getItemId();
+ final Class dataClass = getRequest.getDataClass();
+ final boolean shouldCache = getRequest.isShouldCache();
+ final String url = getRequest.getUrl();
+ final String simpleName = dataClass.getSimpleName();
+ final Flowable dynamicGetObject = mDataStoreFactory.dynamically(url, dataClass)
.dynamicGetObject(url, getRequest.getIdColumnName(), itemId, getRequest.getIdType(),
dataClass, getRequest.isPersist(), shouldCache);
if (Utils.getInstance().withCache(shouldCache)) {
diff --git a/usecases/src/main/java/com/zeyad/usecases/db/RealmManager.java b/usecases/src/main/java/com/zeyad/usecases/db/RealmManager.java
index 034bced..127d7af 100644
--- a/usecases/src/main/java/com/zeyad/usecases/db/RealmManager.java
+++ b/usecases/src/main/java/com/zeyad/usecases/db/RealmManager.java
@@ -31,20 +31,23 @@ public class RealmManager implements DataBaseManager {
/**
* Gets an {@link Flowable} which will emit an Object
+ *
* @param idColumnName name of ID variable
- * @param itemId ID value
- * @param itemIdType type of the ID
- * @param dataClass type of the data requested
- * @param type of the data requested
+ * @param itemId ID value
+ * @param itemIdType type of the ID
+ * @param dataClass type of the data requested
+ * @param type of the data requested
* @return a {@link Flowable} containing an object of type M.
*/
@NonNull
@Override
public Flowable getById(@NonNull final String idColumnName, final Object itemId,
final Class itemIdType, Class dataClass) {
- return Flowable.defer(() -> getRealm(Realm.getDefaultInstance())
- .flatMap(realm -> getItemById(realm, dataClass, idColumnName, itemId, itemIdType)
- .map(realmModel -> (M) realm.copyFromRealm(realmModel))));
+ return Flowable.defer(() -> {
+ Realm realm = Realm.getDefaultInstance();
+ return getItemById(realm, dataClass, idColumnName, itemId, itemIdType)
+ .map(realmModel -> (M) realm.copyFromRealm(realmModel));
+ });
}
/**
@@ -57,12 +60,11 @@ public Flowable getById(@NonNull final String idColumnName, final Object
public Flowable> getAll(Class clazz) {
return Flowable.defer(() -> {
Realm realm = Realm.getDefaultInstance();
- return getRealm(realm)
- .map(realm1 -> realm1.where(clazz).findAll())
- .filter(RealmResults::isLoaded)
- .>map(realm::copyFromRealm)
- .flatMap(ms -> ms.isEmpty() ? Flowable.error(new IllegalAccessException(String
- .format("%s(s) were not found!", clazz.getSimpleName()))) : Flowable.just(ms));
+ return realm.where(clazz).findAll().asFlowable()
+ .filter(o -> ((RealmResults) o).isLoaded())
+ .map(o -> realm.copyFromRealm((RealmResults) o))
+ .flatMap(o -> ((RealmResults) o).isEmpty() ? Flowable.error(new IllegalAccessException(String
+ .format("%s(s) were not found!", clazz.getSimpleName()))) : Flowable.just(o));
});
}
@@ -78,7 +80,7 @@ public Flowable> getAll(Class clazz) {
public Flowable> getQuery(@NonNull RealmQueryProvider queryFactory) {
return Flowable.defer(() -> {
Realm realm = Realm.getDefaultInstance();
- return getRealm(realm).map(realm1 -> queryFactory.create(realm).findAll())
+ return queryFactory.create(realm).findAll().asFlowable()
.filter(RealmResults::isLoaded)
.map(realm::copyFromRealm);
});
@@ -93,16 +95,10 @@ public Flowable> getQuery(@NonNull RealmQueryProv
@NonNull
@Override
// TODO: 6/13/17 Remove ? remove : create flow
- public Single put(@Nullable M realmModel, @NonNull Class dataClass) {
+ public Single put(@NonNull M realmModel, @NonNull Class dataClass) {
return Single.fromCallable(() -> {
- if (realmModel == null) {
- throw new IllegalArgumentException("RealmObject is null");
- } else {
- return getRealm(Realm.getDefaultInstance()).map(realm1 ->
- RealmObject.isValid(executeWriteOperationInRealm(realm1,
- () -> realm1.copyToRealmOrUpdate(realmModel))))
- .blockingFirst();
- }
+ return RealmObject.isValid(executeWriteOperationInRealm(Realm.getDefaultInstance(),
+ (ExecuteAndReturn) realm -> realm.copyToRealmOrUpdate(realmModel)));
});
}
@@ -121,11 +117,10 @@ public Single put(@Nullable JSONObject jsonObject, @Nullable String idC
if (jsonObject == null) {
throw new IllegalArgumentException("JSONObject is invalid");
} else {
- updateJsonObjectWithIdValue(jsonObject, idColumnName, itemIdType, dataClass);
- return getRealm(Realm.getDefaultInstance()).map(realm1 ->
- RealmObject.isValid(executeWriteOperationInRealm(realm1,
- () -> realm1.createOrUpdateObjectFromJson(dataClass, jsonObject))))
- .blockingFirst();
+ final JSONObject updatedJSON = updateJsonObjectWithIdValue(jsonObject, idColumnName, itemIdType, dataClass);
+ return RealmObject.isValid(executeWriteOperationInRealm(Realm.getDefaultInstance(),
+ (ExecuteAndReturn) realm -> realm.createOrUpdateObjectFromJson(dataClass,
+ updatedJSON)));
}
});
}
@@ -133,10 +128,8 @@ public Single put(@Nullable JSONObject jsonObject, @Nullable String idC
@NonNull
@Override
public Single putAll(List realmObjects, Class dataClass) {
- return Single.fromCallable(() -> getRealm(Realm.getDefaultInstance())
- .map(realm1 -> executeWriteOperationInRealm(realm1,
- () -> realm1.copyToRealmOrUpdate(realmObjects)).size() == realmObjects.size())
- .blockingFirst());
+ return Single.fromCallable(() -> executeWriteOperationInRealm(Realm.getDefaultInstance(),
+ (ExecuteAndReturn>) realm -> realm.copyToRealmOrUpdate(realmObjects)).size() == realmObjects.size());
}
/**
@@ -151,12 +144,11 @@ public Single putAll(List realmObjects, Class
public Single putAll(@NonNull JSONArray jsonArray, String idColumnName, Class itemIdType,
@NonNull Class dataClass) {
return Single.fromCallable(() -> {
- updateJsonArrayWithIdValue(jsonArray, idColumnName, itemIdType, dataClass);
- return getRealm(Realm.getDefaultInstance()).map(realm1 -> {
- executeWriteOperationInRealm(realm1, () ->
- realm1.createOrUpdateAllFromJson(dataClass, jsonArray));
- return true;
- }).blockingFirst();
+ final JSONArray updatedJSONArray = updateJsonArrayWithIdValue(jsonArray, idColumnName, itemIdType,
+ dataClass);
+ executeWriteOperationInRealm(Realm.getDefaultInstance(), (Execute) realm ->
+ realm.createOrUpdateAllFromJson(dataClass, updatedJSONArray));
+ return true;
});
}
@@ -168,11 +160,10 @@ public Single putAll(@NonNull JSONArray jsonArray, String idColumnName,
@NonNull
@Override
public Single evictAll(@NonNull Class clazz) {
- return Single.fromCallable(() -> getRealm(Realm.getDefaultInstance())
- .map(realm1 -> {
- executeWriteOperationInRealm(realm1, () -> realm1.delete(clazz));
- return true;
- }).blockingFirst());
+ return Single.fromCallable(() -> {
+ executeWriteOperationInRealm(Realm.getDefaultInstance(), (Execute) realm -> realm.delete(clazz));
+ return true;
+ });
}
/**
@@ -185,37 +176,32 @@ public Single evictAll(@NonNull Class clazz) {
@NonNull
@Override
public Single evictCollection(@NonNull String idFieldName, @NonNull List