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

[feat] 위니 피드 / 상세페이지 피드, 댓글 조회 #125

Merged
merged 17 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
android:name=".presentation.main.feed.upload.loading.LoadingActivity"
android:exported="false"
android:screenOrientation="portrait" />
<activity
android:name=".presentation.main.feed.detail.DetailActivity"
android:exported="false"
android:screenOrientation="portrait" />
<activity
android:name=".presentation.main.mypage.MypageHelpActivity"
android:exported="false"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.android.go.sopt.winey.data.model.remote.response

import com.android.go.sopt.winey.domain.entity.CommentList
import com.android.go.sopt.winey.domain.entity.DetailFeed
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ResponseGetFeedDetailDto(
@SerialName("getFeedResponseDto")
val getFeedResponseDto: GetFeedResponseDto,
@SerialName("getCommentResponseList")
val getCommentResponseList: List<GetCommentResponseList>
) {
@Serializable
data class GetFeedResponseDto(
@SerialName("createdAt")
val createdAt: String,
@SerialName("feedId")
val feedId: Int,
@SerialName("feedImage")
val feedImage: String,
@SerialName("feedMoney")
val feedMoney: Long,
@SerialName("feedTitle")
val feedTitle: String,
@SerialName("isLiked")
val isLiked: Boolean,
@SerialName("likes")
val likes: Long,
@SerialName("nickName")
val nickName: String,
@SerialName("userId")
val userId: Int,
@SerialName("writerLevel")
val writerLevel: Int,
@SerialName("comments")
val comments: Long,
@SerialName("timeAgo")
val timeAgo: String
)

@Serializable
data class GetCommentResponseList(
@SerialName("commentId")
val commentId: Long,
@SerialName("author")
val author: String,
@SerialName("content")
val content: String,
@SerialName("createdAt")
val createdAt: String,
@SerialName("authorLevel")
val authorLevel: Int,
@SerialName("authorId")
val authorId: Int
)

fun toDetailFeed(): DetailFeed = DetailFeed(
feedId = getFeedResponseDto.feedId,
feedImage = getFeedResponseDto.feedImage,
feedMoney = getFeedResponseDto.feedMoney,
feedTitle = getFeedResponseDto.feedTitle,
isLiked = getFeedResponseDto.isLiked,
likes = getFeedResponseDto.likes,
nickName = getFeedResponseDto.nickName,
userId = getFeedResponseDto.userId,
writerLevel = getFeedResponseDto.writerLevel,
comments = getFeedResponseDto.comments,
timeAgo = getFeedResponseDto.timeAgo,
commentList = getCommentResponseList.map { list ->
CommentList(
commentId = list.commentId,
author = list.author,
content = list.content,
authorId = list.authorId,
authorLevel = list.authorLevel
)
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.android.go.sopt.winey.data.service.FeedService
import com.android.go.sopt.winey.data.source.FeedDataSource
import com.android.go.sopt.winey.data.source.paging.MyFeedPagingSource
import com.android.go.sopt.winey.data.source.paging.WineyFeedPagingSource
import com.android.go.sopt.winey.domain.entity.DetailFeed
import com.android.go.sopt.winey.domain.entity.Like
import com.android.go.sopt.winey.domain.entity.WineyFeed
import com.android.go.sopt.winey.domain.repository.FeedRepository
Expand Down Expand Up @@ -52,6 +53,11 @@ class FeedRepositoryImpl @Inject constructor(
feedDataSource.postFeedLike(feedId, requestPostLikeDto).toLike()
}

override suspend fun getFeedDetail(feedId: Int): Result<DetailFeed?> =
runCatching {
feedDataSource.getFeedDetail(feedId).data?.toDetailFeed()
}

companion object {
const val WINEYFEED_PAGE_SIZE = 20
const val MYFEED_PAGE_SIZE = 10
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.android.go.sopt.winey.data.service

import com.android.go.sopt.winey.data.model.remote.request.RequestPostLikeDto
import com.android.go.sopt.winey.data.model.remote.response.ResponseGetFeedDetailDto
import com.android.go.sopt.winey.data.model.remote.response.ResponseGetWineyFeedListDto
import com.android.go.sopt.winey.data.model.remote.response.ResponsePostLikeDto
import com.android.go.sopt.winey.data.model.remote.response.ResponsePostWineyFeedDto
Expand Down Expand Up @@ -45,4 +46,9 @@ interface FeedService {
@Part file: MultipartBody.Part?,
@PartMap requestMap: HashMap<String, RequestBody>
): BaseResponse<ResponsePostWineyFeedDto>

@GET("feed/{feedId}")
suspend fun getFeedDetail(
@Path("feedId") feedId: Int
): BaseResponse<ResponseGetFeedDetailDto>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.android.go.sopt.winey.data.source

import com.android.go.sopt.winey.data.model.remote.request.RequestPostLikeDto
import com.android.go.sopt.winey.data.model.remote.response.ResponseGetFeedDetailDto
import com.android.go.sopt.winey.data.model.remote.response.ResponsePostLikeDto
import com.android.go.sopt.winey.data.model.remote.response.ResponsePostWineyFeedDto
import com.android.go.sopt.winey.data.model.remote.response.base.BaseResponse
Expand All @@ -26,4 +27,9 @@ class FeedDataSource @Inject constructor(
requestMap: HashMap<String, RequestBody>
): BaseResponse<ResponsePostWineyFeedDto> =
feedService.postWineyFeed(file, requestMap)

suspend fun getFeedDetail(
feedId: Int
): BaseResponse<ResponseGetFeedDetailDto> =
feedService.getFeedDetail(feedId)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.android.go.sopt.winey.domain.entity

data class DetailFeed(
val feedId: Int,
val feedImage: String,
val feedMoney: Long,
val feedTitle: String,
var isLiked: Boolean,
var likes: Long,
val nickName: String,
val userId: Int,
val writerLevel: Int,
val comments: Long,
val timeAgo: String,
val commentList: List<CommentList>
)

data class CommentList(
val commentId: Long,
val author: String,
val content: String,
val authorLevel: Int,
val authorId: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.android.go.sopt.winey.domain.repository
import androidx.paging.PagingData
import com.android.go.sopt.winey.data.model.remote.request.RequestPostLikeDto
import com.android.go.sopt.winey.data.model.remote.response.ResponsePostWineyFeedDto
import com.android.go.sopt.winey.domain.entity.DetailFeed
import com.android.go.sopt.winey.domain.entity.Like
import com.android.go.sopt.winey.domain.entity.WineyFeed
import kotlinx.coroutines.flow.Flow
Expand All @@ -22,4 +23,6 @@ interface FeedRepository {
file: MultipartBody.Part?,
requestMap: HashMap<String, RequestBody>
): Result<ResponsePostWineyFeedDto?>

suspend fun getFeedDetail(feedId: Int): Result<DetailFeed?>
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import com.android.go.sopt.winey.util.view.setOnSingleClickListener

class WineyFeedAdapter(
private val likeButtonClick: (feedId: Int, isLiked: Boolean) -> Unit,
private val showPopupMenu: (View, WineyFeed) -> Unit
private val showPopupMenu: (View, WineyFeed) -> Unit,
private val toFeedDetail: (feedId: Int, writerLevel: Int) -> Unit
) :
PagingDataAdapter<WineyFeed, WineyFeedAdapter.WineyFeedViewHolder>(diffUtil) {
private val currentData: ItemSnapshotList<WineyFeed>
Expand All @@ -23,7 +24,8 @@ class WineyFeedAdapter(
class WineyFeedViewHolder(
private val binding: ItemWineyfeedPostBinding,
private val onLikeButtonClick: (feedId: Int, isLiked: Boolean) -> Unit,
private val showPopupMenu: (View, WineyFeed) -> Unit
private val showPopupMenu: (View, WineyFeed) -> Unit,
private val toFeedDetail: (feedId: Int, writerLevel: Int) -> Unit
) : RecyclerView.ViewHolder(binding.root) {

fun onBind(data: WineyFeed?) {
Expand All @@ -37,9 +39,13 @@ class WineyFeedAdapter(
onLikeButtonClick(data.feedId, !data.isLiked)
}

btnWineyfeedMore.setOnClickListener { view ->
btnWineyfeedMore.setOnSingleClickListener { view ->
showPopupMenu(view, data)
}

lWineyfeedPost.setOnSingleClickListener {
toFeedDetail(data.feedId, data.writerLevel)
}
}
}

Expand All @@ -60,7 +66,7 @@ class WineyFeedAdapter(
): WineyFeedViewHolder {
val binding =
ItemWineyfeedPostBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return WineyFeedViewHolder(binding, likeButtonClick, showPopupMenu)
return WineyFeedViewHolder(binding, likeButtonClick, showPopupMenu, toFeedDetail)
}

override fun onBindViewHolder(holder: WineyFeedViewHolder, position: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.android.go.sopt.winey.domain.entity.User
import com.android.go.sopt.winey.domain.entity.WineyFeed
import com.android.go.sopt.winey.domain.repository.DataStoreRepository
import com.android.go.sopt.winey.presentation.main.MainViewModel
import com.android.go.sopt.winey.presentation.main.feed.detail.DetailActivity
import com.android.go.sopt.winey.presentation.main.feed.upload.UploadActivity
import com.android.go.sopt.winey.presentation.main.mypage.MyPageFragment
import com.android.go.sopt.winey.util.binding.BindingFragment
Expand Down Expand Up @@ -75,7 +76,8 @@ class WineyFeedFragment : BindingFragment<FragmentWineyFeedBinding>(R.layout.fra
},
showPopupMenu = { view, wineyFeed ->
showPopupMenu(view, wineyFeed)
}
},
toFeedDetail = { feedId, writerLevel -> navigateToDetail(feedId, writerLevel) }
)
binding.rvWineyfeedPost.adapter = ConcatAdapter(
wineyFeedHeaderAdapter,
Expand Down Expand Up @@ -252,10 +254,15 @@ class WineyFeedFragment : BindingFragment<FragmentWineyFeedBinding>(R.layout.fra
startActivity(intent)
}

private fun navigateToDetail(feedId: Int, writerLevel: Int) {
val intent = Intent(requireContext(), DetailActivity::class.java)
intent.putExtra("feedId", feedId)
intent.putExtra("writerLevel", writerLevel)
startActivity(intent)
}

companion object {
private const val LV_KNIGHT = 2
private const val MSG_WINEYFEED_ERROR = "ERROR"

private const val TAG_GOAL_DIALOG = "NO_GOAL_DIALOG"
private const val TAG_DELETE_DIALOG = "DELETE_DIALOG"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.android.go.sopt.winey.databinding.ItemDetailCommentBinding
import com.android.go.sopt.winey.domain.entity.CommentList
import com.android.go.sopt.winey.util.view.ItemDiffCallback

class CommentAdapter() : ListAdapter<CommentList, CommentAdapter.CommentViewHolder>(diffUtil) {
class CommentViewHolder(
private val binding: ItemDetailCommentBinding
) : RecyclerView.ViewHolder(binding.root) {
fun onBind(data: CommentList) {
binding.apply {
this.data = data
executePendingBindings()
}
}
}

override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): CommentViewHolder {
val binding =
ItemDetailCommentBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return CommentViewHolder(binding)
}

override fun onBindViewHolder(holder: CommentViewHolder, position: Int) {
holder.onBind(getItem(position))
}

companion object {
private val diffUtil = ItemDiffCallback<CommentList>(
onItemsTheSame = { old, new -> old.commentId == new.commentId },
onContentsTheSame = { old, new -> old == new }
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.android.go.sopt.winey.presentation.main.feed.detail

import android.os.Bundle
import androidx.fragment.app.commit
import com.android.go.sopt.winey.R
import com.android.go.sopt.winey.databinding.ActivityDetailBinding
import com.android.go.sopt.winey.util.binding.BindingActivity
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class DetailActivity : BindingActivity<ActivityDetailBinding>(R.layout.activity_detail) {
private lateinit var detailFragment: DetailFragment

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val feedId = intent.getIntExtra("feedId", 0)
val writerLevel = intent.getIntExtra("writerLevel", 0)
putArgsToDetail(feedId, writerLevel)
setDefaultFragment(savedInstanceState)
}

private fun putArgsToDetail(feedId: Int, writerLevel: Int) {
detailFragment = DetailFragment()
detailFragment.arguments = Bundle().apply {
putInt("feedId", feedId)
putInt("writerLevel", writerLevel)
}
}

private fun setDefaultFragment(savedInstanceState: Bundle?) {
if (savedInstanceState == null) {
supportFragmentManager.commit {
replace(R.id.fcv_detail, detailFragment)
}
}
}
}
Loading