Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature/#68] : fcm, like api #72

Merged
merged 24 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0f7f218
#68 [FEAT] : set up feed like api
sohyun127 Sep 4, 2024
0a73bad
#68 [FEAT] : set up like single event
sohyun127 Sep 5, 2024
4a8dd3d
#68 [FEAT] : set up like logic
sohyun127 Sep 5, 2024
158611f
#68 [MOD] : change function name
sohyun127 Sep 5, 2024
68a3136
#68 [FEAT] : set up comment like api
sohyun127 Sep 5, 2024
e72473e
#68 [MOD] : change name
sohyun127 Sep 5, 2024
295fe73
#68 [FEAT] : set up comment like action handler
sohyun127 Sep 5, 2024
63b327b
#68 [FEAT] : set up comment like logic at profile comment
sohyun127 Sep 5, 2024
7e49059
#68 [MOD] : change name
sohyun127 Sep 5, 2024
9f1aaa9
#68 [FEAT] : set up home detail recycler view divider
sohyun127 Sep 5, 2024
c70bd98
#68 [FEAT] : set up home detail like logic, comment scroll to bottom
sohyun127 Sep 5, 2024
0f06c60
#68 [FIX] : fix home detail divider
sohyun127 Sep 5, 2024
38248e8
Merge branch 'develop' of https://github.com/Team-Wable/WABLE-ANDROID…
sohyun127 Sep 5, 2024
7d2920b
#68 [FEAT] : set up fcm alert dialog
sohyun127 Sep 5, 2024
b8f648f
#68 [FEAT] : set up app logo
sohyun127 Sep 5, 2024
a832ea8
Merge branch 'feature/#66-splash' of https://github.com/Team-Wable/WA…
sohyun127 Sep 5, 2024
987e20f
#68 [HOTFIX] : fix multipart anotation
sohyun127 Sep 5, 2024
9d34ae1
#68 [FEAT] : set up fcm logic
sohyun127 Sep 5, 2024
4f232d1
#68 [FIX] : fix block double click comment post
sohyun127 Sep 5, 2024
f762007
#68 [FIX] : fix fcm logic
sohyun127 Sep 5, 2024
20739a9
Merge branch 'develop' of https://github.com/Team-Wable/WABLE-ANDROID…
sohyun127 Sep 5, 2024
73691b4
#68 [FIX] : fix ci error
sohyun127 Sep 5, 2024
f82fa72
#68 [HOTFIX] : fix home state error
sohyun127 Sep 6, 2024
25bcd3a
#68 [REFACTOR] : change likefeeds with update function
sohyun127 Sep 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ dependencies {
// firebase
implementation(platform(libs.firebase.bom))
implementation(libs.firebase.analytics)
implementation(libs.google.play.services)
implementation(libs.firebase.messaging.ktx)
Comment on lines +74 to +75
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ν˜Ήμ‹œ 이거 μ΅œμ‹  λ²„μ „μ—μ„œ λŒμ•„κ°€λ‚˜μš”? zν”Œλ¦½6μ—μ„œ fcmμ•ˆμ˜€κΈΈλž˜ 버전 μ—…ν•˜λ‹ˆκΉŒ 였긴 ν–ˆμŠ΅λ‹ˆλ‹€
저도 μ •ν™•ν•œ 원인은 λͺ¨λ₯΄κ² μ–΄μš”γ… 

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아직 ν‘Έμ‹œμ•Œλ¦Ό μ•ˆλ κ±°μ—μš” γ… .γ…  μˆ˜μ • 쀑 γ…Žγ…Ž λ‹€μŒ PRμ—μ„œ μˆ˜μ •ν•˜κ² μŠ΅λ‹ˆλ‹€-!!


// kakao
implementation(libs.kakao.login)
}
12 changes: 12 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@
android:theme="@style/Theme.Wable"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/white" />
Comment on lines +26 to +28
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ΄λ²ˆμ—” meta data에 iconμΆ”κ°€ μ•ˆ 해도 λ˜λ‚˜μš”?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μΆ”κ°€ν•΄μ•Όν•©λ‹ˆλ‹€!!! μˆ˜μ •ν•˜λ‹€κ°€ 빼놓고 μΆ”κ°€ μ•ˆν–ˆλ„€μš” ..γ…Žγ…Ž


<service
android:name=".service.WableFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>

<activity
android:name="com.teamwable.main_compose.MainComposeActivity"
android:exported="true">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.teamwable.wable.service

import android.app.Notification
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import androidx.core.app.NotificationCompat
import com.google.firebase.messaging.Constants.MessageNotificationKeys.ENABLE_NOTIFICATION
import com.google.firebase.messaging.Constants.MessageNotificationKeys.NOTIFICATION_PREFIX
import com.google.firebase.messaging.Constants.MessageNotificationKeys.NOTIFICATION_PREFIX_OLD
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import com.teamwable.main.MainActivity
import com.teamwable.ui.extensions.colorOf
import com.teamwable.ui.util.FcmTag.CHANNEL_ID
import com.teamwable.ui.util.FcmTag.NOTIFICATION_BODY
import com.teamwable.ui.util.FcmTag.NOTIFICATION_TITLE
import com.teamwable.ui.util.FcmTag.RELATED_CONTENT_ID
import timber.log.Timber

class WableFirebaseMessagingService : FirebaseMessagingService() {
private lateinit var title: String
private lateinit var body: String

override fun onNewToken(token: String) {
super.onNewToken(token)
Timber.d("fcm new token : $token")
}

override fun onMessageReceived(message: RemoteMessage) {
super.onMessageReceived(message)
sendPushAlarm(
title = if (::title.isInitialized) title else "",
body = if (::body.isInitialized) body else "",
contentId = message.data[RELATED_CONTENT_ID] ?: return,
)
}

private fun sendPushAlarm(title: String, body: String, contentId: String) {
val notificationManager =
getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager
val notification = buildNotification(title, body, contentId)
notificationManager?.notify((System.currentTimeMillis()).toInt(), notification)
}

override fun handleIntent(intent: Intent?) {
val newPushAlarmIntent = intent?.apply {
val temp = extras?.apply {
title = getString(NOTIFICATION_TITLE).orEmpty()
body = getString(NOTIFICATION_BODY).orEmpty()
remove(ENABLE_NOTIFICATION)
remove(getKeyWithOldPrefix())
}
replaceExtras(temp)
}
super.handleIntent(newPushAlarmIntent)
}

private fun getKeyWithOldPrefix(): String {
val key = ENABLE_NOTIFICATION
return if (!key.startsWith(NOTIFICATION_PREFIX)) {
key
} else {
key.replace(
NOTIFICATION_PREFIX,
NOTIFICATION_PREFIX_OLD,
)
}
}

private fun buildNotification(
title: String,
body: String,
contentId: String,
): Notification {
val pendingIntent = createPendingIntent(contentId)
return NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(com.teamwable.common.R.drawable.ic_share_symbol)
.setContentTitle(title)
.setContentText(body)
.setColor(colorOf(com.teamwable.ui.R.color.white))
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.setShowWhen(true)
.build()
}

private fun createPendingIntent(contentId: String): PendingIntent {
val intent = Intent(this, MainActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
putExtra(RELATED_CONTENT_ID, contentId)
}
return PendingIntent.getActivity(
this,
(System.currentTimeMillis()).toInt(),
intent,
PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_MUTABLE,
)
}
}
Binary file added core/common/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions core/common/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
Binary file modified core/common/src/main/res/mipmap-hdpi/ic_launcher.webp
Binary file not shown.
Binary file not shown.
Binary file modified core/common/src/main/res/mipmap-hdpi/ic_launcher_round.webp
Binary file not shown.
Binary file modified core/common/src/main/res/mipmap-mdpi/ic_launcher.webp
Binary file not shown.
Binary file not shown.
Binary file modified core/common/src/main/res/mipmap-mdpi/ic_launcher_round.webp
Binary file not shown.
Binary file modified core/common/src/main/res/mipmap-xhdpi/ic_launcher.webp
Binary file not shown.
Binary file not shown.
Binary file modified core/common/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
Binary file not shown.
Binary file modified core/common/src/main/res/mipmap-xxhdpi/ic_launcher.webp
Binary file not shown.
Binary file not shown.
Binary file modified core/common/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
Binary file not shown.
Binary file modified core/common/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
Binary file not shown.
Binary file not shown.
Binary file modified core/common/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
Binary file not shown.
4 changes: 4 additions & 0 deletions core/common/src/main/res/values/ic_launcher_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#FFFFFF</color>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.teamwable.data.mapper.toData

import com.teamwable.network.dto.request.RequestPostCommentLikeDto
import com.teamwable.network.dto.request.RequestPostFeedLikeDto

internal fun String.toPostFeedLikeDto(): RequestPostFeedLikeDto =
RequestPostFeedLikeDto(this)

internal fun Pair<String, String>.toPostCommentLikeDto(): RequestPostCommentLikeDto =
RequestPostCommentLikeDto(first, second)
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ interface CommentRepository {
suspend fun postComment(contentId: Long, commentText: String): Result<Unit>

suspend fun postGhost(request: Ghost): Result<Unit>

suspend fun postCommentLike(commentId: Long, commentContent: String): Result<Unit>

suspend fun deleteCommentLike(commentId: Long): Result<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ interface FeedRepository {
suspend fun getHomeDetail(feedId: Long): Result<Feed>

suspend fun postGhost(request: Ghost): Result<Boolean>

suspend fun postFeedLike(feedId: Long): Result<Unit>

suspend fun deleteFeedLike(feedId: Long): Result<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.map
import com.teamwable.data.mapper.toData.toPostCommentDto
import com.teamwable.data.mapper.toData.toPostCommentLikeDto
import com.teamwable.data.mapper.toData.toPostGhostDto
import com.teamwable.data.mapper.toModel.toComment
import com.teamwable.data.repository.CommentRepository
Expand All @@ -17,7 +18,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import javax.inject.Inject

class DefaultCommentRepository @Inject constructor(
internal class DefaultCommentRepository @Inject constructor(
private val apiService: CommentService,
) : CommentRepository {
override fun getHomeDetailComments(feedId: Long): Flow<PagingData<Comment>> {
Expand Down Expand Up @@ -63,4 +64,19 @@ class DefaultCommentRepository @Inject constructor(
}.onFailure {
return it.handleThrowable()
}

override suspend fun postCommentLike(commentId: Long, commentContent: String): Result<Unit> = runCatching {
val request = Pair("commentLiked", commentContent).toPostCommentLikeDto()
apiService.postCommentLike(commentId, request)
Unit
}.onFailure {
return it.handleThrowable()
}

override suspend fun deleteCommentLike(commentId: Long): Result<Unit> = runCatching {
apiService.deleteCommentLike(commentId)
Unit
}.onFailure {
return it.handleThrowable()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.map
import com.teamwable.data.mapper.toData.toPostFeedLikeDto
import com.teamwable.data.mapper.toData.toPostGhostDto
import com.teamwable.data.mapper.toModel.toFeed
import com.teamwable.data.repository.FeedRepository
Expand Down Expand Up @@ -58,4 +59,18 @@ class DefaultFeedRepository @Inject constructor(
}.onFailure {
return it.handleThrowable()
}

override suspend fun postFeedLike(feedId: Long): Result<Unit> = runCatching {
apiService.postFeedLike(feedId, "contentLiked".toPostFeedLikeDto())
Unit
}.onFailure {
return it.handleThrowable()
}

override suspend fun deleteFeedLike(feedId: Long): Result<Unit> = runCatching {
apiService.deleteFeedLike(feedId)
Unit
}.onFailure {
return it.handleThrowable()
}
}
6 changes: 6 additions & 0 deletions core/model/src/main/java/com/teamwable/model/LikeState.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.teamwable.model

data class LikeState(
val isLiked: Boolean,
val count: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.teamwable.network.datasource

import com.teamwable.network.dto.request.RequestGhostDto
import com.teamwable.network.dto.request.RequestPostCommentDto
import com.teamwable.network.dto.request.RequestPostCommentLikeDto
import com.teamwable.network.dto.response.ResponseCommentDto
import com.teamwable.network.util.BaseResponse
import com.teamwable.network.util.BaseUnitResponse
Expand Down Expand Up @@ -40,4 +41,15 @@ interface CommentService {
suspend fun postGhost(
@Body request: RequestGhostDto,
): BaseUnitResponse<Unit>

@POST("api/v1/comment/{commentId}/liked")
suspend fun postCommentLike(
@Path(value = "commentId") commentId: Long,
@Body alarmTriggerType: RequestPostCommentLikeDto,
): BaseUnitResponse<Unit>

@DELETE("api/v1/comment/{commentId}/unliked")
suspend fun deleteCommentLike(
@Path(value = "commentId") commentId: Long,
): BaseUnitResponse<Unit>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.teamwable.network.datasource

import com.teamwable.network.dto.request.RequestGhostDto
import com.teamwable.network.dto.request.RequestPostFeedLikeDto
import com.teamwable.network.dto.response.ResponseFeedDto
import com.teamwable.network.util.BaseResponse
import com.teamwable.network.util.BaseUnitResponse
Expand Down Expand Up @@ -37,4 +38,15 @@ interface FeedService {
suspend fun postGhost(
@Body request: RequestGhostDto,
): BaseUnitResponse<Unit>

@POST("api/v1/content/{contentId}/liked")
suspend fun postFeedLike(
@Path(value = "contentId") contentId: Long,
@Body alarmTriggerType: RequestPostFeedLikeDto,
): BaseUnitResponse<Unit>

@DELETE("api/v1/content/{contentId}/unliked")
suspend fun deleteFeedLike(
@Path(value = "contentId") contentId: Long,
): BaseUnitResponse<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface ProfileService {
@PATCH("api/v1/withdrawal")
suspend fun patchWithdrawal(@Body requestWithdrawalDto: RequestWithdrawalDto): BaseUnitResponse<Unit>

@Multipart
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 : μ•„! ν—·

@PATCH("api/v1/user-profile2")
suspend fun patchUserProfile(
@Part("info") requestProfileEdit: RequestBody,
Expand All @@ -40,7 +41,6 @@ interface ProfileService {
@Query("nickname") nickname: String,
): BaseUnitResponse<Unit>

@Multipart
@POST("api/v1/report/slack")
suspend fun postReport(
@Body request: RequestReportDto,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.teamwable.network.dto.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class RequestPostCommentLikeDto(
@SerialName("notificationTriggerType") val notificationTriggerType: String,
@SerialName("notificationText") val notificationText: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.teamwable.network.dto.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class RequestPostFeedLikeDto(
@SerialName("alarmTriggerType") val alarmTriggerType: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.teamwable.model.Comment
interface CommentClickListener {
fun onGhostBtnClick(postAuthorId: Long, commentId: Long)

fun onLikeBtnClick(id: Long)
fun onLikeBtnClick(viewHolder: CommentViewHolder, comment: Comment)

fun onPostAuthorProfileClick(id: Long)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ class CommentViewHolder private constructor(
commentClickListener: CommentClickListener,
) : RecyclerView.ViewHolder(binding.root) {
private lateinit var item: Comment
val likeBtn = binding.btnCommentLike
val likeCountTv = binding.tvCommentLikeCount

init {
setupClickListener(itemView, binding.tvCommentContent) { commentClickListener.onItemClick(item.feedId ?: return@setupClickListener) }
setupClickListener(binding.btnCommentGhost) { commentClickListener.onGhostBtnClick(item.postAuthorId, item.commentId) }
setupClickListener(binding.btnCommentLike) { commentClickListener.onLikeBtnClick(item.commentId) }
setupClickListener(binding.btnCommentLike) { commentClickListener.onLikeBtnClick(this, item) }
setupClickListener(binding.ivCommentProfileImg, binding.tvCommentNickname) { commentClickListener.onPostAuthorProfileClick(item.postAuthorId) }
setupClickListener(binding.btnCommentMore) { commentClickListener.onKebabBtnClick(item) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface FeedClickListener {

fun onGhostBtnClick(postAuthorId: Long, feedId: Long)

fun onLikeBtnClick(id: Long)
fun onLikeBtnClick(viewHolder: FeedViewHolder, id: Long, isLiked: Boolean)

fun onPostAuthorProfileClick(id: Long)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ class FeedViewHolder private constructor(
feedClickListener: FeedClickListener,
) : RecyclerView.ViewHolder(binding.root) {
private lateinit var item: Feed
val likeBtn = binding.btnFeedLike
val likeCountTv = binding.tvFeedLikeCount

init {
setupClickListener(itemView, binding.tvFeedContent, binding.btnFeedComment) { feedClickListener.onItemClick(item) }
setupClickListener(binding.btnFeedGhost) { feedClickListener.onGhostBtnClick(item.postAuthorId, item.feedId) }
setupClickListener(binding.btnFeedLike) { feedClickListener.onLikeBtnClick(item.feedId) }
setupClickListener(binding.btnFeedLike) { feedClickListener.onLikeBtnClick(this, item.feedId, item.isLiked) }
setupClickListener(binding.ivFeedProfileImg, binding.tvFeedNickname) { feedClickListener.onPostAuthorProfileClick(item.postAuthorId) }
setupClickListener(binding.ivFeedImg) { feedClickListener.onFeedImageClick(item.image) }
setupClickListener(binding.btnFeedMore) { feedClickListener.onKebabBtnClick(item) }
Expand Down
Loading