|
|
@@ -2,9 +2,9 @@ package com.miekir.newmvp.main.presenter;
|
|
|
|
|
|
import com.miekir.common.utils.LogTool;
|
|
|
import com.miekir.mvp.presenter.BasePresenter;
|
|
|
-import com.miekir.newmvp.main.bean.MainBean;
|
|
|
import com.miekir.newmvp.main.model.IMainModel;
|
|
|
-import com.miekir.newmvp.main.model.MainModel;
|
|
|
+import com.miekir.newmvp.main.model.MainFileModel;
|
|
|
+import com.miekir.newmvp.main.model.MainNetModel;
|
|
|
import com.miekir.newmvp.main.view.IMainView;
|
|
|
|
|
|
import io.reactivex.Observable;
|
|
|
@@ -21,23 +21,45 @@ import io.reactivex.schedulers.Schedulers;
|
|
|
* Description:
|
|
|
*/
|
|
|
public class MainPresenter extends BasePresenter<IMainView> {
|
|
|
- // todo 在BasePresenter中注入Model
|
|
|
+ public static final int REPO_NET = 1;
|
|
|
+ public static final int REPO_FILE = 2;
|
|
|
private IMainModel mMainModel;
|
|
|
|
|
|
+ /**
|
|
|
+ * 设置当前仓库
|
|
|
+ * @param repository 仓库
|
|
|
+ */
|
|
|
+ public void setRepository(int repository) {
|
|
|
+ switch (repository) {
|
|
|
+ case REPO_NET:
|
|
|
+ mMainModel = new MainNetModel();
|
|
|
+ break;
|
|
|
+ case REPO_FILE:
|
|
|
+ mMainModel = new MainFileModel();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void onInit() {
|
|
|
- mMainModel = new MainModel();
|
|
|
+ mMainModel = new MainNetModel();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 让具体的Model去执行任务
|
|
|
+ */
|
|
|
public void getData() {
|
|
|
- mMainModel.goGetData(new IMainModel.IDataCallback() {
|
|
|
- @Override
|
|
|
- public void onDataGet(MainBean bean) {
|
|
|
-
|
|
|
- }
|
|
|
+ mMainModel.goGetData(bean -> {
|
|
|
+ // 执行完毕,回调
|
|
|
+ getCallbackView().onMainResult();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 直接在Presenter执行任务
|
|
|
+ */
|
|
|
public void doWork() {
|
|
|
Disposable disposable = Observable.create((ObservableOnSubscribe<String>) emitter -> {
|
|
|
try {
|