fix profile: recycler view
This commit is contained in:
		
							parent
							
								
									d5e4411767
								
							
						
					
					
						commit
						8f963606f7
					
				| @ -43,6 +43,7 @@ class UserNetworkDataSource { | |||||||
|             if (result.status != HttpStatusCode.OK) { |             if (result.status != HttpStatusCode.OK) { | ||||||
|                 error("Status ${result.status}") |                 error("Status ${result.status}") | ||||||
|             } |             } | ||||||
|  |             Log.d("result", result.bodyAsText()) | ||||||
|             result.body() |             result.body() | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,16 +1,17 @@ | |||||||
| package ru.sicampus.bootcamp2025.ui.centerList | package ru.sicampus.bootcamp2025.ui.centerList | ||||||
| 
 | 
 | ||||||
|  | import android.content.Context | ||||||
| import android.view.LayoutInflater | import android.view.LayoutInflater | ||||||
| import android.view.ViewGroup | import android.view.ViewGroup | ||||||
| import androidx.recyclerview.widget.DiffUtil | import androidx.recyclerview.widget.DiffUtil | ||||||
| import androidx.recyclerview.widget.ListAdapter | import androidx.recyclerview.widget.ListAdapter | ||||||
| import androidx.recyclerview.widget.RecyclerView | import androidx.recyclerview.widget.RecyclerView | ||||||
|  | import dagger.hilt.android.qualifiers.ApplicationContext | ||||||
| import ru.myitschool.work.databinding.OneEntryListViewBinding | import ru.myitschool.work.databinding.OneEntryListViewBinding | ||||||
| import ru.myitschool.work.domain.user.EntranceEntity | import ru.myitschool.work.domain.user.EntranceEntity | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class EntranceAdapter( | class EntranceAdapter( | ||||||
|     //private val onCenterClick: (CenterEntity) -> Unit |  | ||||||
| ) : ListAdapter<EntranceEntity, EntranceAdapter.ViewHolder>(EntranceDiff) { | ) : ListAdapter<EntranceEntity, EntranceAdapter.ViewHolder>(EntranceDiff) { | ||||||
| 
 | 
 | ||||||
|     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { |     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | ||||||
| @ -33,7 +34,7 @@ class EntranceAdapter( | |||||||
|     ) : RecyclerView.ViewHolder(binding.root) { |     ) : RecyclerView.ViewHolder(binding.root) { | ||||||
|         fun bind(item : EntranceEntity) { |         fun bind(item : EntranceEntity) { | ||||||
|             binding.time.text = item.enteredAt |             binding.time.text = item.enteredAt | ||||||
|             binding.type.text = item.enterType |             binding.time.text = item.enterType | ||||||
|             binding.entry.text = item.name |             binding.entry.text = item.name | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -12,6 +12,7 @@ import ru.myitschool.work.databinding.FragmentProfileBinding | |||||||
| import ru.myitschool.work.ui.login.EntryActivity | import ru.myitschool.work.ui.login.EntryActivity | ||||||
| import ru.myitschool.work.ui.qr.scan.QrScanFragment | import ru.myitschool.work.ui.qr.scan.QrScanFragment | ||||||
| import ru.myitschool.work.utils.collectWithLifecycle | import ru.myitschool.work.utils.collectWithLifecycle | ||||||
|  | import ru.sicampus.bootcamp2025.ui.centerList.EntranceAdapter | ||||||
| 
 | 
 | ||||||
| class ProfileFragment : Fragment(R.layout.fragment_profile) { | class ProfileFragment : Fragment(R.layout.fragment_profile) { | ||||||
|     private var _viewBinding: FragmentProfileBinding? = null |     private var _viewBinding: FragmentProfileBinding? = null | ||||||
| @ -40,6 +41,8 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { | |||||||
|             fragmentTransaction.addToBackStack(null) |             fragmentTransaction.addToBackStack(null) | ||||||
|             fragmentTransaction.commit() |             fragmentTransaction.commit() | ||||||
|         } |         } | ||||||
|  |         val adapter = EntranceAdapter() | ||||||
|  |         viewBinding.recyclerView.adapter = adapter | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|         viewModel.state.collectWithLifecycle(this) { state -> |         viewModel.state.collectWithLifecycle(this) { state -> | ||||||
| @ -60,14 +63,18 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { | |||||||
|                     else viewBinding.lastEntry.text = "Время последнего входа: ${state.profileInfo.lastEntry}" |                     else viewBinding.lastEntry.text = "Время последнего входа: ${state.profileInfo.lastEntry}" | ||||||
|                     Picasso.get().load(state.profileInfo.avatarUrl).resize(100, 100).centerCrop().into(viewBinding.imageView) |                     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 |                         viewBinding.noData.visibility = View.VISIBLE | ||||||
|                     } |                     } | ||||||
|  |                     else { | ||||||
|  |                         viewBinding.recyclerView.visibility = View.VISIBLE | ||||||
|  |                         adapter.submitList(state.entrancesList) | ||||||
|  | 
 | ||||||
|  |                     } | ||||||
| 
 | 
 | ||||||
|                 } |                 } | ||||||
|                 is ProfileViewModel.State.Error -> { |                 is ProfileViewModel.State.Error -> { | ||||||
|                     viewBinding.errorText.text = state.text |                     viewBinding.errorText.text = state.text | ||||||
| 
 |  | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -30,9 +30,7 @@ class QrResultFragment : Fragment(R.layout.fragment_qr_result) { | |||||||
|             key, bundle -> |             key, bundle -> | ||||||
|             if (key == QrScanDestination.REQUEST_KEY) { |             if (key == QrScanDestination.REQUEST_KEY) { | ||||||
|                 val code = QrScanDestination.getDataIfExist(bundle) |                 val code = QrScanDestination.getDataIfExist(bundle) | ||||||
|                 if (code != null) { |                 viewModel.sendResult(code) | ||||||
|                     viewModel.sendResult(code.toString()) |  | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         viewBinding.close.setOnClickListener { |         viewBinding.close.setOnClickListener { | ||||||
|  | |||||||
| @ -54,7 +54,7 @@ class QrResultViewModel( | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fun sendResult(code : String) { |     fun sendResult(code : String?) { | ||||||
|         updateState(code) |         updateState(code) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user