AddAccountActivity.kt 2.74 KB
Newer Older
ydl committed
1 2
package com.yidianling.user.mine

3
import android.annotation.SuppressLint
ydl committed
4 5
import android.app.Activity
import android.content.Intent
6 7 8 9 10 11 12
import android.os.Bundle
import android.text.TextUtils
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.ydl.ydlcommon.data.http.RxUtils
import com.ydl.ydlcommon.data.http.ThrowableConsumer
import com.yidianling.common.tools.ToastUtil
ydl committed
13
import com.yidianling.user.R
14 15 16 17 18
import com.yidianling.user.databinding.UserMineActivityAddAccountBinding
import com.yidianling.user.mine.bean.AddAccountCmd
import com.yidianling.user.mine.data.AppDataManager
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.functions.Consumer
ydl committed
19 20 21
import kotlinx.android.synthetic.main.user_mine_activity_add_account.*

/**
22 23 24 25 26 27
 * @author liupeng
 * 添加提现账号
 * */
class AddAccountActivity : AppCompatActivity() {

    private lateinit var binding: UserMineActivityAddAccountBinding
ydl committed
28 29 30 31 32 33 34 35

    companion object {
        fun startForResult(activity: Activity, request: Int) {
            var intent = Intent(activity, AddAccountActivity::class.java)
            activity.startActivityForResult(intent, request)
        }
    }

36 37 38 39 40 41
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this, R.layout.user_mine_activity_add_account)
        btn_ensure.setOnClickListener {
            saveAccount()
        }
ydl committed
42 43
    }

44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
    /**
     * 保存支付宝帐号
     */
    @SuppressLint("CheckResult")
    private fun saveAccount() {
        var account = et_account.text.trim().toString()
        if (TextUtils.isEmpty(account)) {
            ToastUtil.toastShort("支付宝帐号不能为空")
            return
        }
        var name = et_name.text.trim().toString()
        if (TextUtils.isEmpty(name)) {
            ToastUtil.toastShort("姓名不能为空")
            return
        }
ydl committed
59

60 61 62 63
        var param = AddAccountCmd(name, account, "1")
        AppDataManager.getHttp().addAccount(param)
            .compose(RxUtils.resultData())
            .observeOn(AndroidSchedulers.mainThread())
64 65
            .subscribe(Consumer {bean ->
                if (bean == null) {
66 67 68 69
                    ToastUtil.toastShort("返回数据错误")
                } else {
                    ToastUtil.toastShort("添加帐号成功")
                    var intent = Intent()
70
                    intent.putExtra(ChooseAccountActivity.ADD_ACCOUNT_REQUEST_KEY, bean)
71 72 73 74 75 76 77 78
                    setResult(Activity.RESULT_OK, intent)
                    finish()
                }
            }, object : ThrowableConsumer() {
                override fun accept(msg: String) {
                    ToastUtil.toastShort(msg)
                }
            })
ydl committed
79
    }
80
}