使用Moxy库实现MVP时遇到困难。我阅读了Moxy的github页面和检查过的示例,但是任何解决方案都无济于事。
在MyFragment中,未调用MyFragmentView方法的回调,但在MyFragmentPresenter中,getViewState()返回的值不为null。
我是说
kendo.toString(10.12, "n5"); //10.12000
在MyPresenter中被调用,但在MyFragment中
getViewState().showProgressDialog();
getViewState().setAccounts(accountsResponse);
getViewState().hideProgressDialog();
未呼叫。
请帮助,怎么了?
我的下面的代码。
成绩
@Override
public void showProgressDialog() {
// some code
}
@Override
public void hideProgressDialog() {
// some code
}
@Override
public void setAccounts(AccountsResponse accounts) {
// some code
}
MyFragmentView
compile 'com.arello-mobile:moxy:1.5.5'
compile 'com.arello-mobile:moxy-app-compat:1.5.5'
compile 'com.arello-mobile:moxy-android:1.5.5'
annotationProcessor 'com.arello-mobile:moxy-compiler:1.5.5'
MyFragmentPresenter
@StateStrategyType(AddToEndSingleStrategy.class)
public interface MyFragmentView extends MvpView {
void showProgressDialog();
void hideProgressDialog();
void showTextTestMessage(String s);
void showCouldNotRetrieveAccounts();
}
MyFragment
@PerFragment
@InjectViewState
public class MyFragmentPresenter extends MvpPresenter<MyFragmentView> {
private ApiService apiService;
@Inject
public MyFragmentPresenter(ApiService apiService) {
this.apiService = apiService;
}
public void getAccounts() {
getViewState().showProgressDialog();
getCompositeDisposable().add(apiService.getAccounts()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.map(accountsResponse -> {
if (accountsResponse.err_code != 0) {
throw new LogicException(accountsResponse.message);
}
return accountsResponse;
})
.subscribe(
accountsResponse -> {
getViewState().setAccounts(accountsResponse);
getViewState().hideProgressDialog();
},
throwable -> {
getViewState().hideProgressDialog();
getViewState().showCouldNotRetrieveAccounts();
}
)
);
}
}
** MyFragmentPagerAdapter **
public class MyFragment extends MvpAppCompatFragment implements MyFragmentView {
@Inject
@InjectPresenter
public MyFragmentPresenter mPresenter;
@ProvidePresenter
public MyFragmentPresenter providePresenter() {
return mPresenter;
}
@Override
public void onActivityCreated (@Nullable Bundle savedInstanceState){
ComponentManager.getInstance().getActivityComponent(getActivity()).inject((MyActivity) getActivity());
super.onActivityCreated(savedInstanceState);
mPresenter.getAccounts();
}
@Override
public void showProgressDialog() {
// some code
}
@Override
public void hideProgressDialog() {
// some code
}
@Override
public void setAccounts(AccountsResponse accounts) {
// some code
}
@Override
public void showCouldNotRetrieveBankAccounts() {
// some code
}
}
答案 0 :(得分:0)
我认为将匕首与moxy连接出现了问题。 在GitHub上检查以下问题: https://github.com/Arello-Mobile/Moxy/issues/100
人们在那里解决了同样的问题