Skip to content

Commit 44988c0

Browse files
committed
+):新增MVP模式开发demo
1 parent e704d53 commit 44988c0

File tree

12 files changed

+351
-6
lines changed

12 files changed

+351
-6
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@
1010
android:theme="@style/AppTheme" >
1111

1212
<activity android:name=".MainActvity"
13-
android:label="主界面"
13+
android:label="@string/app_name"
1414
android:theme="@style/AppTheme">
1515
<intent-filter>
16-
<action android:name="android.intent.action.main"/>
17-
<category android:name="android.intent.category.launcher"/>
16+
<action android:name="android.intent.action.MAIN"/>
17+
<category android:name="android.intent.category.LAUNCHER"/>
1818
</intent-filter>
1919
</activity>
2020
<activity android:name="com.chinaztt.fda.test.GalleryIndicatorActivity"/>
2121
<activity android:name="com.chinaztt.fda.test.PullListviewActivity"/>
2222
<activity android:name="com.chinaztt.fda.test.SPCacheActivity"/>
2323
<activity android:name="com.chinaztt.fda.test.CrashTestActivity"/>
2424
<activity android:name="com.chinaztt.fda.test.TranslucentActivity"/>
25+
<activity android:name="com.chinaztt.fda.test.MVPTestActivity"/>
2526
</application>
2627
<!--添加权限-->
2728

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.chinaztt.fda.biz;
2+
3+
/**
4+
* 当前类注释:用户相关业务操作接口
5+
* 项目名:FastDev4Android
6+
* 包名:com.chinaztt.fda.biz
7+
* 作者:江清清 on 15/10/27 16:32
8+
* 邮箱:[email protected]
9+
* QQ: 781931404
10+
* 公司:江苏中天科技软件技术有限公司
11+
*/
12+
public interface IPersonBiz {
13+
14+
void login(String username,String password,LoginRequestCallBack valueCallBack);
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.chinaztt.fda.biz;
2+
3+
import com.chinaztt.fda.entity.PersonBean;
4+
/**
5+
* 当前类注释:登录请求结果回调
6+
* 项目名:FastDev4Android
7+
* 包名:com.chinaztt.fda.biz
8+
* 作者:江清清 on 15/10/27 19:50
9+
* 邮箱:[email protected]
10+
* QQ: 781931404
11+
* 公司:江苏中天科技软件技术有限公司
12+
*/
13+
public interface LoginRequestCallBack {
14+
//登录成功回调方法
15+
void loginSuccess(PersonBean personBean);
16+
//登录失败回调方法
17+
void loginFailed();
18+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.chinaztt.fda.biz.imp;
2+
3+
import com.chinaztt.fda.biz.IPersonBiz;
4+
import com.chinaztt.fda.biz.LoginRequestCallBack;
5+
import com.chinaztt.fda.entity.PersonBean;
6+
import com.chinaztt.fda.utils.Log;
7+
8+
/**
9+
* 当前类注释:用户相关业务逻辑实现类
10+
* 项目名:FastDev4Android
11+
* 包名:com.chinaztt.fda.biz.imp
12+
* 作者:江清清 on 15/10/27 16:33
13+
* 邮箱:[email protected]
14+
* QQ: 781931404
15+
* 公司:江苏中天科技软件技术有限公司
16+
*/
17+
public class PersonBizImp implements IPersonBiz{
18+
private static final String TAG="PersonBizImp";
19+
@Override
20+
public void login(final String username, final String password, final LoginRequestCallBack valueCallBack) {
21+
Log.d(TAG,"username:"+username+",password:"+password);
22+
new Thread(new Runnable() {
23+
@Override
24+
public void run() {
25+
try {
26+
Thread.sleep(4500);
27+
} catch (InterruptedException e) {
28+
e.printStackTrace();
29+
}
30+
//进行开始登录,这边应该进行请求服务器,进行数据验证
31+
if(username.equals("jiangqq")&&password.equals("12345")){
32+
valueCallBack.loginSuccess(new PersonBean(username,password));
33+
}else{
34+
valueCallBack.loginFailed();
35+
}
36+
}
37+
}).start();
38+
}
39+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.chinaztt.fda.entity;
2+
3+
/**
4+
* 当前类注释:用户信息实体类
5+
* 项目名:FastDev4Android
6+
* 包名:com.chinaztt.fda.entity
7+
* 作者:江清清 on 15/10/27 14:13
8+
* 邮箱:[email protected]
9+
* QQ: 781931404
10+
* 公司:江苏中天科技软件技术有限公司
11+
*/
12+
public class PersonBean {
13+
private String username;
14+
private String password;
15+
16+
public PersonBean() {
17+
}
18+
19+
public PersonBean(String username, String password) {
20+
this.username = username;
21+
this.password = password;
22+
}
23+
24+
public String getUsername() {
25+
return username;
26+
}
27+
28+
public void setUsername(String username) {
29+
this.username = username;
30+
}
31+
32+
public String getPassword() {
33+
return password;
34+
}
35+
36+
public void setPassword(String password) {
37+
this.password = password;
38+
}
39+
40+
@Override
41+
public String toString() {
42+
return "PersonBean{" +
43+
"username='" + username + '\'' +
44+
", password='" + password + '\'' +
45+
'}';
46+
}
47+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.chinaztt.fda.presenter;
2+
3+
import com.chinaztt.fda.biz.IPersonBiz;
4+
import com.chinaztt.fda.biz.LoginRequestCallBack;
5+
import com.chinaztt.fda.biz.imp.PersonBizImp;
6+
import com.chinaztt.fda.entity.PersonBean;
7+
import com.chinaztt.fda.ui.view.ILoginView;
8+
import com.chinaztt.fda.utils.Log;
9+
10+
/**
11+
* 当前类注释:负责完成登录界面View于Model(IPersonBiz)间的交互
12+
* 项目名:FastDev4Android
13+
* 包名:com.chinaztt.fda.presenter
14+
* 作者:江清清 on 15/10/27 16:36
15+
* 邮箱:[email protected]
16+
* QQ: 781931404
17+
* 公司:江苏中天科技软件技术有限公司
18+
*/
19+
public class LoginPresenter {
20+
private static final String TAG="LoginPresenter";
21+
private ILoginView mLoginView;
22+
private IPersonBiz mPersonBiz;
23+
public LoginPresenter(ILoginView view) {
24+
mLoginView = view;
25+
mPersonBiz = new PersonBizImp();
26+
}
27+
28+
public void loginSystem(){
29+
mPersonBiz.login(mLoginView.getUserName(), mLoginView.getPassword(), new LoginRequestCallBack() {
30+
/**
31+
* 登录成功
32+
* @param personBean
33+
*/
34+
@Override
35+
public void loginSuccess(PersonBean personBean) {
36+
Log.d(TAG,"登录成功:"+personBean.toString());
37+
mLoginView.showSuccessInfo(personBean);
38+
}
39+
40+
/**
41+
* 登录失败
42+
*/
43+
@Override
44+
public void loginFailed() {
45+
Log.d(TAG,"登录失败...");
46+
mLoginView.showFailedInfo();;
47+
}
48+
});
49+
}
50+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.chinaztt.fda.test;
2+
3+
import android.os.Bundle;
4+
import android.view.View;
5+
import android.widget.Button;
6+
import android.widget.EditText;
7+
8+
import com.chinaztt.fda.entity.PersonBean;
9+
import com.chinaztt.fda.presenter.LoginPresenter;
10+
import com.chinaztt.fda.ui.R;
11+
import com.chinaztt.fda.ui.base.BaseActivity;
12+
import com.chinaztt.fda.ui.view.ILoginView;
13+
import com.chinaztt.fda.utils.Log;
14+
15+
/**
16+
* 当前类注释:MVP开发模式实例
17+
* 项目名:FastDev4Android
18+
* 包名:com.chinaztt.fda.test
19+
* 作者:江清清 on 15/10/27 13:38
20+
* 邮箱:[email protected]
21+
* QQ: 781931404
22+
* 公司:江苏中天科技软件技术有限公司
23+
*/
24+
public class MVPTestActivity extends BaseActivity implements ILoginView{
25+
private static final String TAG="MVPTestActivity";
26+
27+
private EditText ed_username;
28+
private EditText ed_password;
29+
private Button btn_login;
30+
private LoginPresenter mLoginPresenter;
31+
@Override
32+
protected void onCreate(Bundle savedInstanceState) {
33+
super.onCreate(savedInstanceState);
34+
setContentView(R.layout.mvp_test_layout);
35+
ed_username=(EditText)this.findViewById(R.id.ed_username);
36+
ed_password=(EditText)this.findViewById(R.id.ed_password);
37+
btn_login=(Button)this.findViewById(R.id.btn_login);
38+
mLoginPresenter=new LoginPresenter(this);
39+
btn_login.setOnClickListener(new View.OnClickListener() {
40+
@Override
41+
public void onClick(View v) {
42+
mLoginPresenter.loginSystem();
43+
44+
}
45+
});
46+
}
47+
/**
48+
* 进行返回用户名信息
49+
* @return
50+
*/
51+
@Override
52+
public String getUserName() {
53+
return ed_username.getText().toString().trim();
54+
}
55+
/**
56+
* 进行返回用户密码信息
57+
* @return
58+
*/
59+
@Override
60+
public String getPassword() {
61+
return ed_password.getText().toString().trim();
62+
}
63+
/**
64+
* 登录成功 回调
65+
* @param personBean
66+
*/
67+
@Override
68+
public void showSuccessInfo(PersonBean personBean) {
69+
Log.d(TAG,"showSuccessInfo:"+personBean.toString());
70+
}
71+
/**
72+
* 登录失败 回调
73+
*/
74+
@Override
75+
public void showFailedInfo() {
76+
Log.d(TAG,"showFailedInfo...");
77+
}
78+
}

app/src/main/java/com/chinaztt/fda/ui/MainActvity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import com.chinaztt.fda.test.CrashTestActivity;
1717
import com.chinaztt.fda.test.GalleryIndicatorActivity;
18+
import com.chinaztt.fda.test.MVPTestActivity;
1819
import com.chinaztt.fda.test.PullListviewActivity;
1920
import com.chinaztt.fda.test.SPCacheActivity;
2021
import com.chinaztt.fda.test.TranslucentActivity;
@@ -40,7 +41,7 @@ protected void onCreate(Bundle savedInstanceState) {
4041
setContentView(R.layout.activity_main);
4142
mItems = this.getResources().getStringArray(R.array.main_list);
4243
mClassItems = new Class[]{GalleryIndicatorActivity.class, PullListviewActivity.class, SPCacheActivity.class, CrashTestActivity.class
43-
, TranslucentActivity.class};
44+
, TranslucentActivity.class,MVPTestActivity.class};
4445

4546
lv_main = (ListView) this.findViewById(R.id.lv_main);
4647
mInflater = getLayouInflater();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.chinaztt.fda.ui.view;
2+
3+
import com.chinaztt.fda.entity.PersonBean;
4+
5+
/**
6+
* 当前类注释:登录页面 相关操作 功能接口
7+
* 项目名:FastDev4Android
8+
* 包名:com.chinaztt.fda.ui.view
9+
* 作者:江清清 on 15/10/27 16:35
10+
* 邮箱:[email protected]
11+
* QQ: 781931404
12+
* 公司:江苏中天科技软件技术有限公司
13+
*/
14+
public interface ILoginView {
15+
//获取用户名
16+
String getUserName();
17+
//获取密码
18+
String getPassword();
19+
20+
void showSuccessInfo(PersonBean personBean);
21+
void showFailedInfo();
22+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent" android:layout_height="match_parent"
4+
android:orientation="vertical">
5+
6+
<LinearLayout
7+
android:layout_width="fill_parent"
8+
android:layout_height="49dp"
9+
android:background="#e7abff"
10+
android:gravity="center"
11+
android:orientation="horizontal">
12+
<TextView
13+
android:layout_width="wrap_content"
14+
android:layout_height="wrap_content"
15+
android:text="MVP开发模式实例"
16+
android:id="@+id/tv"
17+
android:textSize="16sp"
18+
android:textColor="@color/white"
19+
/>
20+
</LinearLayout>
21+
<LinearLayout
22+
android:layout_marginTop="50dp"
23+
android:layout_width="fill_parent"
24+
android:layout_height="45dp"
25+
android:orientation="horizontal"
26+
android:layout_marginRight="5dp"
27+
android:layout_marginLeft="5dp"
28+
android:gravity="center_vertical"
29+
>
30+
<TextView
31+
android:layout_width="wrap_content"
32+
android:layout_height="wrap_content"
33+
android:textSize="16sp"
34+
android:text="用户名:"/>
35+
<EditText
36+
android:id="@+id/ed_username"
37+
android:layout_width="fill_parent"
38+
android:layout_height="wrap_content"
39+
android:textSize="16sp"
40+
android:hint="请输入用户名"/>
41+
</LinearLayout>
42+
43+
<LinearLayout
44+
android:layout_marginTop="10dp"
45+
android:layout_width="fill_parent"
46+
android:layout_height="45dp"
47+
android:orientation="horizontal"
48+
android:layout_marginRight="5dp"
49+
android:layout_marginLeft="5dp"
50+
android:gravity="center_vertical"
51+
>
52+
<TextView
53+
android:layout_width="wrap_content"
54+
android:layout_height="wrap_content"
55+
android:textSize="16sp"
56+
android:text="密 码:"/>
57+
<EditText
58+
android:id="@+id/ed_password"
59+
android:layout_width="fill_parent"
60+
android:layout_height="wrap_content"
61+
android:textSize="16sp"
62+
android:hint="请输入用户名"/>
63+
</LinearLayout>
64+
65+
<Button
66+
android:id="@+id/btn_login"
67+
android:layout_width="fill_parent"
68+
android:layout_height="45dp"
69+
android:layout_marginTop="10dp"
70+
android:layout_marginLeft="8dp"
71+
android:layout_marginRight="8dp"
72+
android:textSize="16sp"
73+
android:text="登录"/>
74+
75+
</LinearLayout>

0 commit comments

Comments
 (0)