Feature: response for findStroke

This commit is contained in:
Emelyanov535 2023-12-19 16:47:08 +04:00
parent b416011a1d
commit d16dc4ccca
8 changed files with 68 additions and 41 deletions

View File

@ -0,0 +1,25 @@
package com.example.android_programming
import com.example.android_programming.model.User
class GlobalUser private constructor() {
private var user: User? = null
fun setUser(user: User?) {
this.user = user
}
fun getUser(): User? {
return user
}
companion object {
private var instance: GlobalUser? = null
fun getInstance(): GlobalUser {
return instance ?: synchronized(this) {
instance ?: GlobalUser().also { instance = it }
}
}
}
}

View File

@ -30,26 +30,4 @@ fun MainContent() {
Navigate()
}
}
class GlobalUser private constructor() {
private var user: User? = null
fun setUser(user: User?) {
this.user = user
}
fun getUser(): User? {
return user
}
companion object {
private var instance: GlobalUser? = null
fun getInstance(): GlobalUser {
return instance ?: synchronized(this) {
instance ?: GlobalUser().also { instance = it }
}
}
}
}

View File

@ -6,8 +6,6 @@ import com.example.android_programming.api.model.OrderSneakerRemote
import com.example.android_programming.api.model.SneakerRemote
import com.example.android_programming.api.model.UserRemote
import com.example.android_programming.api.model.UserRemoteSignIn
import com.example.android_programming.model.Order
import com.example.android_programming.model.Sneaker
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
@ -52,6 +50,13 @@ interface BackendService {
@Path("id") id: Int
)
@GET("sneaker/findSneakersByString/{string}")
suspend fun findSneakersByString(
@Path("string") str: String,
nextPageNumber: Int,
loadSize: Int
): List<SneakerRemote>
//USER
@POST("user/signup")
suspend fun SignUp(

View File

@ -4,6 +4,9 @@ import androidx.paging.ExperimentalPagingApi
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.PagingSource
import androidx.paging.PagingState
import androidx.paging.compose.collectAsLazyPagingItems
import com.example.android_programming.di.AppContainer
import com.example.android_programming.api.BackendService
import com.example.android_programming.api.SneakerRemoteMediator
@ -15,6 +18,8 @@ import com.example.android_programming.model.Sneaker
import com.example.android_programming.database.repository.SneakerRepoImpl
import com.example.android_programming.businessLogic.repo.SneakerRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.flowOf
class RestSneakerRepository(
private val service: BackendService,
@ -23,7 +28,6 @@ class RestSneakerRepository(
private val dbRemoteKeyRepository: RemoteKeysRepositoryImpl
) : SneakerRepository {
override fun getAllSneakers(): Flow<PagingData<Sneaker>> {
val pagingSourceFactory = { dbSneakerRepository.getAllSneakersPagingSource() }

View File

@ -4,12 +4,15 @@ import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.PagingData
import com.example.android_programming.R
import com.example.android_programming.api.repository.RestSneakerRepository
import com.example.android_programming.businessLogic.repo.SneakerRepository
import com.example.android_programming.model.Sneaker
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.launch
class SneakerViewModel(private val sneakerRepository: SneakerRepository): ViewModel() {
@ -19,6 +22,7 @@ class SneakerViewModel(private val sneakerRepository: SneakerRepository): ViewMo
val description = mutableStateOf("")
val price = mutableStateOf("")
val photo = mutableIntStateOf(R.drawable.img)
fun insertSneaker() = viewModelScope.launch {
val sneaker = Sneaker(
brand = brand.value,

View File

@ -12,6 +12,7 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
@ -32,21 +33,7 @@ fun HomeScreen(navHostController: NavHostController) {
modifier = Modifier
.fillMaxSize()
.background(Color.White)
/*.verticalScroll(rememberScrollState())*/
) {
Row {
// Поле для поиска
SearchField(
modifier = Modifier
.fillMaxWidth()
.padding(20.dp, 20.dp, 20.dp, 10.dp)
.clip(RoundedCornerShape(10.dp))
) { searchText ->
// Обработка введенного текста поиска
}
}
Sales()
FilterByBrand()
RecyclerView(navHostController = navHostController)
}
}

View File

@ -1,10 +1,15 @@
package com.example.android_programming.composeui.Screens.HomeScreen.SneakerRecyclerView
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
@ -13,6 +18,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
@ -23,6 +29,9 @@ import com.example.android_programming.model.Sneaker
import com.example.android_programming.businessLogic.vmodel.AppViewModelProvider
import com.example.android_programming.businessLogic.vmodel.OrderViewModel
import com.example.android_programming.businessLogic.vmodel.SneakerViewModel
import com.example.android_programming.composeui.Screens.HomeScreen.FilterByBrand.FilterByBrand
import com.example.android_programming.composeui.Screens.HomeScreen.Sales
import com.example.android_programming.composeui.Screens.HomeScreen.SearchField.SearchField
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@ -35,9 +44,23 @@ fun RecyclerView(navHostController: NavHostController, sneakerViewModel: Sneaker
.fillMaxSize()
.padding(bottom = 60.dp)
) {
Row {
// Поле для поиска
SearchField(
modifier = Modifier
.fillMaxWidth()
.padding(20.dp, 20.dp, 20.dp, 10.dp)
.clip(RoundedCornerShape(10.dp))
) { searchText ->
// Обработка введенного текста поиска
}
}
Sales()
FilterByBrand()
val sneakerLazyPagingItems = sneakerViewModel.sneakerList.collectAsLazyPagingItems()
LazyVerticalGrid(
modifier = Modifier
.fillMaxSize(),
columns = GridCells.Fixed(2)
) {
items(
@ -55,3 +78,4 @@ fun RecyclerView(navHostController: NavHostController, sneakerViewModel: Sneaker

View File

@ -15,7 +15,7 @@ interface AppContainer {
val basketRepo: BasketRepository
companion object {
const val TIMEOUT = 5000L
const val TIMEOUT = 500L
const val LIMIT = 10
}
}