fix profile: recycler view

This commit is contained in:
Ксении 2025-02-20 11:27:47 +03:00
parent d5e4411767
commit 8f963606f7
5 changed files with 15 additions and 8 deletions

View File

@ -43,6 +43,7 @@ class UserNetworkDataSource {
if (result.status != HttpStatusCode.OK) {
error("Status ${result.status}")
}
Log.d("result", result.bodyAsText())
result.body()
}

View File

@ -1,16 +1,17 @@
package ru.sicampus.bootcamp2025.ui.centerList
import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import dagger.hilt.android.qualifiers.ApplicationContext
import ru.myitschool.work.databinding.OneEntryListViewBinding
import ru.myitschool.work.domain.user.EntranceEntity
class EntranceAdapter(
//private val onCenterClick: (CenterEntity) -> Unit
) : ListAdapter<EntranceEntity, EntranceAdapter.ViewHolder>(EntranceDiff) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
@ -33,7 +34,7 @@ class EntranceAdapter(
) : RecyclerView.ViewHolder(binding.root) {
fun bind(item : EntranceEntity) {
binding.time.text = item.enteredAt
binding.type.text = item.enterType
binding.time.text = item.enterType
binding.entry.text = item.name
}
}

View File

@ -12,6 +12,7 @@ import ru.myitschool.work.databinding.FragmentProfileBinding
import ru.myitschool.work.ui.login.EntryActivity
import ru.myitschool.work.ui.qr.scan.QrScanFragment
import ru.myitschool.work.utils.collectWithLifecycle
import ru.sicampus.bootcamp2025.ui.centerList.EntranceAdapter
class ProfileFragment : Fragment(R.layout.fragment_profile) {
private var _viewBinding: FragmentProfileBinding? = null
@ -40,6 +41,8 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) {
fragmentTransaction.addToBackStack(null)
fragmentTransaction.commit()
}
val adapter = EntranceAdapter()
viewBinding.recyclerView.adapter = adapter
viewModel.state.collectWithLifecycle(this) { state ->
@ -60,14 +63,18 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) {
else viewBinding.lastEntry.text = "Время последнего входа: ${state.profileInfo.lastEntry}"
Picasso.get().load(state.profileInfo.avatarUrl).resize(100, 100).centerCrop().into(viewBinding.imageView)
if (state.entrancesList.size == 0) {
if (state.entrancesList.isEmpty()) {
viewBinding.noData.visibility = View.VISIBLE
}
else {
viewBinding.recyclerView.visibility = View.VISIBLE
adapter.submitList(state.entrancesList)
}
}
is ProfileViewModel.State.Error -> {
viewBinding.errorText.text = state.text
}
}

View File

@ -30,9 +30,7 @@ class QrResultFragment : Fragment(R.layout.fragment_qr_result) {
key, bundle ->
if (key == QrScanDestination.REQUEST_KEY) {
val code = QrScanDestination.getDataIfExist(bundle)
if (code != null) {
viewModel.sendResult(code.toString())
}
viewModel.sendResult(code)
}
}
viewBinding.close.setOnClickListener {

View File

@ -54,7 +54,7 @@ class QrResultViewModel(
}
}
fun sendResult(code : String) {
fun sendResult(code : String?) {
updateState(code)
}