【56】kotlin搭建mvp。

首先搭建Base.

BaseView

package com.anguo.baselibary.presenter.view

interface BaseView {
    fun showLoading()
    fun hideLoading()
    fun onError()
}

BasePresenter

package com.anguo.baselibary.presenter

import com.anguo.baselibary.presenter.view.BaseView

open class BasePresenter<T:BaseView> {
    lateinit var mView:T
}

实际运行模块 为用户中心  

RegisterView

package com.anguo.user.present.view

import com.anguo.baselibary.presenter.view.BaseView

 interface RegisterView:BaseView {
     fun onRegisterResult(result:Boolean){
     }

}

RegisterPersenter

package com.anguo.user.present

import com.anguo.baselibary.presenter.BasePresenter
import com.anguo.user.present.view.RegisterView

class RegisterPersenter : BasePresenter<RegisterView>() {
    fun register(mobile: String, verifyCode: String) {
        /*业务逻辑*/
        mView.onRegisterResult(true)
    }
}

activity。xml

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".ui.activity.RegisterActivity">

    <Button
        android:id="@+id/mRegiterBtn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/register" />
</LinearLayout>

RegisterActivity

package com.anguo.user.ui.activity

import android.os.Bundle
import com.anguo.baselibary.ui.activity.BaseMvpActivity
import com.anguo.user.R
import com.anguo.user.present.RegisterPersenter
import com.anguo.user.present.view.RegisterView
import kotlinx.android.synthetic.main.activity_register.*
import org.jetbrains.anko.toast


class RegisterActivity : BaseMvpActivity<RegisterPersenter>(), RegisterView {

    override fun onRegisterResult(result: Boolean) {
        toast("注册成功")
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_register)
        mPersenter = RegisterPersenter()
        mPersenter.mView = this;
        mRegiterBtn.setOnClickListener {

            mPersenter.register("", "");
        }
    }
}

这样 基本的一个mvp就搭建完成了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

安果移不动

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值