day1_commit_4_fixed_loginButton_Del_custom_UserName_Cheak
This commit is contained in:
parent
26a3f2ee2b
commit
682eb972cc
@ -1,7 +1,5 @@
|
|||||||
package ru.myitschool.work.ui.login
|
package ru.myitschool.work.ui.login
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.net.ConnectivityManager
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.Editable
|
import android.text.Editable
|
||||||
import android.text.InputType
|
import android.text.InputType
|
||||||
@ -67,8 +65,7 @@ class LoginFragment : Fragment(R.layout.fragment_login) {
|
|||||||
|
|
||||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
||||||
val username = s.toString()
|
val username = s.toString()
|
||||||
// Проверяем, совпадает ли введённый текст с "Maksim"
|
binding.login.isEnabled = username.isNotEmpty() // Кнопка активна, если поле не пустое
|
||||||
binding.login.isEnabled = username == "Maksim" // Кнопка активна, если введённый текст равен "Maksim"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun afterTextChanged(s: Editable?) {}
|
override fun afterTextChanged(s: Editable?) {}
|
||||||
@ -76,19 +73,8 @@ class LoginFragment : Fragment(R.layout.fragment_login) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun performLogin(username: String) {
|
private fun performLogin(username: String) {
|
||||||
// Проверяем наличие интернет-соединения
|
lifecycleScope.launch {
|
||||||
if (!isNetworkAvailable(requireContext())) {
|
viewModel.authenticate(username) // Вызываем метод authenticate из ViewModel
|
||||||
Toast.makeText(context, "Нет подключения к интернету", Toast.LENGTH_SHORT).show()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Здесь можно добавить проверку на совпадение с "Maksim"
|
|
||||||
if (username == "Maksim") {
|
|
||||||
lifecycleScope.launch {
|
|
||||||
viewModel.authenticate(username) // Вызываем метод authenticate из ViewModel
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Toast.makeText(context, "Неверное имя пользователя", Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,12 +107,6 @@ class LoginFragment : Fragment(R.layout.fragment_login) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isNetworkAvailable(context: Context): Boolean {
|
|
||||||
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
|
||||||
val activeNetworkInfo = connectivityManager.activeNetworkInfo
|
|
||||||
return activeNetworkInfo != null && activeNetworkInfo.isConnected
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
_binding = null
|
_binding = null
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user