public Observable<PluginInfo> loadPlugin(@NonNull final String pluginName) {
return fetchPluginInfo(pluginName).flatMap(
new Function<PluginInfo, ObservableSource<HomePluginConfigInfo>>() {
@Override public ObservableSource<HomePluginConfigInfo> apply(PluginInfo info) {
return info == null ? getDownloadPluginInfo(pluginName)
: getUpdatePluginInfo(pluginName, info);
}
}).flatMap(new Function<HomePluginConfigInfo, ObservableSource<File>>() {
@Override public ObservableSource<File> apply(HomePluginConfigInfo homePluginConfigInfo) {
//下载插件
return downloadPlugin(homePluginConfigInfo.mPluginUrl, homePluginConfigInfo.mLocalPath);
}
}).observeOn(Schedulers.io()).flatMap(new Function<File, ObservableSource<PluginInfo>>() {
@Override public ObservableSource<PluginInfo> apply(File file) {
//插件的安装
return installPlugin(file.getAbsolutePath());
}
}).doOnNext(new Consumer<PluginInfo>() {
@Override public void accept(PluginInfo pluginInfo) {
//插件预加载
if (pluginInfo != null) preLoadPlugin(pluginInfo);
}
});
}