Skip to content

Commit

Permalink
[Add] 커뮤니티 데이터 갱신 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
seohyeon121 committed Aug 20, 2024
1 parent 39b6a16 commit f99035d
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,25 @@ import com.example.energy.presentation.view.base.BaseFragment
class CommunityCuriousFragment : BaseFragment<FragmentCommunityCuriousBinding>({ FragmentCommunityCuriousBinding.inflate(it)}) {

private lateinit var postCommunityAdapter: PostCommunityRVAdapter
private var accessToken : String? = ""

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

//토큰 가져오기
// var sharedPreferences = requireActivity().getSharedPreferences("userToken", Context.MODE_PRIVATE)
// var accessToken = sharedPreferences?.getString("accessToken", "none")
val accessToken = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6Imtpaml3aTFAbmF2ZXIuY29tIiwiaWF0IjoxNzIzODg3ODYzLCJleHAiOjE3MjY0Nzk4NjN9.qGR9PibGimGon0_82i_Z73nxXJzK1BDoPLWRLjC0QI4"
accessToken = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InRqZ3VzaWRAbmF2ZXIuY29tIiwiaWF0IjoxNzI0MTY4NjQwLCJleHAiOjE3MjY3NjA2NDB9.fUaTieyCFhodHH1YTWJTNVTmDFZuvW6RjJ2t_tVzs_M"
}

override fun onResume() {
super.onResume()
// API를 다시 호출하여 데이터를 갱신
refreshData()
}

//test
CommunityRepository.getListCommunity(accessToken, "INQUIRY", 0, 10, "") {
private fun refreshData() { // 게시글 조회
CommunityRepository.getListCommunity(accessToken!!, "INQUIRY", 0, 10, "") {
response ->
response.let {
//통신성공
Expand All @@ -36,20 +44,5 @@ class CommunityCuriousFragment : BaseFragment<FragmentCommunityCuriousBinding>({
}
}
}

// // community_post에 데이터 리스트 생성
// communityDB = CommunityPostDatabase.getInstance(requireContext())!!
//
// // 백그라운드 스레드에서 데이터베이스 접근
// lifecycleScope.launch {
// withContext(Dispatchers.IO) {
// val allPosts = communityDB.communityPostDao().getAllPosts()
// postInfo.addAll(allPosts.filter { it.categoryString == "궁금해요" })
// }
// // RecyclerView 초기화 및 데이터 연결 (메인 스레드)
// postCommunityAdapter = PostCommunityRVAdapter(postInfo)
// binding.curiousCommunityPostRv.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
// binding.curiousCommunityPostRv.adapter = postCommunityAdapter
// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,24 @@ import com.example.energy.presentation.view.base.BaseFragment
class CommunityDailyFragment : BaseFragment<FragmentCommunityDailyBinding>({ FragmentCommunityDailyBinding.inflate(it)}) {

private lateinit var postCommunityAdapter: PostCommunityRVAdapter
private var accessToken : String? = ""

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

//토큰 가져오기
// var sharedPreferences = requireActivity().getSharedPreferences("userToken", Context.MODE_PRIVATE)
// var accessToken = sharedPreferences?.getString("accessToken", "none")
val accessToken = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6Imtpaml3aTFAbmF2ZXIuY29tIiwiaWF0IjoxNzIzODg3ODYzLCJleHAiOjE3MjY0Nzk4NjN9.qGR9PibGimGon0_82i_Z73nxXJzK1BDoPLWRLjC0QI4"
accessToken = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InRqZ3VzaWRAbmF2ZXIuY29tIiwiaWF0IjoxNzI0MTY4NjQwLCJleHAiOjE3MjY3NjA2NDB9.fUaTieyCFhodHH1YTWJTNVTmDFZuvW6RjJ2t_tVzs_M"
}

override fun onResume() {
super.onResume()
// API를 다시 호출하여 데이터를 갱신
refreshData()
}

//test
private fun refreshData() { // 게시글 조회
CommunityRepository.getListCommunity(accessToken!!, "DAILY", 0, 10, "") {
response ->
response.let {
Expand All @@ -36,20 +44,5 @@ class CommunityDailyFragment : BaseFragment<FragmentCommunityDailyBinding>({ Fra
}
}
}

// // community_post에 데이터 리스트 생성
// communityDB = CommunityPostDatabase.getInstance(requireContext())!!
//
// // 백그라운드 스레드에서 데이터베이스 접근
// lifecycleScope.launch {
// withContext(Dispatchers.IO) {
// val allPosts = communityDB.communityPostDao().getAllPosts()
// postInfo.addAll(allPosts.filter { it.categoryString == "일상" })
// }
// // RecyclerView 초기화 및 데이터 연결 (메인 스레드)
// postCommunityAdapter = PostCommunityRVAdapter(postInfo)
// binding.dailyCommunityPostRv.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
// binding.dailyCommunityPostRv.adapter = postCommunityAdapter
// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.os.Bundle
import android.util.Log
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
Expand All @@ -26,6 +27,7 @@ import com.example.energy.databinding.DialogCommunityCommentWriterSeeMoreBinding
import com.example.energy.databinding.DialogCommunityUserSeeMoreBinding
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.google.android.material.bottomsheet.BottomSheetDialog

Expand All @@ -43,6 +45,7 @@ class CommunityDetailActivity : AppCompatActivity(){
private var postId: Int = 0
private var selectedComment: CommentModel? = null // 선택된 댓글 객체를 추적
private var writerId: Int? = null
private var loadingDialog: Dialog? = null

@SuppressLint("SuspiciousIndentation")
override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -123,6 +126,7 @@ class CommunityDetailActivity : AppCompatActivity(){

override fun onResume() {
super.onResume()
showLoading() //데이터 로딩 페이지
// API를 다시 호출하여 데이터를 갱신
refreshData()
}
Expand All @@ -134,6 +138,7 @@ class CommunityDetailActivity : AppCompatActivity(){
response.let {
Log.d("게시글댓글정보", "${response}")
//통신성공
hideLoading()
if (response != null) {
// 댓글 RecyclerView 연결
commentAdapter = ItemCommentAdapter(response, writerId)
Expand Down Expand Up @@ -167,6 +172,7 @@ class CommunityDetailActivity : AppCompatActivity(){
CommunityRepository.getDetailCommunity(accessToken!!, postId) { response ->
if (response != null) {
//통신성공
hideLoading()
var isLiked = response.liked
var likeCount = response.likeNum
writerStatus = response.helpStatus
Expand Down Expand Up @@ -565,4 +571,23 @@ class CommunityDetailActivity : AppCompatActivity(){
binding.communityDetailLikeIcon.setImageResource(R.drawable.icon_unlike)
}
}

private fun showLoading() { //데이터 로딩 페이지 함수
if (loadingDialog == null) {
loadingDialog = Dialog(this, R.style.LoadingDialog)
val binding = DialogLoadingBinding.inflate(layoutInflater) // 로딩 레이아웃 바인딩
loadingDialog?.setContentView(binding.root)
loadingDialog?.window?.setLayout(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
) // 다이얼로그 크기를 전체 화면으로 설정
loadingDialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
loadingDialog?.setCanceledOnTouchOutside(false) // 바깥 영역 터치해도 닫힘 X
}
loadingDialog?.show()
}

private fun hideLoading() { //로딩 페이지 숨기는 함수
loadingDialog?.dismiss()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,25 @@ import com.example.energy.presentation.view.base.BaseFragment
class CommunityHelpFragment : BaseFragment<FragmentCommunityHelpBinding>({ FragmentCommunityHelpBinding.inflate(it)}) {

private lateinit var postCommunityAdapter: PostCommunityRVAdapter
private var accessToken : String? = ""

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

//토큰 가져오기
// var sharedPreferences = requireActivity().getSharedPreferences("userToken", Context.MODE_PRIVATE)
// var accessToken = sharedPreferences?.getString("accessToken", "none")
val accessToken = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6Imtpaml3aTFAbmF2ZXIuY29tIiwiaWF0IjoxNzIzODg3ODYzLCJleHAiOjE3MjY0Nzk4NjN9.qGR9PibGimGon0_82i_Z73nxXJzK1BDoPLWRLjC0QI4"
accessToken = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InRqZ3VzaWRAbmF2ZXIuY29tIiwiaWF0IjoxNzI0MTY4NjQwLCJleHAiOjE3MjY3NjA2NDB9.fUaTieyCFhodHH1YTWJTNVTmDFZuvW6RjJ2t_tVzs_M"
}

override fun onResume() {
super.onResume()
// API를 다시 호출하여 데이터를 갱신
refreshData()
}

//test
CommunityRepository.getListCommunity(accessToken, "HELP", 0, 10, "") {
private fun refreshData() { // 게시글 조회
CommunityRepository.getListCommunity(accessToken!!, "HELP", 0, 10, "") {
response ->
response.let {
//통신성공
Expand All @@ -36,20 +44,5 @@ class CommunityHelpFragment : BaseFragment<FragmentCommunityHelpBinding>({ Fragm
}
}
}

// // community_post에 데이터 리스트 생성
// communityDB = CommunityPostDatabase.getInstance(requireContext())!!
//
// // 백그라운드 스레드에서 데이터베이스 접근
// lifecycleScope.launch {
// withContext(Dispatchers.IO) {
// val allPosts = communityDB.communityPostDao().getAllPosts()
// postInfo.addAll(allPosts.filter { it.categoryString == "도와줘요" })
// }
// // RecyclerView 초기화 및 데이터 연결 (메인 스레드)
// postCommunityAdapter = PostCommunityRVAdapter(postInfo)
// binding.helpCommunityPostRv.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
// binding.helpCommunityPostRv.adapter = postCommunityAdapter
// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,25 @@ import com.example.energy.presentation.view.base.BaseFragment
class CommunityScooterFragment : BaseFragment<FragmentCommunityScooterBinding>({ FragmentCommunityScooterBinding.inflate(it)}) {

private lateinit var postCommunityAdapter: PostCommunityRVAdapter
private var accessToken : String? = ""

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

//토큰 가져오기
// var sharedPreferences = requireActivity().getSharedPreferences("userToken", Context.MODE_PRIVATE)
// var accessToken = sharedPreferences?.getString("accessToken", "none")
val accessToken = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6Imtpaml3aTFAbmF2ZXIuY29tIiwiaWF0IjoxNzIzODg3ODYzLCJleHAiOjE3MjY0Nzk4NjN9.qGR9PibGimGon0_82i_Z73nxXJzK1BDoPLWRLjC0QI4"
accessToken = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InRqZ3VzaWRAbmF2ZXIuY29tIiwiaWF0IjoxNzI0MTY4NjQwLCJleHAiOjE3MjY3NjA2NDB9.fUaTieyCFhodHH1YTWJTNVTmDFZuvW6RjJ2t_tVzs_M"
}

override fun onResume() {
super.onResume()
// API를 다시 호출하여 데이터를 갱신
refreshData()
}

//test
CommunityRepository.getListCommunity(accessToken, "SCOOTER", 0, 10, "") {
private fun refreshData() { // 게시글 조회
CommunityRepository.getListCommunity(accessToken!!, "SCOOTER", 0, 10, "") {
response ->
response.let {
//통신성공
Expand All @@ -36,20 +44,5 @@ class CommunityScooterFragment : BaseFragment<FragmentCommunityScooterBinding>({
}
}
}

// // community_post에 데이터 리스트 생성
// communityDB = CommunityPostDatabase.getInstance(requireContext())!!
//
// // 백그라운드 스레드에서 데이터베이스 접근
// lifecycleScope.launch {
// withContext(Dispatchers.IO) {
// val allPosts = communityDB.communityPostDao().getAllPosts()
// postInfo.addAll(allPosts.filter { it.categoryString == "스쿠터" })
// }
// // RecyclerView 초기화 및 데이터 연결 (메인 스레드)
// postCommunityAdapter = PostCommunityRVAdapter(postInfo)
// binding.scooterCommunityPostRv.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
// binding.scooterCommunityPostRv.adapter = postCommunityAdapter
// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,24 @@ import com.example.energy.presentation.view.base.BaseFragment
class CommunityWheelchairFragment : BaseFragment<FragmentCommunityWheelchairBinding>({ FragmentCommunityWheelchairBinding.inflate(it)}) {

private lateinit var postCommunityAdapter: PostCommunityRVAdapter
private var accessToken : String? = ""
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

//토큰 가져오기
// var sharedPreferences = requireActivity().getSharedPreferences("userToken", Context.MODE_PRIVATE)
// var accessToken = sharedPreferences?.getString("accessToken", "none")
val accessToken = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6Imtpaml3aTFAbmF2ZXIuY29tIiwiaWF0IjoxNzIzODg3ODYzLCJleHAiOjE3MjY0Nzk4NjN9.qGR9PibGimGon0_82i_Z73nxXJzK1BDoPLWRLjC0QI4"
accessToken = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InRqZ3VzaWRAbmF2ZXIuY29tIiwiaWF0IjoxNzI0MTY4NjQwLCJleHAiOjE3MjY3NjA2NDB9.fUaTieyCFhodHH1YTWJTNVTmDFZuvW6RjJ2t_tVzs_M"
}

override fun onResume() {
super.onResume()
// API를 다시 호출하여 데이터를 갱신
refreshData()
}

//test
CommunityRepository.getListCommunity(accessToken, "WHEELCHAIR", 0, 10, "") {
private fun refreshData() { // 게시글 조회
CommunityRepository.getListCommunity(accessToken!!, "WHEELCHAIR", 0, 10, "") {
response ->
response.let {
//통신성공
Expand All @@ -35,20 +43,5 @@ class CommunityWheelchairFragment : BaseFragment<FragmentCommunityWheelchairBind
}
}
}

// // community_post에 데이터 리스트 생성
// communityDB = CommunityPostDatabase.getInstance(requireContext())!!
//
// // 백그라운드 스레드에서 데이터베이스 접근
// lifecycleScope.launch {
// withContext(Dispatchers.IO) {
// val allPosts = communityDB.communityPostDao().getAllPosts()
// postInfo.addAll(allPosts.filter { it.categoryString == "휠체어" })
// }
// // RecyclerView 초기화 및 데이터 연결 (메인 스레드)
// postCommunityAdapter = PostCommunityRVAdapter(postInfo)
// binding.wheelchairCommunityPostRv.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
// binding.wheelchairCommunityPostRv.adapter = postCommunityAdapter
// }
}
}
7 changes: 7 additions & 0 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@
<style name="CustomDialog" parent="Theme.AppCompat.Dialog">
<item name="android:background">@android:color/transparent</item>
</style>

<style name="LoadingDialog" parent="Theme.AppCompat.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowSoftInputMode">stateUnchanged</item>
</style>
</resources>

0 comments on commit f99035d

Please sign in to comment.