评论、点赞、收藏功能完善

This commit is contained in:
zhangsan 2024-05-22 14:01:53 +08:00
parent 30a466968e
commit 61fe13b37d
28 changed files with 782 additions and 498 deletions

View File

@ -46,8 +46,7 @@
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
<!-- </activity>-->
<activity android:name="edu.whut.jianshu.Activity.SendSpecificActivity" />
<activity android:name="edu.whut.jianshu.Activity.BookIntroActivity" />
<activity android:name="edu.whut.jianshu.Activity.SendMarkingActivity" />
<activity android:name="edu.whut.jianshu.Activity.MainActivity"
android:configChanges="orientation|keyboard|keyboardHidden|navigation"
/>

View File

@ -3,7 +3,6 @@ package edu.whut.jianshu.Activity
import android.content.Context
import android.content.Intent
import android.util.Log
import cn.bmob.v3.Bmob
import cn.bmob.v3.BmobQuery
import cn.bmob.v3.exception.BmobException
import cn.bmob.v3.listener.FindListener
@ -19,12 +18,9 @@ import androidx.recyclerview.widget.StaggeredGridLayoutManager
import cn.bmob.v3.listener.SaveListener
import com.bifan.txtreaderlib.ui.HwTxtPlayActivity
import com.bumptech.glide.Glide
import edu.whut.jianshu.Adapter.GoodperceptionAdapter
import edu.whut.jianshu.Data.entity.BookShelf
import edu.whut.jianshu.Data.entity.Book_info_bmob
import edu.whut.jianshu.Data.entity.Bookcontent_bmob
import edu.whut.jianshu.Data.entity.Perception_bmob
import edu.whut.jianshu.Data.vo.Perception
import edu.whut.jianshu.Adapter.MarkingAdapter
import edu.whut.jianshu.Data.entity.*
import edu.whut.jianshu.Data.vo.Marking
import edu.whut.jianshu.R
import kotlinx.android.synthetic.main.activity_book_info.*
import kotlinx.android.synthetic.main.bookinfo_title.*
@ -36,8 +32,8 @@ import java.io.InputStream
class BookInformationActivity : AppCompatActivity() {
private lateinit var adapter: GoodperceptionAdapter
private val perceptionList = ArrayList<Perception>()
private lateinit var adapter: MarkingAdapter
private val MarkingList = ArrayList<Marking>()
private var isCommented = false
private lateinit var bookName: String
private lateinit var authorName: String
@ -56,23 +52,33 @@ class BookInformationActivity : AppCompatActivity() {
bookInfoTextView = findViewById(R.id.bookinfo_introduce)
userId = getSharedPreferences("userinf", Context.MODE_PRIVATE).getString("user_id", "").toString()
sourceActivityClass = intent.getSerializableExtra("Source_Activity") as? Class<*>
loadPerceptions()
loadMarkings()
setupRecyclerView()
loadBookInfo()
judgeInBookshelf()
setClickListeners()
judgeComment()
}
private fun loadPerceptions() {
val queryPerception = BmobQuery<Perception_bmob>()
queryPerception.addWhereEqualTo("b_name", bookName) //查询指定书名的精彩点评
queryPerception.findObjects(object : FindListener<Perception_bmob>() {
override fun done(list: List<Perception_bmob>, e: BmobException?) {
private fun loadMarkings() {
val queryMarking = BmobQuery<Marking_bmob>()
queryMarking.addWhereEqualTo("bookname", bookName) //查询指定书名的精彩点评
queryMarking.findObjects(object : FindListener<Marking_bmob>() {
override fun done(list: List<Marking_bmob>, e: BmobException?) {
if (e == null) {
bookinfo_swipeRefresh.isRefreshing = false
list.forEach { perceptionList.add(Perception(it.objectId)) }
list.forEach {
if (it.userid == userId) {
when (it.grade) {
1 -> b_henhao.setImageResource(R.drawable.recommend2)
2 -> b_yiban.setImageResource(R.drawable.normal2)
3 -> b_buxing.setImageResource(R.drawable.bad2)
}
}
MarkingList.add(Marking(it.objectId, it.countOfLike, it.countOfCollect, it.userid, it.grade, it.evaluation))
}
adapter.notifyDataSetChanged()
} else {
Log.e("BookInfo", "Error loading perceptions: ${e.message}")
}
@ -83,7 +89,7 @@ class BookInformationActivity : AppCompatActivity() {
private fun setupRecyclerView() {
val layoutManager = StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL)
bookinfo_recyclerView.layoutManager = layoutManager
adapter=GoodperceptionAdapter(perceptionList)
adapter=MarkingAdapter(MarkingList)
bookinfo_recyclerView.adapter = adapter
}
@ -216,12 +222,12 @@ class BookInformationActivity : AppCompatActivity() {
private fun setCommentClickListeners() {
if (!isCommented) {
val commentClickListener = View.OnClickListener {
val intent = Intent(this, SendSpecificActivity::class.java)
val intent = Intent(this, SendMarkingActivity::class.java)
intent.putExtra("bookname", bookName)
when (it.id) {
R.id.b_henhao -> intent.putExtra("comment_rank", 1)
R.id.b_yiban -> intent.putExtra("comment_rank", 2)
R.id.b_buxing -> intent.putExtra("comment_rank", 3)
R.id.b_henhao -> intent.putExtra("evaluation_grade", 1)
R.id.b_yiban -> intent.putExtra("evaluation_grade", 2)
R.id.b_buxing -> intent.putExtra("evaluation_grade", 3)
}
ContextCompat.startActivity(this, intent, null)
}
@ -233,53 +239,6 @@ class BookInformationActivity : AppCompatActivity() {
}
}
// private fun updateBookComment(isRecommended: Boolean) {
// if (!isCommented) {
// isCommented = true
// val queryBook = BmobQuery<Book_info_bmob>()
// queryBook.addWhereEqualTo("name", bookName)
// queryBook.findObjects(object : FindListener<Book_info_bmob>() {
// override fun done(books: List<Book_info_bmob>, e: BmobException?) {
// if (e == null) {
// for (book in books) {
// updateBookRankings(book, isRecommended)
// b_henhao.setImageResource(R.drawable.recommend2)
// }
// Toast.makeText(this@BookInformationActivity, "评价成功!", Toast.LENGTH_LONG)
// .show()
// } else {
// Log.e("BookInfo", "Error updating book comment: ${e.message}")
// }
// }
// })
// } else {
// Toast.makeText(this, "仅能评价一次!", Toast.LENGTH_SHORT).show()
// }
// }
private fun judgeComment(){
val query=BmobQuery<Perception_bmob>()
query.addWhereEqualTo("userid",userId)
query.addWhereEqualTo("b_name",bookName)
query.findObjects(object : FindListener<Perception_bmob>() {
override fun done(lists: List<Perception_bmob>, e: BmobException?) {
if (e == null) {
if(lists.isNotEmpty()) {
isCommented=true
val Myperception = lists[0]
if (Myperception.evaluation == 1)
b_henhao.setImageResource(R.drawable.recommend2)
else if (Myperception.evaluation == 2)
b_yiban.setImageResource(R.drawable.normal2)
else if (Myperception.evaluation == 3)
b_buxing.setImageResource(R.drawable.bad2)
}
} else {
Log.d("error", "error")
}
}
})
}
private fun loadBookCover(coverUrl: String) {
Glide.with(this) // 传入 Context
.load(coverUrl) // 加载图片的 URL

View File

@ -44,7 +44,8 @@ class MyPostActivity : AppCompatActivity() {
if (e == null) {
for (item in list) {
if (item.userid == userId) {
perceptionList.add(Perception(item.objectId))
perceptionList.add(Perception(
item.objectId,item.b_name,item.countOfLike,item.countOfCollect,item.userid,item.perception))
}
}
adapter.notifyDataSetChanged()

View File

@ -40,7 +40,8 @@ class PerceptionActivity : AppCompatActivity() {
if (e == null) {
perception_swipeRefresh.isRefreshing = false
for (i in list){
PerceptionList.add(Perception(i.objectId))
PerceptionList.add(Perception(
i.objectId,i.b_name,i.countOfLike,i.countOfCollect,i.userid,i.perception))
val adapter =PerceptionAdapter(PerceptionList)
perception_recyclerView.adapter = adapter
}

View File

@ -6,6 +6,7 @@ import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.os.Bundle
import android.util.Log
import android.view.inputmethod.InputMethodManager
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.StaggeredGridLayoutManager
@ -14,6 +15,8 @@ import cn.bmob.v3.BmobQuery
import cn.bmob.v3.exception.BmobException
import cn.bmob.v3.listener.FindListener
import cn.bmob.v3.listener.SaveListener
import com.bumptech.glide.Glide
import edu.whut.jianshu.Adapter.BookAdapter
import edu.whut.jianshu.Adapter.CommentAdapter
import edu.whut.jianshu.Data.entity.Book_info_bmob
import edu.whut.jianshu.Data.entity.Comment_bmob
@ -27,7 +30,8 @@ import java.net.HttpURLConnection
import java.net.URL
class Perception_informationActivity:AppCompatActivity() {
private lateinit var perceptionid:String
private lateinit var adapter: CommentAdapter
private lateinit var perceptionId:String
private lateinit var bookName:String
private val commentlist=ArrayList<Comment>()
lateinit var userId:String
@ -35,38 +39,55 @@ class Perception_informationActivity:AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_perception_infomation)
userId = getSharedPreferences("userinf", Context.MODE_PRIVATE).getString("user_id", "").toString()
perceptionid = intent.getStringExtra("PerceptionId").toString()
Log.d("mytest",perceptionid)
perceptionId = intent.getStringExtra("PerceptionId").toString()
inits()
adapter = CommentAdapter(commentlist)
comment_recyclerview.adapter = adapter
val layoutManager =
StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL)//第一个参数是列数
comment_recyclerview.layoutManager = layoutManager
var adapter = CommentAdapter(commentlist)
comment_recyclerview.adapter = adapter
submitComment.setOnClickListener {
val comment= Comment_bmob()
comment.text=yourcomment.text.toString()
comment.perceptionid=perceptionid
comment.comment_personid= userId
comment.save(object : SaveListener<String>() {
override fun done(objectId: String?, e: BmobException?) {
if (e == null) {
Toast.makeText(
this@Perception_informationActivity,
"评论成功!",
Toast.LENGTH_SHORT
).show()
yourcomment.text=null
} else {
Toast.makeText(
this@Perception_informationActivity,
"评论失败!",
Toast.LENGTH_SHORT
).show()
}
val commentText = yourcomment.text.toString()
if (commentText.isNotBlank()) {
val comment = Comment_bmob().apply {
text = commentText
perceptionid = perceptionId
comment_personid = userId
}
})
comment.save(object : SaveListener<String>() {
override fun done(objectId: String?, e: BmobException?) {
if (e == null) {
Toast.makeText(
this@Perception_informationActivity,
"评论成功!",
Toast.LENGTH_SHORT
).show()
yourcomment.text = null
// 隐藏软键盘
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(yourcomment.windowToken, 0)
val newComment = Comment(objectId ?: "")
commentlist.add(newComment)
adapter.notifyItemInserted(commentlist.size - 1)
comment_recyclerview.scrollToPosition(commentlist.size - 1)
} else {
Toast.makeText(
this@Perception_informationActivity,
"评论失败!",
Toast.LENGTH_SHORT
).show()
}
}
})
} else {
Toast.makeText(
this@Perception_informationActivity,
"评论内容不能为空",
Toast.LENGTH_SHORT
).show()
}
}
inf_bookInf.setOnClickListener{
val intent = Intent(this, BookInformationActivity::class.java)
intent.putExtra("Book_name", bookName)
@ -75,125 +96,76 @@ class Perception_informationActivity:AppCompatActivity() {
}
}
private fun inits(){
//加载随笔
val query = BmobQuery<Perception_bmob>()
query.addWhereEqualTo("objectId",perceptionid)
//加载用户头像
query.addWhereEqualTo("objectId", 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) {
//找发布用户
inf_textView_perception.text=p.perception
postTime.text="发表于 "+p.createdAt
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)) {
inf_postPersonName.text=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`)
inf_user_icon.setImageBitmap(bitmap)
} catch (e: Exception) {
e.printStackTrace()
}
}
}.start()
override fun done(perceptionList: MutableList<Perception_bmob>?, perceptionException: BmobException?) {
if (perceptionException == null && perceptionList != null && perceptionList.isNotEmpty()) {
val perception = perceptionList.first()
inf_textView_perception.text = perception.perception
postTime.text = "发表于 " + perception.createdAt
}
}
} else {
Log.d("myLog", "error")
}
}
})
// 查找发布用户
val queryUser = BmobQuery<User_bmob>()
queryUser.addWhereEqualTo("objectId", perception.userid)
queryUser.findObjects(object : FindListener<User_bmob>() {
override fun done(userList: List<User_bmob>, userException: BmobException?) {
if (userException == null && userList.isNotEmpty()) {
val user = userList.first()
inf_postPersonName.text = user.nickName
// 使用 Glide 加载图片
Glide.with(inf_user_icon.context)
.load(user.face?.url)
.placeholder(R.drawable.pre_load) // 占位符图片
.error(R.drawable.pre_load) // 错误图片
.into(inf_user_icon)
} else {
Log.d("myLog", "User query error: ${userException?.message}")
}
}
}
})
// 查找书籍信息
val queryBook = BmobQuery<Book_info_bmob>()
queryBook.addWhereEqualTo("name", perception.b_name)
queryBook.findObjects(object : FindListener<Book_info_bmob>() {
override fun done(bookList: List<Book_info_bmob>, bookException: BmobException?) {
if (bookException == null && bookList.isNotEmpty()) {
val book = bookList.first()
inf_bookAuthor.text = book.author_name
// 使用 Glide 加载书籍封面图片
Glide.with(inf_book_pic.context)
.load(book.picture?.url)
.placeholder(R.drawable.pre_load) // 占位符图片
.error(R.drawable.pre_load) // 错误图片
.into(inf_book_pic)
} else {
Log.d("myLog", "Book query error: ${bookException?.message}")
}
}
})
} else {
Log.d("myLog", "Perception query error: ${perceptionException?.message}")
}
}
})
//加载书籍封面
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
inf_bookName.text = bookName
val queryBook = BmobQuery<Book_info_bmob>()
queryBook.findObjects(object : FindListener<Book_info_bmob>() {
override fun done(list: List<Book_info_bmob>, e: BmobException?) {
if (e == null) {
for (i in list) {
if (p.b_name.equals(i.name)) {
inf_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`)
inf_book_pic.setImageBitmap(
bitmap
)
} catch (e: Exception) {
e.printStackTrace()
}
}
}.start()
}
}
} else {
Log.d("myLog", "error")
}
}
})
}
// 加载评论
commentlist.clear()
val bmobQuery = BmobQuery<Comment_bmob>()
bmobQuery.addWhereEqualTo("perceptionid", perceptionId)
bmobQuery.findObjects(object : FindListener<Comment_bmob>() {
override fun done(list: List<Comment_bmob>?, e: BmobException?) {
if (e == null && list != null) {
for (comment in list) {
commentlist.add(Comment(comment.objectId))
}
comment_cnt.text = "评论 ${commentlist.size}"
adapter.notifyDataSetChanged()
} else {
Log.d("myLog", "Error retrieving comments: ${e?.message}")
}
}
})
val bmobquery=BmobQuery<Comment_bmob>()
bmobquery.addWhereEqualTo("perceptionid",perceptionid)
bmobquery.findObjects(object:FindListener<Comment_bmob>(){
override fun done(list:List<Comment_bmob>,e:BmobException?){
if(e==null){
var cnt=0
for(i in list){
cnt++
commentlist.add(Comment(i.objectId))
val adapter = CommentAdapter(commentlist)
comment_recyclerview.adapter = adapter
}
comment_cnt.text="评论 "+cnt.toString()
}
}
})
}
}

View File

@ -14,13 +14,15 @@ import cn.bmob.v3.listener.UpdateListener
import edu.whut.jianshu.Data.entity.User_bmob
import edu.whut.jianshu.R
import kotlinx.android.synthetic.main.activity_editinfo.*
class ReAddressActivity : AppCompatActivity() {
lateinit var userId:String
lateinit var userId: String
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_editinfo)
userId = getSharedPreferences("userinf", Context.MODE_PRIVATE).getString("user_id", "").toString()
t_title.text="修改地址"
userId = getSharedPreferences("userinf", Context.MODE_PRIVATE).getString("user_id", "")
.toString()
t_title.text = "修改地址"
val extra_address = intent.getStringExtra("extra_address")
et_item.setHint(extra_address)
back2my.setOnClickListener() {
@ -42,29 +44,25 @@ class ReAddressActivity : AppCompatActivity() {
for (i in list) {
if (user_account.equals(i.account)) {
flag = true //找到
Log.d("myLog", "find sucessflly")
//-------更新数据库中的sex
i.setaddress(curAddress)
i.update(i.objectId, object : UpdateListener() {
override fun done(p0: BmobException?) {
if (p0 == null) {
Toast.makeText(
this@ReAddressActivity,
"地址修改成功!",
Toast.LENGTH_SHORT
).show()
//跳转个人信息页面,但是跳转之后原来的信息消失,需要重新进才能刷新
startActivity(intent)
// startActivityForResult(intent,1)
finish()
i.setaddress(curAddress)
i.update(i.objectId, object : UpdateListener() {
override fun done(p0: BmobException?) {
if (p0 == null) {
Toast.makeText(
this@ReAddressActivity,
"地址修改成功!",
Toast.LENGTH_SHORT
).show()
//跳转个人信息页面,但是跳转之后原来的信息消失,需要重新进才能刷新
startActivity(intent)
finish()
} else {
Log.d("myLog", "can't modify name")
}
} else {
Log.d("myLog", "can't modify name")
}
})
}
else{
}
})
} else {
Toast.makeText(
this@ReAddressActivity,
"请输入自己的账号!",

View File

@ -8,70 +8,68 @@ import android.view.WindowManager
import android.view.inputmethod.InputMethodManager
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import cn.bmob.v3.Bmob
import cn.bmob.v3.exception.BmobException
import cn.bmob.v3.listener.SaveListener
import edu.whut.jianshu.Data.entity.Perception_bmob
import edu.whut.jianshu.Data.entity.Marking_bmob
import edu.whut.jianshu.R
import kotlinx.android.synthetic.main.activity_sendspecific.*
import kotlinx.android.synthetic.main.activity_book_info.*
import kotlinx.android.synthetic.main.activity_sendmarking.*
class SendSpecificActivity: AppCompatActivity() {
class SendMarkingActivity: AppCompatActivity() {
lateinit var userId:String
lateinit var bookname:String
var comment_rank: Int? = null
var evaluation_grade: Int=0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_sendspecific)
sendspecific_content.requestFocus()
setContentView(R.layout.activity_sendmarking)
sendmarking_content.requestFocus()
// 弹出软键盘
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(sendspecific_content, InputMethodManager.SHOW_IMPLICIT)
imm.showSoftInput(sendmarking_content, InputMethodManager.SHOW_IMPLICIT)
// 防止自动弹出软键盘时页面被顶起
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
comment_rank = intent.getIntExtra("comment_rank",0)
evaluation_grade = intent.getIntExtra("evaluation_grade",0)
bookname = intent.getStringExtra("bookname")?: ""
userId = getSharedPreferences("userinf", Context.MODE_PRIVATE).getString("user_id", "").toString()
sendspecific_title.text="点评《"+bookname+""
sendmarking_title.text="点评《"+bookname+""
judgeComment()
setClickListeners()
}
private fun judgeComment(){
if(comment_rank==1)
sendspecific_henhao.setImageResource(R.drawable.recommend2)
else if(comment_rank==2)
sendspecific_yiban.setImageResource(R.drawable.normal2)
else if(comment_rank==3)
sendspecific_buxing.setImageResource(R.drawable.bad2)
when (evaluation_grade) {
1 -> sendmarking_henhao.setImageResource(R.drawable.recommend2)
2 -> sendmarking_yiban.setImageResource(R.drawable.normal2)
3 -> sendmarking_buxing.setImageResource(R.drawable.bad2)
}
}
private fun setClickListeners(){
sendspecific_cancel.setOnClickListener {
sendmarking_cancel.setOnClickListener {
val intent = Intent(this, BookInformationActivity::class.java)
intent.putExtra("Book_name", bookname)
startActivity(intent)
finish()
}
sendspecific_submit.setOnClickListener {
val perception= Perception_bmob()
perception.b_name=bookname
perception.userid=userId
perception.perception=sendspecific_content.text.toString()
perception.evaluation= comment_rank!!
perception.save(object : SaveListener<String>() {
sendmarking_submit.setOnClickListener {
val Marking= Marking_bmob()
Marking.bookname=bookname
Marking.userid=userId
Marking.evaluation=sendmarking_content.text.toString()
Marking.grade=evaluation_grade
Marking.save(object : SaveListener<String>() {
override fun done(objectId: String?, e: BmobException?) {
if (e == null) {
// 保存成功
Toast.makeText(
this@SendSpecificActivity,
this@SendMarkingActivity,
"点评成功!",
Toast.LENGTH_SHORT
).show()
Log.d("sendspecific", "Perception_bmob saved successfully. objectId: $objectId")
val intent = Intent(this@SendSpecificActivity, BookInformationActivity::class.java)
val intent = Intent(this@SendMarkingActivity, BookInformationActivity::class.java)
intent.putExtra("Book_name", bookname)
startActivity(intent)
finish()
} else {
// 保存失败
Log.e("sendspecific", "Failed to save Perception_bmob: ${e.message}")
}
}
})

View File

@ -1,7 +1,5 @@
package edu.whut.jianshu.Adapter
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.util.Log
import android.view.LayoutInflater
import android.view.View
@ -12,20 +10,20 @@ import androidx.recyclerview.widget.RecyclerView
import cn.bmob.v3.BmobQuery
import cn.bmob.v3.exception.BmobException
import cn.bmob.v3.listener.FindListener
import com.bumptech.glide.Glide
import edu.whut.jianshu.Data.entity.Comment_bmob
import edu.whut.jianshu.Data.entity.User_bmob
import edu.whut.jianshu.Data.vo.Comment
import edu.whut.jianshu.R
import java.io.InputStream
import java.net.HttpURLConnection
import java.net.URL
class CommentAdapter(val commentlist: List<Comment>) :
class CommentAdapter(val commentList: List<Comment>) :
RecyclerView.Adapter<CommentAdapter.ViewHolder>() {
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val user_icon: ImageView = view.findViewById(R.id.inf_comment_user_icon)
val user_name: TextView = view.findViewById(R.id.inf_comment_postPersonName)
val userIcon: ImageView = view.findViewById(R.id.inf_comment_user_icon)
val userName: TextView = view.findViewById(R.id.inf_comment_postPersonName)
val content: TextView = view.findViewById(R.id.inf_comment_textView_perception)
val commentTime:TextView=view.findViewById(R.id.inf_comment_commentTime)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
@ -33,48 +31,40 @@ class CommentAdapter(val commentlist: List<Comment>) :
return ViewHolder(view)
}
override fun onBindViewHolder(holder: CommentAdapter.ViewHolder, position: Int) {
val comment = commentlist[position]
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val comment = commentList[position]
val query = BmobQuery<Comment_bmob>()
query.addWhereEqualTo("objectId", comment.commentid)
query.findObjects(object : FindListener<Comment_bmob>() {
override fun done(list: List<Comment_bmob>, e: BmobException?) {
if (e == null) {
for (i in list) {
holder.content.text = i.text
Log.d("zytt",i.text)
val query2 = BmobQuery<User_bmob>()
query2.addWhereEqualTo("objectId",i.comment_personid)
query2.findObjects(object:FindListener<User_bmob>(){
override fun done(list:List<User_bmob>,e:BmobException?){
if(e==null){
for(j in list){
holder.user_name.text=j.nickName
object : Thread() {
override fun run() {
try {
val url = URL(j!!.face.url)
val connection: HttpURLConnection =
url.openConnection() as HttpURLConnection
connection.setRequestMethod("GET")
connection.setConnectTimeout(5000)
val `in`: InputStream = connection.getInputStream()
val bitmap: Bitmap =
BitmapFactory.decodeStream(`in`)
holder.user_icon.setImageBitmap(bitmap)
} catch (e: Exception) {
e.printStackTrace()
}
}
}.start()
}
}
override fun done(commentList: List<Comment_bmob>, e: BmobException?) {
if (e == null && commentList.isNotEmpty()) {
val commentBmob = commentList.first()
holder.content.text = commentBmob.text
holder.commentTime.text=" "+commentBmob.createdAt
val queryUser = BmobQuery<User_bmob>()
queryUser.addWhereEqualTo("objectId", commentBmob.comment_personid)
queryUser.findObjects(object : FindListener<User_bmob>() {
override fun done(userList: List<User_bmob>, e: BmobException?) {
if (e == null && userList.isNotEmpty()) {
val user = userList.first()
holder.userName.text = user.nickName
// 使用 Glide 加载用户头像
Glide.with(holder.userIcon.context)
.load(user.face?.url)
.placeholder(R.drawable.pre_load) // 占位符图片
.error(R.drawable.pre_load) // 错误图片
.into(holder.userIcon)
} else {
Log.d("myLog", "User query error: ${e?.message}")
}
})
}
}
})
} else {
Log.d("myLog", "Comment query error: ${e?.message}")
}
}
})
}
override fun getItemCount() = commentlist.size
}
override fun getItemCount() = commentList.size
}

View File

@ -1,70 +0,0 @@
package edu.whut.jianshu.Adapter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import cn.bmob.v3.BmobQuery
import cn.bmob.v3.exception.BmobException
import cn.bmob.v3.listener.FindListener
import com.bumptech.glide.Glide
import edu.whut.jianshu.Data.entity.Perception_bmob
import edu.whut.jianshu.Data.entity.User_bmob
import edu.whut.jianshu.Data.vo.Perception
import edu.whut.jianshu.R
class GoodperceptionAdapter(val perceptionList: List<Perception>) : RecyclerView.Adapter<GoodperceptionAdapter.ViewHolder>() {
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val user_Image: ImageView = view.findViewById(R.id.goodperception_avatar)
val user_name: TextView = view.findViewById(R.id.user_Name)
val perception: TextView = view.findViewById(R.id.goodContent)
val evaluation_state:ImageView=view.findViewById(R.id.evaluation_state)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.goodperception_item, parent, false)
return ViewHolder(view)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val perception = perceptionList[position]
// 从 Perception_bmob 表中查找与 perception 对应的数据
BmobQuery<Perception_bmob>()
.addWhereEqualTo("objectId", perception.perceptionid)
.findObjects(object : FindListener<Perception_bmob>() {
override fun done(perceptionList: MutableList<Perception_bmob>?, exception: BmobException?) {
if (exception == null && perceptionList != null && perceptionList.isNotEmpty()) {
val perceptionData = perceptionList.first()
holder.perception.text = perceptionData.perception
if (perceptionData.evaluation == 1)
holder.evaluation_state.setImageResource(R.drawable.recommend1)
else if (perceptionData.evaluation == 2)
holder.evaluation_state.setImageResource(R.drawable.normal1)
else if (perceptionData.evaluation == 3)
holder.evaluation_state.setImageResource(R.drawable.bad1)
// 从 User_bmob 表中查找与 perceptionData.userid 对应的数据
BmobQuery<User_bmob>()
.addWhereEqualTo("objectId", perceptionData.userid)
.findObjects(object : FindListener<User_bmob>() {
override fun done(userList: MutableList<User_bmob>?, userException: BmobException?) {
if (userException == null && userList != null && userList.isNotEmpty()) {
val userData = userList.first()
holder.user_name.text = userData.nickName
Glide.with(holder.itemView.context)
.load(userData.face.url)
.placeholder(R.drawable.pre_load)
.error(R.drawable.fail_load)
.into(holder.user_Image)
}
}
})
}
}
})
}
override fun getItemCount() =perceptionList.size
}

View File

@ -0,0 +1,229 @@
package edu.whut.jianshu.Adapter
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 cn.bmob.v3.listener.QueryListener
import cn.bmob.v3.listener.SaveListener
import cn.bmob.v3.listener.UpdateListener
import com.bumptech.glide.Glide
import edu.whut.jianshu.Data.entity.*
import edu.whut.jianshu.Data.vo.Marking
import edu.whut.jianshu.R
class MarkingAdapter(val markingList: List<Marking>) :
RecyclerView.Adapter<MarkingAdapter.ViewHolder>() {
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val user_Image: ImageView = view.findViewById(R.id.goodperception_avatar)
val user_name: TextView = view.findViewById(R.id.user_Name)
val evaluation: TextView = view.findViewById(R.id.goodContent)
val marking_likecnt:TextView=view.findViewById(R.id.marking_likecnt)
val marking_collectcnt:TextView=view.findViewById(R.id.marking_collectcnt)
val marking_grade: ImageView = view.findViewById(R.id.marking_grade)
val marking_like:ImageView=view.findViewById(R.id.marking_like)
val marking_collect:ImageView=view.findViewById(R.id.marking_collect)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view =
LayoutInflater.from(parent.context).inflate(R.layout.goodperception_item, parent, false)
return ViewHolder(view)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val marking = markingList[position]
when (marking.grade) {
1 -> holder.marking_grade.setImageResource(R.drawable.recommend1)
2 -> holder.marking_grade.setImageResource(R.drawable.normal1)
3 -> holder.marking_grade.setImageResource(R.drawable.bad1)
}
holder.evaluation.text=marking.evaluation
holder.marking_collectcnt.text=marking.countOfCollect.toString()
holder.marking_likecnt.text=marking.countOfLike.toString()
BmobQuery<User_bmob>()
.addWhereEqualTo("objectId", marking.userid)
.findObjects(object : FindListener<User_bmob>() {
override fun done(
userList: MutableList<User_bmob>?,
userException: BmobException?
) {
if (userException == null && userList != null && userList.isNotEmpty()) {
val userData = userList.first()
holder.user_name.text = userData.nickName
Glide.with(holder.itemView.context)
.load(userData.face.url)
.placeholder(R.drawable.pre_load)
.error(R.drawable.fail_load)
.into(holder.user_Image)
}
}
})
updateIcon<Like_bmob>(
marking.userid, marking.markingid,
R.drawable.like2, R.drawable.like1
) { holder.marking_like.setImageResource(it) }
updateIcon<Collect_bmob>(
marking.userid, marking.markingid,
R.drawable.collect2, R.drawable.collect1
) { holder.marking_collect.setImageResource(it) }
holder.marking_like.setOnClickListener {
handleLikeAction(marking, holder)
}
holder.marking_collect.setOnClickListener {
handleCollectAction(marking, holder)
}
}
// 抽取的更新图标方法
private inline fun <reified T> updateIcon(
userId: String, articleId: String,
iconActive: Int, iconInactive: Int,
crossinline setIcon: (Int) -> Unit
) {
BmobQuery<T>()
.addWhereEqualTo("userid", userId)
.addWhereEqualTo("articleid", articleId)
.findObjects(object : FindListener<T>() {
override fun done(resultList: MutableList<T>?, userException: BmobException?) {
if (userException == null && resultList != null && resultList.isNotEmpty()) {
setIcon(iconActive)
} else {
setIcon(iconInactive)
}
}
})
}
private fun handleLikeAction(marking: Marking, holder: ViewHolder) {
val currentDrawable = holder.marking_like.drawable.constantState
val like1Drawable = ContextCompat.getDrawable(holder.marking_like.context, R.drawable.like1)?.constantState
val like2Drawable = ContextCompat.getDrawable(holder.marking_like.context, R.drawable.like2)?.constantState
if (currentDrawable == like1Drawable) {
holder.marking_like.setImageResource(R.drawable.like2)
updateLikeStatus(marking, holder, true)
} else if (currentDrawable == like2Drawable) {
holder.marking_like.setImageResource(R.drawable.like1)
updateLikeStatus(marking, holder, false)
}
}
private fun handleCollectAction(marking: Marking, holder: ViewHolder) {
val currentDrawable = holder.marking_collect.drawable.constantState
val collect1Drawable = ContextCompat.getDrawable(holder.marking_collect.context, R.drawable.collect1)?.constantState
val collect2Drawable = ContextCompat.getDrawable(holder.marking_collect.context, R.drawable.collect2)?.constantState
if (currentDrawable == collect1Drawable) {
holder.marking_collect.setImageResource(R.drawable.collect2)
updateCollectStatus(marking, holder, true)
} else if (currentDrawable == collect2Drawable) {
holder.marking_collect.setImageResource(R.drawable.collect1)
updateCollectStatus(marking, holder, false)
}
}
private fun updateLikeStatus(marking: Marking, holder: ViewHolder, isLiked: Boolean) {
if (isLiked) {
val like = Like_bmob().apply {
userid = marking.userid
articleid = marking.markingid
}
like.save(object : SaveListener<String>() {
override fun done(objectId: String?, e: BmobException?) {
if (e == null) updateMarkingLikeCount(marking, holder, true)
}
})
} else {
val query = BmobQuery<Like_bmob>()
query.addWhereEqualTo("userid", marking.userid)
query.addWhereEqualTo("articleid", marking.markingid)
query.findObjects(object : FindListener<Like_bmob>() {
override fun done(items: MutableList<Like_bmob>?, e: BmobException?) {
if (e == null && items != null && items.isNotEmpty()) {
items.first().delete(object : UpdateListener() {
override fun done(ex: BmobException?) {
if (ex == null) updateMarkingLikeCount(marking, holder, false)
}
})
}
}
})
}
}
private fun updateCollectStatus(marking: Marking, holder: ViewHolder, isCollected: Boolean) {
if (isCollected) {
val collect = Collect_bmob().apply {
userid = marking.userid
articleid = marking.markingid
}
collect.save(object : SaveListener<String>() {
override fun done(objectId: String?, e: BmobException?) {
if (e == null) updateMarkingCollectCount(marking, holder, true)
}
})
} else {
val query = BmobQuery<Collect_bmob>()
query.addWhereEqualTo("userid", marking.userid)
query.addWhereEqualTo("articleid", marking.markingid)
query.findObjects(object : FindListener<Collect_bmob>() {
override fun done(items: MutableList<Collect_bmob>?, e: BmobException?) {
if (e == null && items != null && items.isNotEmpty()) {
items.first().delete(object : UpdateListener() {
override fun done(ex: BmobException?) {
if (ex == null) updateMarkingCollectCount(marking, holder, false)
}
})
}
}
})
}
}
private fun updateMarkingLikeCount(marking: Marking, holder: ViewHolder, increment: Boolean) {
val bmobQuery = BmobQuery<Marking_bmob>()
bmobQuery.getObject(marking.markingid, object : QueryListener<Marking_bmob>() {
override fun done(theMarking: Marking_bmob?, ex: BmobException?) {
if (ex == null && theMarking != null) {
theMarking.countOfLike = if (increment) theMarking.countOfLike + 1 else theMarking.countOfLike - 1
holder.marking_likecnt.text = theMarking.countOfLike.toString()
theMarking.update(marking.markingid, object : UpdateListener() {
override fun done(p0: BmobException?) {
// 处理更新结果
}
})
}
}
})
}
private fun updateMarkingCollectCount(marking: Marking, holder: ViewHolder, increment: Boolean) {
val bmobQuery = BmobQuery<Marking_bmob>()
bmobQuery.getObject(marking.markingid, object : QueryListener<Marking_bmob>() {
override fun done(theMarking: Marking_bmob?, ex: BmobException?) {
if (ex == null && theMarking != null) {
theMarking.countOfCollect = if (increment) theMarking.countOfCollect + 1 else theMarking.countOfCollect - 1
holder.marking_collectcnt.text = theMarking.countOfCollect.toString()
theMarking.update(marking.markingid, object : UpdateListener() {
override fun done(p0: BmobException?) {
// 处理更新结果
}
})
}
}
})
}
override fun getItemCount() = markingList.size
}

View File

@ -12,12 +12,14 @@ import androidx.recyclerview.widget.RecyclerView
import cn.bmob.v3.BmobQuery
import cn.bmob.v3.exception.BmobException
import cn.bmob.v3.listener.FindListener
import cn.bmob.v3.listener.QueryListener
import cn.bmob.v3.listener.SaveListener
import cn.bmob.v3.listener.UpdateListener
import com.bumptech.glide.Glide
import edu.whut.jianshu.Activity.BookInformationActivity
import edu.whut.jianshu.Activity.Perception_informationActivity
import edu.whut.jianshu.Data.entity.Book_info_bmob
import edu.whut.jianshu.Data.entity.Perception_bmob
import edu.whut.jianshu.Data.entity.User_bmob
import edu.whut.jianshu.Data.entity.*
import edu.whut.jianshu.Data.vo.Marking
import edu.whut.jianshu.Data.vo.Perception
import edu.whut.jianshu.R
@ -26,18 +28,22 @@ class PerceptionAdapter(val perceptionList: List<Perception>) :
RecyclerView.Adapter<PerceptionAdapter.ViewHolder>() {
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val perception_perception: TextView = view.findViewById(R.id.perception_content)
//随笔相关
val perception_content: TextView = view.findViewById(R.id.perception_content)
val perception_likecnt:TextView=view.findViewById(R.id.perception_likecnt)
val perception_collectcnt:TextView=view.findViewById(R.id.perception_collectcnt)
val perception_like:ImageView=view.findViewById(R.id.perception_likeicon)
val perception_collect:ImageView=view.findViewById(R.id.perception_collecticon)
//用户头像
val perception_userIcon: ImageView = view.findViewById(R.id.perception_avatar)
val perception_posetPerson: TextView = view.findViewById(R.id.perception_username)
val perception_username: TextView = view.findViewById(R.id.perception_username)
//书籍封面
val perception_bookPic: ImageView = view.findViewById(R.id.perception_bookpic)
val perception_bookName: TextView = view.findViewById(R.id.perception_bookName)
val perception_bookAuthor: TextView = view.findViewById(R.id.perception_bookAuthor)
val perception_bookInf: View = view.findViewById(R.id.perception_bookInf)
lateinit var perceptionid: String
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
@ -47,78 +53,212 @@ class PerceptionAdapter(val perceptionList: List<Perception>) :
}
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) {
bookName = p.b_name
//找发布用户
holder.perception_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.perception_posetPerson.text = i.nickName
//加载图片
Glide.with(holder.itemView.context)
.load(i.face.url) // 确保你的Book对象有正确的图片URL
.placeholder(R.drawable.pre_load) // 可以设置一个占位图
.error(R.drawable.fail_load) // 设置加载失败的图
.into(holder.perception_userIcon)
}
}
} else {
Log.d("perception", "error")
}
}
})
val queryBook = BmobQuery<Book_info_bmob>()
queryBook.addWhereEqualTo("name", bookName)
queryBook.findObjects(object : FindListener<Book_info_bmob>() {
override fun done(list: List<Book_info_bmob>, e: BmobException?) {
if (e == null) {
for (i in list) {
holder.perception_bookName.text=bookName
holder.perception_bookAuthor.text=i.author_name
Glide.with(holder.itemView.context)
.load(i.picture.url) // 确保你的Book对象有正确的图片URL
.placeholder(R.drawable.pre_load) // 可以设置一个占位图
.error(R.drawable.fail_load) // 设置加载失败的图
.into(holder.perception_bookPic)
}
} else {
Log.d("myLog", "error")
}
}
})
}
holder.perception_content.text=perception.perception
holder.perception_collectcnt.text=perception.countOfCollect.toString()
holder.perception_likecnt.text=perception.countOfLike.toString()
BmobQuery<User_bmob>()
.addWhereEqualTo("objectId", perception.userid)
.findObjects(object : FindListener<User_bmob>() {
override fun done(
userList: MutableList<User_bmob>?,
userException: BmobException?
) {
if (userException == null && userList != null && userList.isNotEmpty()) {
val userData = userList.first()
holder.perception_username.text = userData.nickName
Glide.with(holder.itemView.context)
.load(userData.face.url)
.placeholder(R.drawable.pre_load)
.error(R.drawable.fail_load)
.into(holder.perception_userIcon)
}
}
})
val queryBook = BmobQuery<Book_info_bmob>()
queryBook.addWhereEqualTo("name", perception.bookname)
queryBook.findObjects(object : FindListener<Book_info_bmob>() {
override fun done(list: List<Book_info_bmob>, e: BmobException?) {
if (e == null) {
for (i in list) {
holder.perception_bookName.text = perception.bookname
holder.perception_bookAuthor.text = i.author_name
Glide.with(holder.itemView.context)
.load(i.picture.url) // 确保你的Book对象有正确的图片URL
.placeholder(R.drawable.pre_load) // 可以设置一个占位图
.error(R.drawable.fail_load) // 设置加载失败的图
.into(holder.perception_bookPic)
}
} else {
Log.d("myLog", "error")
}
}
})
updateIcon<Like_bmob>(
perception.userid, perception.perceptionid,
R.drawable.like2, R.drawable.like1
) { holder.perception_like.setImageResource(it) }
updateIcon<Collect_bmob>(
perception.userid, perception.perceptionid,
R.drawable.collect2, R.drawable.collect1
) { holder.perception_collect.setImageResource(it) }
holder.perception_like.setOnClickListener {
handleLikeAction(perception, holder)
}
holder.perception_collect.setOnClickListener {
handleCollectAction(perception, holder)
}
holder.perception_bookInf.setOnClickListener() {
val intent = Intent(holder.itemView.context, BookInformationActivity::class.java)
intent.putExtra("Book_name", bookName)
intent.putExtra("Book_name", perception.bookname)
ContextCompat.startActivity(holder.itemView.context, intent, null)
}
holder.perception_perception.setOnClickListener {
holder.perception_content.setOnClickListener {
val intent = Intent(holder.itemView.context, Perception_informationActivity::class.java)
intent.putExtra("PerceptionId", holder.perceptionid)
intent.putExtra("PerceptionId", perception.perceptionid)
ContextCompat.startActivity(holder.itemView.context, intent, null)
}
//给评论图标设置点击事件
//给评论图标设置点击事件
// holder.comment.setOnClickListener(View.OnClickListener { showPopupcomment() })
}
// 抽取的更新图标方法
private inline fun <reified T> updateIcon(
userId: String, articleId: String,
iconActive: Int, iconInactive: Int,
crossinline setIcon: (Int) -> Unit
) {
BmobQuery<T>()
.addWhereEqualTo("userid", userId)
.addWhereEqualTo("articleid", articleId)
.findObjects(object : FindListener<T>() {
override fun done(resultList: MutableList<T>?, userException: BmobException?) {
if (userException == null && resultList != null && resultList.isNotEmpty()) {
setIcon(iconActive)
} else {
setIcon(iconInactive)
}
}
})
}
private fun handleLikeAction(perception: Perception, holder: PerceptionAdapter.ViewHolder) {
val currentDrawable = holder.perception_like.drawable.constantState
val like1Drawable = ContextCompat.getDrawable(holder.perception_like.context, R.drawable.like1)?.constantState
val like2Drawable = ContextCompat.getDrawable(holder.perception_like.context, R.drawable.like2)?.constantState
if (currentDrawable == like1Drawable) {
holder.perception_like.setImageResource(R.drawable.like2)
updateLikeStatus(perception, holder, true)
} else if (currentDrawable == like2Drawable) {
holder.perception_like.setImageResource(R.drawable.like1)
updateLikeStatus(perception, holder, false)
}
}
private fun handleCollectAction(perception: Perception, holder: PerceptionAdapter.ViewHolder) {
val currentDrawable = holder.perception_collect.drawable.constantState
val collect1Drawable = ContextCompat.getDrawable(holder.perception_collect.context, R.drawable.collect1)?.constantState
val collect2Drawable = ContextCompat.getDrawable(holder.perception_collect.context, R.drawable.collect2)?.constantState
if (currentDrawable == collect1Drawable) {
holder.perception_collect.setImageResource(R.drawable.collect2)
updateCollectStatus(perception, holder, true)
} else if (currentDrawable == collect2Drawable) {
holder.perception_collect.setImageResource(R.drawable.collect1)
updateCollectStatus(perception, holder, false)
}
}
private fun updateLikeStatus(perception: Perception, holder: PerceptionAdapter.ViewHolder, isLiked: Boolean) {
if (isLiked) {
val like = Like_bmob().apply {
userid = perception.userid
articleid = perception.perceptionid
}
like.save(object : SaveListener<String>() {
override fun done(objectId: String?, e: BmobException?) {
if (e == null) updatePerceptionLikeCount(perception, holder, true)
}
})
} else {
val query = BmobQuery<Like_bmob>()
query.addWhereEqualTo("userid", perception.userid)
query.addWhereEqualTo("articleid", perception.perceptionid)
query.findObjects(object : FindListener<Like_bmob>() {
override fun done(items: MutableList<Like_bmob>?, e: BmobException?) {
if (e == null && items != null && items.isNotEmpty()) {
items.first().delete(object : UpdateListener() {
override fun done(ex: BmobException?) {
if (ex == null) updatePerceptionLikeCount(perception, holder, false)
}
})
}
}
})
}
}
private fun updateCollectStatus(perception: Perception, holder: PerceptionAdapter.ViewHolder, isCollected: Boolean) {
if (isCollected) {
val collect = Collect_bmob().apply {
userid = perception.userid
articleid = perception.perceptionid
}
collect.save(object : SaveListener<String>() {
override fun done(objectId: String?, e: BmobException?) {
if (e == null) updatePerceptionCollectCount(perception, holder, true)
}
})
} else {
val query = BmobQuery<Collect_bmob>()
query.addWhereEqualTo("userid", perception.userid)
query.addWhereEqualTo("articleid", perception.perceptionid)
query.findObjects(object : FindListener<Collect_bmob>() {
override fun done(items: MutableList<Collect_bmob>?, e: BmobException?) {
if (e == null && items != null && items.isNotEmpty()) {
items.first().delete(object : UpdateListener() {
override fun done(ex: BmobException?) {
if (ex == null) updatePerceptionCollectCount(perception, holder, false)
}
})
}
}
})
}
}
private fun updatePerceptionLikeCount(perception: Perception, holder: PerceptionAdapter.ViewHolder, increment: Boolean) {
val bmobQuery = BmobQuery<Perception_bmob>()
bmobQuery.getObject(perception.perceptionid, object : QueryListener<Perception_bmob>() {
override fun done(thePerception: Perception_bmob?, ex: BmobException?) {
if (ex == null && thePerception != null) {
thePerception.countOfLike = if (increment) thePerception.countOfLike + 1 else thePerception.countOfLike - 1
holder.perception_likecnt.text = thePerception.countOfLike.toString()
thePerception.update(perception.perceptionid, object : UpdateListener() {
override fun done(p0: BmobException?) {
// 处理更新结果
}
})
}
}
})
}
private fun updatePerceptionCollectCount(perception: Perception, holder: PerceptionAdapter.ViewHolder, increment: Boolean) {
val bmobQuery = BmobQuery<Perception_bmob>()
bmobQuery.getObject(perception.perceptionid, object : QueryListener<Perception_bmob>() {
override fun done(thePerception: Perception_bmob?, ex: BmobException?) {
if (ex == null && thePerception != null) {
thePerception.countOfCollect = if (increment) thePerception.countOfCollect + 1 else thePerception.countOfCollect - 1
holder.perception_collectcnt.text = thePerception.countOfCollect.toString()
thePerception.update(perception.perceptionid, object : UpdateListener() {
override fun done(p0: BmobException?) {
// 处理更新结果
}
})
}
}
})
}
override fun getItemCount() = perceptionList.size

View File

@ -12,14 +12,4 @@ class Book_info_bmob:BmobObject(){
var tuijian:Int=0
var buxing:Int=0
var countOfReaders:Int=0
fun settuijian(tuijian1: Int){
this.tuijian=tuijian1
}
fun setyiban(yiban1: Int){
this.yiban=yiban1
}
fun setbuxing(buxing1: Int){
this.buxing=buxing1
}
}

View File

@ -0,0 +1,8 @@
package edu.whut.jianshu.Data.entity
import cn.bmob.v3.BmobObject
class Collect_bmob:BmobObject() {
var userid:String=""
var articleid:String=""
}

View File

@ -0,0 +1,8 @@
package edu.whut.jianshu.Data.entity
import cn.bmob.v3.BmobObject
class Like_bmob:BmobObject() {
var userid:String=""
var articleid:String=""
}

View File

@ -0,0 +1,12 @@
package edu.whut.jianshu.Data.entity
import cn.bmob.v3.BmobObject
class Marking_bmob:BmobObject() {
var evaluation: String = ""
var bookname: String = ""
var userid: String = ""
var grade:Int=0 //1->推荐 2->一般 3->不行
var countOfLike:Int=0
var countOfCollect:Int=0
}

View File

@ -4,7 +4,8 @@ import cn.bmob.v3.BmobObject
class Perception_bmob:BmobObject() {
var perception: String = ""
var b_name: String = ""
var post_person: String = ""
var userid: String = ""
var evaluation:Int=0
var countOfLike:Int=0
var countOfCollect:Int=0
var countOfComment:Int=0
}

View File

@ -0,0 +1,10 @@
package edu.whut.jianshu.Data.vo
class Marking (
var markingid:String,
var countOfLike:Int,
var countOfCollect:Int,
var userid:String,
var grade:Int,
var evaluation:String
)

View File

@ -1,3 +1,10 @@
package edu.whut.jianshu.Data.vo
class Perception(val perceptionid:String)
class Perception(
var perceptionid:String,
var bookname:String,
var countOfLike:Int,
var countOfCollect:Int,
var userid:String,
var perception:String
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 848 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 728 B

View File

@ -0,0 +1,4 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="20dp" />
<solid android:color="#B0C4DE" />
</shape>

View File

@ -7,7 +7,9 @@
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/bookinfo_swipeRefresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/bookinfo_bottom">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -206,7 +208,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="精彩随笔"
android:text="精彩点评"
android:textSize="16dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/Book_name_View" />

View File

@ -182,7 +182,7 @@
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:src="@drawable/collect" />
android:src="@drawable/collect1" />
<TextView
android:layout_width="wrap_content"

View File

@ -38,12 +38,12 @@
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="8dp"
android:layout_marginTop="35dp"
android:layout_marginTop="25dp"
android:layout_marginEnd="177dp"
android:layout_marginBottom="16dp"
android:textSize="@dimen/s_dp_16"
android:layout_toEndOf="@+id/inf_user_icon"
android:text="百利甜斤鱼子"
android:textColor="@color/black" />
android:text="百利甜斤鱼子" />
</RelativeLayout>
@ -97,8 +97,7 @@
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="钱钟书"
android:textColor="@color/black"
android:textSize="15sp" />
android:textSize="16sp" />
<TextView
android:id="@+id/inf_bookName"
@ -109,8 +108,7 @@
android:lines="1"
android:paddingTop="15dp"
android:text="围城"
android:textColor="@color/black"
android:textSize="15sp" />
android:textSize="16sp" />
</LinearLayout>
@ -135,7 +133,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="发表于 "
android:textColor="@color/black" />
android:textColor="#808080" />
<TextView
android:id="@+id/comment_cnt"

View File

@ -10,7 +10,7 @@
android:gravity="center_horizontal">
<TextView
android:id="@+id/sendspecific_title"
android:id="@+id/sendmarking_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="点评xx"
@ -22,23 +22,23 @@
android:layout_height="50dp"
android:layout_margin="10dp"
android:orientation="horizontal">
sendmarking
<ImageView
android:id="@+id/sendspecific_henhao"
android:id="@+id/sendmarking_henhao"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_weight="1"
app:srcCompat="@drawable/recommend1" />
<ImageView
android:id="@+id/sendspecific_yiban"
android:id="@+id/sendmarking_yiban"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_weight="1"
app:srcCompat="@drawable/normal1" />
<ImageView
android:id="@+id/sendspecific_buxing"
android:id="@+id/sendmarking_buxing"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_weight="1"
@ -52,7 +52,7 @@
android:layout_marginEnd="10dp"
android:layout_marginTop="10dp" />
<EditText
android:id="@+id/sendspecific_content"
android:id="@+id/sendmarking_content"
android:layout_width="match_parent"
android:layout_height="350dp"
android:layout_marginLeft="20dp"
@ -64,7 +64,7 @@
android:orientation="horizontal">
<TextView
android:id="@+id/sendspecific_cancel"
android:id="@+id/sendmarking_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
@ -78,7 +78,7 @@
android:layout_weight="1" />
<TextView
android:id="@+id/sendspecific_submit"
android:id="@+id/sendmarking_submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#00BFFF"

View File

@ -3,37 +3,48 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="200dp"
android:orientation="vertical">
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal">
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical">
<ImageView
android:id="@+id/inf_comment_user_icon"
android:layout_width="36dp"
android:layout_height="38dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:paddingRight="5dp"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_margin="4dp"
android:src="@drawable/touxiang" />
<TextView
android:id="@+id/inf_comment_postPersonName"
android:layout_width="156dp"
android:layout_height="20dp"
android:layout_marginStart="5dp"
android:layout_marginTop="19dp"
android:layout_toEndOf="@+id/inf_comment_user_icon"
android:text="百利甜斤鱼子" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="百利甜斤鱼子"
android:textSize="14sp"
android:gravity="center_vertical" />
<TextView
android:id="@+id/inf_comment_commentTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="2024-05-22 11:00:00"
android:textSize="14sp"
android:textColor="#808080"
android:gravity="center_vertical" />
</LinearLayout>
<TextView
android:id="@+id/inf_comment_textView_perception"
android:layout_width="380dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="多边形裁剪用于裁剪掉被裁剪多边形(又称为实体多边形后文用S表示)位于窗口(又称为裁剪多边形后文用C表示)之外的部分。裁剪的结果多边形是由实体多边形位于裁剪多边形内的边界和裁剪多边形位于实体多边形内的边界组成的。" />
</LinearLayout>
android:layout_marginStart="40dp"
android:layout_marginTop="4dp"
android:text="多边形裁剪用于裁剪掉被裁剪多边形(又称为实体多边形后文用S表示)位于窗口(又称为裁剪多边形后文用C表示)之外的部分。裁剪的结果多边形是由实体多边形位于裁剪多边形内的边界和裁剪多边形位于实体多边形内的边界组成的。"
android:textSize="14sp" />
</LinearLayout>

View File

@ -34,7 +34,7 @@
android:text="张三" />
<ImageView
android:id="@+id/evaluation_state"
android:id="@+id/marking_grade"
android:layout_width="99dp"
android:layout_height="30dp"
android:src="@drawable/recommend1" />
@ -69,14 +69,18 @@
android:orientation="horizontal">
<ImageView
android:id="@+id/marking_like"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginLeft="50dp"
android:layout_marginLeft="40dp"
android:src="@drawable/like1" />
<TextView
android:layout_gravity="center"
android:id="@+id/marking_likecnt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/s_dp_5"
android:text="点赞数" />
</LinearLayout>
@ -88,15 +92,19 @@
android:gravity="end">
<ImageView
android:id="@+id/marking_collect"
android:layout_width="25dp"
android:layout_height="25dp"
android:src="@drawable/comment1" />
android:src="@drawable/collect1" />
<TextView
android:layout_gravity="center"
android:id="@+id/marking_collectcnt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="50dp"
android:text="评论数" />
android:layout_marginLeft="@dimen/s_dp_5"
android:layout_marginRight="40dp"
android:text="收藏数" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

View File

@ -54,7 +54,7 @@
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:background="@drawable/mydimgrey"
android:background="@drawable/color_lightsteelblue"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
@ -125,12 +125,16 @@
android:orientation="horizontal">
<ImageView
android:id="@+id/perception_likeicon"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginLeft="50dp"
android:src="@drawable/like1" />
<TextView
android:layout_gravity="center"
android:layout_marginLeft="@dimen/s_dp_5"
android:id="@+id/perception_likecnt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="点赞数" />
@ -144,11 +148,15 @@
android:gravity="end">
<ImageView
android:id="@+id/perception_collecticon"
android:layout_width="25dp"
android:layout_height="25dp"
android:src="@drawable/collect" />
<TextView
android:layout_gravity="center"
android:layout_marginLeft="@dimen/s_dp_5"
android:id="@+id/perception_collectcnt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="50dp"