Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package us.slab.seller.viewmodel
- import android.annotation.SuppressLint
- import android.view.View
- import android.view.ViewGroup
- import android.widget.EditText
- import chela.kotlin.Ch
- import chela.kotlin.DptoPx
- import chela.kotlin.view.ChStyleModel
- import chela.kotlin.view.ChViewModel
- import com.chela.annotation.EX
- import com.chela.annotation.STYLE
- import com.chela.annotation.VM
- import us.slab.seller.App
- import us.slab.seller.R
- import us.slab.seller.holder.Signin
- import us.slab.seller.vo.User
- @VM
- @SuppressLint("StaticFieldLeak")
- object SigninVM:ChViewModel(){
- override fun start(){
- holder.start()
- mx.forEachIndexed { i, _ -> mx[i] = 100.0 }
- ma.forEachIndexed { i, _ -> mx[i] = 0.0 }
- }
- override fun end(){
- holder.end()
- mx.forEachIndexed { i, _ -> mx[i] = 0.0 }
- ma.forEachIndexed { i, _ -> mx[i] = 0.0 }
- }
- override fun paused(){
- holder.paused()
- }
- fun isValid(){
- val v = if(Ch.ruleset.isOk("se.userid" to inputId["userid"], "se.pass" to inputPw["pass"])) "btn"
- else "btnDisable"
- if(v != signIn["background"]){
- App.looper(Ch.time(350)) {
- signIn.scaleX = it.bounceOut(0.85, 1.0)
- signIn.scaleY = it.bounceOut(0.85, 1.0)
- Signin.renderSync()
- }
- }
- signIn.background = v
- Signin.renderSync()
- }
- fun inputEffect(pos:Pair<Int, Int>, view: View, drawable:Int){
- val (x, y) = pos
- val v = View(view.context)
- val dp = Ch.window.DptoPx
- Ch.prop.layout.width(v, 14.0*dp)
- Ch.prop.layout.height(v, 14.0*dp)
- Ch.prop.view.background(v, drawable)
- Ch.prop.view.x(v, x.toDouble() - 3.0*dp)
- Ch.prop.view.y(v, y.toDouble() - 10.0*dp)
- Ch.view.addView(R.id.main, v)
- val s = Ch.math.rand(1.5, 2.0)
- val a = Ch.math.rand(0.2, 0.5)
- val r = Ch.math.rand(-37.0, 37.0)
- App.looper(
- Ch.time(400),
- Ch.ended { (v.parent as ViewGroup).removeView(v) }) {
- Ch.prop.view.scaleX(v, it.circleOut(1.0, s))
- Ch.prop.view.scaleY(v, it.circleOut(1.0, s))
- Ch.prop.view.alpha(v, it.circleIn(a, 0.0))
- Ch.prop.view.rotation(v, it.circleIn(0.0, r))
- }
- }
- val delay = 50
- val time = Ch.time(700)
- val mx = mutableListOf(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
- val ma = mutableListOf(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
- val holder = ModalHolder()
- val label0 = Label0
- val label1 = Label1
- val vali0 = Vali0
- val vali1 = Vali1
- val inputId = InputId
- val inputPw = InputPw
- var isLock = false
- val signIn = SignInBtn
- val forgot = ForgotBtn
- val signup = SignUpBtn
- }
- @STYLE object Label0:ChStyleModel(){
- val style = "label"
- val marginStart:Double get() = SigninVM.mx[0]
- val alpha:Double get() = SigninVM.ma[0]
- val text:Any get() = Ch.i18n["signin.label0"]
- }
- @STYLE object Label1:ChStyleModel(){
- val style = "label"
- val marginStart:Double get() = SigninVM.mx[2]
- val alpha:Double get() = SigninVM.ma[2]
- val text:Any get() = Ch.i18n["signin.label1"]
- }
- @STYLE object Vali0:ChStyleModel(){
- val style = "valiError"
- var text = ""
- }
- @STYLE object Vali1:ChStyleModel(){
- val style = "valiError"
- var text = ""
- }
- @STYLE object InputId:ChStyleModel(){
- @EX var userid = ""
- val style = "input"
- val marginStart:Double get() = SigninVM.mx[1]
- val alpha:Double get() = SigninVM.ma[1]
- val inputType = Ch.prop.text.type.text
- val maxLength = 30
- val focusChange = AppVM.inputFocus
- @SuppressLint("StaticFieldLeak")
- val textChanged = object: Ch.OnTextChanged(){
- override fun onChanged(view: EditText, s:CharSequence, start:Int, before:Int, count:Int){
- val v = "$s"
- if(v.isEmpty()) userid = ""
- else if(!Ch.ruleset.isOk("se.useridInput" to v)){
- if(Vali0.text == ""){
- Vali0.text = Ch.i18n["signin.valiId"]
- Signin.renderSync()
- }
- view.setText(userid)
- view.setSelection(userid.length)
- SigninVM.inputEffect(pos(), view, R.drawable.crop_fa635c)
- }else{
- userid = v
- if(before < count) {
- if (Vali0.text != "") {
- Vali0.text = ""
- Signin.renderSync()
- }
- SigninVM.inputEffect(pos(), view, R.drawable.crop)
- }
- }
- SigninVM.isValid()
- }
- }
- }
- @STYLE object InputPw:ChStyleModel(){
- @EX var pass = ""
- val style = "input"
- val marginStart:Double get() = SigninVM.mx[3]
- val alpha:Double get() = SigninVM.ma[3]
- val inputType = Ch.prop.text.type.textPassword
- val maxLength = 30
- val focusChange = AppVM.inputFocus
- @SuppressLint("StaticFieldLeak")
- val textChanged = object: Ch.OnTextChanged(){
- override fun onChanged(view: EditText, s:CharSequence, start:Int, before:Int, count:Int){
- val v = "$s"
- if(v.isEmpty()) pass = ""
- else if(!Ch.ruleset.isOk("se.passInput" to v)){
- if(Vali1.text == ""){
- Vali1.text = Ch.i18n["signin.valiPw"]
- Signin.renderSync()
- }
- view.setText(pass)
- view.setSelection(pass.length)
- SigninVM.inputEffect(pos(), view, R.drawable.crop_fa635c)
- }else{
- pass = v
- if (before < count) {
- if (Vali1.text != "") {
- Vali1.text = ""
- Signin.renderSync()
- }
- SigninVM.inputEffect(pos(), view, R.drawable.crop)
- }
- }
- SigninVM.isValid()
- }
- }
- }
- @STYLE object SignInBtn:ChStyleModel(){
- override fun end() {
- background = "btnDisable"
- scaleX = 1.0
- scaleY = 1.0
- }
- val style = "button"
- val marginStart:Double get() = SigninVM.mx[4]
- val alpha:Double get() = SigninVM.ma[4]
- val text:Any get() = Ch.i18n["signin.btnSignin"]
- var textColor = "#ffffff"
- var background = "btnDisable"
- var scaleX = 1.0
- var scaleY = 1.0
- var click = View.OnClickListener{
- if(SigninVM.isLock) return@OnClickListener
- if(!Ch.net.isOn()) Signin.alert(Ch.i18n["alert.disconnect"])
- else if(!Ch.ruleset.isOk("se.userid" to InputId.userid)){
- Signin.alert(Ch.i18n["alert.userid"])
- }else if(!Ch.ruleset.isOk("se.pass" to InputPw.pass)){
- Signin.alert(Ch.i18n["alert.pw"])
- }else{
- SigninVM.isLock = true
- val result = Ch.net.api("login", "userid" to InputId.userid, "pass" to InputPw.pass){
- val user = it.result as User
- it.header("authtoken")?.let{user.authtoken = it}
- App.user = user
- //Ch.sql.DB?.exec("se_add", user)
- App.modalRouter.pop()
- SigninVM.isLock = false
- }
- if(result is Ch.ApiResult.fail){
- Signin.alert(Ch.i18n["signin.failed"])
- SigninVM.isLock = false
- }
- }
- }
- }
- @STYLE object ForgotBtn:ChStyleModel(){
- val style = "button"
- val marginStart:Double get() = SigninVM.mx[5]
- val alpha:Double get() = SigninVM.ma[5]
- val text:Any get() = Ch.i18n["signin.btnForgot.ko"]
- val fontFamily = "nn"
- var textColor = "#ffffff"
- var textSize = 20.0.DptoPx
- var click = View.OnClickListener{
- if(SigninVM.isLock) return@OnClickListener
- }
- }
- @STYLE object SignUpBtn:ChStyleModel(){
- val style = "button"
- val marginStart:Double get() = SigninVM.mx[6]
- val alpha:Double get() = SigninVM.ma[6]
- val text:Any get() = Ch.i18n["signin.btnSignup"]
- var textColor = "#444444"
- var background = "btnBorder"
- var click = View.OnClickListener{
- if(SigninVM.isLock) return@OnClickListener
- }
- }
Add Comment
Please, Sign In to add comment