mirror of
https://github.com/WuXiaolong/AndroidMVPSample.git
synced 2025-12-20 10:35:41 +08:00
update
This commit is contained in:
@@ -2,17 +2,18 @@ package com.wuxiaolong.androidmvpsample.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.wuxiaolong.androidmvpsample.R;
|
||||
import com.wuxiaolong.androidmvpsample.mvp.MvpActivity;
|
||||
import com.wuxiaolong.androidmvpsample.mvp.main.MainModel;
|
||||
import com.wuxiaolong.androidmvpsample.mvp.main.MainPresenter;
|
||||
import com.wuxiaolong.androidmvpsample.mvp.main.MainView;
|
||||
import com.wuxiaolong.androidmvpsample.mvp.other.MvpActivity;
|
||||
import com.wuxiaolong.androidmvpsample.retrofit.ApiCallback;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
||||
/**
|
||||
* 由Activity/Fragment实现View里方法,包含一个Presenter的引用
|
||||
@@ -27,16 +28,14 @@ public class MainActivity extends MvpActivity<MainPresenter> implements MainView
|
||||
|
||||
@Bind(R.id.text)
|
||||
TextView text;
|
||||
@Bind(R.id.mProgressBar)
|
||||
ProgressBar mProgressBar;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
ButterKnife.bind(this);
|
||||
//请求接口
|
||||
mvpPresenter.loadData("101010100");
|
||||
initToolBarAsHome("MVP+Retrofit+Rxjava");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,13 +63,53 @@ public class MainActivity extends MvpActivity<MainPresenter> implements MainView
|
||||
|
||||
@Override
|
||||
public void showLoading() {
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
showProgressDialog();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideLoading() {
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
dismissProgressDialog();
|
||||
}
|
||||
|
||||
|
||||
@OnClick({R.id.button1, R.id.button2})
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.button1:
|
||||
loadData();
|
||||
break;
|
||||
case R.id.button2:
|
||||
//请求接口
|
||||
mvpPresenter.loadData("101310222");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//全国+国外主要城市代码http://mobile.weather.com.cn/js/citylist.xml
|
||||
private void loadData() {
|
||||
showProgressDialog();
|
||||
addSubscription(apiStores.loadData("101190201"),
|
||||
new ApiCallback<MainModel>() {
|
||||
@Override
|
||||
public void onSuccess(MainModel model) {
|
||||
MainModel.WeatherinfoBean weatherinfo = model.getWeatherinfo();
|
||||
String showData = getResources().getString(R.string.city) + weatherinfo.getCity()
|
||||
+ getResources().getString(R.string.wd) + weatherinfo.getWD()
|
||||
+ getResources().getString(R.string.ws) + weatherinfo.getWS()
|
||||
+ getResources().getString(R.string.time) + weatherinfo.getTime();
|
||||
text.setText(showData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int code, String msg) {
|
||||
toastShow(msg);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
dismissProgressDialog();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user