Skip to content

Commit

Permalink
Merge pull request #71 from Fill-ENERGY/Feature/#4-community
Browse files Browse the repository at this point in the history
[Feat] 커뮤니티와 채팅 api 연결
  • Loading branch information
znayeonzn authored Aug 22, 2024
2 parents 075aae0 + c99d021 commit e1cdf14
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ class NoteRepository {
Log.d("NoteRepository", "메시지 전송 성공: ${response.body()?.message}")
callback(response.body())
} else {
Log.e("NoteRepository", "메시지 전송 실패: ${response.errorBody()?.string()}")
Log.e("NoteRepository", "메시지 전송 실패: ${response.errorBody()?.string()}!")
callback(null)
}


}

override fun onFailure(call: Call<MessageResponse>, t: Throwable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.example.energy.presentation.view.community
import android.annotation.SuppressLint
import android.app.Dialog
import android.content.Context
import android.content.Context.INPUT_METHOD_SERVICE
import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
Expand All @@ -13,6 +14,8 @@ import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat.getSystemService
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.energy.R
import com.example.energy.data.repository.community.BoardModel
Expand All @@ -21,6 +24,10 @@ import com.example.energy.data.repository.community.CommunityRepository
import com.example.energy.data.repository.community.HelpStatusRequest
import com.example.energy.data.repository.community.PostBoardRequest
import com.example.energy.data.repository.community.WriteCommentRequest
import com.example.energy.data.repository.note.ChatThreadsResponse
import com.example.energy.data.repository.note.MessageResponse
import com.example.energy.data.repository.note.NoteRepository
import com.example.energy.data.repository.note.RecentMessage
import com.example.energy.databinding.ActivityCommunityDetailBinding
import com.example.energy.databinding.DialogCommunityBlockBinding
import com.example.energy.databinding.DialogCommunityCommentWriterSeeMoreBinding
Expand All @@ -29,7 +36,9 @@ import com.example.energy.databinding.DialogCommunityWriterSeeMoreBinding
import com.example.energy.databinding.DialogHelpStatusBinding
import com.example.energy.databinding.DialogLoadingBinding
import com.example.energy.databinding.DialogPostCommunitySuccessBinding
import com.example.energy.presentation.view.note.NoteLiveChatActivity
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.internal.ViewUtils.hideKeyboard

class CommunityDetailActivity : AppCompatActivity(){
private lateinit var binding: ActivityCommunityDetailBinding
Expand Down Expand Up @@ -121,8 +130,45 @@ class CommunityDetailActivity : AppCompatActivity(){
binding.communityDetailBackIcon.setOnClickListener {
finish() //현재 Activity 종료
}



// 채팅하기 버튼 클릭 시
binding.communityDetailChattingBtn.setOnClickListener {
NoteRepository.communityGetMessages(accessToken!!, writerId!!) { response ->

if (response != null) {
Log.d("커뮤니티채팅버튼","채팅으로 이동 성공 ${writerId}")

//if (response.result?.threadId == null) {

//}

val intent = Intent(this, NoteLiveChatActivity::class.java)

intent.putExtra("Username", writerId)
intent.putExtra("Id","dfdkssf")
intent.putExtra("threadId", writerId)
intent.putExtra("receiverId", writerId)


//intent.putExtra("cursor", )



startActivity(intent)



}
}
}
}





override fun onResume() {
super.onResume()
showLoading() //데이터 로딩 페이지
Expand Down Expand Up @@ -176,6 +222,8 @@ class CommunityDetailActivity : AppCompatActivity(){
var likeCount = response.likeNum
writerStatus = response.helpStatus



//binding.communityDetailUserProfile.setImageResource(postInfo.userProfile!!)
binding.communityDetailUserName.text = response.memberName
binding.communityDetailTitle.text = response.title
Expand All @@ -199,6 +247,54 @@ class CommunityDetailActivity : AppCompatActivity(){
}
}


// 채팅하기 버튼 클릭 시
binding.communityDetailChattingBtn.setOnClickListener {
NoteRepository.communityGetMessages(accessToken!!, writerId!!) { responseMessage ->

if (responseMessage != null) {
Log.d("커뮤니티채팅버튼","채팅으로 이동 성공 ${writerId}")

//if (response.result?.threadId == null) {

//}

val intent = Intent(this, NoteLiveChatActivity::class.java)

intent.putExtra("Username", response.memberName)
intent.putExtra("Id",response.memberId)
intent.putExtra("threadId", responseMessage.result?.threadId)
intent.putExtra("receiverId", writerId)
intent.putExtra("unreadMessageCount", 0)
intent.putExtra("cursor", 0)


startActivity(intent)



//if threadid = null값이면 그냥 맨 페이지



/*
val intent = Intent(itemView.context, NoteLiveChatActivity::class.java)
intent.putExtra("Username", note.name)
intent.putExtra("Id",note.nickname)
intent.putExtra("threadId", note.threadId)
intent.putExtra("receiverId", note.receiverId)
intent.putExtra("cursor", note.recentMessage?.messageId)
intent.putExtra("unreadMessageCount", note.unreadMessageCount)
ContextCompat.startActivity(itemView.context, intent, null)
*/
}
}
}


// 좋아요 아이콘 클릭 시
binding.communityDetailLikeIcon.setOnClickListener {
isLiked = !isLiked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class NoteAdapter(
intent.putExtra("Id",note.nickname)
intent.putExtra("threadId", note.threadId)
intent.putExtra("receiverId", note.receiverId)
intent.putExtra("cursor", note.recentMessage?.messageId)
intent.putExtra("cursor", note.recentMessage?.messageId ?:0)
intent.putExtra("unreadMessageCount", note.unreadMessageCount)
ContextCompat.startActivity(itemView.context, intent, null)
}
Expand All @@ -109,7 +109,7 @@ class NoteAdapter(
if (getClamped()) { // 스와이프 상태에서만 버튼 클릭이 유효
note.threadId?.let { threadId -> leaveChatRoom(threadId) }
removeData(this.layoutPosition)
Toast.makeText(binding.root.context, "삭제했습니다.", Toast.LENGTH_SHORT).show()
Toast.makeText(binding.root.context, "채팅방 나가기", Toast.LENGTH_SHORT).show()
onSwipeClickListener(note, layoutPosition)
}
}
Expand Down
Loading

0 comments on commit e1cdf14

Please sign in to comment.