Skip to content

Commit

Permalink
Post.kt signature changed
Browse files Browse the repository at this point in the history
  • Loading branch information
T8RIN committed Nov 7, 2022
1 parent 336811a commit f88bf35
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 69 deletions.
Binary file modified app/release/app-release.apk
Binary file not shown.
18 changes: 10 additions & 8 deletions app/src/main/java/ru/tech/cookhelper/data/remote/dto/PostDto.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@ package ru.tech.cookhelper.data.remote.dto
import ru.tech.cookhelper.data.remote.utils.Dto
import ru.tech.cookhelper.domain.model.FileData
import ru.tech.cookhelper.domain.model.Post
import ru.tech.cookhelper.domain.model.User

data class PostDto(
val id: String,
val authorId: Long,
val id: Long,
val author: User,
val timestamp: Long,
val label: String?,
val text: String?,
val label: String,
val text: String,
val likes: List<Long>,
val comments: List<String>,
val reposts: List<Long>,
val attachments: List<FileData>
val attachments: List<FileData>,
val images: List<FileData>
) : Dto {
override fun asDomain(): Post = Post(
id = id,
authorId = authorId,
author = author,
timestamp = timestamp,
label = label ?: "",
text = text ?: "",
label = label,
text = text,
likes = likes,
comments = comments,
reposts = reposts,
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/ru/tech/cookhelper/domain/model/Post.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package ru.tech.cookhelper.domain.model
import ru.tech.cookhelper.domain.utils.Domain

data class Post(
val id: String,
val authorId: Long,
val id: Long,
val author: User,
val timestamp: Long,
val label: String,
val text: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ fun FancyToastHost(fancyToastValues: FancyToastValues) {
modifier = Modifier
.fillMaxSize()
.imePadding()
.navigationBarsPadding()
) {
Card(
colors = CardDefaults.cardColors(contentColor = MaterialTheme.colorScheme.onTertiaryContainer),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@ import androidx.compose.ui.unit.dp
import dev.olshevski.navigation.reimagined.hilt.hiltViewModel
import ru.tech.cookhelper.R
import ru.tech.cookhelper.core.utils.ConnectionUtils.isOnline
import ru.tech.cookhelper.domain.model.FileData
import ru.tech.cookhelper.domain.model.User
import ru.tech.cookhelper.presentation.app.components.sendToast
import ru.tech.cookhelper.presentation.profile.components.*
import ru.tech.cookhelper.presentation.profile.viewModel.ProfileViewModel
import ru.tech.cookhelper.presentation.recipe_post_creation.components.Separator
import ru.tech.cookhelper.presentation.ui.utils.android.ContextUtils.findActivity
import ru.tech.cookhelper.presentation.ui.utils.android.Logger.makeLog
import ru.tech.cookhelper.presentation.ui.utils.compose.PaddingUtils.addPadding
import ru.tech.cookhelper.presentation.ui.utils.navigation.Dialog
import ru.tech.cookhelper.presentation.ui.utils.navigation.Screen
Expand Down Expand Up @@ -95,20 +92,20 @@ fun ProfileScreen(
)
Spacer(Modifier.height(20.dp))
ImageCarousel(
data = testList,
data = emptyList(),
onImageClick = { id ->
screenController.navigate(
Screen.FullscreenImagePager(
id = id,
images = testList,
images = emptyList(),
)
)
},
onAddImage = { viewModel.addImage(it) },
onExpand = {
screenController.navigate(
Screen.AllImages(
images = testList,
images = emptyList(),
canAddImages = true,
onAddImage = { viewModel.addImage(it) }
)
Expand Down Expand Up @@ -146,29 +143,10 @@ fun ProfileScreen(
itemsIndexed(viewModel.posts, key = { _, post -> post.id }) { index, post ->
PostItem(
post = post,
authorLoader = {
User(
id = 1,
avatar = listOf(
FileData(
"https://sun1-89.userapi.com/impf/zNPPyzy-fIkM0yKJRQxrgTXvs0GRq8o3r3R2cg/FzpwGJudQi4.jpg?size=1461x2160&quality=95&sign=16250424fdef8401465f946368bc8188&type=album",
""
)
),
name = "Малик",
surname = "Мухаметзянов",
token = "",
email = "",
nickname = "t8rin",
verified = true,
fridge = emptyList(),
lastSeen = 0L
)
},
onImageClick = { id ->
onImageClick = {
screenController.navigate(
Screen.FullscreenImagePager(
id = id,
id = it.id,
images = post.images
)
)
Expand All @@ -194,21 +172,4 @@ fun ProfileScreen(
//TODO: Recipes
}
}
}

private val testList = listOf(
FileData("https://ciroccodentalcenterpa.com/wp-content/uploads/foods-fight-plaque.jpg", "1"),
FileData(
"https://ciroccodentalcenterpa.com/wp-content/uploads/foods-fight-plaque.jpg",
"2"
),
FileData(
"https://sun1-89.userapi.com/impf/zNPPyzy-fIkM0yKJRQxrgTXvs0GRq8o3r3R2cg/FzpwGJudQi4.jpg?size=1461x2160&quality=95&sign=16250424fdef8401465f946368bc8188&type=album",
"3"
),
FileData("https://ciroccodentalcenterpa.com/wp-content/uploads/foods-fight-plaque.jpg", "4"),
FileData(
"https://ciroccodentalcenterpa.com/wp-content/uploads/foods-fight-plaque.jpg",
"5"
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import ru.tech.cookhelper.domain.model.FileData
import ru.tech.cookhelper.domain.model.Post
import ru.tech.cookhelper.domain.model.User
import ru.tech.cookhelper.presentation.app.components.Picture
Expand All @@ -31,15 +32,12 @@ import java.util.*
fun PostItem(
post: Post,
clientUserId: Long,
authorLoader: (authorId: Long) -> User,
onImageClick: (imageId: String) -> Unit,
onAuthorClick: (authorId: Long) -> Unit,
onPostClick: (postId: String) -> Unit,
onLikeClick: (postId: String) -> Unit,
onCommentsClick: (postId: String) -> Unit = onPostClick
onImageClick: (image: FileData) -> Unit,
onAuthorClick: (author: User) -> Unit,
onPostClick: () -> Unit,
onLikeClick: () -> Unit,
onCommentsClick: () -> Unit = onPostClick
) {
val author = authorLoader(post.authorId)

val timestamp by remember {
derivedStateOf {
val df =
Expand All @@ -59,14 +57,14 @@ fun PostItem(
Column(
Modifier
.fillMaxWidth()
.clickable { onPostClick(post.id) }
.clickable { onPostClick() }
) {
Spacer(Modifier.size(16.dp))
AuthorBubble(
modifier = Modifier.padding(start = 20.dp),
author = author,
author = post.author,
timestamp = timestamp,
onClick = { onAuthorClick(post.authorId) }
onClick = { onAuthorClick(post.author) }
)
Spacer(Modifier.size(16.dp))

Expand Down Expand Up @@ -94,7 +92,7 @@ fun PostItem(
.squareSize()
.align(Alignment.Center)
.clickable {
onImageClick(image.id)
onImageClick(image)
},
shape = shape
)
Expand All @@ -105,7 +103,7 @@ fun PostItem(
Row(Modifier.padding(horizontal = 15.dp)) {
val liked = post.likes.contains(clientUserId)
PostActionButton(
onClick = { onLikeClick(post.id) },
onClick = { onLikeClick() },
icon = if (liked) Icons.Rounded.Favorite else Icons.Rounded.FavoriteBorder,
text = post.likes.size.run { if (this != 0) toString() else "" },
contentColor = if (liked) LikeColor else Gray,
Expand All @@ -115,7 +113,7 @@ fun PostItem(
)
Spacer(Modifier.size(8.dp))
PostActionButton(
onClick = { onCommentsClick(post.id) },
onClick = { onCommentsClick() },
icon = Icons.Rounded.ChatBubbleOutline,
text = post.comments.size.run { if (this != 0) toString() else "" }
)
Expand Down

0 comments on commit f88bf35

Please sign in to comment.