Compare commits
No commits in common. "main" and "frontend_temp" have entirely different histories.
main
...
frontend_t
@ -4,7 +4,6 @@ import retrofit2.Response
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Header
|
||||
import retrofit2.http.PATCH
|
||||
import retrofit2.http.POST
|
||||
import retrofit2.http.Path
|
||||
import retrofit2.http.Query
|
||||
@ -19,18 +18,19 @@ interface ApiService {
|
||||
|
||||
@GET("/api/{login}/info")
|
||||
suspend fun getUserInfo(
|
||||
@Path("login") login: String,
|
||||
@Header("Authorization") authHeader: String
|
||||
@Path("login") login: String,
|
||||
@Header("Authorization") authHeader: String
|
||||
): Response<EmployeeData>
|
||||
|
||||
@GET("/api/employee/{login}") // Получение информации о сотруднике
|
||||
suspend fun getEmployeeInfo(@Path("login") login: String): Response<EmployeeData>
|
||||
|
||||
@PATCH("/api/open") // Открыть дверь
|
||||
@POST("api/{username}/open")
|
||||
suspend fun openDoor(
|
||||
@Header("Authorization") authHeader: String,
|
||||
@Path("username") username: String,
|
||||
@Header("Authorization") authHeader: String, // Добавляем заголовок
|
||||
@Body request: OpenDoorRequest
|
||||
): Response<Unit> // Измените Response<String> на Response<Unit>
|
||||
): Response<String>
|
||||
|
||||
@POST("/api/employee/toggleAccess") // Метод для блокировки/разблокировки доступа
|
||||
suspend fun toggleAccess(@Body request: ToggleAccessRequest): Response<Unit>
|
||||
@ -54,6 +54,4 @@ data class ToggleAccessRequest(
|
||||
)
|
||||
|
||||
// Модель данных для запроса открытия двери
|
||||
data class OpenDoorRequest(
|
||||
val value: Long // Код для открытия двери
|
||||
)
|
||||
data class OpenDoorRequest(val value: Long)
|
@ -15,7 +15,7 @@ class AccessLogAdapter(private val accessLogs: List<AccessLog>) : RecyclerView.A
|
||||
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)
|
||||
|
@ -34,7 +34,7 @@ class AdminFragment : Fragment(R.layout.fragment_admin) {
|
||||
|
||||
setupUI()
|
||||
}
|
||||
//.
|
||||
|
||||
private fun setupUI() {
|
||||
binding.viewEmployeeInfo.setOnClickListener {
|
||||
val login = binding.employeeLogin.text.toString()
|
||||
|
@ -8,7 +8,7 @@ import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.setFragmentResultListener
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.squareup.picasso.Picasso
|
||||
import com.bumptech.glide.Glide
|
||||
import kotlinx.coroutines.launch
|
||||
import ru.myitschool.work.R
|
||||
import ru.myitschool.work.api.ApiService
|
||||
@ -69,37 +69,16 @@ class MainFragment : Fragment(R.layout.fragment_main) {
|
||||
// Переход к экрану сканирования QR-кода
|
||||
findNavController().navigate(R.id.qrScanFragment) // Убедитесь, что у вас есть правильный ID для навигации
|
||||
}
|
||||
|
||||
// Проверяем роль пользователя и показываем кнопку AdminPanel, если роль admin
|
||||
if (SessionManager.userRole == "admin") {
|
||||
binding.adminPanelButton?.visibility = View.VISIBLE
|
||||
binding.adminPanelButton?.setOnClickListener {
|
||||
findNavController().navigate(R.id.adminFragment) // Переход к экрану администратора
|
||||
}
|
||||
} else {
|
||||
binding.adminPanelButton?.visibility = View.GONE // Скрываем кнопку, если не admin
|
||||
}
|
||||
}
|
||||
|
||||
private fun fetchUserInfo() {
|
||||
lifecycleScope.launch {
|
||||
val login = SessionManager.userLogin ?: run {
|
||||
binding.error.text = "Пользователь не авторизован"
|
||||
binding.error.visibility = View.VISIBLE
|
||||
return@launch
|
||||
}
|
||||
val authHeader = SessionManager.getAuthHeader() ?: run {
|
||||
binding.error.text = "Ошибка авторизации"
|
||||
binding.error.visibility = View.VISIBLE
|
||||
return@launch
|
||||
}
|
||||
val login = SessionManager.userLogin ?: return@launch
|
||||
val authHeader = SessionManager.getAuthHeader() ?: return@launch
|
||||
|
||||
try {
|
||||
val response = apiService.getUserInfo(login, authHeader)
|
||||
|
||||
// Логируем код ответа
|
||||
Log.d("MainFragment", "Response code: ${response.code()}")
|
||||
|
||||
if (response.isSuccessful) {
|
||||
val employeeData = response.body()
|
||||
employeeData?.let {
|
||||
@ -107,15 +86,11 @@ class MainFragment : Fragment(R.layout.fragment_main) {
|
||||
binding.position.text = it.position
|
||||
binding.lastEntry.text = it.lastVisit
|
||||
|
||||
// Логируем URL аватара
|
||||
Log.d("MainFragment", "Avatar URL: ${it.avatarUrl}")
|
||||
|
||||
// Загрузка аватара с помощью Picasso
|
||||
if (it.avatarUrl != null) {
|
||||
Picasso.get()
|
||||
// Загрузка аватара
|
||||
if (it.avatarUrl != null) { // Предполагается, что у вас есть поле avatarUrl
|
||||
// Используйте библиотеку, такую как Glide или Picasso, для загрузки изображения
|
||||
Glide.with(this@MainFragment)
|
||||
.load(it.avatarUrl)
|
||||
.placeholder(R.drawable.ic_refresh) // Замените на ваш ресурс-заполнитель
|
||||
.error(R.drawable.ic_close) // Замените на ваш ресурс ошибки
|
||||
.into(binding.photo)
|
||||
binding.photo.visibility = View.VISIBLE
|
||||
} else {
|
||||
@ -136,9 +111,4 @@ class MainFragment : Fragment(R.layout.fragment_main) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
_binding = null
|
||||
super.onDestroyView()
|
||||
}
|
||||
}
|
@ -22,7 +22,7 @@ class RootActivity : AppCompatActivity() {
|
||||
navController.setGraph(R.navigation.nav_graph) // Устанавливаем граф навигации
|
||||
}
|
||||
|
||||
// Настройка кнопки "Назад"
|
||||
// Настраиваем кнопку "Назад"
|
||||
onBackPressedDispatcher.addCallback(
|
||||
this,
|
||||
object : OnBackPressedCallback(true) {
|
||||
|
@ -5,10 +5,8 @@ import androidx.navigation.fragment.findNavController
|
||||
import ru.myitschool.work.SessionManager
|
||||
import ru.myitschool.work.api.OpenDoorRequest
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.util.Base64
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
@ -16,14 +14,14 @@ import kotlinx.coroutines.launch
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import ru.myitschool.work.R
|
||||
import android.util.Base64
|
||||
import android.util.Log
|
||||
import ru.myitschool.work.api.ApiService
|
||||
import ru.myitschool.work.core.Constants
|
||||
import ru.myitschool.work.databinding.FragmentQrScanResultBinding
|
||||
|
||||
class QrResult : Fragment(R.layout.fragment_qr_scan_result) {
|
||||
private var _binding: FragmentQrScanResultBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private lateinit var binding: FragmentQrScanResultBinding
|
||||
private lateinit var apiService: ApiService
|
||||
|
||||
override fun onCreateView(
|
||||
@ -31,7 +29,7 @@ class QrResult : Fragment(R.layout.fragment_qr_scan_result) {
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = FragmentQrScanResultBinding.inflate(inflater, container, false)
|
||||
binding = FragmentQrScanResultBinding.inflate(inflater, container, false)
|
||||
apiService = Retrofit.Builder()
|
||||
.baseUrl(Constants.SERVER_ADDRESS)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
@ -44,12 +42,8 @@ class QrResult : Fragment(R.layout.fragment_qr_scan_result) {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
// Получаем данные из аргументов
|
||||
val qrData = QrScanDestination.getDataIfExist(requireArguments())
|
||||
Log.d("QrResult", "QR Data: $qrData") // Логируем полученные данные
|
||||
|
||||
if (qrData != null) {
|
||||
binding.result.text = "Результат сканирования: $qrData" // Отображаем результат сканирования
|
||||
sendRequestToServer(qrData)
|
||||
} else {
|
||||
binding.result.text = "Вход был отменён/Operation was cancelled"
|
||||
@ -65,23 +59,19 @@ class QrResult : Fragment(R.layout.fragment_qr_scan_result) {
|
||||
try {
|
||||
val qrValue = qrData.toLong() // Преобразуем данные QR-кода в Long
|
||||
val login = SessionManager.userLogin ?: "default_login" // Замените на ваш логин
|
||||
val password = "your_password" // Замените на ваш пароль
|
||||
val password = "password123" // Замените на ваш пароль
|
||||
val authHeader = "Basic " + Base64.encodeToString("$login:$password".toByteArray(), Base64.NO_WRAP)
|
||||
|
||||
// Логируем данные перед отправкой
|
||||
Log.d("QrResult", "Sending request with QR value: $qrValue and authHeader: $authHeader")
|
||||
|
||||
// Создаем объект запроса
|
||||
val request = OpenDoorRequest(qrValue)
|
||||
|
||||
// Вызываем метод openDoor с правильными параметрами
|
||||
val response = apiService.openDoor(authHeader, request)
|
||||
val response = apiService.openDoor(login, authHeader, OpenDoorRequest(qrValue))
|
||||
|
||||
// Логируем код ответа и тело ответа
|
||||
Log.d("QrResult", "Response code: ${response.code()}")
|
||||
Log.d("QrResult", "Response body: ${response.body()}")
|
||||
|
||||
if (response.isSuccessful) {
|
||||
if (response.code() == 200) {
|
||||
binding.result.text = "Door Opened" // Сообщение о том, что дверь открыта
|
||||
} else {
|
||||
binding.result.text = "Door Closed" // Сообщение о том, что дверь закрыта
|
||||
@ -89,14 +79,9 @@ class QrResult : Fragment(R.layout.fragment_qr_scan_result) {
|
||||
} catch (e: NumberFormatException) {
|
||||
binding.result.text = "Некорректные данные QR-кода"
|
||||
} catch (e: Exception) {
|
||||
binding.result.text = "Что-то пошло не так/Something went wrong: ${e.message}"
|
||||
Log.e("QrResult", "Error sending request to server", e)
|
||||
binding.result.text = "Что-то пошло не так: ${e.message}"
|
||||
Log.e("QrResult", "Error: ${e.message}", e) // Логируем ошибку
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
_binding = null
|
||||
super.onDestroyView()
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
@ -34,10 +33,6 @@
|
||||
android:id="@+id/refresh"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:backgroundTint="@color/colorPrimary"
|
||||
android:textColor="@android:color/white"
|
||||
android:padding="12dp"
|
||||
app:cornerRadius="16dp"
|
||||
android:text="@string/refresh" />
|
||||
|
||||
<TextView
|
||||
@ -57,22 +52,6 @@
|
||||
android:id="@+id/scan_qr_code"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:backgroundTint="@color/colorPrimary"
|
||||
android:textColor="@android:color/white"
|
||||
android:padding="12dp"
|
||||
app:cornerRadius="16dp"
|
||||
android:text="Сканировать QR-код"
|
||||
android:visibility="gone" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/adminPanelButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:backgroundTint="@color/colorPrimary"
|
||||
android:textColor="@android:color/white"
|
||||
android:padding="12dp"
|
||||
app:cornerRadius="16dp"
|
||||
android:text="Admin Panel"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
|
Loading…
x
Reference in New Issue
Block a user