fix: Блокировка входа и выхода у сотрудника + фикс темной темы(она крашила приложение)

This commit is contained in:
yastruckov 2025-02-20 15:30:08 +03:00
parent 8cd87144b8
commit 44ff91387f
7 changed files with 41 additions and 27 deletions

View File

@ -27,6 +27,9 @@ class ScannerStateNetworkDataSource(
basicAuth(username, password)
}
}
if(result.status == HttpStatusCode.PreconditionFailed){
error("Нельзя блокировать вход администратору")
}
if (result.status != HttpStatusCode.OK) {
error("Status ${result.status}")
}

View File

@ -21,6 +21,7 @@ class AdminFragment : Fragment(R.layout.fragment_admin) {
private var _binding: FragmentAdminBinding? = null
private val binding get() = _binding!!
private val viewModel: AdminViewModel by viewModels{ AdminViewModel.Factory }
private var currentBtnState: Boolean = false
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
_binding = FragmentAdminBinding.bind(view)
binding.searchBtn.setOnClickListener {
@ -97,15 +98,17 @@ class AdminFragment : Fragment(R.layout.fragment_admin) {
AdminViewModel.BlockState.Success -> {
binding.error.visibility = View.GONE
binding.userInfo.visibility = View.VISIBLE
currentBtnState = !currentBtnState
btnState(currentBtnState)
}
}
}
}
private fun showUserData(user: EmployeeEntity){
binding.userName.text = user.name
binding.position.text = user.position
if(user.qrEnabled){
private fun btnState(bool : Boolean){
currentBtnState = bool
if(bool){
binding.blockBtn.text = ContextCompat.getString(requireContext(), R.string.block_btn)
buttonRecolor(requireContext(), binding.blockBtn, R.color.accent_color, R.color.white )
}
@ -113,6 +116,11 @@ class AdminFragment : Fragment(R.layout.fragment_admin) {
binding.blockBtn.text = ContextCompat.getString(requireContext(), R.string.unblock_btn)
buttonRecolor(requireContext(), binding.blockBtn, R.color.bg_color, R.color.secondary_text_color )
}
}
private fun showUserData(user: EmployeeEntity){
binding.userName.text = user.name
binding.position.text = user.position
btnState(user.qrEnabled)
Picasso.get().load(user.photoUrl).into(binding.avatar)
}

View File

@ -65,7 +65,6 @@ class AdminViewModel(
}
)
}
searchUser(login)
}
companion object {
@Suppress("UNCHECKED_CAST")

View File

@ -1,10 +1,10 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="ru.myitschool.work.ui.login.LoginFragment">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="ru.myitschool.work.ui.login.LoginFragment">
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline_left"
@ -101,7 +101,7 @@ tools:context="ru.myitschool.work.ui.login.LoginFragment">
android:fontFamily="@font/montserrat_bold"
android:text="@string/login_error"
android:textAlignment="center"
android:textColor="@color/red"
android:textColor="@color/error_color"
android:textSize="20sp"
android:visibility="gone"
tools:visibility="gone" />

View File

@ -150,12 +150,6 @@
app:layout_constraintLeft_toRightOf="@+id/guideline_left"
app:layout_constraintRight_toLeftOf="@+id/guideline_right">
<Button
android:id="@+id/admin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Admin" />
<TextView
android:id="@+id/position"
style="@style/font_medium"
@ -183,11 +177,19 @@
android:layout_height="60dp"
android:layout_marginTop="28dp"
android:backgroundTint="@color/accent_color"
app:icon="@drawable/logo_scan"
app:cornerRadius="16dp"
android:text="@string/scan_btn"
android:textAllCaps="false"
android:textSize="20sp"
android:text="@string/scan_btn" />
app:cornerRadius="16dp"
app:icon="@drawable/logo_scan"
app:iconSize="32dp"
app:iconTint="@color/white" />
<Button
android:id="@+id/admin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Admin" />
</LinearLayout>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="theme_color">#000000</color>
<color name="primary_text_color">#FFFFFF</color>
<color name="secondary_text_color">#B0B0B0</color>
<color name="bg_color">#434343</color>
<color name="input_color">#6A6A6A</color>
</resources>

View File

@ -5,10 +5,4 @@
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
<color name="theme_color">#000000</color>
<color name="primary_text_color">#FFFFFF</color>
<color name="secondary_text_color">#B0B0B0</color>
<color name="bg_color">#434343</color>
<color name="input_color">#6A6A6A</color>
</resources>