以类Retrofit的形式,获取Assets目录的数据。
添加依赖
- 添加仓库到根build.gradle
allprojects { repositories { ... maven { url 'https://jitpack.io' } } }
- 添加依赖
dependencies { implementation 'com.github.wangmingshuo:rsm:0.1.3' }
Rsm.init(this);
Rsm.get().addCallAdapterFactory(RxJava2CallAdapterFactory.create());
Rsm.get().addCallAdapterFactory(ObjectCallAdapterFactory.create());
Rsm.get().addConverterFactory(GsonConverterFactory.create());
和Retrofit方法一样,先定义Service
public interface AssetService {
@AssetName("test.json")
List<TestBean> test();
}
调用方法
List<TestBean> list = Rsm.getInstance().create(AssetService.class).test();
支持RxJava2返回类型
public interface AssetService {
@AssetName("test.json")
Observable<List<TestBean>> testAsync();
}