Сделал кринж года, есть пагинация, но мне вообще не нравится не проект, не реализация, не мои программистические способности :(
This commit is contained in:
parent
dc5cc2e862
commit
e903f1729c
@ -62,6 +62,8 @@ dependencies {
|
||||
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2")
|
||||
implementation ("androidx.lifecycle:lifecycle-runtime-ktx:2.4.0")
|
||||
|
||||
implementation ("androidx.paging:paging-runtime:3.2.1")
|
||||
|
||||
|
||||
implementation("androidx.core:core-ktx:1.9.0")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.1")
|
||||
|
@ -1,10 +1,20 @@
|
||||
package com.example.labwork.button_navigation
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.Button
|
||||
import androidx.compose.material.ButtonDefaults
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
@ -12,8 +22,12 @@ import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.navigation.NavHostController
|
||||
import com.example.labwork.database.DAO.UserDao
|
||||
import com.example.labwork.models.Bicycle
|
||||
@ -22,6 +36,7 @@ import com.example.labwork.pages.product.FormNewProduct
|
||||
import com.example.labwork.pages.product.ListProduct
|
||||
import com.example.labwork.pages.user.RegisteryOrLogin
|
||||
import com.example.labwork.repository.BicycleRepository
|
||||
import com.example.labwork.ui.theme.LightBluePolitech
|
||||
import com.example.labwork.viewmodel.BicycleViewModel
|
||||
import com.example.labwork.viewmodel.UserViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -43,25 +58,76 @@ fun ScreenListProduct(
|
||||
navHostController: NavHostController
|
||||
) {
|
||||
val bicycles by bicycleViewModel.bicycles.collectAsState()
|
||||
var currentIndex by remember { mutableStateOf(0) }
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
bicycleViewModel.fetchBicycles()
|
||||
}
|
||||
|
||||
val paginatedBicycles = bicycles.chunked(3)
|
||||
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxHeight().padding(bottom = 65.dp)
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier.fillMaxWidth().padding(top = 8.dp)
|
||||
) {
|
||||
Button(
|
||||
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(9.dp),
|
||||
onClick = {
|
||||
if (currentIndex > 0) {
|
||||
currentIndex--
|
||||
}
|
||||
},
|
||||
shape = RoundedCornerShape(15.dp),
|
||||
enabled = currentIndex > 0
|
||||
) {
|
||||
Text(text = "Предыдущая страничка",
|
||||
color = Color.White,
|
||||
fontSize = 10.sp,
|
||||
textAlign = TextAlign.Center)
|
||||
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
|
||||
Button(
|
||||
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(9.dp),
|
||||
onClick = {
|
||||
if (currentIndex < paginatedBicycles.size - 1) {
|
||||
currentIndex++
|
||||
}
|
||||
},
|
||||
shape = RoundedCornerShape(15.dp),
|
||||
enabled = currentIndex < paginatedBicycles.size - 1
|
||||
) {
|
||||
Text(text = "Следущая страничка",
|
||||
color = Color.White,
|
||||
fontSize = 10.sp,
|
||||
textAlign = TextAlign.Center)
|
||||
}
|
||||
}
|
||||
FormNewProduct(bicycleViewModel, navHostController)
|
||||
LazyColumn {
|
||||
itemsIndexed(bicycles) { index, item ->
|
||||
ListProduct(
|
||||
item = item,
|
||||
bicycleViewModel = bicycleViewModel,
|
||||
navHostController = navHostController
|
||||
)
|
||||
paginatedBicycles.getOrNull(currentIndex)?.let { paginatedList ->
|
||||
itemsIndexed(paginatedList) { _, item ->
|
||||
ListProduct(
|
||||
item = item,
|
||||
bicycleViewModel = bicycleViewModel,
|
||||
navHostController = navHostController
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -59,7 +59,6 @@ fun LoginPage(
|
||||
user?.let { userProfile ->
|
||||
ProfileForm(item = userProfile, userViewModel = userViewModel, navHostController = navHostController)
|
||||
}
|
||||
//navHostController.navigate("Info")
|
||||
}
|
||||
|
||||
else {
|
||||
|
Loading…
Reference in New Issue
Block a user