mirror of
https://github.com/WuXiaolong/AndroidMVPSample.git
synced 2025-06-07 05:44:37 +08:00
77 lines
2.2 KiB
Java
77 lines
2.2 KiB
Java
package com.wuxiaolong.androidmvpsample.ui;
|
||
|
||
import android.os.Bundle;
|
||
import android.os.Handler;
|
||
import android.support.v7.app.AppCompatActivity;
|
||
import android.view.View;
|
||
import android.widget.ProgressBar;
|
||
import android.widget.TextView;
|
||
|
||
import com.wuxiaolong.androidmvpsample.R;
|
||
import com.wuxiaolong.androidmvpsample.model.MainModelBean;
|
||
import com.wuxiaolong.androidmvpsample.presenter.MainPresenter;
|
||
import com.wuxiaolong.androidmvpsample.view.MainView;
|
||
|
||
/**
|
||
* Created by WuXiaolong on 2015/9/23.
|
||
* 由Activity/Fragment实现View里方法,包含一个Presenter的引用
|
||
*/
|
||
public class MainActivity extends AppCompatActivity implements MainView {
|
||
private ProgressBar mProgressBar;
|
||
private TextView text;
|
||
private MainPresenter mMainPresenter;
|
||
private Handler mHandler = new Handler();
|
||
|
||
@Override
|
||
protected void onCreate(Bundle savedInstanceState) {
|
||
super.onCreate(savedInstanceState);
|
||
setContentView(R.layout.activity_main);
|
||
initView();
|
||
|
||
}
|
||
|
||
|
||
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();
|
||
text.setText(showData);
|
||
}
|
||
|
||
|
||
@Override
|
||
public void showProgress() {
|
||
mProgressBar.setVisibility(View.VISIBLE);
|
||
}
|
||
|
||
@Override
|
||
public void hideProgress() {
|
||
mProgressBar.setVisibility(View.GONE);
|
||
}
|
||
|
||
|
||
}
|