Данные Firebase не импортируются и не отображаются в эмуляторе. Синхронизация успешна, сборка успешна, установка успешна, однако отображается только изображение и текущая дата (не дата в базе данных Firebase) и нулевое (пост) отображение
Основная активность:
класс MainActivity: AppCompatActivity () {
var selectedCategory= FUNNY
lateinit var thoughtsAdapter: ThoughtsAdapter
val thoughts = arrayListOf<Thought>()
val thoughtsCollectionRef = FirebaseFirestore.getInstance().collection(THOUGHT_REF)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
fab.setOnClickListener {
val addThoughtIntent = Intent(this, AddThoughtActivity::class.java)
startActivity(addThoughtIntent)
}
thoughtsAdapter = ThoughtsAdapter(thoughts)
thoughListView.adapter = thoughtsAdapter
val layoutManager = LinearLayoutManager(this)
thoughListView.layoutManager= layoutManager
thoughtsCollectionRef
.get()
.addOnSuccessListener { snapshot ->
for (document in snapshot.documents) {
val data = document.data
val name = data?.get("USERNAME") as? String
val timestamp = data?.get("TIMESTAMP") as? Timestamp
val thoughtText = data?.get("THOUGHT_TEXT") as? String
val numberLikes = data?.get("NUMBER_LIKES") as? Long
val numberComments = data?.get("NUMBER_COMMENTS") as? Long
val newThought = Thought(
name, timestamp, thoughtText,
numberLikes?.toInt(), numberComments?.toInt()
)
thoughts.add(newThought)
}
thoughtsAdapter.notifyDataSetChanged()
}.addOnFailureListener { exception: Exception ->
Log.e("Exception", "Could not add post: Exception")
}
}
fun mainFunnyClicked(view: View) {
if (selectedCategory == FUNNY) {
mainFunnyButton.isChecked = true
return
}
mainSeriouButton.isChecked = false
mainCrazyButton.isChecked = false
mainPopularButton.isChecked = false
selectedCategory = FUNNY
}
fun mainSeriousClicked(view: View) {
if (selectedCategory == SERIOUS) {
mainSeriouButton.isChecked = true
return
}
mainFunnyButton.isChecked = false
mainCrazyButton.isChecked = false
mainPopularButton.isChecked = false
selectedCategory = SERIOUS
}
fun mainCrazyClicked(view: View) {
if (selectedCategory == CRAZY) {
mainCrazyButton.isChecked = true
return
}
mainFunnyButton.isChecked = false
mainSeriouButton.isChecked = false
mainPopularButton.isChecked = false
selectedCategory = CRAZY
}
fun mainPopularClicked(view: View) {
if (selectedCategory == POPULAR) {
mainPopularButton.isChecked = true
return
}
mainFunnyButton.isChecked = false
mainCrazyButton.isChecked = false
mainSeriouButton.isChecked = false
selectedCategory = POPULAR
}
}
Активность мысли:
класс MousetsAdapter (val мысли: ArrayList): RecyclerView.Adapter () {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent?.context).inflate(R.layout.thought_list_view, parent, false)
return ViewHolder(view)
}
override fun getItemCount(): Int {
return thoughts.count()
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder?.bindThought(thoughts[position])
}
inner class ViewHolder (itemView: View) : RecyclerView.ViewHolder (itemView){
val username = itemView?.findViewById<TextView>(R.id.ListViewUsername)
val timestamp = itemView?.findViewById<TextView>(R.id.ListViewTimestamp)
val thoughttext = itemView?.findViewById<TextView>(R.id.ListViewThoughtText)
val numberlikes = itemView?.findViewById<TextView>(R.id.ListViewNumberLikesLabel)
val likesimage = itemView?.findViewById<ImageView>(R.id.ListViewLikesImage)
fun bindThought (thought: Thought) {
username?.text = thought.username
thoughttext?.text = thought.thoughtText
numberlikes?.text = thought.numberLikes.toString()
val dateFormatter = SimpleDateFormat("MMM d, h:mm a", Locale.getDefault ())
val dateString = dateFormatter.format(Date ())
timestamp?.text = dateString
}
}
}
Я ожидаю, что имя пользователя, дата создания сообщения, мысль / сообщение, как изображение, лайки и комментарии будут отображаться
Только текущая дата, например, изображение и отображение нуля