我正在开发一个使用干净架构的应用程序。在演示者中,当涉及到方法 onCompleted 时,我必须从 Main 活动中调用函数。这是我的主持人:
public class CheckInPresenter implements Presenter {
UseCase postCheckInUseCase;
Context context;
@Inject
CheckInPresenter(@Named("putCheckIn") UseCase postCheckInUseCase){
this.postCheckInUseCase = postCheckInUseCase;
}
public void initialize(){this.initializeCheckIn();}
public void initializeCheckIn(){this.putCheckIn();}
public void putCheckIn(){
this.postCheckInUseCase.execute(new CheckInSubscriber());
}
@Override
public void resume() {
}
@Override
public void pause() {
}
@Override
public void destroy() {
}
private final class CheckInSubscriber extends DefaultSubscriber<EventEntity>{
@Override
public void onCompleted() {
Log.d("onCompleted", "OnCompleted");
}
@Override
public void onError(Throwable e) {
Log.d("onError", "OnError: " + e.getMessage());
}
@Override
public void onNext(EventEntity eventEntity) {
Log.d("onNext", "OnNext");
}
}
}
这是我必须调用的 MainActivity 函数:
public void getDataForToolbar() {
SharedPreferences sharedPreferences = getSharedPreferences(getResources().getString(R.string.Account_json), Context.MODE_PRIVATE);
final String account = sharedPreferences.getString(getResources().getString(R.string.account_json), null);
if (account != null) {
Gson gson = new Gson();
mAccount = gson.fromJson(account, AccountModel.class);
for (CompanyModel com : mAccount.getCompanies()) {
String name = com.getName();
company_name.setText(name);
logo_url = com.getLogo_url();
}
if (logo_url == null || logo_url.isEmpty()) {
Picasso
.with(this)
.load(R.drawable.default_company)
.resize(70, 58)
.transform(new RoundedTransformation(8, 0))
.into(toolbarImage);
} else {
picassoLoader(this, toolbarImage, logo_url);
}
String username = mAccount.getUsername();
if(mAccount.getStatus()){
aUsername.setText(username + "/" + getResources().getString(R.string.on_duty));
aUsername.setBackgroundColor(ContextCompat.getColor(mContext, R.color.colorGreen));
}else{
aUsername.setText(username + "/" + getResources().getString(R.string.off_duty));
aUsername.setBackgroundColor(ContextCompat.getColor(mContext, R.color.colorWhite));
}
}
}
有人可以帮助我如何在 Presenter 中将此函数调用到我的 onCompleted 方法中吗?提前致谢。