day3_commit1_fixed_mainfragment
This commit is contained in:
parent
194a1dc466
commit
9818c97148
@ -1,31 +1,25 @@
|
||||
package ru.myitschool.work.ui.main
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kotlinx.coroutines.launch
|
||||
import ru.myitschool.work.R
|
||||
import ru.myitschool.work.api.ApiService
|
||||
import ru.myitschool.work.api.AccessLog
|
||||
import ru.myitschool.work.api.EmployeeData
|
||||
import ru.myitschool.work.core.Constants
|
||||
import ru.myitschool.work.databinding.FragmentMainBinding
|
||||
import ru.myitschool.work.SessionManager
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import ru.myitschool.work.SessionManager
|
||||
|
||||
class MainFragment : Fragment(R.layout.fragment_main) {
|
||||
private var _binding: FragmentMainBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private lateinit var apiService: ApiService
|
||||
private lateinit var accessLogAdapter: AccessLogAdapter
|
||||
private val accessLogs = mutableListOf<AccessLog>()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@ -42,55 +36,44 @@ class MainFragment : Fragment(R.layout.fragment_main) {
|
||||
|
||||
setupUI()
|
||||
fetchUserInfo()
|
||||
fetchAccessLogs()
|
||||
}
|
||||
|
||||
private fun setupUI() {
|
||||
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
|
||||
accessLogAdapter = AccessLogAdapter(accessLogs)
|
||||
binding.recyclerView.adapter = accessLogAdapter
|
||||
|
||||
// Инициализация UI компонентов, если необходимо
|
||||
binding.refresh.setOnClickListener {
|
||||
fetchUserInfo()
|
||||
fetchAccessLogs()
|
||||
}
|
||||
}
|
||||
|
||||
private fun fetchUserInfo() {
|
||||
lifecycleScope.launch {
|
||||
val login = SessionManager.userLogin ?: return@launch
|
||||
val authHeader = "Basic ${SessionManager.getAuthHeader()}"
|
||||
val authHeader = SessionManager.getAuthHeader() // Получаем заголовок авторизации
|
||||
|
||||
Log.d("MainFragment", "Fetching user info for login: $login with authHeader: $authHeader")
|
||||
|
||||
val response = apiService.getUserInfo(login, authHeader)
|
||||
|
||||
Log.d("MainFragment", "Response code: ${response.code()}") // Логируем код ответа
|
||||
|
||||
if (response.isSuccessful) {
|
||||
val employeeData = response.body()
|
||||
employeeData?.let {
|
||||
binding.fullname.text = it.name
|
||||
binding.position.text = it.position
|
||||
binding.lastEntry.text = it.lastVisit
|
||||
// Здесь можно установить изображение пользователя, если оно доступно
|
||||
binding.photo.visibility = View.VISIBLE
|
||||
binding.fullname.visibility = View.VISIBLE
|
||||
binding.position.visibility = View.VISIBLE
|
||||
binding.lastEntry.visibility = View.VISIBLE
|
||||
}
|
||||
} else {
|
||||
binding.error.text = "Ошибка получения данных"
|
||||
binding.error.text = "Ошибка получения данных: ${response.message()}"
|
||||
binding.error.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun fetchAccessLogs() {
|
||||
// Здесь вы можете реализовать логику для получения данных о проходах
|
||||
// Например, вы можете сделать запрос к API для получения списка AccessLog
|
||||
// Для примера, добавим несколько фиктивных данных
|
||||
accessLogs.clear()
|
||||
accessLogs.add(AccessLog("2024-02-31 08:31", "Reader 1", "карта"))
|
||||
accessLogs.add(AccessLog("2024-02-31 09:00", "Reader 2", "смартфон"))
|
||||
accessLogAdapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
_binding = null
|
||||
super.onDestroyView()
|
||||
|
Loading…
x
Reference in New Issue
Block a user