feat: начал делать список всех сотрудников для админа
This commit is contained in:
parent
e69a86b9d9
commit
f6e9f28e3c
@ -0,0 +1,50 @@
|
||||
package ru.myitschool.work.ui.admin.usersList
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.paging.PagingDataAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import ru.myitschool.work.R
|
||||
import ru.myitschool.work.databinding.ItemEmployeeBinding
|
||||
import ru.myitschool.work.databinding.ItemVisitBinding
|
||||
import ru.myitschool.work.entities.EmployeeEntity
|
||||
import ru.myitschool.work.entities.EmployeeEntranceEntity
|
||||
import ru.myitschool.work.utils.monthConverter
|
||||
import ru.myitschool.work.utils.timeConverter
|
||||
|
||||
class EmployeeListAdapter : PagingDataAdapter<EmployeeEntity, EmployeeListAdapter.ViewHolder>(DiffUtil) {
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) : ViewHolder{
|
||||
return ViewHolder(
|
||||
ItemEmployeeBinding.inflate(
|
||||
LayoutInflater.from(parent.context), parent, false
|
||||
)
|
||||
)
|
||||
}
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val item = getItem(position)
|
||||
if (item != null) {
|
||||
holder.bind(item)
|
||||
}
|
||||
|
||||
}
|
||||
inner class ViewHolder(
|
||||
private val binding: ItemEmployeeBinding,
|
||||
) : RecyclerView.ViewHolder(binding.root) {
|
||||
fun bind(item: EmployeeEntity) {
|
||||
binding.userName.text = item.name
|
||||
binding.position.text = item.position
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
object DiffUtil : androidx.recyclerview.widget.DiffUtil.ItemCallback<EmployeeEntity>() {
|
||||
override fun areItemsTheSame(oldItem: EmployeeEntity, newItem: EmployeeEntity): Boolean {
|
||||
return oldItem.id == newItem.id
|
||||
}
|
||||
override fun areContentsTheSame(oldItem: EmployeeEntity, newItem: EmployeeEntity): Boolean {
|
||||
return oldItem == newItem
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package ru.myitschool.work.ui.admin.usersList
|
||||
|
||||
import androidx.paging.PagingSource
|
||||
import androidx.paging.PagingState
|
||||
import ru.myitschool.work.entities.EmployeeEntity
|
||||
|
||||
class EmployeeListPagingSource(
|
||||
private val request: suspend(pageNum: Int, pageSize: Int) ->Result<List<EmployeeEntity>>
|
||||
) : PagingSource<Int, EmployeeEntity>() {
|
||||
override fun getRefreshKey(state: PagingState<Int, EmployeeEntity>): Int? {
|
||||
return state.anchorPosition?.let{
|
||||
state.closestPageToPosition(it)?.prevKey?.plus(1) ?:
|
||||
state.closestPageToPosition(it)?.nextKey?.minus(1)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, EmployeeEntity> {
|
||||
val pageNum = params.key ?: 0
|
||||
return request.invoke(
|
||||
pageNum, params.loadSize
|
||||
).fold(
|
||||
onSuccess = { value ->
|
||||
LoadResult.Page(
|
||||
data = value,
|
||||
prevKey = (pageNum - 1).takeIf { it >= 0 },
|
||||
nextKey = (pageNum + 1).takeIf { value.size == params.loadSize }
|
||||
)
|
||||
|
||||
},
|
||||
onFailure = { e->
|
||||
println(e)
|
||||
LoadResult.Error(e)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
@ -63,26 +63,28 @@
|
||||
android:id="@+id/block_employee"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginTop="20dp"
|
||||
android:background="@drawable/history_corner_radius"
|
||||
android:paddingTop="16dp"
|
||||
android:orientation="vertical"
|
||||
android:paddingHorizontal="20dp"
|
||||
app:layout_constrainedWidth="true"
|
||||
android:paddingTop="16dp"
|
||||
app:layout_constrainedHeight="true"
|
||||
app:layout_constraintTop_toBottomOf="@+id/block_header"
|
||||
app:layout_constrainedWidth="true"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintVertical_bias="1"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintLeft_toRightOf="@+id/guideline_left"
|
||||
app:layout_constraintRight_toLeftOf="@+id/guideline_right">
|
||||
app:layout_constraintRight_toLeftOf="@+id/guideline_right"
|
||||
app:layout_constraintTop_toBottomOf="@+id/block_header"
|
||||
app:layout_constraintVertical_bias="0.0">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:orientation="horizontal"
|
||||
android:paddingHorizontal="12dp"
|
||||
android:visibility="gone">
|
||||
android:visibility="gone"
|
||||
tools:visibility="gone">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/avatar"
|
||||
@ -97,29 +99,31 @@
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_gravity="center_vertical">
|
||||
android:orientation="vertical"
|
||||
android:visibility="visible"
|
||||
tools:visibility="visible">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/visit_reader_id"
|
||||
android:id="@+id/userName"
|
||||
style="@style/font_medium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:textSize="12sp"
|
||||
android:singleLine="true"
|
||||
tools:text="Артемий ФИО"/>
|
||||
android:textSize="12sp"
|
||||
tools:text="Артемий ФИО" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/уь_direction"
|
||||
android:id="@+id/position"
|
||||
style="@style/secondary_text_color"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="12sp"
|
||||
android:singleLine="true"
|
||||
tools:text="Вход"/>
|
||||
android:textSize="12sp"
|
||||
tools:text="Вход" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@ -130,26 +134,44 @@
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginStart="16dp"
|
||||
android:backgroundTint="@color/accent_color"
|
||||
android:fontFamily="@font/montserrat_medium"
|
||||
android:singleLine="true"
|
||||
android:text="@string/block_btn"
|
||||
android:textAllCaps="false"
|
||||
android:fontFamily="@font/montserrat_medium"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="8sp"
|
||||
android:singleLine="true"
|
||||
app:cornerRadius="16dp"
|
||||
tools:ignore="SmallSp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/content"
|
||||
android:id="@+id/usersList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:listitem="@layout/item_employee" />
|
||||
android:visibility="visible"
|
||||
tools:listitem="@layout/item_employee"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/error"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:fontFamily="@font/montserrat_bold"
|
||||
android:lineSpacingExtra="8sp"
|
||||
android:textAlignment="center"
|
||||
android:textSize="24sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@+id/block_employee"
|
||||
tools:text="Error"
|
||||
tools:visibility="gone" />
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -27,7 +27,7 @@
|
||||
android:layout_gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/visit_reader_id"
|
||||
android:id="@+id/userName"
|
||||
style="@style/font_medium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@ -37,7 +37,7 @@
|
||||
tools:text="Артемий ФИО"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/уь_direction"
|
||||
android:id="@+id/position"
|
||||
style="@style/secondary_text_color"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
Loading…
x
Reference in New Issue
Block a user