Skip to content

Commit

Permalink
✨ Add 좋아요 기능 구현 [미완성]
Browse files Browse the repository at this point in the history
좋아요 기능 구현 [recyclerView의 교체 안됌] Related to : #52
  • Loading branch information
kimjingyoung committed Apr 25, 2024
1 parent e7b2c1b commit 3ed2fe2
Show file tree
Hide file tree
Showing 8 changed files with 281 additions and 245 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ enum class PostType(var str:String, var number:Int){
enum class PostStatus(var str:String, var number:Int) {
POST_STATUS_NORMAL("정상", 1),
POST_STATUS_REMOVE("샥제", 2),
POST_STATUS_MODIFY("수정", 3)
POST_STATUS_MODIFY("수정", 3),
}

// 남자 또는 여자를 나타내는 값을 정의한다.
enum class Gender(var str:String, var num:Int){
Expand Down Expand Up @@ -410,6 +411,7 @@ enum class CommentStatus(var str:String, var number: Int) {
COMMENT_STATUS_NORMAL("정상", 1),
COMMENT_STATUS_REMOVE("삭제", 2),
COMMENT_STATUS_MODIFY("수정", 3)
}

enum class ReviewState(var str:String, var number:Int) {
REVIEW_STATE_NORMAL("정상", 0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ 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.StorageReference
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.farmingLife.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
Expand All @@ -25,12 +26,11 @@ class LikeDao {
companion object {

// 농산품 좋아요 리스트
suspend fun getCropLikeList(userIdx:Int): List<LikeModel>{
suspend fun getLikeList(userIdx:Int): List<LikeModel>{
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) }
Expand All @@ -49,18 +49,17 @@ class LikeDao {



// 게시판 좋아요 리스트
suspend fun getPostLikeList(userIdx:Int): List<LikeModel>{
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 getLikeList(userIdx:Int): List<LikeModel>{
// return withContext(Dispatchers.IO) {
// val likeListRef = Firebase.firestore.collection("LikeData")
// val query = likeListRef.whereEqualTo("like_status", 1)
// .whereEqualTo("like_user_idx", userIdx)
// .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<CommunityPostModel>{
Expand All @@ -73,18 +72,18 @@ class LikeDao {
}
}

// 주말농장 좋아요 리스트
suspend fun getFarmLikeList(userIdx:Int): List<LikeModel>{
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 getFarmLikeList(userIdx:Int): List<LikeModel>{
// 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<FarmModel> {
Expand All @@ -96,18 +95,18 @@ class LikeDao {
}
}

// 체험활동 좋아요 리스트
suspend fun getActivityLikeList(userIdx:Int): List<LikeModel>{
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 getActivityLikeList(userIdx:Int): List<LikeModel>{
// 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<ActivityModel> {
Expand All @@ -119,18 +118,18 @@ class LikeDao {
}
}

// 농기구 좋아요 리스트
suspend fun getRentalLikeList(userIdx:Int): List<LikeModel>{
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 getRentalLikeList(userIdx:Int): List<LikeModel>{
// 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<RentalModel> {
Expand All @@ -143,10 +142,17 @@ class LikeDao {
}

// 이미지 데이터를 받아오는 메서드
suspend fun gettingCommunityPostImage(context: Context, imageFileName:String, imageView: ImageView){
suspend fun gettingImage(context: Context, imageFileName:String, imageView: ImageView, type: String){
val job1 = CoroutineScope(Dispatchers.IO).launch {
// 이미지에 접근할 수 있는 객체를 가져온다.
val storageRef = Firebase.storage.reference.child("image/community/$imageFileName")
var storageRef : StorageReference

if( type == "POST"){
storageRef = Firebase.storage.reference.child("image/community/$imageFileName")
} else {
storageRef = Firebase.storage.reference.child(imageFileName)
}

// 이미지의 주소를 가지고 있는 Uri 객체를 받아온다.
val imageUri = storageRef.downloadUrl.await()
// 이미지 데이터를 받아와 이미지 뷰에 보여준다.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kr.co.lion.farming_customer.fragment

import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
Expand All @@ -9,7 +10,6 @@ import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.divider.MaterialDividerItemDecoration
Expand Down Expand Up @@ -39,7 +39,6 @@ import kr.co.lion.farming_customer.model.CommunityModel
import kr.co.lion.farming_customer.model.CropModel
import kr.co.lion.farming_customer.model.farmingLife.ActivityModel
import kr.co.lion.farming_customer.model.farmingLife.FarmModel
import kr.co.lion.farming_customer.viewmodel.CommunityViewModel
import kr.co.lion.farming_customer.viewmodel.HomeViewModel
import kr.co.lion.farming_customer.viewmodel.farmingLife.RowGridItemViewModel
import kr.co.lion.farming_customer.viewmodel.tradeCrop.TradeViewModel
Expand Down Expand Up @@ -99,7 +98,7 @@ class HomeFragment : Fragment() {
}
fragmentHomeBinding.viewPagerFarm.adapter?.notifyDataSetChanged()
fragmentHomeBinding.viewPagerCrop.adapter?.notifyDataSetChanged()
fragmentHomeBinding.recyclerViewBoard.adaper?.notifyDataSetChanged()
fragmentHomeBinding.recyclerViewBoard.adapter?.notifyDataSetChanged()
}
}

Expand Down
Loading

0 comments on commit 3ed2fe2

Please sign in to comment.