package com.zjgsu.jianshu

import android.R.attr
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.appcompat.view.menu.MenuAdapter
import cn.bmob.v3.Bmob
import cn.bmob.v3.BmobQuery
import cn.bmob.v3.exception.BmobException
import cn.bmob.v3.listener.FindListener
import kotlinx.android.synthetic.main.activity_my.*
import kotlinx.android.synthetic.main.activity_re_myinfo.*
import android.R.attr.data
import com.zjgsu.jianshu.Bmob.User_bmob


class ReMyinfoActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_re_myinfo)
        //返回个人信息
        back.setOnClickListener(){
            val intent=Intent(this,MyActivity::class.java)
            startActivity(intent)
            finish()
        }


        val extra_account=intent.getStringExtra("extra_account")
//        Log.d("helloReceive","$extraUserData")
        Log.d("myLog",extra_account.toString())

        Bmob.initialize(this, "8f9f1d1ea520b0ce4f84a6fa83a5f754") //连接bmob
        val query = BmobQuery<User_bmob>()
//        query.addWhereEqualTo("account",extra_account)
        query.findObjects(object : FindListener<User_bmob>() {
            var flag:Boolean=false
            override fun done(list: List<User_bmob>, e: BmobException?) {
                if (e == null) {
                    for (i in list) {
                        if (extra_account.equals(i.account)) {
                            flag = true
                            tCurrentName.setText(i.nickName)
                            tCurrentSignature.setText(i.signature)
                            tCurrentAddress.setText((i.address))
                            tCurrentEmail.setText(i.email)
                            tCurrentTel.setText(i.phone)
                            tCurrentSex.setText(i.sex)
                        }
                    }
                    if(flag==false){
                        Log.d("myLog","can't find account")
                    }
                }
            }


        })

        //跳转修改昵称
        re_name.setOnClickListener(){
            val extra_user_data=tCurrentName.text
            val intent=Intent(this,ReNameActivity::class.java)
            intent.putExtra("extra_account",extra_account)
            intent.putExtra("extra_user_data",extra_user_data)
//            startActivity(intent
            startActivityForResult(intent,1)
            finish()
        }
        //跳转修改个性签名
        re_signature.setOnClickListener(){
            val extra_signature=tCurrentSignature.text
            val intent=Intent(this,ReSignatureActivity::class.java)
            intent.putExtra("extra_account",extra_account)
            intent.putExtra("extra_signature",extra_signature)
            startActivityForResult(intent,1)
            finish()
        }
        //跳转修改性别
        re_sex.setOnClickListener(){
            val extra_sex=tCurrentSex.text
            val intent=Intent(this,ReSexActivity::class.java)
            intent.putExtra("extra_account",extra_account)
            intent.putExtra("extra_sex",extra_sex)
            startActivityForResult(intent,1)
            finish()
        }
        //跳转修改邮箱
        re_email.setOnClickListener(){
            val extra_email=tCurrentEmail.text
            val intent=Intent(this,ReEmailActivity::class.java)
            intent.putExtra("extra_account",extra_account)
            intent.putExtra("extra_email",extra_email)
            startActivityForResult(intent,1)
            finish()
        }
        //跳转修改手机号
        re_telephone.setOnClickListener(){
            val extra_tel=tCurrentTel.text
            val intent=Intent(this,RePhoneActivity::class.java)
            intent.putExtra("extra_account",extra_account)
            intent.putExtra("extra_tel",extra_tel)
            startActivity(intent)
            finish()
        }
        //跳转修改地址
        re_address.setOnClickListener(){
            val extra_address=tCurrentAddress.text
            val intent=Intent(this,ReAddressActivity::class.java)
            intent.putExtra("extra_account",extra_account)
            intent.putExtra("extra_address",extra_address)
            startActivity(intent)
            finish()
        }
    }



}