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()