Skip to content

Commit

Permalink
首次提交
Browse files Browse the repository at this point in the history
  • Loading branch information
TkkSoCool committed Jan 31, 2018
0 parents commit 1a53105
Show file tree
Hide file tree
Showing 61 changed files with 1,901 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 91 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/smartfox_info.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
11 changes: 11 additions & 0 deletions api/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apply plugin: 'java'
apply plugin: 'com.github.dcendents.android-maven'
group='com.github.Tkk'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'io.reactivex.rxjava2:rxjava:2.1.0'
}

sourceCompatibility = "1.7"
targetCompatibility = "1.7"
22 changes: 22 additions & 0 deletions api/src/main/java/com/tkk/api/Binder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.tkk.api;


import com.tkk.api.entity.Event;

import io.reactivex.processors.FlowableProcessor;

/**
* Created on 2018/1/24
*
* @author 唐开阔
* @describe 用于绑定
*/

public interface Binder<T> {
/**
* 绑定事件,注册观察者
* @param mFlowableProcessor 事件发射器
* @param target 绑定者
*/
void bind(T target,FlowableProcessor<Event> mFlowableProcessor);
}
68 changes: 68 additions & 0 deletions api/src/main/java/com/tkk/api/RxEventProcessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.tkk.api;

import com.tkk.api.entity.Event;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.processors.FlowableProcessor;
import io.reactivex.processors.PublishProcessor;

/**
* Created on 2018/1/24
* @author 唐开阔
* @describe 事件处理器
*
*/

public class RxEventProcessor {
static volatile RxEventProcessor sInstance;
private FlowableProcessor<Event> mProcessor;
private Map<Integer, Unbinder> subscriberUnbinds = new HashMap<>();

private RxEventProcessor() {
mProcessor = PublishProcessor.create();
mProcessor = mProcessor.toSerialized();
}

public synchronized static RxEventProcessor get() {
if (null == sInstance) {
sInstance = new RxEventProcessor();
}
return sInstance;
}

public void post(String tag, Object... objects) {
Event event = new Event(tag, objects);
mProcessor.onNext(event);
}

public void bind(Object target) {
int subscriberId = target.hashCode();
//判断是否已经注册
if (!subscriberUnbinds.containsKey(subscriberId)) {
String className = target.getClass().getName();
try {
Class<?> finderClass = Class.forName(className + "$$SEND_ENEVT");
Object targetEventProcessor = finderClass.newInstance();
Binder binder = (Binder) targetEventProcessor;
Unbinder unbinder = (Unbinder) targetEventProcessor;
binder.bind(target, mProcessor);
subscriberUnbinds.put(subscriberId, unbinder);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}

public void unBind(Object target) {
int subscriberId = target.hashCode();
if (subscriberUnbinds.containsKey(subscriberId)){
subscriberUnbinds.get(subscriberId).unBind();
}
}
}
12 changes: 12 additions & 0 deletions api/src/main/java/com/tkk/api/ThreadType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.tkk.api;

/**
* Created on 2018/1/25
*
* @author 唐开阔
* @describe
*/

public enum ThreadType {
MAIN, IO, NEW, COMPUTATION, TRAMPOLINE, SINGLE
}
14 changes: 14 additions & 0 deletions api/src/main/java/com/tkk/api/Unbinder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.tkk.api;

/**
* Created on 2018/1/24
*
* @author 唐开阔
* @describe 用于取消绑定
*/
public interface Unbinder {
/**
* 解除绑定
*/
void unBind();
}
Loading

0 comments on commit 1a53105

Please sign in to comment.