feat: почти прописаны все запросы на сервер(data и domain слои) + начал делать пагинацию списка пользователей

This commit is contained in:
yastruckov 2025-02-19 15:35:07 +03:00
parent a3e2a923b8
commit 00f7009856
53 changed files with 429 additions and 91 deletions

View File

@ -68,6 +68,7 @@ dependencies {
implementation(libs.androidx.camera.mlkit.vision) implementation(libs.androidx.camera.mlkit.vision)
implementation(libs.androidx.paging.runtime.ktx) implementation(libs.androidx.paging.runtime.ktx)
defaultLibrary() defaultLibrary()
implementation(libs.hilt.android) implementation(libs.hilt.android)
kapt(libs.hilt.android.compiler) kapt(libs.hilt.android.compiler)
} }

View File

@ -0,0 +1,36 @@
package ru.myitschool.work.data.deleteEmployee
import android.content.Context
import io.ktor.client.call.body
import io.ktor.client.request.basicAuth
import io.ktor.client.request.patch
import io.ktor.http.HttpStatusCode
import io.ktor.http.headers
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.withContext
import ru.myitschool.work.core.Constants
import ru.myitschool.work.data.UserDataStoreManager
import ru.myitschool.work.utils.NetworkModule
class DeleteEmployeeNetworkDataSource(
context: Context
) {
private val client = NetworkModule.httpClient
private val userDataStoreManager = UserDataStoreManager.getInstance(context)
suspend fun deleteEmployee(login: String):Result<Unit> = withContext(Dispatchers.IO){
runCatching {
val username = userDataStoreManager.usernameFlow.first()
val password = userDataStoreManager.passwordFlow.first()
val result = client.patch("${Constants.SERVER_ADDRESS}/api/employee/$login/delete"){
headers{
basicAuth(username, password)
}
}
if (result.status != HttpStatusCode.OK) {
error("Status ${result.status}")
}
result.body()
}
}
}

View File

@ -0,0 +1,9 @@
package ru.myitschool.work.data.deleteEmployee
import ru.myitschool.work.domain.deleteEmployee.DeleteEmployeeRepo
class DeleteEmployeeRepoImpl : DeleteEmployeeRepo {
override suspend fun deleteEmployee(login: String): Result<Unit> {
TODO("Not yet implemented")
}
}

View File

@ -1,4 +1,4 @@
package ru.myitschool.work.data.door package ru.myitschool.work.data.door.open
import android.content.Context import android.content.Context
import io.ktor.client.call.body import io.ktor.client.call.body

View File

@ -1,6 +1,6 @@
package ru.myitschool.work.data.door package ru.myitschool.work.data.door.open
import ru.myitschool.work.domain.door.DoorRepo import ru.myitschool.work.domain.door.open.DoorRepo
class DoorRepoImpl( class DoorRepoImpl(
private val networkDataSource: DoorNetworkDataSource private val networkDataSource: DoorNetworkDataSource

View File

@ -0,0 +1,40 @@
package ru.myitschool.work.data.employeeList
import android.content.Context
import io.ktor.client.call.body
import io.ktor.client.request.basicAuth
import io.ktor.client.request.get
import io.ktor.client.statement.bodyAsText
import io.ktor.http.HttpStatusCode
import io.ktor.http.headers
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.withContext
import ru.myitschool.work.core.Constants
import ru.myitschool.work.data.UserDataStoreManager
import ru.myitschool.work.dto.EmployeePagingDTO
import ru.myitschool.work.utils.NetworkModule
class EmployeeListNetworkDataSource(
context: Context
) {
private val client = NetworkModule.httpClient
private val userDataStoreManager = UserDataStoreManager.getInstance(context)
suspend fun getInfo():Result<EmployeePagingDTO> = withContext(Dispatchers.IO){
runCatching {
val username = userDataStoreManager.usernameFlow.first()
val password = userDataStoreManager.passwordFlow.first()
val result = client.get("${Constants.SERVER_ADDRESS}/api/employee/all"){
headers{
basicAuth(username, password)
}
}
if (result.status != HttpStatusCode.OK) {
error("Status ${result.status}")
}
println(result.bodyAsText())
result.body()
}
}
}

View File

@ -0,0 +1,10 @@
package ru.myitschool.work.data.employeeList
import ru.myitschool.work.domain.employeeList.EmployeeListRepo
import ru.myitschool.work.entities.EmployeeEntity
class EmployeeListRepoImpl : EmployeeListRepo {
override suspend fun getList(): Result<List<EmployeeEntity>> {
TODO("Not yet implemented")
}
}

View File

@ -11,7 +11,7 @@ import kotlinx.coroutines.flow.first
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import ru.myitschool.work.core.Constants import ru.myitschool.work.core.Constants
import ru.myitschool.work.data.UserDataStoreManager import ru.myitschool.work.data.UserDataStoreManager
import ru.myitschool.work.data.dto.EmployeeEntranceListPagingDTO import ru.myitschool.work.dto.EmployeeEntranceListPagingDTO
import ru.myitschool.work.utils.NetworkModule import ru.myitschool.work.utils.NetworkModule
class AllEntranceListNetworkDataSource( class AllEntranceListNetworkDataSource(

View File

@ -1,7 +1,7 @@
package ru.myitschool.work.data.entrance.allEntrances package ru.myitschool.work.data.entrance.allEntrances
import ru.myitschool.work.domain.employeeEntrance.allEntrances.AllEntranceListRepo import ru.myitschool.work.domain.employeeEntrance.allEntrances.AllEntranceListRepo
import ru.myitschool.work.domain.entities.EmployeeEntranceEntity import ru.myitschool.work.entities.EmployeeEntranceEntity
class AllEntranceListRepoImpl( class AllEntranceListRepoImpl(
private val networkDataSource: AllEntranceListNetworkDataSource private val networkDataSource: AllEntranceListNetworkDataSource

View File

@ -12,7 +12,7 @@ import kotlinx.coroutines.flow.first
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import ru.myitschool.work.core.Constants import ru.myitschool.work.core.Constants
import ru.myitschool.work.data.UserDataStoreManager import ru.myitschool.work.data.UserDataStoreManager
import ru.myitschool.work.data.dto.EmployeeEntranceListPagingDTO import ru.myitschool.work.dto.EmployeeEntranceListPagingDTO
import ru.myitschool.work.utils.NetworkModule import ru.myitschool.work.utils.NetworkModule
class EmployeeEntranceListNetworkDataSource( class EmployeeEntranceListNetworkDataSource(

View File

@ -1,6 +1,6 @@
package ru.myitschool.work.data.entrance.employeeEntrances package ru.myitschool.work.data.entrance.employeeEntrances
import ru.myitschool.work.domain.entities.EmployeeEntranceEntity import ru.myitschool.work.entities.EmployeeEntranceEntity
import ru.myitschool.work.domain.employeeEntrance.employeeEntrances.EmployeeEntranceListRepo import ru.myitschool.work.domain.employeeEntrance.employeeEntrances.EmployeeEntranceListRepo
class EmployeeEntranceListRepoImpl( class EmployeeEntranceListRepoImpl(

View File

@ -0,0 +1,39 @@
package ru.myitschool.work.data.entrance.lastEntrance
import android.content.Context
import io.ktor.client.call.body
import io.ktor.client.request.basicAuth
import io.ktor.client.request.post
import io.ktor.client.statement.bodyAsText
import io.ktor.http.HttpStatusCode
import io.ktor.http.headers
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.withContext
import ru.myitschool.work.core.Constants
import ru.myitschool.work.data.UserDataStoreManager
import ru.myitschool.work.dto.EmployeeEntranceDTO
import ru.myitschool.work.utils.NetworkModule
class LastEntranceNetworkDataSource(
context: Context
) {
private val client = NetworkModule.httpClient
private val userDataStoreManager = UserDataStoreManager.getInstance(context)
suspend fun getLastEntrance():Result<EmployeeEntranceDTO> = withContext(Dispatchers.IO){
runCatching {
val username = userDataStoreManager.usernameFlow.first()
val password = userDataStoreManager.passwordFlow.first()
val result = client.post("${Constants.SERVER_ADDRESS}/api/entrance/last"){
headers{
basicAuth(username, password)
}
}
if (result.status != HttpStatusCode.OK) {
error("Status ${result.status}")
}
println(result.bodyAsText())
result.body()
}
}
}

View File

@ -0,0 +1,19 @@
package ru.myitschool.work.data.entrance.lastEntrance
import ru.myitschool.work.domain.employeeEntrance.lastEntrance.LastEntranceRepo
import ru.myitschool.work.entities.EmployeeEntranceEntity
class LastEntranceRepoImpl(
private val networkDataSource: LastEntranceNetworkDataSource
) : LastEntranceRepo {
override suspend fun getLastEntrance(): Result<EmployeeEntranceEntity> {
return networkDataSource.getLastEntrance().map { dto ->
EmployeeEntranceEntity(
id = dto.id ?: 0,
scanTime = dto.scanTime,
readerName = dto.readerName ?: "",
type = dto.type ?: ""
)
}
}
}

View File

@ -1,22 +0,0 @@
package ru.myitschool.work.data.info
import ru.myitschool.work.domain.entities.UserEntity
import ru.myitschool.work.domain.info.InfoRepo
class InfoRepoImpl(
private val networkDataSource: InfoNetworkDataSource
): InfoRepo {
override suspend fun getInfo(): Result<UserEntity> {
return networkDataSource.getInfo().map { dto->
UserEntity(
id = dto.id ?: 0,
login = dto.login ?: "",
name = dto.name ?: "",
authority = dto.authority ?: "",
photoUrl = dto.photoUrl,
position = dto.position ?: ""
)
}
}
}

View File

@ -1,4 +1,4 @@
package ru.myitschool.work.data.info package ru.myitschool.work.data.profile
import android.content.Context import android.content.Context
import io.ktor.client.call.body import io.ktor.client.call.body
@ -12,16 +12,16 @@ import kotlinx.coroutines.flow.first
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import ru.myitschool.work.core.Constants import ru.myitschool.work.core.Constants
import ru.myitschool.work.data.UserDataStoreManager import ru.myitschool.work.data.UserDataStoreManager
import ru.myitschool.work.data.dto.UserDTO import ru.myitschool.work.dto.EmployeeDTO
import ru.myitschool.work.utils.NetworkModule import ru.myitschool.work.utils.NetworkModule
class InfoNetworkDataSource( class ProfileNetworkDataSource(
context: Context context: Context
) { ) {
private val client = NetworkModule.httpClient private val client = NetworkModule.httpClient
private val userDataStoreManager = UserDataStoreManager.getInstance(context) private val userDataStoreManager = UserDataStoreManager.getInstance(context)
suspend fun getInfo():Result<UserDTO> = withContext(Dispatchers.IO){ suspend fun getInfo():Result<EmployeeDTO> = withContext(Dispatchers.IO){
runCatching { runCatching {
val username = userDataStoreManager.usernameFlow.first() val username = userDataStoreManager.usernameFlow.first()
val password = userDataStoreManager.passwordFlow.first() val password = userDataStoreManager.passwordFlow.first()

View File

@ -0,0 +1,23 @@
package ru.myitschool.work.data.profile
import ru.myitschool.work.entities.EmployeeEntity
import ru.myitschool.work.domain.profile.ProfileRepo
class ProfileRepoImpl(
private val networkDataSource: ProfileNetworkDataSource
): ProfileRepo {
override suspend fun getInfo(): Result<EmployeeEntity> {
return networkDataSource.getInfo().map { dto->
EmployeeEntity(
id = dto.id ?: 0,
login = dto.login ?: "",
name = dto.name ?: "Не указано",
authority = dto.authority ?: "EMPLOYEE",
photoUrl = dto.photoUrl,
position = dto.position ?: "Отсутствует",
qrEnabled = dto.qrEnabled ?: false
)
}
}
}

View File

@ -0,0 +1,39 @@
package ru.myitschool.work.data.profile.admin
import android.content.Context
import io.ktor.client.call.body
import io.ktor.client.request.basicAuth
import io.ktor.client.request.post
import io.ktor.client.statement.bodyAsText
import io.ktor.http.HttpStatusCode
import io.ktor.http.headers
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.withContext
import ru.myitschool.work.core.Constants
import ru.myitschool.work.data.UserDataStoreManager
import ru.myitschool.work.dto.EmployeeDTO
import ru.myitschool.work.utils.NetworkModule
class EmployeeNetworkDataSource(
context: Context
) {
private val client = NetworkModule.httpClient
private val userDataStoreManager = UserDataStoreManager.getInstance(context)
suspend fun getProfile(login : String):Result<EmployeeDTO> = withContext(Dispatchers.IO){
runCatching {
val username = userDataStoreManager.usernameFlow.first()
val password = userDataStoreManager.passwordFlow.first()
val result = client.post("${Constants.SERVER_ADDRESS}/api/employee/$login"){
headers{
basicAuth(username, password)
}
}
if (result.status != HttpStatusCode.OK) {
error("Status ${result.status}")
}
println(result.bodyAsText())
result.body()
}
}
}

View File

@ -0,0 +1,22 @@
package ru.myitschool.work.data.profile.admin
import ru.myitschool.work.entities.EmployeeEntity
import ru.myitschool.work.domain.profile.admin.EmployeeProfileRepo
class EmployeeProfileRepoImpl(
private val networkDataSource: EmployeeNetworkDataSource
) : EmployeeProfileRepo {
override suspend fun getInfo(login : String): Result<EmployeeEntity> {
return networkDataSource.getProfile(login).map { dto ->
EmployeeEntity(
id = dto.id ?: 0,
login = dto.login ?: "",
name = dto.name ?: "Не указано",
authority = dto.authority ?: "EMPLOYEE",
photoUrl = dto.photoUrl,
position = dto.position ?: "Отсутствует",
qrEnabled = dto.qrEnabled ?: false
)
}
}
}

View File

@ -0,0 +1,36 @@
package ru.myitschool.work.data.scannerState
import android.content.Context
import io.ktor.client.call.body
import io.ktor.client.request.basicAuth
import io.ktor.client.request.patch
import io.ktor.http.HttpStatusCode
import io.ktor.http.headers
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.withContext
import ru.myitschool.work.core.Constants
import ru.myitschool.work.data.UserDataStoreManager
import ru.myitschool.work.utils.NetworkModule
class ScannerStateNetworkDataSource(
context: Context
) {
private val client = NetworkModule.httpClient
private val userDataStoreManager = UserDataStoreManager.getInstance(context)
suspend fun setScannerState(state: String, login: String):Result<Unit> = withContext(Dispatchers.IO){
runCatching {
val username = userDataStoreManager.usernameFlow.first()
val password = userDataStoreManager.passwordFlow.first()
val result = client.patch("${Constants.SERVER_ADDRESS}/api/employee/$login/$state"){
headers{
basicAuth(username, password)
}
}
if (result.status != HttpStatusCode.OK) {
error("Status ${result.status}")
}
result.body()
}
}
}

View File

@ -0,0 +1,11 @@
package ru.myitschool.work.data.scannerState
import ru.myitschool.work.domain.scannerBlockState.ScannerStateRepo
class ScannerStateRepoImpl(
private val networkDataSource: ScannerStateNetworkDataSource
) : ScannerStateRepo {
override suspend fun changeState(state: String, login: String) : Result<Unit> {
return networkDataSource.setScannerState(state, login)
}
}

View File

@ -0,0 +1,5 @@
package ru.myitschool.work.domain.deleteEmployee
interface DeleteEmployeeRepo {
suspend fun deleteEmployee(login : String): Result<Unit>
}

View File

@ -0,0 +1,7 @@
package ru.myitschool.work.domain.deleteEmployee
class DeleteEmployeeUseCase(
private val repo: DeleteEmployeeRepo
) {
suspend operator fun invoke(login : String) = repo.deleteEmployee(login)
}

View File

@ -1,4 +1,4 @@
package ru.myitschool.work.domain.door package ru.myitschool.work.domain.door.open
interface DoorRepo { interface DoorRepo {
suspend fun openDoor(code: String) : Result<Unit> suspend fun openDoor(code: String) : Result<Unit>

View File

@ -1,4 +1,4 @@
package ru.myitschool.work.domain.door package ru.myitschool.work.domain.door.open
class OpenDoorUseCase( class OpenDoorUseCase(
private val repo: DoorRepo private val repo: DoorRepo

View File

@ -1,6 +1,6 @@
package ru.myitschool.work.domain.employeeEntrance.allEntrances package ru.myitschool.work.domain.employeeEntrance.allEntrances
import ru.myitschool.work.domain.entities.EmployeeEntranceEntity import ru.myitschool.work.entities.EmployeeEntranceEntity
interface AllEntranceListRepo { interface AllEntranceListRepo {
suspend fun getList(pageNum : Int, pageSize: Int) : Result<List<EmployeeEntranceEntity>> suspend fun getList(pageNum : Int, pageSize: Int) : Result<List<EmployeeEntranceEntity>>

View File

@ -1,6 +1,6 @@
package ru.myitschool.work.domain.employeeEntrance.allEntrances package ru.myitschool.work.domain.employeeEntrance.allEntrances
class GetAllEmployeesEntranceList( class GetAllEmployeesEntranceListUseCase(
private val repo: AllEntranceListRepo private val repo: AllEntranceListRepo
) { ) {
suspend operator fun invoke(pageNum : Int, pageSize: Int) = repo.getList(pageNum, pageSize) suspend operator fun invoke(pageNum : Int, pageSize: Int) = repo.getList(pageNum, pageSize)

View File

@ -1,6 +1,6 @@
package ru.myitschool.work.domain.employeeEntrance.employeeEntrances package ru.myitschool.work.domain.employeeEntrance.employeeEntrances
import ru.myitschool.work.domain.entities.EmployeeEntranceEntity import ru.myitschool.work.entities.EmployeeEntranceEntity
interface EmployeeEntranceListRepo { interface EmployeeEntranceListRepo {
suspend fun getList(pageNum : Int, pageSize: Int) : Result<List<EmployeeEntranceEntity>> suspend fun getList(pageNum : Int, pageSize: Int) : Result<List<EmployeeEntranceEntity>>

View File

@ -0,0 +1,7 @@
package ru.myitschool.work.domain.employeeEntrance.lastEntrance
class GetLastEntranceUseCase(
private val repo : LastEntranceRepo
) {
suspend operator fun invoke() = repo.getLastEntrance()
}

View File

@ -0,0 +1,7 @@
package ru.myitschool.work.domain.employeeEntrance.lastEntrance
import ru.myitschool.work.entities.EmployeeEntranceEntity
interface LastEntranceRepo {
suspend fun getLastEntrance() : Result<EmployeeEntranceEntity>
}

View File

@ -0,0 +1,7 @@
package ru.myitschool.work.domain.employeeList
import ru.myitschool.work.entities.EmployeeEntity
interface EmployeeListRepo {
suspend fun getList() : Result<List<EmployeeEntity>>
}

View File

@ -0,0 +1,7 @@
package ru.myitschool.work.domain.employeeList
class GetEmployeeListUseCase(
private val repo: EmployeeListRepo
) {
suspend operator fun invoke() = repo.getList()
}

View File

@ -1,9 +0,0 @@
package ru.myitschool.work.domain.entities
import java.util.Date
data class EmployeeEntranceEntity(
val id : Int?,
val scanTime : Date?,
val readerName: String?,
val type: String?
)

View File

@ -1,7 +0,0 @@
package ru.myitschool.work.domain.info
class GetInfoUseCase(
private val repo: InfoRepo
) {
suspend operator fun invoke() = repo.getInfo()
}

View File

@ -1,7 +0,0 @@
package ru.myitschool.work.domain.info
import ru.myitschool.work.domain.entities.UserEntity
interface InfoRepo {
suspend fun getInfo(): Result<UserEntity>
}

View File

@ -0,0 +1,7 @@
package ru.myitschool.work.domain.profile
class GetProfileUseCase(
private val repo: ProfileRepo
) {
suspend operator fun invoke() = repo.getInfo()
}

View File

@ -0,0 +1,7 @@
package ru.myitschool.work.domain.profile
import ru.myitschool.work.entities.EmployeeEntity
interface ProfileRepo {
suspend fun getInfo(): Result<EmployeeEntity>
}

View File

@ -0,0 +1,7 @@
package ru.myitschool.work.domain.profile.admin
import ru.myitschool.work.entities.EmployeeEntity
interface EmployeeProfileRepo {
suspend fun getInfo(login : String): Result<EmployeeEntity>
}

View File

@ -0,0 +1,7 @@
package ru.myitschool.work.domain.profile.admin
class GetEmployeeProfileUseCase(
private val repo : EmployeeProfileRepo
) {
suspend operator fun invoke(login : String) = repo.getInfo(login)
}

View File

@ -0,0 +1,5 @@
package ru.myitschool.work.domain.scannerBlockState
interface ScannerStateRepo {
suspend fun changeState(state: String, login: String) : Result<Unit>
}

View File

@ -0,0 +1,7 @@
package ru.myitschool.work.domain.scannerBlockState
class SetScannerStateUseCase(
private val repo: ScannerStateRepo
) {
suspend operator fun invoke(state: String, login: String) = repo.changeState(state, login)
}

View File

@ -1,15 +1,16 @@
package ru.myitschool.work.data.dto package ru.myitschool.work.dto
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@Serializable @Serializable
data class UserDTO( data class EmployeeDTO(
@SerialName("id") val id: Long?, @SerialName("id") val id: Long?,
@SerialName("login") val login: String?, @SerialName("login") val login: String?,
@SerialName("name") val name: String?, @SerialName("name") val name: String?,
@SerialName("authority") val authority : String?, @SerialName("authority") val authority : String?,
@SerialName("photoUrl") val photoUrl: String?, @SerialName("photoUrl") val photoUrl: String?,
@SerialName("position") val position: String? @SerialName("position") val position: String?,
@SerialName("qrEnabled") val qrEnabled: Boolean?
) )

View File

@ -1,4 +1,4 @@
package ru.myitschool.work.data.dto package ru.myitschool.work.dto
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable

View File

@ -1,4 +1,4 @@
package ru.myitschool.work.data.dto package ru.myitschool.work.dto
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable

View File

@ -0,0 +1,7 @@
package ru.myitschool.work.dto
import kotlinx.serialization.SerialName
data class EmployeePagingDTO (
@SerialName("content") val content : List<EmployeeDTO>?
)

View File

@ -1,10 +1,11 @@
package ru.myitschool.work.domain.entities package ru.myitschool.work.entities
data class UserEntity( data class EmployeeEntity(
val id: Long, val id: Long,
val login: String, val login: String,
val name: String, val name: String,
val authority: String, val authority: String,
val photoUrl: String?, val photoUrl: String?,
val position: String val position: String,
val qrEnabled: Boolean
) )

View File

@ -0,0 +1,9 @@
package ru.myitschool.work.entities
import java.util.Date
data class EmployeeEntranceEntity(
val id : Int,
val scanTime : Date?,
val readerName: String,
val type: String
)

View File

@ -5,7 +5,7 @@ import android.view.ViewGroup
import androidx.paging.PagingDataAdapter import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import ru.myitschool.work.databinding.ItemVisitBinding import ru.myitschool.work.databinding.ItemVisitBinding
import ru.myitschool.work.domain.entities.EmployeeEntranceEntity import ru.myitschool.work.entities.EmployeeEntranceEntity
import ru.myitschool.work.utils.dateConverter import ru.myitschool.work.utils.dateConverter
class EmployeeEntranceListAdapter : PagingDataAdapter<EmployeeEntranceEntity, EmployeeEntranceListAdapter.ViewHolder>(DiffUtil) { class EmployeeEntranceListAdapter : PagingDataAdapter<EmployeeEntranceEntity, EmployeeEntranceListAdapter.ViewHolder>(DiffUtil) {

View File

@ -2,7 +2,7 @@ package ru.myitschool.work.ui.main
import androidx.paging.PagingSource import androidx.paging.PagingSource
import androidx.paging.PagingState import androidx.paging.PagingState
import ru.myitschool.work.domain.entities.EmployeeEntranceEntity import ru.myitschool.work.entities.EmployeeEntranceEntity
class EmployeeEntranceListPagingSource( class EmployeeEntranceListPagingSource(
private val request: suspend(pageNum: Int, pageSize: Int) ->Result<List<EmployeeEntranceEntity>> private val request: suspend(pageNum: Int, pageSize: Int) ->Result<List<EmployeeEntranceEntity>>

View File

@ -15,7 +15,7 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import ru.myitschool.work.R import ru.myitschool.work.R
import ru.myitschool.work.databinding.FragmentMainBinding import ru.myitschool.work.databinding.FragmentMainBinding
import ru.myitschool.work.domain.entities.UserEntity import ru.myitschool.work.entities.EmployeeEntity
import ru.myitschool.work.ui.qr.scan.QrScanDestination import ru.myitschool.work.ui.qr.scan.QrScanDestination
import ru.myitschool.work.utils.UserState import ru.myitschool.work.utils.UserState
import ru.myitschool.work.utils.collectWhenStarted import ru.myitschool.work.utils.collectWhenStarted
@ -55,7 +55,7 @@ class MainFragment : Fragment(R.layout.fragment_main) {
binding.refresh.visibility = View.VISIBLE binding.refresh.visibility = View.VISIBLE
binding.loading.visibility = View.GONE binding.loading.visibility = View.GONE
binding.error.visibility = View.GONE binding.error.visibility = View.GONE
showUserData(state.userEntity) showUserData(state.employeeEntity)
} }
} }
@ -102,12 +102,12 @@ class MainFragment : Fragment(R.layout.fragment_main) {
} }
private fun showUserData(userEntity: UserEntity) { private fun showUserData(employeeEntity: EmployeeEntity) {
binding.apply { binding.apply {
fullname.text = userEntity.name fullname.text = employeeEntity.name
println(userEntity.name) println(employeeEntity.name)
position.text = userEntity.position position.text = employeeEntity.position
Picasso.get().load(userEntity.photoUrl).into(photo) Picasso.get().load(employeeEntity.photoUrl).into(photo)
error.visibility = View.GONE error.visibility = View.GONE
setViewsVisibility(View.VISIBLE) setViewsVisibility(View.VISIBLE)

View File

@ -15,16 +15,16 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import ru.myitschool.work.data.UserDataStoreManager import ru.myitschool.work.data.UserDataStoreManager
import ru.myitschool.work.data.info.InfoNetworkDataSource import ru.myitschool.work.data.profile.ProfileNetworkDataSource
import ru.myitschool.work.data.info.InfoRepoImpl import ru.myitschool.work.data.profile.ProfileRepoImpl
import ru.myitschool.work.data.entrance.employeeEntrances.EmployeeEntranceListNetworkDataSource import ru.myitschool.work.data.entrance.employeeEntrances.EmployeeEntranceListNetworkDataSource
import ru.myitschool.work.data.entrance.employeeEntrances.EmployeeEntranceListRepoImpl import ru.myitschool.work.data.entrance.employeeEntrances.EmployeeEntranceListRepoImpl
import ru.myitschool.work.domain.info.GetInfoUseCase import ru.myitschool.work.domain.profile.GetProfileUseCase
import ru.myitschool.work.domain.employeeEntrance.employeeEntrances.GetEmployeeEntranceListUseCase import ru.myitschool.work.domain.employeeEntrance.employeeEntrances.GetEmployeeEntranceListUseCase
import ru.myitschool.work.utils.UserState import ru.myitschool.work.utils.UserState
class MainViewModel( class MainViewModel(
private val infoUseCase: GetInfoUseCase, private val infoUseCase: GetProfileUseCase,
private val listUseCase: GetEmployeeEntranceListUseCase, private val listUseCase: GetEmployeeEntranceListUseCase,
application: Application application: Application
) : AndroidViewModel(application) { ) : AndroidViewModel(application) {
@ -79,8 +79,8 @@ class MainViewModel(
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
val Factory: ViewModelProvider.Factory = object : ViewModelProvider.Factory { val Factory: ViewModelProvider.Factory = object : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>, extras: CreationExtras): T { override fun <T : ViewModel> create(modelClass: Class<T>, extras: CreationExtras): T {
val infoRepoImpl = InfoRepoImpl( val profileRepoImpl = ProfileRepoImpl(
networkDataSource = InfoNetworkDataSource( networkDataSource = ProfileNetworkDataSource(
context = extras[ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY] as Application context = extras[ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY] as Application
) )
) )
@ -90,7 +90,7 @@ class MainViewModel(
) )
) )
val infoUseCase = GetInfoUseCase(infoRepoImpl) val infoUseCase = GetProfileUseCase(profileRepoImpl)
val listUseCase = GetEmployeeEntranceListUseCase(listInfoImpl) val listUseCase = GetEmployeeEntranceListUseCase(listInfoImpl)
return MainViewModel( return MainViewModel(

View File

@ -10,9 +10,9 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import ru.myitschool.work.data.door.DoorNetworkDataSource import ru.myitschool.work.data.door.open.DoorNetworkDataSource
import ru.myitschool.work.data.door.DoorRepoImpl import ru.myitschool.work.data.door.open.DoorRepoImpl
import ru.myitschool.work.domain.door.OpenDoorUseCase import ru.myitschool.work.domain.door.open.OpenDoorUseCase
class QrResultViewModel( class QrResultViewModel(
private val useCase: OpenDoorUseCase, private val useCase: OpenDoorUseCase,

View File

@ -1,9 +1,9 @@
package ru.myitschool.work.utils package ru.myitschool.work.utils
import ru.myitschool.work.domain.entities.UserEntity import ru.myitschool.work.entities.EmployeeEntity
sealed class UserState { sealed class UserState {
object Loading : UserState() object Loading : UserState()
data class Success(val userEntity: UserEntity) : UserState() data class Success(val employeeEntity: EmployeeEntity) : UserState()
object Error : UserState() object Error : UserState()
} }

View File

@ -27,7 +27,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="16dp" android:layout_margin="16dp"
android:contentDescription="@string/close_button" android:contentDescription="@string/close_btn"
android:src="@drawable/ic_close" android:src="@drawable/ic_close"
app:elevation="0dp" app:elevation="0dp"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"