mirror of
https://github.com/WuXiaolong/AndroidMVPSample.git
synced 2025-12-24 03:09:33 +08:00
update
This commit is contained in:
@@ -2,25 +2,14 @@ package com.wuxiaolong.androidmvpsample.ui;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.smlxt.lxts.R;
|
||||
import com.smlxt.lxts.ui.login.LoginActivity;
|
||||
import com.smlxt.lxts.utils.ActivityManager;
|
||||
import com.smlxt.lxts.utils.AppConstants;
|
||||
import com.smlxt.lxts.utils.LogUtil;
|
||||
import com.smlxt.lxts.utils.SharedPreferencesUtil;
|
||||
import com.smlxt.lxts.view.CustomLoading;
|
||||
import com.umeng.analytics.MobclickAgent;
|
||||
import com.wuxiaolong.androidmvpsample.R;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import rx.Subscription;
|
||||
@@ -31,14 +20,7 @@ import rx.subscriptions.CompositeSubscription;
|
||||
*/
|
||||
public class BaseFragment extends Fragment {
|
||||
public Activity mActivity;
|
||||
public String TAG = "wxl";
|
||||
public ProgressDialog progressDialog;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_base, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
@@ -55,11 +37,6 @@ public class BaseFragment extends Fragment {
|
||||
}
|
||||
|
||||
|
||||
// @Override
|
||||
// public void onDestroy() {
|
||||
// super.onDestroy();
|
||||
// Log.d(TAG, mActivity + "=onDestroy");
|
||||
// }
|
||||
public void toastShow(int resId) {
|
||||
Toast.makeText(mActivity, resId, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
@@ -68,47 +45,6 @@ public class BaseFragment extends Fragment {
|
||||
Toast.makeText(mActivity, resId, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
CustomLoading customLoading;
|
||||
|
||||
public CustomLoading showProgressDialog() {
|
||||
// progressDialog = new ProgressDialog(mActivity);
|
||||
// progressDialog.setMessage("加载中");
|
||||
// progressDialog.show();
|
||||
// return progressDialog;
|
||||
customLoading = new CustomLoading(mActivity, R.style.CustomDialog);
|
||||
customLoading.show();
|
||||
return customLoading;
|
||||
}
|
||||
|
||||
public void dismissProgressDialog() {
|
||||
if (customLoading != null && customLoading.isShowing()) {
|
||||
customLoading.dismiss();
|
||||
}
|
||||
// if (progressDialog != null && progressDialog.isShowing()) {
|
||||
// progressDialog.dismiss();// progressDialog.hide();会导致android.view.WindowLeaked
|
||||
// }
|
||||
}
|
||||
|
||||
public void startLogin() {
|
||||
toastShow("登陆超时,请重新登录");
|
||||
SharedPreferencesUtil.setString(mActivity, AppConstants.USER_PASSWORD, "");
|
||||
ActivityManager.getInstance().finishAllActivity();
|
||||
mActivity.startActivity(new Intent(mActivity, LoginActivity.class));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
LogUtil.d("BaseFragment onResume=" + this.getClass().getSimpleName());
|
||||
MobclickAgent.onPageStart(this.getClass().getSimpleName()); //统计页面,"MainScreen"为页面名称,可自定义
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
MobclickAgent.onPageEnd(this.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
@@ -119,8 +55,9 @@ public class BaseFragment extends Fragment {
|
||||
private CompositeSubscription mCompositeSubscription;
|
||||
|
||||
public void onUnsubscribe() {
|
||||
//取消注册,以避免内存泄露
|
||||
if (mCompositeSubscription != null) {
|
||||
mCompositeSubscription.unsubscribe();//取消注册,以避免内存泄露
|
||||
mCompositeSubscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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