package com.zjgsu.jianshu
import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import cn.bmob.v3.Bmob
import cn.bmob.v3.BmobQuery
import cn.bmob.v3.exception.BmobException
import cn.bmob.v3.listener.FindListener
import com.zjgsu.jianshu.Bmob.Book_info_bmob
import com.zjgsu.jianshu.R
import kotlinx.android.synthetic.main.activity_book_info.*
import kotlinx.android.synthetic.main.activity_bookintro.*
import kotlinx.android.synthetic.main.expandable3.*
import kotlinx.android.synthetic.main.expandable4.*

class BookIntroActivity:AppCompatActivity() {
    private lateinit var Bookname: String
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_bookintro)
        supportActionBar?.hide()
        Bmob.initialize(this, "8f9f1d1ea520b0ce4f84a6fa83a5f754")//连接bmob
        Bookname = intent.getStringExtra("Book_name").toString()
        Log.d("zy123","yes")
        inits()
        intro_titleback.setOnClickListener {
            val intent = Intent(this, BookInformationActivity::class.java)
            intent.putExtra("Book_name", Bookname)
            startActivity(intent)
            finish()
        }
    }
    private fun inits(){
        val query = BmobQuery<Book_info_bmob>()
        query.addWhereEqualTo("name", Bookname)
        query.findObjects(object : FindListener<Book_info_bmob>() {
            override fun done(list: List<Book_info_bmob>, e: BmobException?) {
                if (e == null) {
                    for (i in list) {
                        expandable3.text = i.introduce
                        expandable4.text = i.evaluate
                        thebkname.text=Bookname
                    }
                } else {
                    Log.d("error", "error")
                }
            }
        })
    }
}