├── rxbus
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── anadeainc
│ │ │ └── rxbus
│ │ │ ├── Subscribe.java
│ │ │ ├── BusProvider.java
│ │ │ ├── Bus.java
│ │ │ ├── AbstractSubscriber.java
│ │ │ ├── AnnotatedSubscriber.java
│ │ │ ├── CustomSubscriber.java
│ │ │ └── RxBus.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── anadeainc
│ │ └── rxbus
│ │ ├── AbstractSubscriberTest.java
│ │ ├── AnnotatedSubscriberTest.java
│ │ ├── CustomSubscriberTest.java
│ │ ├── RxBusAnnotatedSubscriptionTest.java
│ │ └── RxBusCustomSubscriptionTest.java
├── proguard-rules.pro
├── maveninstall.gradle
├── bintrayupload.gradle
├── build.gradle
└── jacoco.gradle
├── example
├── .gitignore
├── src
│ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── anadeainc
│ │ │ │ └── example
│ │ │ │ ├── ExampleEvent.java
│ │ │ │ ├── FragmentEvent.java
│ │ │ │ ├── FragmentOne.java
│ │ │ │ ├── FragmentTwo.java
│ │ │ │ ├── BaseFragment.java
│ │ │ │ └── MainActivity.java
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── strings.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── fragment_two.xml
│ │ │ │ ├── fragment_one.xml
│ │ │ │ └── activity_main.xml
│ │ └── AndroidManifest.xml
│ └── test
│ │ └── java
│ │ └── com
│ │ └── anadeainc
│ │ └── example
│ │ └── ExampleUnitTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── CHANGELOG.md
├── .gitignore
├── gradlew.bat
├── README.md
├── gradlew
└── LICENSE.txt
/rxbus/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':example', ':rxbus'
2 |
--------------------------------------------------------------------------------
/rxbus/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anadea/RxBus/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/rxbus/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/example/src/main/java/com/anadeainc/example/ExampleEvent.java:
--------------------------------------------------------------------------------
1 | package com.anadeainc.example;
2 |
3 | enum ExampleEvent {
4 | ONE, TWO
5 | }
6 |
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anadea/RxBus/HEAD/example/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anadea/RxBus/HEAD/example/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anadea/RxBus/HEAD/example/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anadea/RxBus/HEAD/example/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Anadea/RxBus/HEAD/example/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/java/com/anadeainc/example/FragmentEvent.java:
--------------------------------------------------------------------------------
1 | package com.anadeainc.example;
2 |
3 | enum FragmentEvent {
4 | FRAGMENT_ONE, FRAGMENT_TWO
5 | }
6 |
--------------------------------------------------------------------------------
/example/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/example/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | Change Log
2 | ==========
3 |
4 | Version 1.0.1 *(2017-01-31)*
5 | ----------------------------
6 |
7 | Added BusProvider to obtaining singleton instance.
8 |
9 | Version 1.0.0 *(2017-01-27)*
10 | ----------------------------
11 |
12 | Initial release.
13 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Jan 19 10:39:19 CET 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/example/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/example/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/example/src/test/java/com/anadeainc/example/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.anadeainc.example;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/example/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RxBus
3 | Event.ONE
4 | Event.TWO
5 | Message
6 | Fragment One
7 | Fragment Two
8 | Event.ONE times:
9 | Message times:
10 | Event.TWO times:
11 | Activity received from:
12 |
13 |
14 |
--------------------------------------------------------------------------------
/rxbus/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # OSX files
2 | .DS_Store
3 |
4 | # Built application files
5 | *.apk
6 | *.ap_
7 |
8 | # Files for the ART/Dalvik VM
9 | *.dex
10 |
11 | # Java class files
12 | *.class
13 |
14 | # Generated files
15 | bin/
16 | gen/
17 | out/
18 |
19 | # Gradle files
20 | .gradle/
21 | build/
22 |
23 | # Local configuration file (sdk path, etc)
24 | /gradle.properties
25 | /local.properties
26 |
27 | # Log Files
28 | *.log
29 |
30 | # Android Studio Navigation editor temp files
31 | .navigation/
32 |
33 | # Android Studio captures folder
34 | captures/
35 |
36 | ## Directory-based project format:
37 | .idea/
38 |
39 | # Intellij
40 | *.iml
41 |
42 | # Keystore files
43 | *.jks
44 |
45 | # External native build folder generated in Android Studio 2.2 and later
46 | .externalNativeBuild
--------------------------------------------------------------------------------
/example/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/rxbus/src/main/java/com/anadeainc/rxbus/Subscribe.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Anadea Inc
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.anadeainc.rxbus;
18 |
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | @Retention(RetentionPolicy.RUNTIME)
25 | @Target(ElementType.METHOD)
26 | public @interface Subscribe {
27 | }
28 |
--------------------------------------------------------------------------------
/example/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/and/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | -keepattributes *Annotation*
20 | -keepclassmembers class ** {
21 | @com.anadeainc.rxbus.Subscribe public *;
22 | }
23 |
24 | -keep enum com.anadeainc.example.FragmentEvent { *; }
25 |
26 | -dontnote android.net.http.*
27 | -dontnote org.apache.commons.codec.**
28 | -dontnote org.apache.http.**
--------------------------------------------------------------------------------
/rxbus/src/main/java/com/anadeainc/rxbus/BusProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Anadea Inc
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.anadeainc.rxbus;
18 |
19 | public final class BusProvider {
20 |
21 | private BusProvider() {
22 | }
23 |
24 | public static Bus getInstance() {
25 | return BusHolder.INSTANCE;
26 | }
27 |
28 | private static final class BusHolder {
29 | final static Bus INSTANCE = new RxBus();
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/rxbus/maveninstall.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.github.dcendents.android-maven'
2 |
3 | group = publishedGroupId
4 | version = libraryVersion
5 |
6 | install {
7 | repositories.mavenInstaller {
8 | pom {
9 | project {
10 | packaging 'aar'
11 | groupId publishedGroupId
12 | artifactId artifact
13 |
14 | name libraryName
15 | description libraryDescription
16 | url siteUrl
17 |
18 | licenses {
19 | license {
20 | name licenseName
21 | url licenseUrl
22 | }
23 | }
24 | developers {
25 | developer {
26 | id developerId
27 | name developerName
28 | email developerEmail
29 | }
30 | }
31 | scm {
32 | connection gitUrl
33 | developerConnection gitUrl
34 | url siteUrl
35 | }
36 | }
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/example/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'me.tatarka.retrolambda'
3 |
4 | android {
5 | compileSdkVersion 25
6 | buildToolsVersion "25.0.2"
7 |
8 | defaultConfig {
9 | applicationId "com.anadeainc.example"
10 | minSdkVersion 16
11 | targetSdkVersion 25
12 | versionCode 1
13 | versionName "1.0"
14 | }
15 |
16 | buildTypes {
17 | debug {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 |
27 | compileOptions {
28 | sourceCompatibility JavaVersion.VERSION_1_8
29 | targetCompatibility JavaVersion.VERSION_1_8
30 | }
31 |
32 | lintOptions {
33 | disable 'GoogleAppIndexingWarning', 'Overdraw'
34 | return void
35 | }
36 |
37 | }
38 |
39 | dependencies {
40 | compile fileTree(dir: 'libs', include: ['*.jar'])
41 | compile 'com.android.support:appcompat-v7:25.1.0'
42 | compile project(path: ':rxbus')
43 | testCompile 'junit:junit:4.12'
44 | }
45 |
--------------------------------------------------------------------------------
/rxbus/src/main/java/com/anadeainc/rxbus/Bus.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Anadea Inc
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.anadeainc.rxbus;
18 |
19 | import android.support.annotation.NonNull;
20 |
21 | import io.reactivex.functions.Consumer;
22 |
23 | public interface Bus {
24 |
25 | void register(@NonNull Object observer);
26 |
27 | CustomSubscriber obtainSubscriber(@NonNull Class eventClass,
28 | @NonNull Consumer receiver);
29 |
30 | void registerSubscriber(@NonNull Object observer, @NonNull CustomSubscriber subscriber);
31 |
32 | void unregister(@NonNull Object observer);
33 |
34 | void post(@NonNull Object event);
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/rxbus/bintrayupload.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.jfrog.bintray'
2 |
3 | task sourcesJar(type: Jar) {
4 | classifier = 'sources'
5 | from android.sourceSets.main.java.srcDirs
6 | }
7 |
8 | task javadoc(type: Javadoc) {
9 | source = android.sourceSets.main.java.srcDirs
10 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
11 | }
12 |
13 | task javadocJar(type: Jar, dependsOn: javadoc) {
14 | classifier = 'javadoc'
15 | from javadoc.destinationDir
16 | }
17 |
18 | artifacts {
19 | archives javadocJar
20 | archives sourcesJar
21 | }
22 |
23 | bintray {
24 | user = BINTRAY_USER
25 | key = BINTRAY_KEY
26 |
27 | configurations = ['archives']
28 |
29 | override = true
30 |
31 | pkg {
32 | repo = bintrayRepo
33 | name = bintrayName
34 |
35 | websiteUrl = siteUrl
36 | issueTrackerUrl = issueUrl
37 | vcsUrl = gitUrl
38 |
39 | licenses = allLicenses
40 |
41 | publish = true
42 | publicDownloadNumbers = true
43 |
44 | version {
45 | name = libraryVersion
46 | desc = libraryDescription
47 | vcsTag = libraryVersion
48 |
49 | gpg {
50 | sign = true
51 | passphrase = BINTRAY_GPG
52 | }
53 | }
54 | }
55 | }
--------------------------------------------------------------------------------
/rxbus/src/main/java/com/anadeainc/rxbus/AbstractSubscriber.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Anadea Inc
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.anadeainc.rxbus;
18 |
19 | import io.reactivex.disposables.Disposable;
20 | import io.reactivex.functions.Consumer;
21 |
22 | abstract class AbstractSubscriber implements Consumer, Disposable {
23 |
24 | private volatile boolean disposed;
25 |
26 | @Override
27 | public void accept(T event) {
28 | try {
29 | acceptEvent(event);
30 | } catch (Exception e) {
31 | throw new RuntimeException("Could not dispatch event: " + event.getClass(), e);
32 | }
33 | }
34 |
35 | @Override
36 | public void dispose() {
37 | if (!disposed) {
38 | disposed = true;
39 | release();
40 | }
41 | }
42 |
43 | @Override
44 | public boolean isDisposed() {
45 | return disposed;
46 | }
47 |
48 | protected abstract void acceptEvent(T event) throws Exception;
49 |
50 | protected abstract void release();
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/example/src/main/java/com/anadeainc/example/FragmentOne.java:
--------------------------------------------------------------------------------
1 | package com.anadeainc.example;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.Button;
9 | import android.widget.TextView;
10 |
11 | public class FragmentOne extends BaseFragment {
12 |
13 | private TextView eventOneCountView;
14 | private int eventOneCount;
15 |
16 | @Nullable
17 | @Override
18 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
19 | @Nullable Bundle savedInstanceState) {
20 | return inflater.inflate(R.layout.fragment_one, container, false);
21 | }
22 |
23 | @Override
24 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
25 | super.onViewCreated(view, savedInstanceState);
26 |
27 | eventBus.registerSubscriber(this, eventBus
28 | .obtainSubscriber(ExampleEvent.class, exampleEvent -> {
29 | eventOneCount++;
30 | eventOneCountView.setText(String.valueOf(eventOneCount));
31 | }).withFilter(exampleEvent -> exampleEvent == ExampleEvent.ONE));
32 |
33 | eventOneCountView = (TextView) view.findViewById(R.id.fragmentOne_eventOneCount);
34 | messageCountView = (TextView) view.findViewById(R.id.fragmentOne_eventMessageCount);
35 |
36 | sendToActivity = (Button) view.findViewById(R.id.fragmentOne_sendButton);
37 | sendToActivity.setOnClickListener(v -> eventBus.post(FragmentEvent.FRAGMENT_ONE));
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/example/src/main/java/com/anadeainc/example/FragmentTwo.java:
--------------------------------------------------------------------------------
1 | package com.anadeainc.example;
2 |
3 |
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.Button;
10 | import android.widget.TextView;
11 |
12 | public class FragmentTwo extends BaseFragment {
13 |
14 | private TextView eventTwoCountView;
15 | private int eventTwoCount;
16 |
17 | @Nullable
18 | @Override
19 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
20 | @Nullable Bundle savedInstanceState) {
21 | return inflater.inflate(R.layout.fragment_two, container, false);
22 | }
23 |
24 | @Override
25 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
26 | super.onViewCreated(view, savedInstanceState);
27 |
28 | eventBus.registerSubscriber(this, eventBus
29 | .obtainSubscriber(ExampleEvent.class, exampleEvent -> {
30 | eventTwoCount++;
31 | eventTwoCountView.setText(String.valueOf(eventTwoCount));
32 | }).withFilter(exampleEvent -> exampleEvent == ExampleEvent.TWO));
33 |
34 | eventTwoCountView = (TextView) view.findViewById(R.id.fragmentTwo_eventTwoCount);
35 | messageCountView = (TextView) view.findViewById(R.id.fragmentTwo_eventMessageCount);
36 |
37 | sendToActivity = (Button) view.findViewById(R.id.fragmentTwo_sendButton);
38 | sendToActivity.setOnClickListener(v -> eventBus.post(FragmentEvent.FRAGMENT_TWO));
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/example/src/main/java/com/anadeainc/example/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.anadeainc.example;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.Fragment;
6 | import android.view.View;
7 | import android.widget.Button;
8 | import android.widget.TextView;
9 |
10 | import com.anadeainc.rxbus.Bus;
11 | import com.anadeainc.rxbus.BusProvider;
12 | import com.anadeainc.rxbus.RxBus;
13 |
14 | public abstract class BaseFragment extends Fragment {
15 |
16 | protected Bus eventBus = BusProvider.getInstance();
17 |
18 | protected TextView messageCountView;
19 | protected int messageCount;
20 |
21 | protected Button sendToActivity;
22 |
23 | @Override
24 | public void onCreate(@Nullable Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setRetainInstance(true);
27 | }
28 |
29 | @Override
30 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
31 | super.onViewCreated(view, savedInstanceState);
32 | eventBus.register(this);
33 | eventBus.registerSubscriber(this, eventBus.obtainSubscriber(String.class, this::updateStringLabel));
34 | }
35 |
36 | @Override
37 | public void onDestroyView() {
38 | super.onDestroyView();
39 | sendToActivity.setOnClickListener(null);
40 | eventBus.unregister(this);
41 | }
42 |
43 | @Override
44 | public void onDestroy() {
45 | super.onDestroy();
46 | eventBus = null;
47 | }
48 |
49 | private void updateStringLabel(String message) {
50 | messageCount++;
51 | messageCountView.setText(String.valueOf(messageCount));
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/rxbus/src/main/java/com/anadeainc/rxbus/AnnotatedSubscriber.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Anadea Inc
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.anadeainc.rxbus;
18 |
19 | import android.support.annotation.NonNull;
20 |
21 | import java.lang.reflect.Method;
22 |
23 | class AnnotatedSubscriber extends AbstractSubscriber {
24 |
25 | private final int hashCode;
26 |
27 | private Object observer;
28 | private Method method;
29 |
30 | AnnotatedSubscriber(@NonNull Object observer, @NonNull Method method) {
31 | this.observer = observer;
32 | this.method = method;
33 |
34 | hashCode = 31 * observer.hashCode() + method.hashCode();
35 | }
36 |
37 | @Override
38 | protected void acceptEvent(T event) throws Exception {
39 | method.invoke(observer, event);
40 | }
41 |
42 | @Override
43 | protected void release() {
44 | observer = null;
45 | method = null;
46 | }
47 |
48 | @Override
49 | public boolean equals(Object other) {
50 | if (this == other) return true;
51 | if (other == null || getClass() != other.getClass()) return false;
52 |
53 | AnnotatedSubscriber> that = (AnnotatedSubscriber>) other;
54 |
55 | return observer.equals(that.observer) && method.equals(that.method);
56 | }
57 |
58 | @Override
59 | public int hashCode() {
60 | return hashCode;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/rxbus/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply from: 'jacoco.gradle'
3 |
4 | android {
5 | compileSdkVersion 25
6 | buildToolsVersion "25.0.2"
7 |
8 | defaultConfig {
9 | minSdkVersion 16
10 | targetSdkVersion 25
11 | versionCode 2
12 | versionName "1.0.1"
13 | }
14 |
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 |
22 | compileOptions {
23 | sourceCompatibility JavaVersion.VERSION_1_7
24 | targetCompatibility JavaVersion.VERSION_1_7
25 | }
26 |
27 | testOptions {
28 | unitTests.returnDefaultValues = true
29 | }
30 | }
31 |
32 | dependencies {
33 | compile fileTree(dir: 'libs', include: ['*.jar'])
34 |
35 | compile 'com.android.support:support-annotations:25.1.1'
36 |
37 | // Rx
38 | compile 'io.reactivex.rxjava2:rxjava:2.0.5'
39 | compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
40 |
41 | testCompile 'junit:junit:4.12'
42 | testCompile 'org.mockito:mockito-core:1.10.19'
43 | }
44 |
45 | ext {
46 | bintrayRepo = 'maven'
47 | bintrayName = 'rxbus'
48 |
49 | publishedGroupId = 'com.github.anadea'
50 | libraryName = 'RxBus'
51 | artifact = 'rxbus'
52 |
53 | libraryDescription = 'Event bus based on RxJava and optimized for Android'
54 |
55 | siteUrl = 'https://github.com/Anadea/RxBus'
56 | issueUrl = 'https://github.com/Anadea/RxBus/issues'
57 | gitUrl = 'https://github.com/Anadea/RxBus.git'
58 |
59 | libraryVersion = '1.0.1'
60 |
61 | developerId = 'dubroff'
62 | developerName = 'Artem Dubrov'
63 | developerEmail = 'and@anadeainc.com'
64 |
65 | licenseName = 'The Apache Software License, Version 2.0'
66 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
67 | allLicenses = ['Apache-2.0']
68 |
69 | }
70 |
71 | apply from: 'maveninstall.gradle'
72 | apply from: 'bintrayupload.gradle'
--------------------------------------------------------------------------------
/example/src/main/res/layout/fragment_two.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
25 |
26 |
30 |
31 |
36 |
37 |
38 |
43 |
44 |
48 |
49 |
54 |
55 |
--------------------------------------------------------------------------------
/example/src/main/res/layout/fragment_one.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
25 |
26 |
30 |
31 |
36 |
37 |
38 |
43 |
44 |
48 |
49 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/rxbus/src/test/java/com/anadeainc/rxbus/AbstractSubscriberTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Anadea Inc
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.anadeainc.rxbus;
18 |
19 | import org.junit.Test;
20 | import org.junit.runner.RunWith;
21 | import org.mockito.Mock;
22 | import org.mockito.Spy;
23 | import org.mockito.runners.MockitoJUnitRunner;
24 |
25 | import static org.junit.Assert.assertEquals;
26 | import static org.junit.Assert.assertFalse;
27 | import static org.junit.Assert.assertTrue;
28 | import static org.junit.Assert.fail;
29 | import static org.mockito.Mockito.doThrow;
30 | import static org.mockito.Mockito.times;
31 | import static org.mockito.Mockito.verify;
32 |
33 | @RunWith(MockitoJUnitRunner.class)
34 | public class AbstractSubscriberTest {
35 |
36 | @Mock
37 | Object event;
38 |
39 | @Spy
40 | AbstractSubscriber