2024-04-25 10:33:59 +08:00
|
|
|
package com.zjgsu.jianshu
|
|
|
|
|
|
|
|
|
|
import android.content.Intent
|
|
|
|
|
import android.graphics.Bitmap
|
|
|
|
|
import android.graphics.BitmapFactory
|
|
|
|
|
import android.util.Log
|
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
|
import android.view.View
|
|
|
|
|
import android.view.ViewGroup
|
|
|
|
|
import android.widget.ImageView
|
|
|
|
|
import android.widget.TextView
|
|
|
|
|
import androidx.core.content.ContextCompat
|
|
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
|
|
import cn.bmob.v3.BmobQuery
|
|
|
|
|
import cn.bmob.v3.exception.BmobException
|
|
|
|
|
import cn.bmob.v3.listener.FindListener
|
|
|
|
|
import com.zjgsu.jianshu.Activity.Perception_informationActivity
|
2024-04-26 19:57:44 +08:00
|
|
|
import com.zjgsu.jianshu.Bmob.Book_info_bmob
|
2024-04-25 10:33:59 +08:00
|
|
|
import com.zjgsu.jianshu.Bmob.Perception_bmob
|
|
|
|
|
import com.zjgsu.jianshu.Bmob.User_bmob
|
|
|
|
|
import java.io.InputStream
|
|
|
|
|
import java.net.HttpURLConnection
|
|
|
|
|
import java.net.URL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PerceptionAdapter(val perceptionList: List<Perception>) : RecyclerView.Adapter<PerceptionAdapter.ViewHolder>() {
|
|
|
|
|
|
|
|
|
|
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
|
|
|
|
val perceptionList_perception: TextView = view.findViewById(R.id.textView_perception)
|
|
|
|
|
//用户头像
|
|
|
|
|
val perceptionList_userIcon: ImageView = view.findViewById(R.id.user_icon)
|
|
|
|
|
val perceptionList_posetPerson: TextView = view.findViewById(R.id.postPersonName)
|
|
|
|
|
//书籍封面
|
|
|
|
|
val perceptionList_bookPic: ImageView = view.findViewById(R.id.book_pic)
|
|
|
|
|
val perceptionList_bookName: TextView = view.findViewById(R.id.bookName)
|
|
|
|
|
val perceptionList_bookAuthor: TextView = view.findViewById(R.id.bookAuthor)
|
|
|
|
|
val perceptionList_bookInf: View = view.findViewById(R.id.bookInf)
|
|
|
|
|
val comment:ImageView=view.findViewById(R.id.gotocomment)
|
|
|
|
|
lateinit var perceptionid:String
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
|
|
|
|
val view = LayoutInflater.from(parent.context).inflate(R.layout.perception_item, parent, false)
|
|
|
|
|
return ViewHolder(view)
|
|
|
|
|
}
|
|
|
|
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
|
|
|
|
var bookName:String=""
|
|
|
|
|
val perception = perceptionList[position]
|
|
|
|
|
//设置text
|
|
|
|
|
holder.perceptionid=perception.perceptionid
|
|
|
|
|
val query = BmobQuery<Perception_bmob>()
|
|
|
|
|
query.addWhereEqualTo("objectId",perception.perceptionid)
|
|
|
|
|
//加载用户头像
|
|
|
|
|
query.findObjects(object : FindListener<Perception_bmob>() {
|
|
|
|
|
override fun done(p0: MutableList<Perception_bmob>?, p1: BmobException?) {
|
|
|
|
|
if (p1 == null) {
|
|
|
|
|
if (p0 != null && p0.size > 0) {
|
|
|
|
|
for (p in p0) {
|
|
|
|
|
Log.d("myLog123", p.post_person)
|
|
|
|
|
//找发布用户
|
|
|
|
|
holder.perceptionList_perception.text=p.perception
|
|
|
|
|
val queryUser = BmobQuery<User_bmob>()
|
|
|
|
|
queryUser.findObjects(object : FindListener<User_bmob>() {
|
|
|
|
|
override fun done(list: List<User_bmob>, e: BmobException?) {
|
|
|
|
|
if (e == null) {
|
|
|
|
|
for (i in list) {
|
|
|
|
|
if (p.userid.equals(i.objectId)) {
|
|
|
|
|
holder.perceptionList_posetPerson.setText(i.nickName)
|
|
|
|
|
// flag = true //找到
|
|
|
|
|
Log.d("myLog", "find sucessflly")
|
|
|
|
|
//加载图片
|
|
|
|
|
object : Thread() {
|
|
|
|
|
override fun run() {
|
|
|
|
|
try {
|
|
|
|
|
val url = URL(i!!.face?.url)
|
|
|
|
|
val connection: HttpURLConnection =
|
|
|
|
|
url.openConnection() as HttpURLConnection
|
|
|
|
|
connection.setRequestMethod("GET")
|
|
|
|
|
connection.setConnectTimeout(3000)
|
|
|
|
|
val `in`: InputStream = connection.getInputStream()
|
|
|
|
|
val bitmap: Bitmap =
|
|
|
|
|
BitmapFactory.decodeStream(`in`)
|
|
|
|
|
holder.perceptionList_userIcon.setImageBitmap(bitmap)
|
|
|
|
|
} catch (e: Exception) {
|
|
|
|
|
e.printStackTrace()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Log.d("myLog", "error")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
//加载书籍封面
|
|
|
|
|
query.findObjects(object : FindListener<Perception_bmob>() {
|
|
|
|
|
override fun done(p0: MutableList<Perception_bmob>?, p1: BmobException?) {
|
|
|
|
|
if (p1 == null) {
|
|
|
|
|
if (p0 != null && p0.size > 0) {
|
|
|
|
|
for (p in p0) {
|
|
|
|
|
Log.d("myLog", p.b_name)
|
|
|
|
|
bookName=p.b_name
|
|
|
|
|
holder.perceptionList_bookName.text=bookName
|
2024-04-26 19:57:44 +08:00
|
|
|
val queryBook = BmobQuery<Book_info_bmob>()
|
|
|
|
|
queryBook.findObjects(object : FindListener<Book_info_bmob>() {
|
|
|
|
|
override fun done(list: List<Book_info_bmob>, e: BmobException?) {
|
2024-04-25 10:33:59 +08:00
|
|
|
if (e == null) {
|
|
|
|
|
for (i in list) {
|
|
|
|
|
if (p.b_name.equals(i.name)) {
|
|
|
|
|
holder.perceptionList_bookAuthor.text=i.author_name
|
|
|
|
|
//加载图片
|
|
|
|
|
object : Thread() {
|
|
|
|
|
override fun run() {
|
|
|
|
|
try {
|
|
|
|
|
val url = URL(i!!.picture?.url)
|
|
|
|
|
val connection: HttpURLConnection =
|
|
|
|
|
url.openConnection() as HttpURLConnection
|
|
|
|
|
connection.setRequestMethod("GET")
|
|
|
|
|
connection.setConnectTimeout(3000)
|
|
|
|
|
val `in`: InputStream = connection.getInputStream()
|
|
|
|
|
val bitmap: Bitmap =
|
|
|
|
|
BitmapFactory.decodeStream(`in`)
|
|
|
|
|
holder.perceptionList_bookPic.setImageBitmap(bitmap)
|
|
|
|
|
} catch (e: Exception) {
|
|
|
|
|
e.printStackTrace()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Log.d("myLog", "error")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
holder.perceptionList_bookInf.setOnClickListener(){
|
|
|
|
|
val intent= Intent(holder.itemView.context,Book_informationActivity::class.java)
|
|
|
|
|
intent.putExtra("Book_name",bookName)
|
|
|
|
|
ContextCompat.startActivity(holder.itemView.context, intent, null)
|
|
|
|
|
}
|
|
|
|
|
holder.perceptionList_perception.setOnClickListener {
|
|
|
|
|
val intent= Intent(holder.itemView.context,Perception_informationActivity::class.java)
|
|
|
|
|
intent.putExtra("PerceptionId",holder.perceptionid)
|
|
|
|
|
ContextCompat.startActivity(holder.itemView.context, intent, null)
|
|
|
|
|
}
|
|
|
|
|
//给评论图标设置点击事件
|
|
|
|
|
//给评论图标设置点击事件
|
|
|
|
|
holder.comment.setOnClickListener(View.OnClickListener { showPopupcomment() })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun getItemCount() =perceptionList.size
|
|
|
|
|
|
|
|
|
|
}
|