mirror of
https://github.com/WuXiaolong/AndroidMVPSample.git
synced 2025-06-06 21:34:04 +08:00
add
This commit is contained in:
parent
b0925459b2
commit
64ebcd133f
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/workspace.xml
|
||||
|
6
.idea/gradle.xml
generated
6
.idea/gradle.xml
generated
@ -12,6 +12,12 @@
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="myModules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
</set>
|
||||
</option>
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
|
@ -2,12 +2,12 @@ apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 23
|
||||
buildToolsVersion "22.0.1"
|
||||
buildToolsVersion "23.0.2"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.wuxiaolong.androidmvpsample"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 23
|
||||
targetSdkVersion 22
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
}
|
||||
@ -21,6 +21,13 @@ android {
|
||||
|
||||
dependencies {
|
||||
compile fileTree(include: ['*.jar'], dir: 'libs')
|
||||
compile 'com.android.support:appcompat-v7:23.0.1'
|
||||
compile 'com.android.support:appcompat-v7:23.3.0'
|
||||
compile 'com.loopj.android:android-async-http:1.4.9'
|
||||
compile 'com.jakewharton:butterknife:7.0.1'
|
||||
compile 'com.squareup.retrofit2:retrofit:2.0.2'
|
||||
compile 'com.squareup.okhttp3:logging-interceptor:3.1.2'
|
||||
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
|
||||
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
|
||||
compile 'io.reactivex:rxandroid:1.1.0'
|
||||
compile 'io.reactivex:rxjava:1.1.0'
|
||||
}
|
||||
|
@ -1,52 +0,0 @@
|
||||
package com.wuxiaolong.androidmvpsample.model;
|
||||
|
||||
import com.loopj.android.http.AsyncHttpClient;
|
||||
import com.loopj.android.http.JsonHttpResponseHandler;
|
||||
import com.wuxiaolong.androidmvpsample.presenter.IMainPresenter;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import cz.msebera.android.httpclient.Header;
|
||||
|
||||
/**
|
||||
* Created by WuXiaolong on 2015/9/23.
|
||||
* 业务具体处理,包括负责存储、检索、操纵数据等
|
||||
*/
|
||||
public class MainModel {
|
||||
private IMainPresenter mIMainPresenter;
|
||||
|
||||
public MainModel(IMainPresenter iMainPresenter) {
|
||||
this.mIMainPresenter = iMainPresenter;
|
||||
}
|
||||
|
||||
public void loadData() {
|
||||
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
|
||||
asyncHttpClient.get("http://www.weather.com.cn/adat/sk/101010100.html", new JsonHttpResponseHandler() {
|
||||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
|
||||
super.onSuccess(statusCode, headers, response);
|
||||
try {
|
||||
MainModelBean mainModelBean = new MainModelBean();
|
||||
JSONObject weatherinfo = response.getJSONObject("weatherinfo");
|
||||
mainModelBean.setCity(weatherinfo.getString("city"));
|
||||
mainModelBean.setWd(weatherinfo.getString("WD"));
|
||||
mainModelBean.setWs(weatherinfo.getString("WS"));
|
||||
mainModelBean.setTime(weatherinfo.getString("time"));
|
||||
mIMainPresenter.loadDataSuccess(mainModelBean);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
|
||||
super.onFailure(statusCode, headers, throwable, errorResponse);
|
||||
mIMainPresenter.loadDataFailure();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.wuxiaolong.androidmvpsample.mvp;
|
||||
|
||||
import com.wuxiaolong.androidmvpsample.retrofit.ApiStores;
|
||||
import com.wuxiaolong.androidmvpsample.retrofit.AppClient;
|
||||
|
||||
/**
|
||||
* Created by WuXiaolong on 2016/3/30.
|
||||
*/
|
||||
public class BasePresenter<V> implements Presenter<V> {
|
||||
public ApiStores apiStores = AppClient.retrofit().create(ApiStores.class);
|
||||
public V mvpView;
|
||||
|
||||
@Override
|
||||
public void attachView(V mvpView) {
|
||||
this.mvpView = mvpView;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void detachView() {
|
||||
this.mvpView = null;
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.wuxiaolong.androidmvpsample.mvp;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.wuxiaolong.androidmvpsample.ui.BaseActivity;
|
||||
|
||||
|
||||
public abstract class MvpActivity<P extends BasePresenter> extends BaseActivity {
|
||||
protected P mvpPresenter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
mvpPresenter = createPresenter();
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
protected abstract P createPresenter();
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (mvpPresenter != null) {
|
||||
mvpPresenter.detachView();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.wuxiaolong.androidmvpsample.mvp;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.View;
|
||||
|
||||
import com.wuxiaolong.androidmvpsample.ui.BaseFragment;
|
||||
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
*/
|
||||
public abstract class MvpFragment<P extends BasePresenter> extends BaseFragment {
|
||||
|
||||
protected P mvpPresenter;
|
||||
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
mvpPresenter = createPresenter();
|
||||
}
|
||||
|
||||
protected abstract P createPresenter();
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
if (mvpPresenter != null) {
|
||||
mvpPresenter.detachView();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.wuxiaolong.androidmvpsample.presenter;
|
||||
package com.wuxiaolong.androidmvpsample.mvp;
|
||||
|
||||
public interface Presenter<V> {
|
||||
|
@ -1,6 +1,4 @@
|
||||
package com.wuxiaolong.androidmvpsample.presenter;
|
||||
|
||||
import com.wuxiaolong.androidmvpsample.model.MainModelBean;
|
||||
package com.wuxiaolong.androidmvpsample.mvp.main;
|
||||
|
||||
/**
|
||||
* Created by WuXiaolong on 2015/9/23.
|
@ -0,0 +1,53 @@
|
||||
package com.wuxiaolong.androidmvpsample.mvp.main;
|
||||
|
||||
/**
|
||||
* Created by WuXiaolong on 2015/9/23.
|
||||
* 业务具体处理,包括负责存储、检索、操纵数据等
|
||||
*/
|
||||
public class MainModel {
|
||||
private String city;
|
||||
private String wd;
|
||||
private String ws;
|
||||
private String time;
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getWd() {
|
||||
return wd;
|
||||
}
|
||||
|
||||
public void setWd(String wd) {
|
||||
this.wd = wd;
|
||||
}
|
||||
|
||||
public String getWs() {
|
||||
return ws;
|
||||
}
|
||||
|
||||
public void setWs(String ws) {
|
||||
this.ws = ws;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(String time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
private IMainPresenter mIMainPresenter;
|
||||
|
||||
public MainModel(IMainPresenter iMainPresenter) {
|
||||
this.mIMainPresenter = iMainPresenter;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.wuxiaolong.androidmvpsample.model;
|
||||
package com.wuxiaolong.androidmvpsample.mvp.main;
|
||||
|
||||
/**
|
||||
* Created by WuXiaolong on 2015/9/23.
|
@ -0,0 +1,20 @@
|
||||
package com.wuxiaolong.androidmvpsample.mvp.main;
|
||||
|
||||
import com.wuxiaolong.androidmvpsample.mvp.BasePresenter;
|
||||
|
||||
/**
|
||||
* Created by WuXiaolong on 2015/9/23.
|
||||
* View和Model的桥梁,它从Model层检索数据后,返回给View层
|
||||
*/
|
||||
public class MainPresenter extends BasePresenter {
|
||||
|
||||
public MainPresenter(MainView view) {
|
||||
attachView(view);
|
||||
}
|
||||
|
||||
|
||||
public void loadData() {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,13 +1,14 @@
|
||||
package com.wuxiaolong.androidmvpsample.view;
|
||||
|
||||
import com.wuxiaolong.androidmvpsample.model.MainModelBean;
|
||||
package com.wuxiaolong.androidmvpsample.mvp.main;
|
||||
|
||||
/**
|
||||
* Created by WuXiaolong on 2015/9/23.
|
||||
* 处理业务需要哪些方法
|
||||
*/
|
||||
public interface MainView {
|
||||
void showData(MainModelBean mainModelBean);
|
||||
|
||||
void getDataSuccess(MainModel model);
|
||||
|
||||
void getDataFail(String msg);
|
||||
|
||||
void showProgress();
|
||||
|
@ -1,46 +0,0 @@
|
||||
package com.wuxiaolong.androidmvpsample.presenter;
|
||||
|
||||
import com.wuxiaolong.androidmvpsample.model.MainModel;
|
||||
import com.wuxiaolong.androidmvpsample.model.MainModelBean;
|
||||
import com.wuxiaolong.androidmvpsample.view.MainView;
|
||||
|
||||
/**
|
||||
* Created by WuXiaolong on 2015/9/23.
|
||||
* View和Model的桥梁,它从Model层检索数据后,返回给View层
|
||||
*/
|
||||
public class MainPresenter implements Presenter<MainView>, IMainPresenter {
|
||||
private MainView mMainView;
|
||||
private MainModel mMainModel;
|
||||
|
||||
public MainPresenter(MainView view) {
|
||||
attachView(view);
|
||||
mMainModel = new MainModel(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachView(MainView view) {
|
||||
this.mMainView = view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachView() {
|
||||
this.mMainView = null;
|
||||
}
|
||||
|
||||
public void loadData() {
|
||||
mMainView.showProgress();
|
||||
mMainModel.loadData();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void loadDataSuccess(MainModelBean mainModelBean) {
|
||||
mMainView.showData(mainModelBean);
|
||||
mMainView.hideProgress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDataFailure() {
|
||||
mMainView.hideProgress();
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.wuxiaolong.androidmvpsample.retrofit;
|
||||
|
||||
/**
|
||||
* Created by WuXiaolong
|
||||
* on 2016/3/24.
|
||||
*/
|
||||
public interface ApiStores {
|
||||
String API_SERVER_URL = "http://www.smlxt.com/supplier/supplier/app/";
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.wuxiaolong.androidmvpsample.retrofit;
|
||||
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
/**
|
||||
* Created by WuXiaolong
|
||||
* on 2016/3/24.
|
||||
*/
|
||||
public class AppClient {
|
||||
public static Retrofit mRetrofit;
|
||||
|
||||
public static Retrofit retrofit() {
|
||||
if (mRetrofit == null) {
|
||||
mRetrofit = new Retrofit.Builder()
|
||||
.baseUrl(ApiStores.API_SERVER_URL)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
|
||||
.build();
|
||||
}
|
||||
return mRetrofit;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,128 @@
|
||||
package com.wuxiaolong.androidmvpsample.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.wuxiaolong.androidmvpsample.R;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import rx.Subscription;
|
||||
import rx.subscriptions.CompositeSubscription;
|
||||
|
||||
public class BaseActivity extends AppCompatActivity {
|
||||
public Activity mActivity;
|
||||
|
||||
@Override
|
||||
public void setContentView(@LayoutRes int layoutResID) {
|
||||
super.setContentView(layoutResID);
|
||||
ButterKnife.bind(this);
|
||||
mActivity = this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setContentView(View view) {
|
||||
super.setContentView(view);
|
||||
ButterKnife.bind(this);
|
||||
mActivity = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentView(View view, ViewGroup.LayoutParams params) {
|
||||
super.setContentView(view, params);
|
||||
ButterKnife.bind(this);
|
||||
mActivity = this;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
onUnsubscribe();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
private CompositeSubscription mCompositeSubscription;
|
||||
|
||||
public void onUnsubscribe() {
|
||||
if (mCompositeSubscription != null) {
|
||||
mCompositeSubscription.unsubscribe();//取消注册,以避免内存泄露
|
||||
}
|
||||
}
|
||||
|
||||
public void addSubscription(Subscription subscription) {
|
||||
// if (mCompositeSubscription == null) {
|
||||
mCompositeSubscription = new CompositeSubscription();
|
||||
// }
|
||||
mCompositeSubscription.add(subscription);
|
||||
}
|
||||
|
||||
public Toolbar initToolBar(String title) {
|
||||
|
||||
Toolbar toolbar = initToolBar();
|
||||
TextView toolbar_title = (TextView) toolbar.findViewById(R.id.toolbar_title);
|
||||
toolbar_title.setText(title);
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
}
|
||||
return toolbar;
|
||||
}
|
||||
|
||||
public Toolbar initToolBar(int title) {
|
||||
Toolbar toolbar = initToolBar();
|
||||
TextView toolbar_title = (TextView) toolbar.findViewById(R.id.toolbar_title);
|
||||
toolbar_title.setText(title);
|
||||
return toolbar;
|
||||
}
|
||||
|
||||
public Toolbar initToolBar() {
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setDisplayShowTitleEnabled(false);
|
||||
}
|
||||
return toolbar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
|
||||
case android.R.id.home:
|
||||
super.onBackPressed();//返回
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void toastShow(int resId) {
|
||||
Toast.makeText(mActivity, resId, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
public void toastShow(String resId) {
|
||||
Toast.makeText(mActivity, resId, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,133 @@
|
||||
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 butterknife.ButterKnife;
|
||||
import rx.Subscription;
|
||||
import rx.subscriptions.CompositeSubscription;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
*/
|
||||
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) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
ButterKnife.bind(this, view);
|
||||
mActivity = getActivity();
|
||||
}
|
||||
|
||||
public Toolbar initToolBar(View view, String title) {
|
||||
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
|
||||
TextView toolbar_title = (TextView) toolbar.findViewById(R.id.toolbar_title);
|
||||
toolbar_title.setText(title);
|
||||
return toolbar;
|
||||
}
|
||||
|
||||
|
||||
// @Override
|
||||
// public void onDestroy() {
|
||||
// super.onDestroy();
|
||||
// Log.d(TAG, mActivity + "=onDestroy");
|
||||
// }
|
||||
public void toastShow(int resId) {
|
||||
Toast.makeText(mActivity, resId, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
public void toastShow(String resId) {
|
||||
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() {
|
||||
super.onDestroy();
|
||||
onUnsubscribe();
|
||||
}
|
||||
|
||||
private CompositeSubscription mCompositeSubscription;
|
||||
|
||||
public void onUnsubscribe() {
|
||||
if (mCompositeSubscription != null) {
|
||||
mCompositeSubscription.unsubscribe();//取消注册,以避免内存泄露
|
||||
}
|
||||
}
|
||||
|
||||
public void addSubscription(Subscription subscription) {
|
||||
// if (mCompositeSubscription == null) {
|
||||
mCompositeSubscription = new CompositeSubscription();
|
||||
// }
|
||||
mCompositeSubscription.add(subscription);
|
||||
}
|
||||
}
|
@ -2,21 +2,21 @@ 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;
|
||||
import com.wuxiaolong.androidmvpsample.mvp.MvpActivity;
|
||||
import com.wuxiaolong.androidmvpsample.mvp.main.MainModelBean;
|
||||
import com.wuxiaolong.androidmvpsample.mvp.main.MainPresenter;
|
||||
import com.wuxiaolong.androidmvpsample.mvp.main.MainView;
|
||||
|
||||
/**
|
||||
* Created by WuXiaolong on 2015/9/23.
|
||||
* 由Activity/Fragment实现View里方法,包含一个Presenter的引用
|
||||
*/
|
||||
public class MainActivity extends AppCompatActivity implements MainView {
|
||||
public class MainActivity extends MvpActivity<MainPresenter> implements MainView {
|
||||
private ProgressBar mProgressBar;
|
||||
private TextView text;
|
||||
private MainPresenter mMainPresenter;
|
||||
@ -30,6 +30,11 @@ public class MainActivity extends AppCompatActivity implements MainView {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MainPresenter createPresenter() {
|
||||
return new MainPresenter(this);
|
||||
}
|
||||
|
||||
|
||||
private void initView() {
|
||||
text = (TextView) findViewById(R.id.text);
|
||||
|
16
app/src/main/res/layout/toolbar.xml
Normal file
16
app/src/main/res/layout/toolbar.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?actionBarSize">
|
||||
<!--android:paddingTop="@dimen/status_bar_height"-->
|
||||
|
||||
<TextView
|
||||
android:id="@+id/toolbar_title"
|
||||
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:textStyle="bold" />
|
||||
</android.support.v7.widget.Toolbar>
|
@ -1,8 +1,9 @@
|
||||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
@ -5,7 +5,7 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:1.3.0'
|
||||
classpath 'com.android.tools.build:gradle:2.1.0'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
|
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,6 @@
|
||||
#Wed Sep 23 14:57:22 CST 2015
|
||||
#Sat Jun 11 21:48:50 CST 2016
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
|
||||
|
Loading…
x
Reference in New Issue
Block a user