8.7
liugl
2020-08-07 386c12bc80d17252ea05b7bf1cb2e85db2e46767
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package com.okgoincar.slab
 
import android.content.Context
import android.os.Handler
import android.os.Looper
import android.widget.Toast
import cn.sinata.xldutils.utils.clickDelay
import cn.sinata.xldutils.utils.getContent
import com.google.gson.Gson
import com.okgoincar.netUtls.callNet
import com.okgoincar.netUtls.getMapByAny
import com.okgoincar.utils.Cache.CacheKey
import com.okgoincar.R
import com.okgoincar.bean.LoginBean
import com.okgoincar.netUtls.Api
import kotlinx.android.synthetic.main.slab_activity_login.*
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast
 
class SlabLoginActivity : MySlabBaseActivity() {
    override fun setContentView() {
        setContentView(R.layout.slab_activity_login)
    }
 
    override fun initView() {
        showTitle(false)
        showHeader(false)
    }
 
    override fun setOnclick() {
        tv_login.clickDelay {
            if (et_number.getContent().isNullOrEmpty()) {
                toast("请输入工号")
                return@clickDelay
            }
            var map = getMapByAny()
            map["jobNum"] = et_number.getContent().trim()
            callNet(true, Api.loginByJobNumber, map) {
                toast("登录成功")
                var bean = gson.fromJson<LoginBean>(it, LoginBean::class.java)
                CacheKey.putKeyStr("jobNum",et_number.getContent().trim())
                CacheKey.putKeyStr("appid", bean.data.appid)
                CacheKey.putKeyStr("token", bean.data.token)
                CacheKey.putKeyStr("userId", bean.data.id.toString())
                CacheKey.putKeyStr("serverId", bean.data.serverId.toString())
                CacheKey.putKeyStr("terminalName", bean.data.terminalId.toString())
                finish()
                startActivity<SlabMainActivity>()
            }
//            toLoginActivity(this,"452229198204010012")
 
        }
    }
 
    override fun setBlackMode(b:Boolean) {
        super.setBlackMode(b)
        if (b){
            iv_back_login.setBackgroundResource(R.mipmap.bg_black)
            ll_center.setBackgroundResource(R.color.black_mode_383838)
            et_number.setBackgroundResource(R.drawable.bg_gray_4_line_black)
        }else{
            iv_back_login.setBackgroundResource(R.mipmap.bg_lab_login)
            ll_center.setBackgroundResource(R.color.write)
            et_number.setBackgroundResource(R.drawable.bg_gray_4_line)
        }
    }
 
    private
    var mBackAppTime: Long = 0
 
    override fun onBackPressed() {
        if (System.currentTimeMillis() - mBackAppTime > 2000) {
            Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT)
                .show()
            mBackAppTime = System.currentTimeMillis()
        } else {
            moveTaskToBack(true)
        }
    }
 
    private fun toLoginActivity(context: Context?, driverCertificate: String?) {
        var map = getMapByAny()
        map["identification"] = driverCertificate
        callNet(context!!,Api.loginByIdentification,map){
            cn.sinata.xldutils.utils.toast("登录成功")
            var bean = Gson().fromJson<LoginBean>(it, LoginBean::class.java)
            CacheKey.putKeyStr("appid", bean.data.appid)
            CacheKey.putKeyStr("token", bean.data.token)
            CacheKey.putKeyStr("userId", bean.data.id.toString())
            CacheKey.putKeyStr("serverId", bean.data.serverId.toString())
            CacheKey.putKeyStr("terminalName", bean.data.terminalId.toString())
            Handler(Looper.getMainLooper()).post {
                context.startActivity<SlabMainActivity>()
            }
        }
    }
 
}