day1_commit_4_fixed_loginButton_added_customUserName_Cheak
This commit is contained in:
parent
d257df7a93
commit
26a3f2ee2b
@ -1,5 +1,7 @@
|
|||||||
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
|
||||||
@ -65,7 +67,8 @@ 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()
|
||||||
binding.login.isEnabled = username.isNotEmpty() // Кнопка активна, если поле не пустое
|
// Проверяем, совпадает ли введённый текст с "Maksim"
|
||||||
|
binding.login.isEnabled = username == "Maksim" // Кнопка активна, если введённый текст равен "Maksim"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun afterTextChanged(s: Editable?) {}
|
override fun afterTextChanged(s: Editable?) {}
|
||||||
@ -73,8 +76,19 @@ class LoginFragment : Fragment(R.layout.fragment_login) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun performLogin(username: String) {
|
private fun performLogin(username: String) {
|
||||||
lifecycleScope.launch {
|
// Проверяем наличие интернет-соединения
|
||||||
viewModel.authenticate(username) // Вызываем метод authenticate из ViewModel
|
if (!isNetworkAvailable(requireContext())) {
|
||||||
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,6 +121,12 @@ 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()
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Войти"
|
android:text="Войти"
|
||||||
android:visibility="gone" />
|
android:visibility="visible" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/error"
|
android:id="@+id/error"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user