Skip to content

Commit

Permalink
Refactor vote to like
Browse files Browse the repository at this point in the history
  • Loading branch information
akiomik committed Mar 27, 2023
1 parent 3af81fb commit 999213c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ package io.github.akiomik.seiun.model.app.bsky.notification
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import io.github.akiomik.seiun.model.app.bsky.feed.PostReplyRef
import io.github.akiomik.seiun.model.com.atproto.repo.StrongRef
import java.util.*

// NOTE: app.bsky.graph.follow or app.bsky.feed.vote or app.bsky.feed.repost
// app.bsky.graph.follow (subject, createdAt) or
// app.bsky.feed.like (subject, createdAt) or
// app.bsky.feed.repost (subject, createdAt) or
// app.bsky.feed.post (text, reply, createdAt)
@JsonClass(generateAdapter = true)
data class NotificationRecord(
@Json(name = "\$type")
val type: String,
val createdAt: Date,
val text: String? = null,
val reply: PostReplyRef? = null,
// val direction: VoteDirection? = null,
val subject: NotificationSubject? = null
val subject: StrongRef? = null
)

This file was deleted.

16 changes: 8 additions & 8 deletions app/src/main/java/io/github/akiomik/seiun/ui/feed/FeedPost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,15 @@ private fun RepostIndicator(viewPost: FeedViewPost) {
}

@Composable
private fun UpvoteIndicator(viewPost: FeedViewPost) {
private fun LikeIndicator(viewPost: FeedViewPost) {
val viewModel: PostViewModel = viewModel()
val upvoted = viewPost.post.viewer?.like != null
val color = if (upvoted) {
val liked = viewPost.post.viewer?.like != null
val color = if (liked) {
Red700
} else {
Color.Gray
}
val icon = if (upvoted) {
val icon = if (liked) {
Icons.Sharp.Favorite
} else {
Icons.Sharp.FavoriteBorder
Expand All @@ -232,12 +232,12 @@ private fun UpvoteIndicator(viewPost: FeedViewPost) {

TextButton(
onClick = {
if (upvoted) {
viewModel.cancelVote(feedPost = viewPost, onError = {
if (liked) {
viewModel.cancelLike(feedPost = viewPost, onError = {
Toast.makeText(context, it.toString(), Toast.LENGTH_LONG).show()
})
} else {
viewModel.upvote(feedPost = viewPost, onError = {
viewModel.like(feedPost = viewPost, onError = {
Toast.makeText(context, it.toString(), Toast.LENGTH_LONG).show()
})
}
Expand Down Expand Up @@ -369,7 +369,7 @@ private fun FeedPostContent(viewPost: FeedViewPost) {
) {
ReplyIndicator(viewPost = viewPost)
RepostIndicator(viewPost = viewPost)
UpvoteIndicator(viewPost = viewPost)
LikeIndicator(viewPost = viewPost)
MenuButton(viewPost = viewPost)
}
Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private fun Avatar(notification: Notification, onClicked: (String) -> Unit) {
}

@Composable
private fun VoteItem(notification: Notification, onProfileClick: (String) -> Unit) {
private fun LikeItem(notification: Notification, onProfileClick: (String) -> Unit) {
val createdAt = DateFormat.format(
DATETIME_FORMAT,
notification.record.createdAt.toInstant().toEpochMilli()
Expand Down Expand Up @@ -210,7 +210,7 @@ fun NotificationListItem(notification: Notification, onProfileClick: (String) ->
.fillMaxWidth()
) {
when (notification.reason) {
"vote" -> VoteItem(notification = notification, onProfileClick = onProfileClick)
"like" -> LikeItem(notification = notification, onProfileClick = onProfileClick)
"repost" -> RepostItem(notification = notification, onProfileClick = onProfileClick)
"follow" -> FollowItem(notification = notification, onProfileClick = onProfileClick)
"invite" -> InviteItem(notification = notification, onProfileClick = onProfileClick)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PostViewModel : ApplicationViewModel() {
private val userRepository = SeiunApplication.instance!!.userRepository
private val postFeedRepository = SeiunApplication.instance!!.postFeedRepository

fun upvote(
fun like(
feedPost: FeedViewPost,
onSuccess: () -> Unit = {},
onError: (Throwable) -> Unit = {}
Expand All @@ -23,7 +23,7 @@ class PostViewModel : ApplicationViewModel() {
)
}

fun cancelVote(
fun cancelLike(
feedPost: FeedViewPost,
onSuccess: () -> Unit = {},
onError: (Throwable) -> Unit = {}
Expand Down

0 comments on commit 999213c

Please sign in to comment.