add recyclerview

This commit is contained in:
adm 2024-10-30 14:52:09 +03:00
parent a8ffa47f1a
commit 9e363fed73
7 changed files with 125 additions and 2 deletions

View File

@ -4,7 +4,7 @@
<selectionStates>
<SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2024-10-25T14:57:29.908730700Z">
<DropdownSelection timestamp="2024-10-29T14:53:18.958676800Z">
<Target type="DEFAULT_BOOT">
<handle>
<DeviceId pluginId="LocalEmulator" identifier="path=C:\Users\adm\.android\avd\Medium_Phone_API_35.avd" />

View File

@ -7,4 +7,11 @@
<component name="ProjectType">
<option name="id" value="Android" />
</component>
<component name="VisualizationToolProject">
<option name="state">
<ProjectState>
<option name="scale" value="0.19619808601885064" />
</ProjectState>
</option>
</component>
</project>

View File

@ -0,0 +1,31 @@
package com.example.autorization.ui.adapters
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView.Adapter
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.example.autorization.R
import com.example.autorization.ui.fragments.signup.User
class UserAdapter(private val users:List<User>): Adapter<UserAdapter.UserViewHolder>() {
inner class UserViewHolder(view: View):ViewHolder(view) {
val userNameTextView = view.findViewById<TextView>(R.id.UserNameTextView)
val userEmailTextView = view.findViewById<TextView>(R.id.UserEmailTextView)
val userPasswordTextView = view.findViewById<TextView>(R.id.UserPasswordTextView)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): UserViewHolder {
return UserViewHolder(LayoutInflater.from(parent.context)
.inflate(R.layout.user_item, parent, false))
}
override fun getItemCount(): Int = users.size
override fun onBindViewHolder(holder: UserViewHolder, position: Int) {
holder.userNameTextView.text = users[position].name
holder.userEmailTextView.text = users[position].email
holder.userPasswordTextView.text = users[position].password
}
}

View File

@ -0,0 +1,38 @@
package com.example.autorization.ui.fragments
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.LayoutManager
import com.example.autorization.R
import com.example.autorization.ui.adapters.UserAdapter
import com.example.autorization.ui.fragments.signup.SignUpViewModel
import com.example.autorization.ui.fragments.signup.User
class UsersFragment : Fragment(R.layout.fragment_users) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val recyclerView = view.findViewById<RecyclerView>(R.id.UserRecyclerView)
val users: List<User> = mutableListOf(
User(email = "test@mail.ru", name = "Alex", password = "123"),
User(email = "test@mail.ru", name = "Bob", password = "321"),
User(email = "test@mail.ru", name = "Alex", password = "123"),
User(email = "test@mail.ru", name = "Bob", password = "321"),
User(email = "test@mail.ru", name = "Alex", password = "123"),
User(email = "test@mail.ru", name = "Alex", password = "123"),
User(email = "test@mail.ru", name = "Bob", password = "321"),
User(email = "test@mail.ru", name = "Alex", password = "123"),
)
recyclerView.layoutManager = LinearLayoutManager(requireContext())
val userAdapter = UserAdapter(users)
recyclerView.adapter = userAdapter
}
}

View File

@ -9,7 +9,7 @@
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment_container_view"
android:name="com.example.autorization.ui.fragments.SplashScreenFragment"
android:name="com.example.autorization.ui.fragments.UsersFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.fragments.UsersFragment">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/UserRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:itemCount="10"
tools:listitem="@layout/user_item" />
</FrameLayout>

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 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_margin="5dp"
android:layout_width="match_parent"
app:cardCornerRadius="20dp"
android:layout_height="100dp">
<LinearLayout
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/UserEmailTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@tools:sample/lorem"/>
<TextView
android:id="@+id/UserNameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@tools:sample/lorem"
/>
<TextView
android:id="@+id/UserPasswordTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@tools:sample/lorem" />
</LinearLayout>
</androidx.cardview.widget.CardView>