add data and login

This commit is contained in:
git 2024-10-11 18:13:10 +03:00
parent 25e1c6a9ee
commit 95d9503f2d
6 changed files with 94 additions and 6 deletions

View File

@ -3,7 +3,31 @@
<component name="deploymentTargetDropDown"> <component name="deploymentTargetDropDown">
<value> <value>
<entry key="app"> <entry key="app">
<State /> <State>
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="C:\Users\Hackaton\.android\avd\Pixel_3a_API_34_extension_level_7_x86_64.avd" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<targetSelectedWithDropDown>
<Target>
<type value="QUICK_BOOT_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="C:\Users\Hackaton\.android\avd\Pixel_3a_API_34_extension_level_7_x86_64.avd" />
</Key>
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2024-10-11T14:59:36.879362800Z" />
</State>
</entry> </entry>
</value> </value>
</component> </component>

View File

@ -12,6 +12,9 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.Sampleapp" android:theme="@style/Theme.Sampleapp"
tools:targetApi="31"> tools:targetApi="31">
<activity
android:name=".AboutUserActivity"
android:exported="false" />
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:exported="true"> android:exported="true">

View File

@ -0,0 +1,15 @@
package com.example.sampleapp
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
class AboutUserActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_about_user_activty)
val textView = findViewById<TextView>(R.id.AboutUserTextView)
textView.text = intent.getStringExtra("user")
}
}

View File

@ -1,10 +1,13 @@
package com.example.sampleapp package com.example.sampleapp
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.widget.Button import android.widget.Button
import android.widget.EditText import android.widget.EditText
import android.widget.Toast import android.widget.Toast
import androidx.core.os.bundleOf
import com.example.sampleapp.data.users
class MainActivity : AppCompatActivity(R.layout.activity_main) { class MainActivity : AppCompatActivity(R.layout.activity_main) {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -12,13 +15,29 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {
val loginEditText = findViewById<EditText>(R.id.LoginEditText) val loginEditText = findViewById<EditText>(R.id.LoginEditText)
val passwordEditText = findViewById<EditText>(R.id.PasswordEditText) val passwordEditText = findViewById<EditText>(R.id.PasswordEditText)
val button = findViewById<Button>(R.id.SendPasswordButton) val button = findViewById<Button>(R.id.SendPasswordButton)
val _dataSourceUsers = users
button.setOnClickListener { button.setOnClickListener {
if(loginEditText.text.toString() == "login" val user = _dataSourceUsers.findLast { user ->
&& passwordEditText.text.toString() == "123") user.login.contentEquals(loginEditText.text.toString()) }
if(user == null) {
Toast.makeText( Toast.makeText(
this, "Welcome!", this,
Toast.LENGTH_SHORT).show() "Такого логина не существует",
Toast.LENGTH_SHORT
).show()
return@setOnClickListener;
}
if(!user.password.contentEquals(
passwordEditText.text.toString())){
Toast.makeText(this,
"Пароли не совпадают"
, Toast.LENGTH_SHORT).show()
return@setOnClickListener
}
val intent = Intent(applicationContext,
AboutUserActivity::class.java)
intent.putExtra("user", user.login)
startActivity(intent)
} }
} }

View File

@ -0,0 +1,11 @@
package com.example.sampleapp.data
data class User (val login:String, val password: String, val id:Int)
val users:List<User> = listOf(
User(login = "login", password = "password", id = 1),
User(login = "login1", password = "password1", id = 2),
User(login = "login2", password = "password2", id = 3),
User(login = "login3", password = "password3", id = 4),
User(login = "login4", password = "password4", id = 5),
)

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AboutUserActivity">
<TextView
android:id="@+id/AboutUserTextView"
android:layout_width="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_height="wrap_content"/>
</androidx.constraintlayout.widget.ConstraintLayout>