mirror of
https://github.com/WuXiaolong/AndroidMVPSample.git
synced 2025-12-20 10:35:41 +08:00
update
This commit is contained in:
@@ -1,33 +1,37 @@
|
||||
package com.wuxiaolong.androidmvpsample.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
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.MainModelBean;
|
||||
import com.wuxiaolong.androidmvpsample.mvp.main.MainModel;
|
||||
import com.wuxiaolong.androidmvpsample.mvp.main.MainPresenter;
|
||||
import com.wuxiaolong.androidmvpsample.mvp.main.MainView;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by WuXiaolong on 2015/9/23.
|
||||
* 由Activity/Fragment实现View里方法,包含一个Presenter的引用
|
||||
*/
|
||||
public class MainActivity extends MvpActivity<MainPresenter> implements MainView {
|
||||
private ProgressBar mProgressBar;
|
||||
private TextView text;
|
||||
private MainPresenter mMainPresenter;
|
||||
private Handler mHandler = new Handler();
|
||||
|
||||
@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);
|
||||
initView();
|
||||
|
||||
ButterKnife.bind(this);
|
||||
//请求接口
|
||||
mvpPresenter.loadData("101010100");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -36,44 +40,30 @@ public class MainActivity extends MvpActivity<MainPresenter> implements MainView
|
||||
}
|
||||
|
||||
|
||||
private void initView() {
|
||||
text = (TextView) findViewById(R.id.text);
|
||||
mProgressBar = (ProgressBar) findViewById(R.id.mProgressBar);
|
||||
mMainPresenter = new MainPresenter(this);
|
||||
//制造延迟效果
|
||||
mHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mMainPresenter.loadData();
|
||||
}
|
||||
}, 2000);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mHandler.removeCallbacksAndMessages(null);
|
||||
mMainPresenter.detachView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showData(MainModelBean mainModelBean) {
|
||||
String showData = getResources().getString(R.string.city) + mainModelBean.getCity()
|
||||
+ getResources().getString(R.string.wd) + mainModelBean.getWd()
|
||||
+ getResources().getString(R.string.ws) + mainModelBean.getWs()
|
||||
+ getResources().getString(R.string.time) + mainModelBean.getTime();
|
||||
public void getDataSuccess(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 getDataFail(String msg) {
|
||||
toastShow("网络不给力");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showProgress() {
|
||||
public void showLoading() {
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideProgress() {
|
||||
public void hideLoading() {
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user