JianShu/app/src/main/java/com/zjgsu/jianshu/Activity/PerceptionActivity.kt

90 lines
3.3 KiB
Kotlin
Raw Normal View History

2024-04-25 10:33:59 +08:00
package com.zjgsu.jianshu
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.recyclerview.widget.LinearLayoutManager
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.Activity.sendPerceptionActivity
import com.zjgsu.jianshu.Bmob.Perception_bmob
import kotlinx.android.synthetic.main.activity_perception.*
import kotlinx.android.synthetic.main.layout_bottom_navigation.*
import kotlin.concurrent.thread
class PerceptionActivity : AppCompatActivity() {
private val PerceptionList = ArrayList<Perception>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_perception)
Bmob.initialize(this, "8f9f1d1ea520b0ce4f84a6fa83a5f754")//连接bmob
inits()
val layoutManager=LinearLayoutManager(this)
perception_recyclerView.layoutManager = layoutManager
val adapter =PerceptionAdapter(PerceptionList)
perception_recyclerView.adapter = adapter
perception_swipeRefresh.setOnRefreshListener {
refreshPerception(adapter)
}
Log.d("myLog",perception_recyclerView.adapter.toString())
fab.setOnClickListener {
Toast.makeText(this,"新建随笔",Toast.LENGTH_SHORT).show()
}
fab.setOnClickListener {
val intent=Intent(this,sendPerceptionActivity::class.java)
intent.putExtra("userid", UserId)
startActivity(intent)
finish()
}
setupBottomNavigation()
}
private fun inits() {
val bmobQuery = BmobQuery<Perception_bmob>()
bmobQuery.findObjects(object : FindListener<Perception_bmob>() {
override fun done(list: List<Perception_bmob>, e: BmobException?) {
if (e == null) {
for (i in list){
PerceptionList.add(Perception(i.objectId))
val adapter =PerceptionAdapter(PerceptionList)
perception_recyclerView.adapter = adapter
}
}
else {
Log.d("error","error")}
}
})
}
private fun refreshPerception(adapter: PerceptionAdapter) {
thread {
Thread.sleep(2000)
runOnUiThread {
inits()
adapter.notifyDataSetChanged()
perception_swipeRefresh.isRefreshing = false
Toast.makeText(this, "刷新成功!", Toast.LENGTH_SHORT).show()
}
}
}
private fun setupBottomNavigation() {
2024-04-26 19:57:44 +08:00
reading_comprehension.setImageResource(R.drawable.perception2)
2024-04-25 10:33:59 +08:00
bookcity.setOnClickListener {
NavigationHelper.navigateTo(this, MainActivity::class.java)
}
bookshelf.setOnClickListener {
NavigationHelper.navigateTo(this, BookShelfActivity::class.java)
}
reading_comprehension.setOnClickListener {
NavigationHelper.navigateTo(this, PerceptionActivity::class.java)
}
homepage.setOnClickListener {
NavigationHelper.navigateTo(this, MyActivity::class.java)
}
}
}