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/api friend] : 친구탭 기록 관련 api 연결 작업 #23

Open
wants to merge 26 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f4fca82
[feat] : #15 친구 목록 조회 view code 정리
SsongSik May 17, 2023
987a4d7
[feat] : #15 전체 친구 목록 조회
SsongSik May 17, 2023
40cf3ca
[feat] : #15 친구 리스트 분기처리
SsongSik May 17, 2023
b32417d
[feat] : #15 더보기 바텀다이얼로그 셋팅
SsongSik May 19, 2023
321e847
[feat] : #15 게시물 숨기기 기능
SsongSik May 20, 2023
e1e6797
[feat] : #15 친구 기록 뷰 수정
SsongSik May 27, 2023
21ffecb
[feat] : #15 친구 기록 이모지 카운트 기능 추가
SsongSik May 27, 2023
e12e0a0
[feat] : #15 친구 기록에 감정리스트 뷰 추가
SsongSik May 27, 2023
9bdfe1e
[feat] : #15 친구 기록 이모지 뷰 위치 조절
SsongSik Jun 12, 2023
5b03eaf
[feat] : #15 친구 기록 my 여부 예외
SsongSik Jun 12, 2023
ac88178
[feat] : #15 Find Friend Fragment Connect
SsongSik Jun 13, 2023
ebe3667
[feat] : #15 Find Friend Fragment Back Button Add
SsongSik Jun 13, 2023
e153205
[feat] : #15 Friend List Profile Image add
SsongSik Jun 15, 2023
ccfa2f9
[feat] : #15 Friend List Selected Text Color Change
SsongSik Jun 15, 2023
70cd622
[feat] : #15 adapterPosition Deprecated -> bindingAdapterPosition Change
SsongSik Jun 15, 2023
1597df5
[feat] : #15 Friend Record ItemClick Remove
SsongSik Jun 15, 2023
69a4608
[feat] : #15 Friend's record hide
SsongSik Jun 18, 2023
b9809d7
[feat] : #15 Friend Record Profile Image HashMap Connect
SsongSik Jun 18, 2023
749a132
[feat] : #15 Test Log Remove
SsongSik Jun 18, 2023
44c7018
[feat] : #15 ViewHolder Context -> itemView.context Modify
SsongSik Jun 18, 2023
787e408
[feat] : #15 Friend Record Time implement
SsongSik Jun 18, 2023
e71355a
[feat] : #15 FriendRecordGetAdapter inner class seperate
SsongSik Jun 23, 2023
6e658ac
[feat] : #15 FriendRecord Emoji Bottom Sheet Design Modify
SsongSik Jun 23, 2023
7baa68f
[feat] : #15 FriendRecord Emoji Bottom Sheet RV Add
SsongSik Jun 23, 2023
e1dfbca
[feat] : #15 FriendRecord Emoji Bottom Sheet EmojiList Implement
SsongSik Jun 23, 2023
02a5c58
[feat] : #15 Friend Emotion Image Add, Bottom Connect
SsongSik Jul 8, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.teampome.pome.model.response

//친구 삭제 Response
data class DeleteFriendRecord(
val data : Boolean
)
13 changes: 13 additions & 0 deletions app/src/main/java/com/teampome/pome/network/AddFriendsService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.teampome.pome.model.base.BaseAllData
import com.teampome.pome.model.base.BasePomeResponse
import com.teampome.pome.model.friend.FriendData
import com.teampome.pome.model.response.DeleteFriend
import com.teampome.pome.model.response.DeleteFriendRecord
import com.teampome.pome.model.response.GetFriendRecord
import com.teampome.pome.model.response.GetFriends
import retrofit2.Response
Expand Down Expand Up @@ -37,8 +38,20 @@ interface AddFriendsService {
@Path("userId") userId: String
) : Response<BasePomeResponse<BaseAllData<GetFriendRecord>>>

//친구 삭제
@DELETE("api/v1/users/friend/{friendId}")
suspend fun deleteFriend(
@Path("friendId") friendId: String
) : Response<BasePomeResponse<DeleteFriend>>

//모든 친구 기록 조회
@GET("api/v1/records/friends")
suspend fun getAllFriendRecord() :
Response<BasePomeResponse<BaseAllData<GetFriendRecord>>>

//기록 숨기기
@DELETE("api/v1/records/{recordId}")
suspend fun deleteFriendRecord(
@Path("recordId") recordId: Int
) : Response<BasePomeResponse<DeleteFriendRecord>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.teampome.pome.presentation.friend

//친구 기록 클릭 리스너
interface FriendDetailRecordClickListener {

fun onFriendDetailMoreClick(recordId : Int)
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
package com.teampome.pome.presentation.friend

import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.teampome.pome.R
import com.teampome.pome.databinding.FragmentFriendBinding
import com.teampome.pome.databinding.PomeCalendarBottomSheetDialogBinding
import com.teampome.pome.databinding.PomeFriendSettingBottomSheetDialogBinding
import com.teampome.pome.databinding.PomeRecordMoreGoalBottomSheetDialogBinding
import com.teampome.pome.util.base.ApiResponse
import com.teampome.pome.util.base.BaseFragment
import com.teampome.pome.util.base.CoroutineErrorHandler
import com.teampome.pome.viewmodel.AddFriendsViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class FriendFragment : BaseFragment<FragmentFriendBinding>(R.layout.fragment_friend) {
class FriendFragment : BaseFragment<FragmentFriendBinding>(R.layout.fragment_friend), FriendDetailRecordClickListener {

private val viewModel: AddFriendsViewModel by viewModels()

private lateinit var friendGetAdapter: FriendGetAdapter
private lateinit var friendRecordGetAdapter: FriendRecordGetAdapter

private lateinit var pomeFriendSettingBottomSheetDialogBinding : PomeFriendSettingBottomSheetDialogBinding
private lateinit var friendSettingBottomSheetDialog: BottomSheetDialog

override fun initView() {
setUpRecyclerView()
friendRecordSetUpRecyclerView()
getAllFriendRecord()

//친구 조회
viewModel.getFriend(object : CoroutineErrorHandler{
Expand All @@ -40,16 +49,26 @@ class FriendFragment : BaseFragment<FragmentFriendBinding>(R.layout.fragment_fri
viewModel.getFriendsResponse.observe(viewLifecycleOwner) {
when(it) {
is ApiResponse.Success -> {
hideLoading()
it.data.data?.let { list ->
(binding.friendListRv.adapter as FriendGetAdapter).submitList(
list
)
if(list.isEmpty()) {
binding.friendNotIv.visibility = View.VISIBLE
binding.friendNotTv.visibility = View.VISIBLE
} else {
binding.friendNotIv.visibility = View.GONE
binding.friendNotTv.visibility = View.GONE
(binding.friendListRv.adapter as FriendGetAdapter).submitList(
list
)
}
}
}
is ApiResponse.Failure -> {

hideLoading()
}
is ApiResponse.Loading -> {
showLoading()
}
is ApiResponse.Loading -> {}
}
}

Expand All @@ -65,13 +84,51 @@ class FriendFragment : BaseFragment<FragmentFriendBinding>(R.layout.fragment_fri
}
}
is ApiResponse.Failure -> {
hideLoading()
}
is ApiResponse.Loading -> {
showLoading()
}
}
}

viewModel.getAllFriendRecordResponse.observe(viewLifecycleOwner){
when(it) {
is ApiResponse.Success -> {
hideLoading()
it.data.data?.content?.let { list ->
(binding.friendDetailRv.adapter as FriendRecordGetAdapter).submitList(
list
)
}
}
is ApiResponse.Failure -> {
hideLoading()
}
is ApiResponse.Loading -> {
showLoading()
}
}
}

viewModel.deleteFriendRecord.observe(viewLifecycleOwner) {
when(it) {
is ApiResponse.Success -> {
hideLoading()
Toast.makeText(requireContext(), "해당 게시글을 숨겼어요", Toast.LENGTH_SHORT).show()
}
is ApiResponse.Failure -> {
hideLoading()
}
is ApiResponse.Loading -> {
showLoading()
}
}
}

binding.friendAllIv.setOnClickListener {
getAllFriendRecord()
}
}

//친구 목록 조회 RV
Expand All @@ -96,21 +153,55 @@ class FriendFragment : BaseFragment<FragmentFriendBinding>(R.layout.fragment_fri

//친구 기록 조회 RV
private fun friendRecordSetUpRecyclerView(){
friendRecordGetAdapter = FriendRecordGetAdapter()
friendRecordGetAdapter = FriendRecordGetAdapter(this)
binding.friendDetailRv.apply {
// setHasFixedSize(true)
layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
adapter = friendRecordGetAdapter
addItemDecoration(
DividerItemDecoration(
requireContext(), DividerItemDecoration.VERTICAL
)
)
}

// 클릭 리스너
friendRecordGetAdapter.setOnItemClickListener {
Toast.makeText(requireContext(), "${it.nickname}", Toast.LENGTH_SHORT).show()
}
}

private fun getAllFriendRecord() {
viewModel.getAllRecordFriend(object : CoroutineErrorHandler{
override fun onError(message: String) {
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show()
hideLoading()
}
})
}

private fun makeFriendSettingBottomDialog(recordId: Int) {
friendSettingBottomSheetDialog = BottomSheetDialog(requireContext())
pomeFriendSettingBottomSheetDialogBinding = PomeFriendSettingBottomSheetDialogBinding.inflate(layoutInflater, null, false)

friendSettingBottomSheetDialog.setContentView(pomeFriendSettingBottomSheetDialogBinding.root)

pomeFriendSettingBottomSheetDialogBinding.apply{
//숨기기
pomeFriendBottomSheetDialogHideTv.setOnClickListener {
viewModel.deleteFriendRecord(recordId, object : CoroutineErrorHandler{
override fun onError(message: String) {
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show()
hideLoading()
}
})
friendSettingBottomSheetDialog.dismiss()
}

//신고
pomeFriendBottomSheetDialogReportTv.setOnClickListener {
friendSettingBottomSheetDialog.dismiss()
}
}
}

override fun onFriendDetailMoreClick(recordId : Int) {
makeFriendSettingBottomDialog(recordId)
friendSettingBottomSheetDialog.show()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ import com.teampome.pome.model.response.GetFriendRecord
import com.teampome.pome.model.response.GetFriends

//친구 기록 조회
class FriendRecordGetAdapter : ListAdapter<GetFriendRecord, FriendRecordGetAdapter.FriendGetRecordViewHolder>(BookDiffCallback) {
class FriendRecordGetAdapter(
private val clickListener: FriendDetailRecordClickListener
) : ListAdapter<GetFriendRecord, FriendRecordGetAdapter.FriendGetRecordViewHolder>(BookDiffCallback) {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FriendGetRecordViewHolder {
return FriendGetRecordViewHolder(
clickListener,
ItemFriendDetailCardBinding.inflate(LayoutInflater.from(parent.context), parent, false),
)
}
Expand All @@ -33,11 +36,18 @@ class FriendRecordGetAdapter : ListAdapter<GetFriendRecord, FriendRecordGetAdapt
}

inner class FriendGetRecordViewHolder(
private val friendDetailRecordClickListener: FriendDetailRecordClickListener,
private val binding : ItemFriendDetailCardBinding,
) : RecyclerView.ViewHolder(binding.root){

fun bind(getFriedRecord: GetFriendRecord){
binding.getFriendRecord = getFriedRecord
with(binding) {
getFriendRecord = getFriedRecord

friendDetailMoreSettingIv.setOnClickListener {
friendDetailRecordClickListener.onFriendDetailMoreClick(getFriedRecord.id)
}
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.teampome.pome.model.base.BaseAllData
import com.teampome.pome.model.base.BasePomeResponse
import com.teampome.pome.model.friend.FriendData
import com.teampome.pome.model.response.DeleteFriend
import com.teampome.pome.model.response.DeleteFriendRecord
import com.teampome.pome.model.response.GetFriendRecord
import com.teampome.pome.model.response.GetFriends
import com.teampome.pome.util.base.ApiResponse
Expand All @@ -21,7 +22,13 @@ interface AddFriendsDataSource {
userId : String
) : Flow<ApiResponse<BasePomeResponse<BaseAllData<GetFriendRecord>>>>

//친구 삭제
fun deleteFriend(
friendId: String
) : Flow<ApiResponse<BasePomeResponse<DeleteFriend>>>

//모든 친구 기록 조회
fun getAllFriendRecord() : Flow<ApiResponse<BasePomeResponse<BaseAllData<GetFriendRecord>>>>

fun deleteFriendRecord(recordId : Int) : Flow<ApiResponse<BasePomeResponse<DeleteFriendRecord>>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.teampome.pome.model.base.BaseAllData
import com.teampome.pome.model.base.BasePomeResponse
import com.teampome.pome.model.friend.FriendData
import com.teampome.pome.model.response.DeleteFriend
import com.teampome.pome.model.response.DeleteFriendRecord
import com.teampome.pome.model.response.GetFriendRecord
import com.teampome.pome.model.response.GetFriends
import com.teampome.pome.network.AddFriendsService
Expand Down Expand Up @@ -34,4 +35,12 @@ class AddFriendsRemoteDataSource @Inject constructor(
override fun deleteFriend(friendId: String): Flow<ApiResponse<BasePomeResponse<DeleteFriend>>> = apiRequestFlow{
service.deleteFriend(friendId)
}

override fun getAllFriendRecord(): Flow<ApiResponse<BasePomeResponse<BaseAllData<GetFriendRecord>>>> = apiRequestFlow {
service.getAllFriendRecord()
}

override fun deleteFriendRecord(recordId : Int): Flow<ApiResponse<BasePomeResponse<DeleteFriendRecord>>> = apiRequestFlow {
service.deleteFriendRecord(recordId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ class AddFriendsRepository @Inject constructor(
fun getFriendRecord(userId : String) = dataSource.getFriendRecord(userId)

fun deleteFriend(friendId: String) = dataSource.deleteFriend(friendId)

fun getAllFriendRecord() = dataSource.getAllFriendRecord()

fun deleteFriendRecord(recordId : Int) = dataSource.deleteFriendRecord(recordId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.teampome.pome.model.base.BasePomeResponse
import com.teampome.pome.model.friend.FriendData
import com.teampome.pome.model.goal.GoalData
import com.teampome.pome.model.response.DeleteFriend
import com.teampome.pome.model.response.DeleteFriendRecord
import com.teampome.pome.model.response.GetFriendRecord
import com.teampome.pome.model.response.GetFriends
import com.teampome.pome.repository.friend.AddFriendsRepository
Expand Down Expand Up @@ -45,6 +46,12 @@ class AddFriendsViewModel @Inject constructor(
private val _deleteFriendResponse = MutableLiveData<ApiResponse<BasePomeResponse<DeleteFriend>>>()
val deleteFriendResponse : LiveData<ApiResponse<BasePomeResponse<DeleteFriend>>> = _deleteFriendResponse

//모든 친구 기록 조회
private val _getAllFriendRecordResponse = MutableLiveData<ApiResponse<BasePomeResponse<BaseAllData<GetFriendRecord>>>>()
val getAllFriendRecordResponse : LiveData<ApiResponse<BasePomeResponse<BaseAllData<GetFriendRecord>>>> = _getAllFriendRecordResponse

private val _deleteFriendRecord = MutableLiveData<ApiResponse<BasePomeResponse<DeleteFriendRecord>>>()
val deleteFriendRecord : LiveData<ApiResponse<BasePomeResponse<DeleteFriendRecord>>> = _deleteFriendRecord

fun findFriendsData(nickName: String, coroutineErrorHandler: CoroutineErrorHandler) = baseRequest(
_findFriendsDataResponse,
Expand Down Expand Up @@ -80,13 +87,28 @@ class AddFriendsViewModel @Inject constructor(
repository.getFriendRecord(userId)
}

//친구 삭제
fun deleteFriend(friendId : String, coroutineErrorHandler: CoroutineErrorHandler) = baseRequest(
_deleteFriendResponse,
coroutineErrorHandler
){
repository.deleteFriend(friendId)
}

fun getAllRecordFriend(coroutineErrorHandler: CoroutineErrorHandler) = baseRequest(
_getAllFriendRecordResponse,
coroutineErrorHandler
){
repository.getAllFriendRecord()
}

fun deleteFriendRecord(recordId : Int, coroutineErrorHandler: CoroutineErrorHandler) = baseRequest(
_deleteFriendRecord,
coroutineErrorHandler
){
repository.deleteFriendRecord(recordId)
}

//친구 조회
val friendGet: LiveData<List<GetFriends?>> = Transformations.map(_getFriendResponse) {
when(it) {
Expand Down
Loading