rajesh
08/16/2021, 12:19 PMPost
, and it has property called isLiked
. I want to retrieve its value in repository class to determine whether to like or unlike a post. I'm using below code but app automatically crash with I/Process: Sending signal. PID: 12911 SIG: 9
when using below code block. what am i doing wrong?
@Query("SELECT * FROM posts WHERE postId = :postId")
fun isPostLiked(postId: Long): Post
suspend fun toggleLike(postId: Long) {
Log.d(TAG, "inside toggle like")
if (db.postDao.isPostLiked(postId = postId).isLiked == true) {
Log.d(TAG, "unlike post")
} else {
Log.d(TAG, "like post")
}
}
Javi ChaquƩs
08/16/2021, 12:28 PM@Query("SELECT * FROM posts WHERE postId = :postId LIMIT 1")
rajesh
08/16/2021, 12:31 PMrajesh
08/16/2021, 12:31 PMIan Lake
08/16/2021, 1:40 PMsuspend fun
and it'll run on the right background thread automaticallyrajesh
08/16/2021, 1:56 PM@Query("SELECT * FROM posts WHERE postId = :postId LIMIT 1")
suspend fun isPostLiked(postId: Long): Post
suspend fun toggleLike(postId: Long) {
Log.d(TAG, "this will be printed")
db.postDao.isPostLiked(postId).isLiked?.let {
if (it) {
Log.d(TAG, "post already liked, its not working")
} else {
Log.d(TAG, "post not liked, its not working")
}
}
}
rajesh
08/16/2021, 2:05 PM@Query("UPDATE posts SET isLiked = 1, likesCount = likesCount + 1 WHERE postId = :postId")
suspend fun likePost(postId: Long)
rajesh
08/16/2021, 2:27 PM