From e50ffd31555f4ddc1b074307aceb4e89a0e9f60f Mon Sep 17 00:00:00 2001 From: kimjingyoung Date: Thu, 25 Apr 2024 02:29:36 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20=EC=A2=8B=EC=95=84=EC=9A=94?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84=20[=EB=AF=B8?= =?UTF-8?q?=EC=99=84=EC=84=B1]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 좋아요 기능 구현 [미완성] Related to : #52 --- farming_customer/app/build.gradle.kts | 9 + .../lion/farming_customer/dao/like/LikeDao.kt | 170 +++++++++ .../farming_customer/fragment/LikeFragment.kt | 324 ++++++++++++++---- .../farming_customer/model/ActivityModel.kt | 18 + .../model/CommunityPostModel.kt | 14 + .../lion/farming_customer/model/CropModel.kt | 16 + .../lion/farming_customer/model/FarmModel.kt | 23 ++ .../lion/farming_customer/model/LikeModel.kt | 7 + .../farming_customer/model/RentalModel.kt | 12 + .../viewmodel/LikeViewModel.kt | 90 ++++- .../app/src/main/res/layout/row_like_crop.xml | 1 - .../app/src/main/res/layout/row_like_post.xml | 15 +- 12 files changed, 626 insertions(+), 73 deletions(-) create mode 100644 farming_customer/app/src/main/java/kr/co/lion/farming_customer/dao/like/LikeDao.kt create mode 100644 farming_customer/app/src/main/java/kr/co/lion/farming_customer/model/ActivityModel.kt create mode 100644 farming_customer/app/src/main/java/kr/co/lion/farming_customer/model/CommunityPostModel.kt create mode 100644 farming_customer/app/src/main/java/kr/co/lion/farming_customer/model/CropModel.kt create mode 100644 farming_customer/app/src/main/java/kr/co/lion/farming_customer/model/FarmModel.kt create mode 100644 farming_customer/app/src/main/java/kr/co/lion/farming_customer/model/LikeModel.kt create mode 100644 farming_customer/app/src/main/java/kr/co/lion/farming_customer/model/RentalModel.kt diff --git a/farming_customer/app/build.gradle.kts b/farming_customer/app/build.gradle.kts index 436bf29..46cdb10 100644 --- a/farming_customer/app/build.gradle.kts +++ b/farming_customer/app/build.gradle.kts @@ -3,6 +3,7 @@ plugins { id("org.jetbrains.kotlin.android") id("kotlin-kapt") id("com.google.gms.google-services") + id ("kotlin-parcelize") } android { @@ -42,6 +43,7 @@ android { } dependencies { + implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2") implementation("androidx.core:core-ktx:1.12.0") implementation("androidx.appcompat:appcompat:1.6.1") implementation("com.google.android.material:material:1.11.0") @@ -65,4 +67,11 @@ dependencies { implementation("com.google.firebase:firebase-firestore:24.11.1") implementation("com.google.firebase:firebase-storage:20.3.0") + // glide + implementation ("com.github.bumptech.glide:glide:4.12.0") + implementation ("com.firebaseui:firebase-ui-storage:7.2.0") + implementation ("com.google.firebase:firebase-storage:20.2.0") + kapt ("com.github.bumptech.glide:compiler:4.12.0") +// implementation ("com.github.bumptech.glide:glide:4.16.0") +// implementation ("com.github.bumptech.glide:glide-okhttp3-integration:4.14.0") } \ No newline at end of file diff --git a/farming_customer/app/src/main/java/kr/co/lion/farming_customer/dao/like/LikeDao.kt b/farming_customer/app/src/main/java/kr/co/lion/farming_customer/dao/like/LikeDao.kt new file mode 100644 index 0000000..7c3b8f3 --- /dev/null +++ b/farming_customer/app/src/main/java/kr/co/lion/farming_customer/dao/like/LikeDao.kt @@ -0,0 +1,170 @@ +package kr.co.lion.farming_customer.dao.like + +import android.content.Context +import android.view.View +import android.widget.ImageView +import com.bumptech.glide.Glide +import com.google.firebase.firestore.Query +import com.google.firebase.firestore.ktx.firestore +import com.google.firebase.ktx.Firebase +import com.google.firebase.storage.ktx.storage +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.tasks.await +import kotlinx.coroutines.withContext +import kr.co.lion.farming_customer.model.ActivityModel +import kr.co.lion.farming_customer.model.CropModel +import kr.co.lion.farming_customer.model.FarmModel +import kr.co.lion.farming_customer.model.LikeModel +import kr.co.lion.farming_customer.model.CommunityPostModel +import kr.co.lion.farming_customer.model.RentalModel + +class LikeDao { + + companion object { + + // 농산품 좋아요 리스트 + suspend fun getCropLikeList(userIdx:Int): List{ + return withContext(Dispatchers.IO) { + val likeListRef = Firebase.firestore.collection("LikeData") + val query = likeListRef.whereEqualTo("like_status", 1) + .whereEqualTo("like_user_idx", userIdx) + .whereEqualTo("like_type", 1) + .orderBy("like_idx", Query.Direction.ASCENDING) + val querySnapshot = query.get().await() + querySnapshot.map { it.toObject(LikeModel::class.java) } + } + } + + // 좋아요 클릭한 농산품 데이터 가져오기 + suspend fun getCropList(like_type_idx:Int): List{ + return withContext(Dispatchers.IO) { + val likeListRef = Firebase.firestore.collection("CropData") + val query = likeListRef.whereEqualTo("crop_idx", like_type_idx) + val querySnapshot = query.get().await() + querySnapshot.map { it.toObject(CropModel::class.java) } + } + } + + + + // 게시판 좋아요 리스트 + suspend fun getPostLikeList(userIdx:Int): List{ + return withContext(Dispatchers.IO) { + val likeListRef = Firebase.firestore.collection("LikeData") + val query = likeListRef.whereEqualTo("like_status", 1) + .whereEqualTo("like_user_idx", userIdx) + .whereEqualTo("like_type", 2) + .orderBy("like_idx", Query.Direction.ASCENDING) + val querySnapshot = query.get().await() + querySnapshot.map { it.toObject(LikeModel::class.java) } + } + } + + // 좋아요 클릭한 게시판 데이터 가져오기 + suspend fun getPostList(like_type_idx:Int): List{ + return withContext(Dispatchers.IO) { + val likeListRef = Firebase.firestore.collection("CommunityPostData") + val query = likeListRef.whereEqualTo("postIdx", like_type_idx) + .whereEqualTo("postStatus", 1) + val querySnapshot = query.get().await() + querySnapshot.map { it.toObject(CommunityPostModel::class.java) } + } + } + + // 주말농장 좋아요 리스트 + suspend fun getFarmLikeList(userIdx:Int): List{ + return withContext(Dispatchers.IO) { + val likeListRef = Firebase.firestore.collection("LikeData") + val query = likeListRef.whereEqualTo("like_status", 1) + .whereEqualTo("like_user_idx", userIdx) + .whereEqualTo("like_type", 3) + .orderBy("like_idx", Query.Direction.ASCENDING) + val querySnapshot = query.get().await() + querySnapshot.map { it.toObject(LikeModel::class.java) } + } + } + + // 좋아요 클릭한 주말농장 데이터 가져오기 + suspend fun getFarmList(like_type_idx:Int): List { + return withContext(Dispatchers.IO) { + val likeListRef = Firebase.firestore.collection("FarmData") + val query = likeListRef.whereEqualTo("farm_idx", like_type_idx) + val querySnapshot = query.get().await() + querySnapshot.map { it.toObject(FarmModel::class.java) } + } + } + + // 체험활동 좋아요 리스트 + suspend fun getActivityLikeList(userIdx:Int): List{ + return withContext(Dispatchers.IO) { + val likeListRef = Firebase.firestore.collection("LikeData") + val query = likeListRef.whereEqualTo("like_status", 1) + .whereEqualTo("like_user_idx", userIdx) + .whereEqualTo("like_type", 4) + .orderBy("like_idx", Query.Direction.ASCENDING) + val querySnapshot = query.get().await() + querySnapshot.map { it.toObject(LikeModel::class.java) } + } + } + + // 좋아요 클릭한 체험활동 데이터 가져오기 + suspend fun getActivityList(like_type_idx:Int): List { + return withContext(Dispatchers.IO) { + val likeListRef = Firebase.firestore.collection("ActivityData") + val query = likeListRef.whereEqualTo("activity_idx", like_type_idx) + val querySnapshot = query.get().await() + querySnapshot.map { it.toObject(ActivityModel::class.java) } + } + } + + // 농기구 좋아요 리스트 + suspend fun getRentalLikeList(userIdx:Int): List{ + return withContext(Dispatchers.IO) { + val likeListRef = Firebase.firestore.collection("LikeData") + val query = likeListRef.whereEqualTo("like_status", 1) + .whereEqualTo("like_user_idx", userIdx) + .whereEqualTo("like_type", 5) + .orderBy("like_idx", Query.Direction.ASCENDING) + val querySnapshot = query.get().await() + querySnapshot.map { it.toObject(LikeModel::class.java) } + } + } + + // 좋아요 클릭한 체험활동 데이터 가져오기 + suspend fun getRentalList(like_type_idx:Int): List { + return withContext(Dispatchers.IO) { + val likeListRef = Firebase.firestore.collection("RentalData") + val query = likeListRef.whereEqualTo("rental_idx", like_type_idx) + val querySnapshot = query.get().await() + querySnapshot.map { it.toObject(RentalModel::class.java) } + } + } + + // 이미지 데이터를 받아오는 메서드 + suspend fun gettingCommunityPostImage(context: Context, imageFileName:String, imageView: ImageView){ + val job1 = CoroutineScope(Dispatchers.IO).launch { + // 이미지에 접근할 수 있는 객체를 가져온다. + val storageRef = Firebase.storage.reference.child("image/community/$imageFileName") + // 이미지의 주소를 가지고 있는 Uri 객체를 받아온다. + val imageUri = storageRef.downloadUrl.await() + // 이미지 데이터를 받아와 이미지 뷰에 보여준다. + val job2 = CoroutineScope(Dispatchers.Main).launch { + Glide.with(context).load(imageUri).into(imageView) + // 이미지 뷰가 나타나게 한다. + imageView.visibility = View.VISIBLE + } + job2.join() + + } + job1.join() + // 이미지는 용량이 매우 클 수 있다. 즉 이미지 데이터를 내려받는데 시간이 오래걸릴 수도 있다. + // 이에, 이미지 데이터를 받아와 보여주는 코루틴을 작업이 끝날 때 까지 대기 하지 않는다. + // 그 이유는 데이터를 받아오는데 걸리는 오랜 시간 동안 화면에 아무것도 나타나지 않을 수 있기 때문이다. + // 따라서 이 메서드는 제일 마지막에 호출해야 한다.(다른 것들을 모두 보여준 후에...) + + } + + } +} \ No newline at end of file diff --git a/farming_customer/app/src/main/java/kr/co/lion/farming_customer/fragment/LikeFragment.kt b/farming_customer/app/src/main/java/kr/co/lion/farming_customer/fragment/LikeFragment.kt index 914ceaf..9d6e9e2 100644 --- a/farming_customer/app/src/main/java/kr/co/lion/farming_customer/fragment/LikeFragment.kt +++ b/farming_customer/app/src/main/java/kr/co/lion/farming_customer/fragment/LikeFragment.kt @@ -1,5 +1,6 @@ package kr.co.lion.farming_customer.fragment +import android.content.Context import android.content.Intent import android.os.Bundle import android.util.Log @@ -8,10 +9,15 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.databinding.DataBindingUtil +import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide import com.google.android.material.divider.MaterialDividerItemDecoration +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch import kr.co.lion.farming_customer.FarmingLifeFragmnetName import kr.co.lion.farming_customer.GridSpaceItemDecoration import kr.co.lion.farming_customer.LikeType @@ -20,121 +26,236 @@ import kr.co.lion.farming_customer.activity.CommunityActivity import kr.co.lion.farming_customer.activity.MainActivity import kr.co.lion.farming_customer.activity.farmingLife.FarmingLifeActivity import kr.co.lion.farming_customer.activity.farmingLifeTools.FarmingLifeToolsDetailActivity +import kr.co.lion.farming_customer.dao.like.LikeDao import kr.co.lion.farming_customer.databinding.FragmentLikeBinding import kr.co.lion.farming_customer.databinding.RowLikeCropBinding import kr.co.lion.farming_customer.databinding.RowLikeFarmActivityBinding import kr.co.lion.farming_customer.databinding.RowLikePostBinding import kr.co.lion.farming_customer.databinding.RowLikeRentalBinding +import kr.co.lion.farming_customer.model.ActivityModel +import kr.co.lion.farming_customer.model.CropModel +import kr.co.lion.farming_customer.model.FarmModel +import kr.co.lion.farming_customer.model.LikeModel +import kr.co.lion.farming_customer.model.CommunityPostModel +import kr.co.lion.farming_customer.model.RentalModel import kr.co.lion.farming_customer.viewmodel.LikeViewModel class LikeFragment : Fragment() { + // ViewModel 생성자에 Context 객체를 명시적으로 전달합니다. + // 세션에서 회원 시퀀스 번호 가져오기.. + val sharedPreferences = + context?.getSharedPreferences("my_preferences", Context.MODE_PRIVATE) + var userIdx: String? = sharedPreferences?.getString("user_idx", "") + lateinit var fragmentLikeBinding: FragmentLikeBinding lateinit var mainActivity: MainActivity - lateinit var likeViewModel : LikeViewModel + lateinit var likeViewModel: LikeViewModel + + lateinit var deco: MaterialDividerItemDecoration + lateinit var deco2: GridSpaceItemDecoration - lateinit var deco:MaterialDividerItemDecoration - lateinit var deco2:GridSpaceItemDecoration + lateinit var LikeList: List + lateinit var cropList: List + lateinit var postList: List + lateinit var farmList: List + lateinit var activityList: List + lateinit var rentalList: List + var selectedType = "" - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - fragmentLikeBinding = DataBindingUtil.inflate(layoutInflater, R.layout.fragment_like, container, false) + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + fragmentLikeBinding = + DataBindingUtil.inflate(layoutInflater, R.layout.fragment_like, container, false) likeViewModel = LikeViewModel() fragmentLikeBinding.likeViewModel = likeViewModel fragmentLikeBinding.lifecycleOwner = this mainActivity = activity as MainActivity - deco = MaterialDividerItemDecoration(mainActivity, MaterialDividerItemDecoration.VERTICAL) - deco2 = GridSpaceItemDecoration(2,40,-10,-10,-10) + lifecycleScope.launch { + val data = likeViewModel.getLikeListAndLikeTypeList("1", "CROP") + selectedType = "CROP" + LikeList = data.LikeList!! + cropList = data.cropList!! + postList = data.postList!! + farmList = data.farmList!! + activityList = data.activityList!! + rentalList = data.rentalList!! - settingUI() - settingToggleButton() +// val Data = likeViewModel.getLikeListAndLikeTypeList(userIdx.toString(), 1) +// cropLikeList = Data.LikeList!! +// cropList = Data.cropList!! + // 여기서 likeList와 cropList를 사용할 수 있습니다. + + settingUI() + settingToggleButton() + } + + deco = MaterialDividerItemDecoration(mainActivity, MaterialDividerItemDecoration.VERTICAL) + deco2 = GridSpaceItemDecoration(2, 40, -10, -10, -10) return fragmentLikeBinding.root } // 초기 설정 - fun settingUI(){ + fun settingUI() { likeViewModel.settingLikeType(LikeType.CROP) } // toggleButton 선택에 따라 recyclerView가 바뀌는 메서드 - fun settingToggleButton(){ + fun settingToggleButton() { fragmentLikeBinding.apply { toggleGroupLikeType.addOnButtonCheckedListener { group, checkedId, isChecked -> - if(isChecked){ - when(checkedId){ + if (isChecked) { + when (checkedId) { R.id.buttonLikeCrop -> { recyclerViewLike.visibility = View.VISIBLE recyclerViewPost.visibility = View.GONE recyclerViewRental.visibility = View.GONE + selectedType = "CROP" + loadLikeData(selectedType) settingRecyclerViewLikeCrop() } + R.id.buttonLikePost -> { recyclerViewLike.visibility = View.GONE recyclerViewPost.visibility = View.VISIBLE recyclerViewRental.visibility = View.GONE + selectedType = "POST" + loadLikeData(selectedType) settingRecyclerViewLikePost() } + R.id.buttonLikeFarm -> { recyclerViewLike.visibility = View.VISIBLE recyclerViewPost.visibility = View.GONE recyclerViewRental.visibility = View.GONE + selectedType = "FARM" + loadLikeData(selectedType) settingRecyclerViewLikeFarmAndActivity() } + R.id.buttonLikeActivity -> { recyclerViewLike.visibility = View.VISIBLE recyclerViewPost.visibility = View.GONE recyclerViewRental.visibility = View.GONE + selectedType = "ACTIVITY" + loadLikeData(selectedType) settingRecyclerViewLikeFarmAndActivity() } + R.id.buttonLikeRental -> { recyclerViewLike.visibility = View.GONE recyclerViewPost.visibility = View.GONE recyclerViewRental.visibility = View.VISIBLE + selectedType = "RENTAL" + loadLikeData(selectedType) settingRecyclerViewLikeRental() } } + +// // 각 리사이클러뷰 어댑터 직접 생성 및 설정 +// when (selectedType) { +// "CROP" -> { +// val cropAdapter = LikeCropRecyclerViewAdapter() // CropListAdapter 생성 +// recyclerViewLike.adapter = cropAdapter // recyclerViewLike 어댑터 설정 +// } +// "POST" -> { +// val postAdapter = LikePostRecyclerViewAdapter() // PostListAdapter 생성 +// recyclerViewPost.adapter = postAdapter // recyclerViewPost 어댑터 설정 +// } +// "FARM", "ACTIVITY" -> { +// val farmActivityAdapter = LikeFarmAndActivityRecyclerViewAdapter() // FarmActivityListAdapter 생성 +// recyclerViewLike.adapter = farmActivityAdapter // recyclerViewLike 어댑터 설정 +// } +// "RENTAL" -> { +// val rentalAdapter = LikeRentalRecyclerViewAdapter() // 매개변수 없이 RentalListAdapter 생성 +// recyclerViewRental.adapter = rentalAdapter // recyclerViewRental 어댑터 설정 +// } +// } + + } + } + } + } + + + + private fun loadLikeData(selectedType: String) { + lifecycleScope.launch { + val data = likeViewModel.getLikeListAndLikeTypeList("1", selectedType) + LikeList = data.LikeList!! + when(selectedType){ + "CROP" -> { + cropList = data.cropList!! + likeViewModel.settingLikeType(LikeType.CROP) + } + "POST" -> { + postList = data.postList!! + likeViewModel.settingLikeType(LikeType.POST) + } + "FARM" -> { + farmList = data.farmList!! + likeViewModel.settingLikeType(LikeType.FARM) } + "ACTIVITY" -> { + activityList = data.activityList!! + likeViewModel.settingLikeType(LikeType.ACTIVITY) + } + "RENTAL" -> { + rentalList = data.rentalList!! + likeViewModel.settingLikeType(LikeType.RENTAL) + } + + } +// Log.d("test11", farmList.toString()) + } } + + // 농산물 recyclerView 설정 - fun settingRecyclerViewLikeCrop(){ + fun settingRecyclerViewLikeCrop() { fragmentLikeBinding.apply { recyclerViewLike.apply { removeItemDecoration(deco) - if(itemDecorationCount == 0){ + if (itemDecorationCount == 0) { addItemDecoration(deco2) } adapter = LikeCropRecyclerViewAdapter() - layoutManager = GridLayoutManager(mainActivity,2) - + layoutManager = GridLayoutManager(mainActivity, 2) + (adapter as LikeCropRecyclerViewAdapter).notifyDataSetChanged() } } } // 게시판 recyclerView 설정 - fun settingRecyclerViewLikePost(){ + fun settingRecyclerViewLikePost() { fragmentLikeBinding.apply { recyclerViewPost.apply { - removeItemDecoration(deco2) - + removeItemDecoration(deco) + if (itemDecorationCount == 0) { + addItemDecoration(deco2) + } adapter = LikePostRecyclerViewAdapter() layoutManager = LinearLayoutManager(mainActivity) - if(recyclerViewPost.itemDecorationCount == 0){ - addItemDecoration(deco) - } + (adapter as LikePostRecyclerViewAdapter).notifyDataSetChanged() } } } // 주말농장 및 체험활동 recyclerView 설정 - fun settingRecyclerViewLikeFarmAndActivity(){ + fun settingRecyclerViewLikeFarmAndActivity() { fragmentLikeBinding.apply { recyclerViewLike.apply { removeItemDecoration(deco) - if(itemDecorationCount == 0){ + if (itemDecorationCount == 0) { addItemDecoration(deco2) } adapter = LikeFarmAndActivityRecyclerViewAdapter() @@ -144,7 +265,7 @@ class LikeFragment : Fragment() { } // 농기구 recyclerView 설정 - fun settingRecyclerViewLikeRental(){ + fun settingRecyclerViewLikeRental() { fragmentLikeBinding.apply { recyclerViewRental.apply { removeItemDecoration(deco) @@ -155,9 +276,14 @@ class LikeFragment : Fragment() { } // 농산물 recyclerView의 Adapter - inner class LikeCropRecyclerViewAdapter:RecyclerView.Adapter(){ - inner class LikeCropViewHolder(rowLikeCropBinding:RowLikeCropBinding):RecyclerView.ViewHolder(rowLikeCropBinding.root){ - val rowLikeCropBinding:RowLikeCropBinding + inner class LikeCropRecyclerViewAdapter : + RecyclerView.Adapter() { + + inner class LikeCropViewHolder(rowLikeCropBinding: RowLikeCropBinding) : + RecyclerView.ViewHolder(rowLikeCropBinding.root) { + + val rowLikeCropBinding: RowLikeCropBinding + init { this.rowLikeCropBinding = rowLikeCropBinding @@ -175,21 +301,37 @@ class LikeFragment : Fragment() { } override fun getItemCount(): Int { - return 9 + return LikeList.size } override fun onBindViewHolder(holder: LikeCropViewHolder, position: Int) { - holder.rowLikeCropBinding.textViewLikeCropName.text = "못난이 감자$position" - holder.rowLikeCropBinding.textViewLikeCropPrice.text = "${position}0,000원" + holder.rowLikeCropBinding.apply { + if (cropList.isEmpty()) { + root.visibility = View.GONE + return + } + textViewLikeCropName.text = cropList[position].crop_title + textViewLikeCropPrice.text = + cropList[position].crop_option_detail[0]["crop_option_price"] + textViewLikeCropCnt.text = + cropList[position].crop_like_cnt.toString() + ratingBarLikeCrop.rating = cropList[position].crop_like_cnt.toFloat() + context?.let { + Glide.with(it).load(cropList[position].crop_images[0]) + .into(imageViewLikeCrop) + } + } } } // 게시판 recyclerView의 Adapter - inner class LikePostRecyclerViewAdapter:RecyclerView.Adapter(){ - inner class LikePostViewHolder(rowLikePostBinding: RowLikePostBinding):RecyclerView.ViewHolder(rowLikePostBinding.root){ - val rowLikePostBinding:RowLikePostBinding + inner class LikePostRecyclerViewAdapter : + RecyclerView.Adapter() { + inner class LikePostViewHolder(rowLikePostBinding: RowLikePostBinding) : + RecyclerView.ViewHolder(rowLikePostBinding.root) { + val rowLikePostBinding: RowLikePostBinding - init{ + init { this.rowLikePostBinding = rowLikePostBinding this.rowLikePostBinding.root.layoutParams = ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, @@ -205,17 +347,29 @@ class LikeFragment : Fragment() { } override fun getItemCount(): Int { - return 10 + return LikeList.size } override fun onBindViewHolder(holder: LikePostViewHolder, position: Int) { holder.rowLikePostBinding.apply { - textViewLikePostLabel.text = "정보" - textViewLikePostTitle.text = "글 제목$position" - textViewLikePostContent.text = "글 내용입니다요 $position" - textViewLikePostViewCnt.text = "$position" - textViewLikePostCommentCnt.text = "$position" - textViewLikePostDate.text = "2024-04-09" +// Log.d("test11", postList.toString()) + if (postList.isEmpty()) { + root.visibility = View.GONE + return + } + textViewLikePostLabel.text = postList[position].postType + textViewLikePostTitle.text = postList[position].postTitle.substring(10) + textViewLikePostContent.text = postList[position].postContent.substring(20) + textViewLikePostViewCnt.text = postList[position].postViewCnt.toString() + textViewLikePostCommentCnt.text = postList[position].postCommentCnt.toString() + textViewLikePostDate.text = postList[position].postRegDt + CoroutineScope(Dispatchers.Main).launch { + if (postList[position].postImages != null) { + LikeDao.gettingCommunityPostImage(mainActivity, postList[position].postImages!![0], imageViewLikePost) + } else { + holder.rowLikePostBinding.imageViewLikePost.setImageResource(R.color.white) + } + } } // 아이템 클릭 이벤트 holder.rowLikePostBinding.root.setOnClickListener { @@ -226,9 +380,11 @@ class LikeFragment : Fragment() { } // 주말농장 및 체험활동 recyclerView의 Adapter - inner class LikeFarmAndActivityRecyclerViewAdapter:RecyclerView.Adapter(){ - inner class LikeFarmAndAcitivityViewHolder(rowLikeFarmActivityBinding: RowLikeFarmActivityBinding):RecyclerView.ViewHolder(rowLikeFarmActivityBinding.root){ - val rowLikeFarmActivityBinding:RowLikeFarmActivityBinding + inner class LikeFarmAndActivityRecyclerViewAdapter : + RecyclerView.Adapter() { + inner class LikeFarmAndAcitivityViewHolder(rowLikeFarmActivityBinding: RowLikeFarmActivityBinding) : + RecyclerView.ViewHolder(rowLikeFarmActivityBinding.root) { + val rowLikeFarmActivityBinding: RowLikeFarmActivityBinding init { this.rowLikeFarmActivityBinding = rowLikeFarmActivityBinding @@ -238,36 +394,64 @@ class LikeFragment : Fragment() { ) } } - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LikeFarmAndAcitivityViewHolder { + + override fun onCreateViewHolder( + parent: ViewGroup, + viewType: Int + ): LikeFarmAndAcitivityViewHolder { val rowLikeFarmActivityBinding = RowLikeFarmActivityBinding.inflate(layoutInflater) - val likeFarmAndActivityViewHolder = LikeFarmAndAcitivityViewHolder(rowLikeFarmActivityBinding) + val likeFarmAndActivityViewHolder = + LikeFarmAndAcitivityViewHolder(rowLikeFarmActivityBinding) return likeFarmAndActivityViewHolder } override fun getItemCount(): Int { - return 9 + return LikeList.size } override fun onBindViewHolder(holder: LikeFarmAndAcitivityViewHolder, position: Int) { holder.rowLikeFarmActivityBinding.apply { - textViewLikeFarmAndActivityName.text = "주말농장 이름$position" - textViewLikeFarmAndActivityLocation.text = "00광역시 00구 00면 $position" - textViewLikeFarmAndActivityPrice.text = "${position}0,000원" - } - // 아이템 클릭 이벤트 - holder.rowLikeFarmActivityBinding.root.setOnClickListener { - val intent = Intent(mainActivity, FarmingLifeActivity::class.java) - intent.putExtra("fragmentName", FarmingLifeFragmnetName.FARMING_LIFE_FARM_DETAIL_FARMGNET) - startActivity(intent) + Log.d("test11", farmList.toString()) + if (farmList.isEmpty() || activityList.isEmpty()) { + root.visibility = View.GONE + return + } + when (selectedType) { + "FARM" -> { + textViewLikeFarmAndActivityName.text = farmList[position].farm_title + textViewLikeFarmAndActivityLocation.text = farmList[position].farm_address +// textViewLikeFarmAndActivityPrice.text = +// farmList[position].farm_option_detail.["price_area"] + } + + "ACTIVITY" -> { + textViewLikeFarmAndActivityName.text = activityList[position].activity_title + textViewLikeFarmAndActivityLocation.text = + activityList[position].activity_address + textViewLikeFarmAndActivityPrice.text = + activityList[position].activity_option_detail[0]["option_price"] + } + } + // 아이템 클릭 이벤트 + holder.rowLikeFarmActivityBinding.root.setOnClickListener { + val intent = Intent(mainActivity, FarmingLifeActivity::class.java) + intent.putExtra( + "fragmentName", + FarmingLifeFragmnetName.FARMING_LIFE_FARM_DETAIL_FARMGNET + ) + startActivity(intent) + } } } } // 농기구 recyclerView의 Adapter - inner class LikeRentalRecyclerViewAdapter:RecyclerView.Adapter(){ - inner class LikeRentalViewHolder(rowLikeRentalBinding: RowLikeRentalBinding):RecyclerView.ViewHolder(rowLikeRentalBinding.root){ - val rowLikeRentalBinding:RowLikeRentalBinding + inner class LikeRentalRecyclerViewAdapter : + RecyclerView.Adapter() { + inner class LikeRentalViewHolder(rowLikeRentalBinding: RowLikeRentalBinding) : + RecyclerView.ViewHolder(rowLikeRentalBinding.root) { + val rowLikeRentalBinding: RowLikeRentalBinding init { this.rowLikeRentalBinding = rowLikeRentalBinding @@ -278,21 +462,28 @@ class LikeFragment : Fragment() { } } - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LikeRentalViewHolder { + override fun onCreateViewHolder( + parent: ViewGroup, + viewType: Int + ): LikeRentalViewHolder { val rowLikeRentalBinding = RowLikeRentalBinding.inflate(layoutInflater) val likeRentalViewHolder = LikeRentalViewHolder(rowLikeRentalBinding) return likeRentalViewHolder } override fun getItemCount(): Int { - return 10 + return LikeList.size } override fun onBindViewHolder(holder: LikeRentalViewHolder, position: Int) { holder.rowLikeRentalBinding.apply { - textViewLikeRentalName.text = "농기구점 이름$position" - textViewLikeRentalPhoneNumber.text = "010-1111-111$position" - textViewLikeRentalAddress.text = "00광역시 00구 00면 $position" + if (rentalList.isEmpty() ) { + root.visibility = View.GONE + return + } + textViewLikeRentalName.text = rentalList[position].rental_name + textViewLikeRentalPhoneNumber.text = rentalList[position].rental_phone + textViewLikeRentalAddress.text = rentalList[position].rental_address } // 아이템 클릭 이벤트 holder.rowLikeRentalBinding.root.setOnClickListener { @@ -303,4 +494,3 @@ class LikeFragment : Fragment() { } } - diff --git a/farming_customer/app/src/main/java/kr/co/lion/farming_customer/model/ActivityModel.kt b/farming_customer/app/src/main/java/kr/co/lion/farming_customer/model/ActivityModel.kt new file mode 100644 index 0000000..8ea93d9 --- /dev/null +++ b/farming_customer/app/src/main/java/kr/co/lion/farming_customer/model/ActivityModel.kt @@ -0,0 +1,18 @@ +package kr.co.lion.farming_customer.model + +data class ActivityModel(val activity_idx : Int = 0, + val activity_seller_idx : Int = 0, + val activity_title : String = "", + val activity_option_detail : List> = emptyList(), + val activity_content_detail : String = "", + val activity_content_warning : String = "", + val activity_content_policy : String = "", + val activity_utility : String = "", + val activity_like_cnt : Int = 0, + val activity_images : List = emptyList(), + val activity_reg_dt : String = "", + val activity_mod_dt : String = "", + val activity_status : Int = 0, + val activity_address : String = "", + val activity_star : Int = 0,) + diff --git a/farming_customer/app/src/main/java/kr/co/lion/farming_customer/model/CommunityPostModel.kt b/farming_customer/app/src/main/java/kr/co/lion/farming_customer/model/CommunityPostModel.kt new file mode 100644 index 0000000..499e371 --- /dev/null +++ b/farming_customer/app/src/main/java/kr/co/lion/farming_customer/model/CommunityPostModel.kt @@ -0,0 +1,14 @@ +package kr.co.lion.farming_customer.model + +data class CommunityPostModel(val postIdx : Int = 0, + val postUserIdx : Int = 0, + val postType : String = "", + val postTitle : String = "", + val postContent : String = "", + val postLikeCnt : Int = 0, + val postCommentCnt : Int = 0, + val postViewCnt : Int = 0, + val postRegDt : String = "", + val postModDt : String = "", + val postImages : List = emptyList(), + val postStatus : Int = 0) diff --git a/farming_customer/app/src/main/java/kr/co/lion/farming_customer/model/CropModel.kt b/farming_customer/app/src/main/java/kr/co/lion/farming_customer/model/CropModel.kt new file mode 100644 index 0000000..cb5c46e --- /dev/null +++ b/farming_customer/app/src/main/java/kr/co/lion/farming_customer/model/CropModel.kt @@ -0,0 +1,16 @@ +package kr.co.lion.farming_customer.model + +data class CropModel(val crop_idx : Int = 0, + val crop_address : String = "", + val crop_seller_idx : Int = 0, + val crop_title : String = "", + val crop_option_detail : List> = emptyList(), + val crop_content_detail : String = "", + val crop_content_detail_images : String = "", + val crop_content_warning : String = "", + val crop_content_policy : String = "", + val crop_like_cnt : Int = 0, + val crop_images : List = emptyList(), + val crop_reg_dt : String = "", + val crop_mod_dt : String = "", + val crop_status : Int = 0) \ No newline at end of file diff --git a/farming_customer/app/src/main/java/kr/co/lion/farming_customer/model/FarmModel.kt b/farming_customer/app/src/main/java/kr/co/lion/farming_customer/model/FarmModel.kt new file mode 100644 index 0000000..bc0656f --- /dev/null +++ b/farming_customer/app/src/main/java/kr/co/lion/farming_customer/model/FarmModel.kt @@ -0,0 +1,23 @@ +package kr.co.lion.farming_customer.model + +data class FarmModel(val farm_idx : Int = 0, + val farm_seller_idx : Int = 0, + val farm_title : String = "", + val farm_option_detail : Map = emptyMap(), + val farm_address : String = "", + val farm_content_detail : String = "", + val farm_content_warning : String = "", + val farm_content_policy : String = "", + val farm_apply_date_start : String = "", + val farm_apply_date_end : String = "", + val farm_use_date_start : String = "", + val farm_use_date_end : String = "", + val farm_can_crop : List = emptyList(), + val farm_utility : Map = emptyMap(), + val farm_like_cnt : Int = 0, + val farm_images : List = emptyList(), + val farm_reg_dt : String = "", + val farm_mod_dt : String = "", + val farm_status : Int = 0,) + + diff --git a/farming_customer/app/src/main/java/kr/co/lion/farming_customer/model/LikeModel.kt b/farming_customer/app/src/main/java/kr/co/lion/farming_customer/model/LikeModel.kt new file mode 100644 index 0000000..788c36c --- /dev/null +++ b/farming_customer/app/src/main/java/kr/co/lion/farming_customer/model/LikeModel.kt @@ -0,0 +1,7 @@ +package kr.co.lion.farming_customer.model + +data class LikeModel (var like_idx : Int = 0, + var like_user_idx : Int = 0, + var like_type_idx : Int = 0, + var like_type : Int = 0, + var like_status : Int = 0) \ No newline at end of file diff --git a/farming_customer/app/src/main/java/kr/co/lion/farming_customer/model/RentalModel.kt b/farming_customer/app/src/main/java/kr/co/lion/farming_customer/model/RentalModel.kt new file mode 100644 index 0000000..7c9d724 --- /dev/null +++ b/farming_customer/app/src/main/java/kr/co/lion/farming_customer/model/RentalModel.kt @@ -0,0 +1,12 @@ +package kr.co.lion.farming_customer.model + +data class RentalModel(val rental_idx : Int = 0, + val rental_name : String = "", + val rental_phone : String = "", + val rental_address : String = "", + val rental_machines : List = emptyList(), + val rental_like_cnt : Int = 0, + val rental_machine_images : List = emptyList(), + val rental_status : Int = 0,) + + diff --git a/farming_customer/app/src/main/java/kr/co/lion/farming_customer/viewmodel/LikeViewModel.kt b/farming_customer/app/src/main/java/kr/co/lion/farming_customer/viewmodel/LikeViewModel.kt index 694f682..7389fcf 100644 --- a/farming_customer/app/src/main/java/kr/co/lion/farming_customer/viewmodel/LikeViewModel.kt +++ b/farming_customer/app/src/main/java/kr/co/lion/farming_customer/viewmodel/LikeViewModel.kt @@ -1,14 +1,100 @@ package kr.co.lion.farming_customer.viewmodel +import android.util.Log import androidx.databinding.BindingAdapter import androidx.databinding.InverseBindingAdapter import androidx.databinding.InverseBindingListener import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext import kr.co.lion.farming_customer.LikeType import kr.co.lion.farming_customer.MaterialButtonToggleGroupWithRadius import kr.co.lion.farming_customer.R +import kr.co.lion.farming_customer.dao.like.LikeDao +import kr.co.lion.farming_customer.model.ActivityModel +import kr.co.lion.farming_customer.model.CropModel +import kr.co.lion.farming_customer.model.FarmModel +import kr.co.lion.farming_customer.model.LikeModel +import kr.co.lion.farming_customer.model.CommunityPostModel +import kr.co.lion.farming_customer.model.RentalModel + +class LikeViewModel() :ViewModel(){ + data class LikeData( + val LikeList: List?, + val cropList: List?, + val postList: List?, + val farmList: List?, + val activityList: List?, + val rentalList: List?, + ) + + // 농산물 좋아요 리스트 + suspend fun getLikeListAndLikeTypeList(userIdx: String, type: String): LikeData = withContext(Dispatchers.IO) { + var LikeList = mutableListOf() + var cropList = mutableListOf() + var postList = mutableListOf() + var farmList = mutableListOf() + var activityList = mutableListOf() + var rentalList = mutableListOf() + + + when (type) { + "CROP" -> { + LikeList = LikeDao.getCropLikeList(userIdx.toInt()).toMutableList() + val likeTypeIndices = LikeList.map { it.like_type_idx } + + for (likeTypeIdx in likeTypeIndices) { + val crop = LikeDao.getCropList(likeTypeIdx) + cropList.addAll(crop) + } + } + + "POST" -> { + LikeList = LikeDao.getPostLikeList(userIdx.toInt()).toMutableList() + val likeTypeIndices = LikeList.map { it.like_type_idx } + + for (likeTypeIdx in likeTypeIndices) { + val post = LikeDao.getPostList(likeTypeIdx) + postList.addAll(post) + } + } + + "FARM" -> { + LikeList = LikeDao.getFarmLikeList(userIdx.toInt()).toMutableList() + val likeTypeIndices = LikeList.map { it.like_type_idx } + + for (likeTypeIdx in likeTypeIndices) { + val farm = LikeDao.getFarmList(likeTypeIdx) + farmList.addAll(farm) + } + } + + "ACTIVITY" -> { + LikeList = LikeDao.getActivityLikeList(userIdx.toInt()).toMutableList() + val likeTypeIndices = LikeList.map { it.like_type_idx } + + for (likeTypeIdx in likeTypeIndices) { + val activity = LikeDao.getActivityList(likeTypeIdx) + activityList.addAll(activity) + } + } + + "RENTAL" -> { + LikeList = LikeDao.getRentalLikeList(userIdx.toInt()).toMutableList() + val likeTypeIndices = LikeList.map { it.like_type_idx } + + for (likeTypeIdx in likeTypeIndices) { + val rental = LikeDao.getRentalList(likeTypeIdx) + rentalList.addAll(rental) + } + } + } + + + LikeData(LikeList, cropList, postList, farmList, activityList, rentalList) + } -class LikeViewModel { // 좋아요 타입 val toggleLikeType = MutableLiveData() @@ -63,4 +149,6 @@ class LikeViewModel { return group.checkedButtonId } } + + } \ No newline at end of file diff --git a/farming_customer/app/src/main/res/layout/row_like_crop.xml b/farming_customer/app/src/main/res/layout/row_like_crop.xml index d81fa52..efaad76 100644 --- a/farming_customer/app/src/main/res/layout/row_like_crop.xml +++ b/farming_customer/app/src/main/res/layout/row_like_crop.xml @@ -27,7 +27,6 @@ android:id="@+id/imageViewLikeCrop" android:layout_width="match_parent" android:layout_height="120dp" - android:background="@color/grey_02" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" diff --git a/farming_customer/app/src/main/res/layout/row_like_post.xml b/farming_customer/app/src/main/res/layout/row_like_post.xml index 6702421..2fcff09 100644 --- a/farming_customer/app/src/main/res/layout/row_like_post.xml +++ b/farming_customer/app/src/main/res/layout/row_like_post.xml @@ -4,6 +4,13 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> + + + + + + android:scaleType="fitXY" />