Skip to content

Commit 627f27f

Browse files
committed
mvp契约类登场
1 parent 4253c6c commit 627f27f

File tree

21 files changed

+342
-195
lines changed

21 files changed

+342
-195
lines changed
1.17 KB
Binary file not shown.
0 Bytes
Binary file not shown.
476 Bytes
Binary file not shown.
21 KB
Binary file not shown.
8.41 KB
Binary file not shown.
0 Bytes
Binary file not shown.
241 KB
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.

.idea/workspace.xml

Lines changed: 221 additions & 156 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/app.iml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/apk_list" />
120120
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
121121
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/build-info" />
122+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
122123
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundle_manifest" />
123124
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/check_manifest_result" />
124125
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/compatible_screen_manifest" />

app/src/main/java/com/kotlinframework/platform/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
package com.kotlinframework.platformimport android.os.Bundleimport android.view.Viewimport android.widget.Toastimport com.kotlinframework.net.network.ApiErrorModelimport com.kotlinframework.net.network.NetResponseObserverimport com.kotlinframework.net.network.NetSchedulerimport com.kotlinframework.net.network.RetrofitManagerimport com.kotlinframework.platform.api.Apiimport com.kotlinframework.platform.api.ApiServiceimport com.kotlinframework.platform.bean.UserBeanimport com.trello.rxlifecycle2.android.ActivityEventimport com.trello.rxlifecycle2.components.support.RxAppCompatActivityimport com.trello.rxlifecycle2.kotlin.bindUntilEventimport kotlinx.android.synthetic.main.activity_main.*class MainActivity : RxAppCompatActivity(), View.OnClickListener { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) initView() } private fun initView() { login.setOnClickListener(this) } /** * 登录测试 */ fun login() { RetrofitManager.instance.createService(ApiService::class.java).login(Api.LOGIN_URL,"18612991023","111111") .compose(NetScheduler.compose()) .bindUntilEvent(this, ActivityEvent.DESTROY) .subscribe(object : NetResponseObserver<UserBean>(this){ override fun success(data: UserBean) { Toast.makeText(this@MainActivity,data.result.phone,Toast.LENGTH_SHORT).show() } override fun failure(statusCode: Int, apiErrorModel: ApiErrorModel) { } }) } /** * 点击事件 */ override fun onClick(v: View?) { when (v!!.id) { R.id.login -> login() R.id.reg -> reg() } } /** * 注册测试 */ private fun reg() { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. }}
1+
package com.kotlinframework.platformimport android.os.Bundleimport android.view.Viewimport android.widget.Toastimport com.kotlinframework.platform.bean.UserBeanimport com.kotlinframework.platform.contract.LoginContractimport com.kotlinframework.platform.presenter.LoginPresenterimport com.trello.rxlifecycle2.components.support.RxAppCompatActivityimport kotlinx.android.synthetic.main.activity_main.*class MainActivity : RxAppCompatActivity(), View.OnClickListener ,LoginContract.ILoginView{ lateinit var loginPresenter:LoginPresenter override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) initView() } /** * 初始化view */ private fun initView() { login.setOnClickListener(this) getMovies.setOnClickListener(this) } /** * 登录测试 */ fun login() { var params= HashMap<String,String> () params.put("phone","18612991023") params.put("pwd","111111") loginPresenter= LoginPresenter() loginPresenter.attach(this) loginPresenter.login(params,this) } /** * 获取影片列表 */ private fun getMovies() { } override fun success(userBean: UserBean) { Toast.makeText(this,userBean.result.phone,Toast.LENGTH_SHORT).show() } override fun failure(string: String) { Toast.makeText(this,string,Toast.LENGTH_SHORT).show() } override fun onDestroy() { super.onDestroy() loginPresenter.detach() } /** * 点击事件 */ override fun onClick(v: View?) { when (v!!.id) { R.id.login -> login() R.id.getMovies-> getMovies() } }}

app/src/main/java/com/kotlinframework/platform/api/ApiService.kt

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package com.kotlinframework.platform.api
22

33
import com.kotlinframework.platform.bean.UserBean
4+
import io.reactivex.Observable
45
import retrofit2.Call
5-
import retrofit2.http.Field
6-
import retrofit2.http.FormUrlEncoded
7-
import retrofit2.http.POST
8-
import retrofit2.http.Url
6+
import retrofit2.http.*
97

108
/**
119
* 接口声明类
@@ -14,6 +12,6 @@ interface UserApiService{
1412

1513
@POST
1614
@FormUrlEncoded
17-
fun login(@Url string: String,@Field("phone") mobile:String,@Field("pwd")pwd: String):Call<UserBean>
15+
fun login(@Url string: String, @FieldMap hashMap: HashMap<String,String>):Observable<UserBean>
1816

1917
}
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
package com.kotlinframework.platform.contract
22

3+
import android.content.Context
4+
import com.kotlinframework.net.network.IModelCallback
5+
import com.kotlinframework.platform.bean.UserBean
6+
import java.util.*
7+
8+
/**
9+
* 契约类统一管理
10+
*/
311
interface LoginContract{
4-
abstract class LoginPresenter{
12+
interface LoginPresenter{
513

6-
abstract fun login(hashMap: HashMap<String,String>)
14+
fun login(hashMap: HashMap<String,String>,context: Context)
715
}
816

917
interface ILoginModel{
1018

19+
fun login(context: Context,hashMap: HashMap<String, String>,modelCallback:IModelCallback<UserBean>)
20+
1121

1222
}
1323

1424
interface ILoginView{
1525

26+
fun success(userBean: UserBean)
27+
fun failure(string: String)
28+
1629
}
1730
}

app/src/main/java/com/kotlinframework/platform/model/IModelCallback.kt

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.kotlinframework.platform.model
2+
3+
import android.content.Context
4+
import com.kotlinframework.net.network.ApiErrorModel
5+
import com.kotlinframework.net.network.IModelCallback
6+
import com.kotlinframework.net.network.NetResponseObserver
7+
import com.kotlinframework.net.network.NetScheduler
8+
import com.kotlinframework.net.network.RetrofitManager
9+
import com.kotlinframework.platform.api.Api
10+
import com.kotlinframework.platform.api.UserApiService
11+
import com.kotlinframework.platform.bean.UserBean
12+
import com.kotlinframework.platform.contract.LoginContract
13+
import java.util.HashMap
14+
15+
/**
16+
* 数据模型层
17+
*/
18+
class LoginModel:LoginContract.ILoginModel{
19+
override fun login(context: Context,hashMap: HashMap<String, String>, modelCallback: IModelCallback<UserBean>) {
20+
RetrofitManager.instance.createService(UserApiService::class.java).login(Api.LOGIN_URL,hashMap)
21+
.compose(NetScheduler.compose())
22+
.subscribe(object : NetResponseObserver<UserBean>(context){
23+
override fun success(data: UserBean) {
24+
25+
modelCallback?.sucess(data)
26+
27+
}
28+
29+
override fun failure(statusCode: Int, apiErrorModel: ApiErrorModel) {
30+
31+
modelCallback?.failure(apiErrorModel.message)
32+
}
33+
34+
})
35+
}
36+
37+
}
38+
39+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.kotlinframework.platform.presenter
2+
3+
import android.content.Context
4+
import com.kotlinframework.net.network.IModelCallback
5+
import com.kotlinframework.platform.bean.UserBean
6+
import com.kotlinframework.platform.contract.LoginContract
7+
import com.kotlinframework.platform.model.LoginModel
8+
import java.util.*
9+
10+
/**
11+
* presenter层
12+
*/
13+
class LoginPresenter : LoginContract.LoginPresenter {
14+
15+
16+
lateinit var loginModel: LoginModel
17+
lateinit var iLoginView: LoginContract.ILoginView
18+
19+
20+
/**
21+
* 绑定view
22+
*/
23+
fun attach(iLoginView: LoginContract.ILoginView) {
24+
this.iLoginView = iLoginView
25+
loginModel = LoginModel()
26+
27+
}
28+
29+
override fun login(hashMap: HashMap<String, String>, context: Context) {
30+
31+
loginModel.login(context, hashMap, object : IModelCallback<UserBean> {
32+
override fun failure(string: String) {
33+
iLoginView?.failure(string)
34+
}
35+
36+
override fun sucess(data: UserBean) {
37+
iLoginView?.success(data)
38+
}
39+
40+
})
41+
}
42+
43+
/**
44+
* 解绑
45+
*/
46+
fun detach() {
47+
if (iLoginView != null) {
48+
iLoginView == null
49+
}
50+
}
51+
52+
53+
}

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <LinearLayout app:layout_constraintTop_toTopOf="parent" android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:id="@+id/login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="登录" /> <Button android:id="@+id/reg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="注册" /> <EditText android:id="@+id/mobile" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout></android.support.constraint.ConstraintLayout>
1+
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <LinearLayout android:id="@+id/topLayout" app:layout_constraintTop_toTopOf="parent" android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:id="@+id/login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="登录" /> <Button android:id="@+id/getMovies" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="获取影院列表" /> </LinearLayout></android.support.constraint.ConstraintLayout>

net/src/main/java/com/kotlinframework/net/gffg.java

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.kotlinframework.net.network
2+
3+
interface IModelCallback<T>{
4+
5+
fun sucess(data: T)
6+
fun failure(string: String)
7+
8+
}

0 commit comments

Comments
 (0)