| | |
| | | import com.sinata.xqmuse.MainActivity |
| | | import com.sinata.xqmuse.R |
| | | import com.sinata.xqmuse.dialog.LoginRuleDialog |
| | | import com.sinata.xqmuse.dialog.LoginRulesDialog |
| | | import com.sinata.xqmuse.dialog.TipDialog |
| | | import com.sinata.xqmuse.dialog.UserRuleDialog |
| | | import com.sinata.xqmuse.network.HttpManager |
| | |
| | | import com.sinata.xqmuse.ui.H5Activity |
| | | import com.sinata.xqmuse.ui.TransparentStatusBarActivity |
| | | import com.sinata.xqmuse.utils.Const |
| | | import com.sinata.xqmuse.utils.event.EmptyEvent |
| | | import com.sinata.xqmuse.utils.extention.clickDelay |
| | | import com.sinata.xqmuse.utils.interfaces.StringCallback |
| | | import com.umeng.socialize.UMAuthListener |
| | | import com.umeng.socialize.UMShareAPI |
| | | import com.umeng.socialize.UMShareConfig |
| | | import com.umeng.socialize.bean.SHARE_MEDIA |
| | | import kotlinx.android.synthetic.main.activity_login.* |
| | | import org.greenrobot.eventbus.EventBus |
| | | import org.jetbrains.anko.sdk27.coroutines.onClick |
| | | import org.jetbrains.anko.startActivity |
| | | import org.jetbrains.anko.startActivityForResult |
| | |
| | | private var openid: String? = null |
| | | private var phone: String? = null |
| | | |
| | | private val androidId by lazy { |
| | | private var user = "" |
| | | private var privacy = "" |
| | | |
| | | private val device by lazy { |
| | | Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID) |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | tv_privacy_rule.clickDelay { |
| | | HttpManager.getH5(LoginRuleDialog.TYPE_PRIVACY).request(this){ _, data-> |
| | | data?.let { |
| | | startActivityForResult<H5Activity>(1,"title" to "隐私协议","url" to it.content,"showClose" to true) |
| | | } |
| | | } |
| | | if (user.isNotEmpty()&&privacy.isNotEmpty()) |
| | | LoginRulesDialog.show(supportFragmentManager,privacy,user,1,object :StringCallback{ |
| | | override fun onResult(rst: String) { |
| | | cb_rule.isChecked = rst.isNotEmpty() |
| | | } |
| | | }) |
| | | } |
| | | |
| | | tv_user_rule.clickDelay { |
| | | HttpManager.getH5(LoginRuleDialog.TYPE_USER).request(this){ _, data-> |
| | | data?.let { |
| | | startActivityForResult<H5Activity>(2,"title" to "用户协议","url" to it.content,"showClose" to true) |
| | | } |
| | | } |
| | | if (user.isNotEmpty()&&privacy.isNotEmpty()) |
| | | LoginRulesDialog.show(supportFragmentManager,privacy,user,0,object :StringCallback{ |
| | | override fun onResult(rst: String) { |
| | | cb_rule.isChecked = rst.isNotEmpty() |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | if (BuildConfig.DEBUG){ |
| | | et_phone.setText("18583738369") |
| | | et_pwd.setText("123456") |
| | | et_pwd.setText("123456ABC") |
| | | et_code.setText("123456") |
| | | } |
| | | getRules() |
| | | } |
| | | |
| | | private fun getRules() { |
| | | HttpManager.getH5(LoginRuleDialog.TYPE_PRIVACY).request(this){ _, data-> |
| | | privacy = data?.content?:"" |
| | | } |
| | | HttpManager.getH5(LoginRuleDialog.TYPE_USER).request(this){ _, data-> |
| | | user = data?.content?:"" |
| | | } |
| | | } |
| | | |
| | | private fun thirdAuth() { |
| | | startActivityForResult<BindPhoneActivity>(200,"type" to RegisterActivity.TYPE_BIND) |
| | | |
| | | // val umShareConfig = UMShareConfig() |
| | | // umShareConfig.isNeedAuthOnGetUserInfo(true) |
| | | // UMShareAPI.get(this).setShareConfig(umShareConfig) |
| | | // UMShareAPI.get(this).getPlatformInfo(this, SHARE_MEDIA.WEIXIN, this) |
| | | val umShareConfig = UMShareConfig() |
| | | umShareConfig.isNeedAuthOnGetUserInfo(true) |
| | | UMShareAPI.get(this).setShareConfig(umShareConfig) |
| | | UMShareAPI.get(this).getPlatformInfo(this, SHARE_MEDIA.WEIXIN, this) |
| | | } |
| | | |
| | | private fun loginByPwd() { |
| | |
| | | } |
| | | |
| | | tv_action.isEnabled = false |
| | | HttpManager.captchaLogin(code, et_phone.text.toString()) |
| | | HttpManager.captchaLogin(device,code, et_phone.text.toString()) |
| | | .request(this, success = { _, data -> |
| | | data?.let { |
| | | loginSuccess(it.accessToken) |
| | |
| | | private fun loginSuccess(token: String) { |
| | | SPUtils.instance().put(Const.User.TOKEN, token).apply() |
| | | startActivity<MainActivity>() |
| | | EventBus.getDefault().post(EmptyEvent(Const.EventCode.CHANGE_USER)) |
| | | finish() |
| | | } |
| | | |
| | |
| | | val avatar = p2?.get("profile_image_url") |
| | | val gender = p2?.get("gender") |
| | | val nickname = p2?.get("name") |
| | | HttpManager.wxLogin(openid, phone,nickname,if (gender == "0") 1 else 2,avatar).request(this,false,{ _, data -> |
| | | HttpManager.wxLogin(device,openid, nickname,if (gender == "0") 1 else 2,avatar).request(this,false,{ _, data -> |
| | | data?.let { |
| | | if (it.isBind == "0"){ |
| | | startActivityForResult<BindPhoneActivity>(200,"type" to RegisterActivity.TYPE_BIND,"token" to it.token,"id" to it.id) |
| | | if (it.bindStatus ==1){ |
| | | startActivityForResult<BindPhoneActivity>(200,"token" to it.accessToken,"openid" to openid) |
| | | }else |
| | | loginSuccess(it.token) |
| | | loginSuccess(it.accessToken) |
| | | } |
| | | }) {_,msg-> |
| | | loginFailed(msg) |
| | |
| | | } |
| | | |
| | | override fun onError(p0: SHARE_MEDIA?, p1: Int, p2: Throwable?) { |
| | | myToast("授权失败 原因:" + p2?.message) |
| | | myToast("授权失败:" + p2?.message) |
| | | } |
| | | |
| | | override fun onStart(p0: SHARE_MEDIA?) { |