diff --git a/.gitignore b/.gitignore index f6b286c..34f8c3b 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ out/ # Gradle files .gradle/ build/ +/*/build/ # Local configuration file (sdk path, etc) local.properties @@ -34,7 +35,7 @@ captures/ # Intellij *.iml -.idea/workspace.xml +.idea/ # Keystore files *.jks diff --git a/app/build.gradle b/app/build.gradle index eff4b58..771383b 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,12 +11,19 @@ android { versionCode 1 versionName "1.0" } + buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_7 + targetCompatibility JavaVersion.VERSION_1_7 + } + lintOptions { abortOnError false } @@ -33,14 +40,15 @@ dependencies { // WITH THESE ONES YOU CAN TEST REMOTE LIBS // REMEMBER TO USE THESE AFTER TEST CAUSE JENKINS TROUBLES - compile "com.baseandroid:baseandroid-busadapter:$adapterVersionName" - compile "com.baseandroid:baseandroid-eventdispatcher:$adapterVersionName" +// compile "com.baseandroid:baseandroid-busadapter:$adapterVersionName" +// compile "com.baseandroid:baseandroid-eventdispatcher:$adapterVersionName" // compile "com.baseandroid:baseandroid-rxeventdispatcher:$adapterVersionName' // WITH THESE ONES YOU CAN USE LOCAL PROJECTS // REMEMBER: COMMENT THESE ONES BEFOR PUSH ON DEVELOP CAUSE JENKINS TROUBLES - //compile project(path: ':baseandroid-busadapter') - //compile project(path: ':baseandroid-eventdispatcher') - //compile project(path: ':baseandroid-rxeventdispatcher') + compile project(path: ':baseandroid-busadapter') + compile project(path: ':baseandroid-eventdispatcher') + compile project(path: ':baseandroid-rxeventdispatcher') + compile project(path: ':baseandroid-greenbus') } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 64ccc47..2f63069 100755 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -3,6 +3,7 @@ package="it.sysdata.eventdispatcher" > + */ + public enum EventBusType { + /** + * Otto Event Bus + */ + OTTO, + /** + * Rx Event Bus + */ + RX, + /** + * GreenRobot Event Bus + */ + GREENROBOT + } + + @Override + public void onCreate() { + super.onCreate(); + + // init event bus + initEventBus(); + } + + private void initEventBus() { + + //EventBusType eventBusType = EventBusType.OTTO; + //EventBusType eventBusType = EventBusType.RX; + EventBusType eventBusType = EventBusType.GREENROBOT; + + switch (eventBusType) { + case OTTO: + initOttoEventBus(); + break; + case RX: + initRxEventBus(); + break; + case GREENROBOT: + initGreenRobotEventBus(); + break; + } + + } + + private void initRxEventBus() { + RxEventProcessor eventProcessor = (RxEventProcessor) RxEventProcessor.newInstance(); + eventProcessor.setVerbose(true); + EventDispatcher.useEventProcessor(eventProcessor); + } + + private void initOttoEventBus() { + EventProcessor eventProcessor = (EventProcessor) OttoEventProcessor.newInstance(); + EventDispatcher.useEventProcessor(eventProcessor); + } + + private void initGreenRobotEventBus() { + GreenRobotEventProcessor eventProcessor = (GreenRobotEventProcessor) GreenRobotEventProcessor.newInstance(); + eventProcessor.setVerbose(true); + EventDispatcher.useEventProcessor(eventProcessor); + } + +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b06e8d1..8c42fdf 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -15,6 +15,6 @@ --> - EventDispatcher + UniversalEventBus Settings diff --git a/baseandroid-eventdispatcher/build.gradle b/baseandroid-eventdispatcher/build.gradle index ee19aa3..4ef4e2c 100755 --- a/baseandroid-eventdispatcher/build.gradle +++ b/baseandroid-eventdispatcher/build.gradle @@ -41,10 +41,12 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + compileOptions { - targetCompatibility 1.7 - sourceCompatibility 1.7 + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 } + lintOptions { abortOnError false } diff --git a/baseandroid-eventdispatcher/src/main/java/com/baseandroid/events/otto/OttoEventProcessor.java b/baseandroid-eventdispatcher/src/main/java/com/baseandroid/events/otto/OttoEventProcessor.java index d80e5b9..e1ce3f3 100755 --- a/baseandroid-eventdispatcher/src/main/java/com/baseandroid/events/otto/OttoEventProcessor.java +++ b/baseandroid-eventdispatcher/src/main/java/com/baseandroid/events/otto/OttoEventProcessor.java @@ -138,25 +138,29 @@ private static void startEventsConsumption() { * This Observable (Observable.interval) cycles every EVENT_CONSUMPTION_INTERVAL millis * we observe results on a new Thread and remove items from non-UI queues */ - rx.Observable.interval(EVENT_CONSUMPTION_INTERVAL, TimeUnit.MILLISECONDS).onBackpressureBuffer().subscribeOn(Schedulers.newThread()).observeOn(Schedulers.newThread()).subscribe(aLong1 -> { - if (!mNetworkEvents.isEmpty()) { - Object ev = mNetworkEvents.remove(0); - logEvent(ev, false); - BUS.post(ev); - } else if (!mDataEvents.isEmpty()) { - Object ev = mDataEvents.remove(0); - logEvent(ev, false); - BUS.post(ev); - } else if (!mGenericEvents.isEmpty()) { - Object ev = mGenericEvents.remove(0); - logEvent(ev, false); - BUS.post(ev); - } else if (!mContextEvents.isEmpty()) { - Object ev = mContextEvents.remove(0); - logEvent(ev, false); - BUS.post(ev); - } - }); + rx.Observable.interval(EVENT_CONSUMPTION_INTERVAL, TimeUnit.MILLISECONDS) + .onBackpressureBuffer() + .subscribeOn(Schedulers.newThread()) + .observeOn(Schedulers.newThread()) + .subscribe(aLong1 -> { + if (!mNetworkEvents.isEmpty()) { + Object ev = mNetworkEvents.remove(0); + logEvent(ev, false); + BUS.post(ev); + } else if (!mDataEvents.isEmpty()) { + Object ev = mDataEvents.remove(0); + logEvent(ev, false); + BUS.post(ev); + } else if (!mGenericEvents.isEmpty()) { + Object ev = mGenericEvents.remove(0); + logEvent(ev, false); + BUS.post(ev); + } else if (!mContextEvents.isEmpty()) { + Object ev = mContextEvents.remove(0); + logEvent(ev, false); + BUS.post(ev); + } + }); /* * This Observable (Observable.interval) cycles every EVENT_CONSUMPTION_INTERVAL millis @@ -232,12 +236,13 @@ public void onPost(Object o) { //init dead events manager if(mDeadEventManager == null) { mDeadEventManager = new DeadEventManager(); - }else{ + } else { BUS.unregister(mDeadEventManager); UI_BUS.unregister(mDeadEventManager); } BUS.register(mDeadEventManager); UI_BUS.register(mDeadEventManager); + //mark us as initialised mInitialised = true; startEventsConsumption(); @@ -270,6 +275,9 @@ public void onPost(Object o) { Collections.sort(mContextEvents, Event.COMPARATOR); break; } + } else if (o != null) { + DeadEvent deadEvent = new DeadEvent(BUS, o); + BUS.post(deadEvent); } } diff --git a/baseandroid-greenbus/.gitignore b/baseandroid-greenbus/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/baseandroid-greenbus/.gitignore @@ -0,0 +1 @@ +/build diff --git a/baseandroid-greenbus/build.gradle b/baseandroid-greenbus/build.gradle new file mode 100644 index 0000000..79c0857 --- /dev/null +++ b/baseandroid-greenbus/build.gradle @@ -0,0 +1,57 @@ +apply plugin: 'com.android.library' + +def libName = 'baseandroid-greenbus' + +android { + compileSdkVersion 23 + buildToolsVersion "23.0.3" + + defaultConfig { + minSdkVersion 9 + targetSdkVersion 23 + versionCode libVersionCode + versionName libVersionName + } + + packagingOptions { + exclude 'LICENSE.txt' + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_7 + targetCompatibility JavaVersion.VERSION_1_7 + } + + lintOptions { + abortOnError false + } + +} + +dependencies { + def adapterVersionName = project.ext.libVersionName + + compile fileTree(dir: 'libs', include: ['*.jar']) + testCompile 'junit:junit:4.12' + compile 'com.android.support:appcompat-v7:23.3.0' + // log + compile 'org.slf4j:slf4j-api:1.7.12' + compile 'com.github.tony19:logback-android-core:1.1.1-4' + compile 'com.github.tony19:logback-android-classic:1.1.1-4' + // GreenRobot Event Bus + compile 'org.greenrobot:eventbus:3.1.1' + // BusAdapter + compile "com.baseandroid:baseandroid-busadapter:$adapterVersionName" + // rxJava + compile 'io.reactivex:rxandroid:1.1.0' + // Because RxAndroid releases are few and far between, it is recommended you also + // explicitly depend on RxJava's latest version for bug fixes and new features. + compile 'io.reactivex:rxjava:1.1.3' +} diff --git a/baseandroid-greenbus/proguard-rules.pro b/baseandroid-greenbus/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/baseandroid-greenbus/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/baseandroid-greenbus/src/androidTest/java/com/baseandroid/eventbus/ExampleInstrumentedTest.java b/baseandroid-greenbus/src/androidTest/java/com/baseandroid/eventbus/ExampleInstrumentedTest.java new file mode 100644 index 0000000..01f5d4e --- /dev/null +++ b/baseandroid-greenbus/src/androidTest/java/com/baseandroid/eventbus/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.baseandroid.eventbus; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.baseandroid.eventbus.test", appContext.getPackageName()); + } +} diff --git a/baseandroid-greenbus/src/main/AndroidManifest.xml b/baseandroid-greenbus/src/main/AndroidManifest.xml new file mode 100644 index 0000000..167d531 --- /dev/null +++ b/baseandroid-greenbus/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + diff --git a/baseandroid-greenbus/src/main/java/com/baseandroid/eventbus/GreenRobotEventProcessor.java b/baseandroid-greenbus/src/main/java/com/baseandroid/eventbus/GreenRobotEventProcessor.java new file mode 100644 index 0000000..e858510 --- /dev/null +++ b/baseandroid-greenbus/src/main/java/com/baseandroid/eventbus/GreenRobotEventProcessor.java @@ -0,0 +1,72 @@ +package com.baseandroid.eventbus; + +import android.util.Log; + +import com.baseandroid.events.Event; +import com.baseandroid.events.EventProcessor; + +import org.greenrobot.eventbus.EventBus; + +/** + * Class managing the events used throughout the application. + * + * @author Luca Conversano + * created on 20/11/2017. + */ +public final class GreenRobotEventProcessor implements EventProcessor { + + private static final String LOG_TAG = GreenRobotEventProcessor.class.getSimpleName(); + private static boolean verbose = false; + + private GreenRobotEventProcessor() { + // No instances. + } + + public static EventProcessor newInstance() { + return new GreenRobotEventProcessor(); + } + + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + @Override + public void onRegister(Object o) { + EventBus.getDefault().register(o); + } + + @Override + public void onUnregister(Object o) { + EventBus.getDefault().unregister(o); + } + + @Override + public void onPost(Object o) { + if (o != null) { + if (verbose) { + Log.i(LOG_TAG, "received new object to post: " + o.getClass().getSimpleName()); + } + //check if it's an event we recognise + if (o.getClass().isAnnotationPresent(Event.class)) { + Event.Type eventType = o.getClass().getAnnotation(Event.class).type(); + if (verbose) { + Log.d(LOG_TAG, "object " + o.getClass().getSimpleName() + " is an event of type " + eventType); + } + EventBus.getDefault().post(o); + } else { + Log.d(LOG_TAG, "received dead event: " + o.getClass().getSimpleName()); + } + } + } + + @Override + public String onSavePoint(Object object) { + return null; + } + + @Override + public void onLoadPoint(Object object, String key) { + + } + +} diff --git a/baseandroid-greenbus/src/main/res/values/strings.xml b/baseandroid-greenbus/src/main/res/values/strings.xml new file mode 100644 index 0000000..2d65eab --- /dev/null +++ b/baseandroid-greenbus/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + baseandroid-greenbus + diff --git a/baseandroid-greenbus/src/test/java/com/baseandroid/eventbus/ExampleUnitTest.java b/baseandroid-greenbus/src/test/java/com/baseandroid/eventbus/ExampleUnitTest.java new file mode 100644 index 0000000..e4db8cf --- /dev/null +++ b/baseandroid-greenbus/src/test/java/com/baseandroid/eventbus/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.baseandroid.eventbus; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() throws Exception { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/baseandroid-rxeventdispatcher/build.gradle b/baseandroid-rxeventdispatcher/build.gradle index ae5b0ac..d0ea199 100755 --- a/baseandroid-rxeventdispatcher/build.gradle +++ b/baseandroid-rxeventdispatcher/build.gradle @@ -62,27 +62,27 @@ dependencies { compile 'io.reactivex:rxjava:1.1.3' } -// pubblicazione maven -if(project.rootProject.file('local.properties').exists()) { - Properties properties = new Properties() - properties.load(project.rootProject.file('local.properties').newDataInputStream()) - ext { - // GROUP_ID - publishedGroupId = 'com.baseandroid' - // ARTIFACT_ID - artifact = libName - // VERSION_ID - libraryVersion = libVersionName - - developerId = properties.getProperty("bintray.developer.id") - developerName = properties.getProperty("bintray.developer.name") - developerEmail = properties.getProperty("bintray.developer.email") - - bintrayRepo = 'maven' - bintrayName = 'baseandroid-rxeventdispatcher' - libraryName = 'baseandroid-rxeventdispatcher' - bintrayOrganization = 'sysdata' - } - - apply from: 'publishBintray.gradle' -} \ No newline at end of file +//// pubblicazione maven +//if(project.rootProject.file('local.properties').exists()) { +// Properties properties = new Properties() +// properties.load(project.rootProject.file('local.properties').newDataInputStream()) +// ext { +// // GROUP_ID +// publishedGroupId = 'com.baseandroid' +// // ARTIFACT_ID +// artifact = libName +// // VERSION_ID +// libraryVersion = libVersionName +// +// developerId = properties.getProperty("bintray.developer.id") +// developerName = properties.getProperty("bintray.developer.name") +// developerEmail = properties.getProperty("bintray.developer.email") +// +// bintrayRepo = 'maven' +// bintrayName = 'baseandroid-rxeventdispatcher' +// libraryName = 'baseandroid-rxeventdispatcher' +// bintrayOrganization = 'sysdata' +// } +// +// apply from: 'publishBintray.gradle' +//} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index e40ada6..31b8dee 100755 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':app', ':baseandroid-busadapter', ':baseandroid-eventdispatcher', ':baseandroid-rxeventdispatcher' +include ':app', ':baseandroid-busadapter', ':baseandroid-eventdispatcher', ':baseandroid-rxeventdispatcher', ':baseandroid-greenbus'