-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
- Loading branch information
There are no files selected for viewing
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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
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" |
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); | ||
} |
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(); | ||
} | ||
} | ||
} |
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 | ||
} |
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(); | ||
} |