
回复
添加资源
添加资源将有机会获得更多曝光,你也可以直接关联已上传资源
去关联
⭐ ViaBus 是一款响应式架构,借助总线转发数据的请求和响应,实现ui、业务的完全解耦。
通过library生成har包,添加har包到要集成的libs文件夹内
在entry的gradle内添加如下代码
implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
allprojects{
repositories{
mavenCentral()
}
}
implementation "com.gitee.archermind-ti:viabus-architecture:1.0.3-beta"
implementation "com.gitee.archermind-ti:viabus-core:1.0.3-beta"
public interface INoteRequest extends IRequest{
void queryList();
void insert(NoteBean bean);
...
}
2.定义 bus,用于支持请求接口的访问。 bus 须继承于BaseBus,如:
public class NoteBus extends BaseBus {
public static INoteRequest note() {
return (INoteRequest) getRequest(INoteRequest.class);
}
...
}
3.将 ui 注册成为响应接收者。 在 ui 中,通过 bus 发送数据请求。并在 onResult 中,依据响应码实现 ui 逻辑的处理
public class TodoListSlice extends BaseBusSlice {
@Override
public void onStart(Intent intent) {
...
// 注册监听
NoteBus.registerResponseObserver(this);
NoteBus.note().queryList();
}
@Override
public void onResultHandle(Result testResult) {
String resultCode = (String) testResult.getResultCode();
switch (resultCode) {
case NoteResultCode.QUERY_LIST:
if (testResult.getResultObject() != null) {
setList((List<NoteBean>) testResult.getResultObject());
mAdapter.notifyDataSetItemRangeChanged(0, mList.size());
}
break;
case NoteResultCode.INSERTED:
if (testResult.getResultObject() != null) {
mList.add(0, (NoteBean) testResult.getResultObject());
mAdapter.notifyDataSetItemInserted(0);
}
break;
...
}
}
}
4.在模块的管理类中,将 业务 注册成为请求处理者。
public class MainAbility extends BaseBusAbility{
@Override
protected void onStart(Intent intent) {
...
initBusiness();
}
private void initBusiness() {
mNoteBusiness = new NoteBusiness();
mNoteBusiness.init(MainAbility.this);
NoteBus.registerRequestHandler(mNoteBusiness);
}
}
public class NoteBusiness extends BaseBusiness<NoteBus> implements INoteRequest {
@Override
public void queryList() {
handleRequest(new IAsync() {
@Override
public Result onExecute(ObservableEmitter<Result> e) throws IOException {
OrmPredicates query = ormContext.where(NoteBean.class);
List<NoteBean> list = ormContext.query(query);
return new Result(NoteResultCode.QUERY_LIST, list);
}
});
}
@Override
public void insert(NoteBean bean) {
handleRequest((e) -> { ... });
}
...
}
由于权限暂未提供USE_SIP和PROCESS_OUTGOING_CALLS替换项,所以目前未实现相关权限判断,此功能非库的主要功能。
RxJava
Copyright 2018 KunMinX
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.