From cf8e779058c47983d22b5f1af15b5cd0068d23dd Mon Sep 17 00:00:00 2001 From: Amon Date: Sat, 30 Dec 2023 14:15:56 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9A=D1=83=D1=80=D1=81=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=8F:=20=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=20=D0=B8=20?= =?UTF-8?q?=D1=81=D0=B4=D0=B0=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/dtf/data/api/ServerService.kt | 2 +- app/src/main/java/com/example/dtf/ui/screens/PostsScreen.kt | 3 +-- .../main/java/com/example/dtf/ui/screens/TopPostsScreen.kt | 6 ++++++ .../java/com/example/dtf/ui/viewmodels/TopPostsViewModel.kt | 2 ++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/example/dtf/data/api/ServerService.kt b/app/src/main/java/com/example/dtf/data/api/ServerService.kt index 3bcdd60..36b0fb6 100644 --- a/app/src/main/java/com/example/dtf/data/api/ServerService.kt +++ b/app/src/main/java/com/example/dtf/data/api/ServerService.kt @@ -112,7 +112,7 @@ interface ServerService { ): User companion object { - private const val BASE_URL = "http://192.168.0.103:8000/" + private const val BASE_URL = "http://192.168.43.115:8000/" private var _token: String = "" diff --git a/app/src/main/java/com/example/dtf/ui/screens/PostsScreen.kt b/app/src/main/java/com/example/dtf/ui/screens/PostsScreen.kt index dcdced4..f0247dd 100644 --- a/app/src/main/java/com/example/dtf/ui/screens/PostsScreen.kt +++ b/app/src/main/java/com/example/dtf/ui/screens/PostsScreen.kt @@ -161,8 +161,7 @@ private fun Post(viewModel: PostsViewModel, navController: NavHostController, po Column( modifier = Modifier - .fillMaxHeight(0.3f) - .heightIn(max = 250.dp) + .heightIn(min=250.dp, max = 300.dp) .fillMaxWidth() .background(Color.White) .clickable { diff --git a/app/src/main/java/com/example/dtf/ui/screens/TopPostsScreen.kt b/app/src/main/java/com/example/dtf/ui/screens/TopPostsScreen.kt index 6077557..3869d62 100644 --- a/app/src/main/java/com/example/dtf/ui/screens/TopPostsScreen.kt +++ b/app/src/main/java/com/example/dtf/ui/screens/TopPostsScreen.kt @@ -203,6 +203,12 @@ fun Post(viewModel: TopPostsViewModel, navController: NavHostController, post: P val likes = remember { mutableIntStateOf(post.likes) } val isLiked = remember { mutableStateOf(false) } + LaunchedEffect(Unit) { + viewModel.getLikes(post.id!!).collect { + likes.intValue = it + } + } + LaunchedEffect(Unit) { viewModel.isLiked(sharedPref, post.id!!).collect { isLiked.value = it diff --git a/app/src/main/java/com/example/dtf/ui/viewmodels/TopPostsViewModel.kt b/app/src/main/java/com/example/dtf/ui/viewmodels/TopPostsViewModel.kt index 260b29d..f107d01 100644 --- a/app/src/main/java/com/example/dtf/ui/viewmodels/TopPostsViewModel.kt +++ b/app/src/main/java/com/example/dtf/ui/viewmodels/TopPostsViewModel.kt @@ -35,6 +35,8 @@ class TopPostsViewModel @Inject constructor( } } + fun getLikes(postId: Int) = likeRepository.countByPost(postId) + fun likePost(sharedPref: PreferencesManager, postId: Int) { val userId = sharedPref.getData("userId", "-1").toInt()