бета аналитика ver 0.2

This commit is contained in:
Данила Мочалов 2023-12-26 23:29:41 +04:00
parent da80721cd1
commit 6f5f1c40d3
5 changed files with 40 additions and 13 deletions

View File

@ -10,7 +10,9 @@ data class ProductModelRemote(
val price: Int = 0,
val old_price: Int? = null,
val order_products: List<OrderProductRemote> = listOf()
val order_products: List<OrderProductRemote> = listOf(),
val purchase_count: Int? = null
)
@Serializable

View File

@ -6,7 +6,7 @@ import androidx.paging.PagingConfig
import androidx.paging.PagingData
import com.example.shawarma.data.api.MyServerService
import com.example.shawarma.data.api.mediators.ProductRemoteMediator
import com.example.shawarma.data.api.models.toProductModel
import com.example.shawarma.data.api.models.ProductModelRemote
import com.example.shawarma.data.api.repos.RestProductRepository
import com.example.shawarma.data.db.AppDatabase
import com.example.shawarma.data.interfaces.dao.ProductDao
@ -62,8 +62,8 @@ class ProductRepository @Inject constructor(
remoteMediator = ProductRemoteMediator(database = database, serverService = MyServerService.getInstance(), query = "items", token = token)
).flow
suspend fun getTopProducts(period: String, token: String) : List<ProductModel> {
return restRepository.getTopProducts(period, token).map { it.toProductModel() }
suspend fun getTopProducts(period: String, token: String) : List<ProductModelRemote> {
return restRepository.getTopProducts(period, token)
}
}

View File

@ -31,7 +31,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.zIndex
import androidx.hilt.navigation.compose.hiltViewModel
import com.example.shawarma.data.models.ProductModel
import com.example.shawarma.data.api.models.ProductModelRemote
import com.example.shawarma.data.sharedpref.PreferencesManager
import com.example.shawarma.ui.theme.MarckFamily
import com.example.shawarma.ui.theme.MyLightYellow
@ -74,10 +74,11 @@ fun TopProductsWidget(productsViewModel: ProductsViewModel) {
fontSize = 40.sp,
modifier = Modifier.padding(top = 15.dp)
)
Text(text = "Топ-10 продуктов за:", modifier = Modifier.padding(top = 60.dp))
Row(
modifier = Modifier
.fillMaxHeight()
.padding(top = 60.dp)
.padding(top = 80.dp)
){
Button(
modifier = Modifier
@ -127,13 +128,13 @@ fun TopProductsWidget(productsViewModel: ProductsViewModel) {
}
if (!topProductsList.isNullOrEmpty()) {
LazyColumn(
modifier = Modifier.padding(top = 120.dp, bottom = 60.dp),
modifier = Modifier.padding(top = 140.dp, bottom = 60.dp),
){
items(
topProductsList.size
) {
TopProductItem(topProductsList[it])
TopProductItem(topProductsList[it], it)
Spacer(modifier = Modifier.size(20.dp))
}
}
@ -142,7 +143,7 @@ fun TopProductsWidget(productsViewModel: ProductsViewModel) {
}
@Composable
fun TopProductItem(product: ProductModel){
fun TopProductItem(product: ProductModelRemote, index: Int){
Card(
border = BorderStroke(width = 2.dp, color = MyOrange),
shape = RoundedCornerShape(size = 20.dp),
@ -156,17 +157,17 @@ fun TopProductItem(product: ProductModel){
horizontalArrangement = Arrangement.SpaceAround
) {
Column(
modifier = Modifier.fillMaxWidth(1f)
modifier = Modifier.fillMaxWidth(0.5f)
) {
Text(
text = product.title,
text = (index + 1).toString() + ". " + product.title,
fontFamily = NunitoFamily,
fontSize = 20.sp,
fontWeight = FontWeight.Bold,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
if (product.oldPrice != null) {
if (product.old_price != null) {
Text(
text = product.price.toString() + " руб.",
fontFamily = NunitoFamily,
@ -185,6 +186,26 @@ fun TopProductItem(product: ProductModel){
}
}
Column(
modifier = Modifier.fillMaxWidth(0.5f)
) {
Text(
text = "Покупок:",
fontFamily = NunitoFamily,
fontSize = 16.sp,
fontWeight = FontWeight.Bold,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Text(
text = product.purchase_count.toString(),
fontFamily = NunitoFamily,
fontSize = 16.sp,
fontWeight = FontWeight.Bold,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
}
}
}
}

View File

@ -23,6 +23,9 @@ class ProductViewModel @Inject constructor(
get() = _product
fun addProduct(name: String, price: Int, oldPrice: Int? = null, token: String) {
if (name.isNullOrEmpty() || price <= 0) {
return
}
viewModelScope.launch {
productRepository.insert(ProductModel(null, name, price, oldPrice), token)
_addingProductState.postValue(true)

View File

@ -4,6 +4,7 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.PagingData
import com.example.shawarma.data.api.models.ProductModelRemote
import com.example.shawarma.data.models.ProductModel
import com.example.shawarma.data.repos.ProductRepository
import dagger.hilt.android.lifecycle.HiltViewModel
@ -26,7 +27,7 @@ class ProductsViewModel @Inject constructor(
}
}
val topProductList = MutableLiveData<List<ProductModel>?>(null)
val topProductList = MutableLiveData<List<ProductModelRemote>?>(null)
fun getTopProductsList(token: String, period: String) {
viewModelScope.launch {