day2_commit_8.1_fixed_buttons_added_RV_test
This commit is contained in:
parent
5323532ad1
commit
c5fd7ffe21
7
app/src/main/java/ru/myitschool/work/api/AccessLog.kt
Normal file
7
app/src/main/java/ru/myitschool/work/api/AccessLog.kt
Normal file
@ -0,0 +1,7 @@
|
||||
package ru.myitschool.work.api
|
||||
|
||||
data class AccessLog(
|
||||
val scanTime: String,
|
||||
val readerId: String,
|
||||
val accessType: String // "карта" или "смартфон"
|
||||
)
|
@ -0,0 +1,34 @@
|
||||
package ru.myitschool.work.ui.main
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import ru.myitschool.work.R
|
||||
import ru.myitschool.work.api.AccessLog
|
||||
|
||||
class AccessLogAdapter(private val accessLogs: List<AccessLog>) : RecyclerView.Adapter<AccessLogAdapter.AccessLogViewHolder>() {
|
||||
|
||||
class AccessLogViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
val scanTime: TextView = itemView.findViewById(R.id.scan_time)
|
||||
val readerId: TextView = itemView.findViewById(R.id.reader_id)
|
||||
val accessType: TextView = itemView.findViewById(R.id.access_type)
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AccessLogViewHolder {
|
||||
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_access_log, parent, false)
|
||||
return AccessLogViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: AccessLogViewHolder, position: Int) {
|
||||
val log = accessLogs[position]
|
||||
holder.scanTime.text = log.scanTime
|
||||
holder.readerId.text = log.readerId
|
||||
holder.accessType.text = log.accessType
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return accessLogs.size
|
||||
}
|
||||
}
|
@ -9,6 +9,8 @@ import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.setFragmentResultListener
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
@ -16,6 +18,7 @@ import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import ru.myitschool.work.R
|
||||
import ru.myitschool.work.SessionManager
|
||||
import ru.myitschool.work.api.AccessLog
|
||||
import ru.myitschool.work.api.ApiService
|
||||
import ru.myitschool.work.core.Constants
|
||||
import ru.myitschool.work.databinding.FragmentMainBinding
|
||||
@ -25,7 +28,7 @@ import java.net.URL
|
||||
|
||||
class MainFragment : Fragment(R.layout.fragment_main) {
|
||||
private var _binding: FragmentMainBinding? = null
|
||||
private val binding get() = _binding
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private val apiService: ApiService by lazy {
|
||||
Retrofit.Builder()
|
||||
@ -35,6 +38,9 @@ class MainFragment : Fragment(R.layout.fragment_main) {
|
||||
.create(ApiService::class.java)
|
||||
}
|
||||
|
||||
private lateinit var accessLogAdapter: AccessLogAdapter
|
||||
private val accessLogs = mutableListOf<AccessLog>() // Список для хранения данных проходов
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
_binding = FragmentMainBinding.bind(view) // Подключаем binding
|
||||
@ -58,8 +64,13 @@ class MainFragment : Fragment(R.layout.fragment_main) {
|
||||
}
|
||||
|
||||
private fun setupUI() {
|
||||
// Настройка RecyclerView
|
||||
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
|
||||
accessLogAdapter = AccessLogAdapter(accessLogs)
|
||||
binding.recyclerView.adapter = accessLogAdapter
|
||||
|
||||
// Проверяем, что binding не null, прежде чем устанавливать слушателей
|
||||
binding?.apply {
|
||||
binding.apply {
|
||||
refresh.setOnClickListener { fetchUserData() }
|
||||
logout.setOnClickListener { logout() }
|
||||
scan.setOnClickListener { navigateToQrScan() }
|
||||
@ -81,6 +92,11 @@ class MainFragment : Fragment(R.layout.fragment_main) {
|
||||
|
||||
// Обновляем UI
|
||||
updateUI(fullName, position, lastVisit, photoUrl)
|
||||
|
||||
// Здесь вы можете добавить данные проходов в список
|
||||
// Пример:
|
||||
accessLogs.add(AccessLog("2024-02-31 08:31", "Считыватель 1", "карта"))
|
||||
accessLogAdapter.notifyDataSetChanged() // Обновляем адаптер
|
||||
}
|
||||
} else {
|
||||
showError(getString(R.string.error_loading_data)) // Показываем ошибку, если данные не загрузились
|
||||
@ -133,7 +149,7 @@ class MainFragment : Fragment(R.layout.fragment_main) {
|
||||
|
||||
private fun showError(message: String?) {
|
||||
// Проверяем, что binding не null, прежде чем обновлять ошибку
|
||||
binding?.apply {
|
||||
binding.apply {
|
||||
if (message != null) {
|
||||
error.text = message
|
||||
error.visibility = View.VISIBLE
|
||||
@ -145,8 +161,10 @@ class MainFragment : Fragment(R.layout.fragment_main) {
|
||||
photo.visibility = View.GONE
|
||||
logout.visibility = View.GONE
|
||||
scan.visibility = View.GONE
|
||||
recyclerView.visibility = View.GONE // Скрываем RecyclerView при ошибке
|
||||
} else {
|
||||
error.visibility = View.GONE
|
||||
recyclerView.visibility = View.VISIBLE // Показываем RecyclerView, если ошибки нет
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
android:gravity="bottom"
|
||||
android:padding="16dp"
|
||||
android:background="@android:color/white">
|
||||
|
||||
<!-- Поле для ФИО -->
|
||||
<TextView
|
||||
android:id="@+id/fullname"
|
||||
@ -14,7 +15,7 @@
|
||||
android:text="Имя Фамилия"
|
||||
android:textSize="18sp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:visibility="gone" />
|
||||
android:visibility="visible" />
|
||||
|
||||
<!-- Фото пользователя. -->
|
||||
<ImageView
|
||||
@ -24,7 +25,7 @@
|
||||
android:layout_gravity="center"
|
||||
android:contentDescription="@string/photo_description"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:visibility="gone" />
|
||||
android:visibility="visible" />
|
||||
|
||||
<!-- Поле для должности -->
|
||||
<TextView
|
||||
@ -33,7 +34,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Должность"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:visibility="gone" />
|
||||
android:visibility="visible" />
|
||||
|
||||
<!-- Поле для даты последнего входа -->
|
||||
<TextView
|
||||
@ -42,10 +43,9 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="2024-02-31 08:31"
|
||||
android:layout_marginBottom="75dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<!-- Кнопка -->
|
||||
android:visibility="visible" />
|
||||
|
||||
<!-- Кнопка обновления -->
|
||||
<Button
|
||||
android:id="@+id/refresh"
|
||||
android:layout_width="match_parent"
|
||||
@ -63,11 +63,17 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/error_placeholder"
|
||||
android:textColor="@android:color/holo_red_dark"
|
||||
android:visibility="visible" />
|
||||
|
||||
android:visibility="gone" />
|
||||
<!-- RecyclerView для списка проходов -->
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:visibility="visible" />
|
||||
|
||||
<!-- Кнопки -->
|
||||
|
||||
<Button
|
||||
android:id="@+id/scan"
|
||||
android:layout_width="match_parent"
|
||||
@ -76,8 +82,7 @@
|
||||
android:layout_marginBottom="12dp"
|
||||
android:backgroundTint="@color/colorPrimary"
|
||||
android:textColor="@android:color/white"
|
||||
android:padding="12dp"
|
||||
android:visibility="gone" />
|
||||
android:visibility="visible" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/logout"
|
||||
@ -87,7 +92,5 @@
|
||||
android:layout_marginBottom="50dp"
|
||||
android:backgroundTint="@color/colorPrimary"
|
||||
android:textColor="@android:color/white"
|
||||
android:padding="12dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
android:visibility="visible" />
|
||||
</LinearLayout>
|
||||
|
27
app/src/main/res/layout/item_access_log.xml
Normal file
27
app/src/main/res/layout/item_access_log.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/scan_time"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Время сканирования"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/reader_id"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Идентификатор считывателя"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/access_type"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Тип прохода"
|
||||
android:textSize="16sp" />
|
||||
</LinearLayout>
|
Loading…
x
Reference in New Issue
Block a user