Skip to content

Commit

Permalink
Merge pull request #41 from WishBunny/feat/#29_selectWishList_addWork
Browse files Browse the repository at this point in the history
Feat/#29 select wish list add work To DEV
  • Loading branch information
codeSweet0828 authored Jan 26, 2024
2 parents 5eacc87 + 7bb0d0e commit 398a3cb
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 45 deletions.
49 changes: 31 additions & 18 deletions app/src/main/java/com/wish/bunny/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ class HomeFragment : Fragment(), CustomAdapter.OnDetailButtonClickListener {

private lateinit var binding: ActivityWishListBinding
private var adapter: CustomAdapter? = null

private val accessToken = "Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI2ZWE3NTFmOS1lNDhlLTQ1OWEtYjYwYi02MzFkMDM4ZmUwZmIiLCJpYXQiOjE3MDYyMjgzMDMsImV4cCI6MTcwODgyMDMwM30.x7mvX8xzWhd-lzB0xooHYIH9pSJfmsgzB7fe7tJhoUI"
//private val accessToken = GlobalApplication.prefs.getString("accessToken", "")
private val writerNo = "6ea751f9-e48e-459a-b60b-631d038fe0fb"
// val writerNo = arguments?.getString("writerNo")
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
Expand All @@ -38,13 +41,15 @@ class HomeFragment : Fragment(), CustomAdapter.OnDetailButtonClickListener {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
defaultClick(view)
loadWishList("NOSET","WRITER002","accessTOKEN","do")
loadDoneWishSize(view, "WRITER002")
btnClickEvent(view)
//지금까지 완료한 리스트 확인하기
val donsListSize = view.findViewById<Button>(R.id.GetDoneButton)
donsListSize.setOnClickListener {
loadWishList("Y","WRITER002","accessTOKEN","")
if(writerNo!= null){
loadWishList("NOSET",writerNo,accessToken,"do")
loadDoneWishSize(view, writerNo)
btnClickEvent(view)
//지금까지 완료한 리스트 확인하기
val donsListSize = view.findViewById<Button>(R.id.GetDoneButton)
donsListSize.setOnClickListener {
loadWishList("Y",writerNo,accessToken,"")
}
}
}
private fun defaultClick(view: View){
Expand Down Expand Up @@ -81,7 +86,10 @@ class HomeFragment : Fragment(), CustomAdapter.OnDetailButtonClickListener {
button2.setTextColor(originalTextColor)
button3.setBackgroundColor(transparentColor)
button3.setTextColor(originalTextColor)
loadWishList("NOSET","WRITER002","accessTOKEN","do")
if(writerNo!= null){
loadWishList("NOSET",writerNo,accessToken,"do")
}

}

button2.setOnClickListener {
Expand All @@ -91,7 +99,10 @@ class HomeFragment : Fragment(), CustomAdapter.OnDetailButtonClickListener {
button1.setTextColor(originalTextColor)
button3.setBackgroundColor(transparentColor)
button3.setTextColor(originalTextColor)
loadWishList("NOSET","WRITER002","accessTOKEN","eat")
if(writerNo!= null){
loadWishList("NOSET",writerNo,accessToken,"eat")
}

}

button3.setOnClickListener {
Expand All @@ -101,7 +112,10 @@ class HomeFragment : Fragment(), CustomAdapter.OnDetailButtonClickListener {
button1.setTextColor(originalTextColor)
button2.setBackgroundColor(transparentColor)
button2.setTextColor(originalTextColor)
loadWishList("NOSET","WRITER002","accessTOKEN","get")
if(writerNo!= null){
loadWishList("NOSET",writerNo,accessToken,"get")
}

}
}

Expand Down Expand Up @@ -131,14 +145,15 @@ class HomeFragment : Fragment(), CustomAdapter.OnDetailButtonClickListener {
private fun loadWishList(achieveYn: String, writerNo: String, accessToken: String, category:String) {
val retrofitAPI = RetrofitConnection.getInstance().create(WishService::class.java)

val call = retrofitAPI.getWishList(achieveYn, writerNo, "Bearer $accessToken",category)
val call = retrofitAPI.getWishList(achieveYn, writerNo, "$accessToken",category)
call.enqueue(object : Callback<WishMapResult> {
override fun onResponse(call: Call<WishMapResult>, response: Response<WishMapResult>) {
val wishMapResult = response.body()

if (wishMapResult != null) {
Log.d("WishList2", "불러오기 성공: ${wishMapResult.list.size} 개의 아이템")
updateUI(wishMapResult.list)
Log.d("writerYn",wishMapResult.writerYn)
updateUI(wishMapResult.list, wishMapResult.writerYn)

Log.d("WishList2", wishMapResult.list.toString())
} else {
Expand All @@ -153,11 +168,8 @@ class HomeFragment : Fragment(), CustomAdapter.OnDetailButtonClickListener {
})
}




private fun updateUI(wishItemList: List<WishItem>) {
adapter = CustomAdapter(requireContext(), wishItemList)
private fun updateUI(wishItemList: List<WishItem>, writerYn: String) {
adapter = CustomAdapter(requireContext(), wishItemList, writerYn)
adapter?.setOnDetailButtonClickListener(this)

binding.wishListRecyclerView.adapter = adapter
Expand All @@ -169,6 +181,7 @@ class HomeFragment : Fragment(), CustomAdapter.OnDetailButtonClickListener {

val bundle = Bundle()
bundle.putString("wishNo", wishNo)
// bundle.putString("writerNo", memberNo)
newFragment.arguments = bundle

replaceFragment(newFragment)
Expand Down
18 changes: 17 additions & 1 deletion app/src/main/java/com/wish/bunny/wish/CustomAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoUnit
import android.app.AlertDialog
import android.widget.ImageButton
import androidx.core.content.ContextCompat

/**
작성자: 김은솔
처리 내용: 위시리스트 CustomAdapter
*/
class CustomAdapter(private val context: Context, private val wishItemList: List<WishItem>) :
class CustomAdapter(private val context: Context, private val wishItemList: List<WishItem>,
private val writerYn: String) :
RecyclerView.Adapter<CustomAdapter.ViewHolder>() {

interface OnDetailButtonClickListener {
Expand Down Expand Up @@ -64,6 +66,7 @@ class CustomAdapter(private val context: Context, private val wishItemList: List
private val content = itemView.findViewById<TextView>(R.id.rv_content)
private val dDay = itemView.findViewById<TextView>(R.id.rv_dDay)
private val tag1 = itemView.findViewById<TextView>(R.id.rv_tag1)
private val doneBtn = itemView.findViewById<ImageButton>(R.id.rv_detail_btn)

init {
//컨텐츠 내용 클릭시 상세 페이지 이동
Expand Down Expand Up @@ -127,9 +130,22 @@ class CustomAdapter(private val context: Context, private val wishItemList: List
val title = wishItem.content
val wishNo = wishItem.wishNo


content.text = wishItem.content
// dDay.text = calculateDDay(wishItem.deadlineDt)
tag1.text = wishItem.tagContents

//로그인 아이디와 작성자가 다른 경우 완료버튼 안보이게
if(writerYn.equals("Y")){
doneBtn.visibility = View.VISIBLE
//성취했을 경우 색깔 변화
if(wishItem.achieveYn.equals("Y")){
doneBtn.setImageDrawable(ContextCompat.getDrawable(itemView.context, R.drawable.active_circle))
}

}else{
doneBtn.visibility = View.GONE
}
}

private fun calculateDDay(deadlineDt: String): String {
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/com/wish/bunny/wish/WishDetail.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.view.View
import android.widget.Button
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.wish.bunny.GlobalApplication
import com.wish.bunny.R
import com.wish.bunny.util.RetrofitConnection
import com.wish.bunny.wish.domain.WishItem
Expand All @@ -23,19 +24,20 @@ class WishDetail : AppCompatActivity() {
private val tvSelectedDate: TextView by lazy { findViewById<TextView>(R.id.tvSelectedDate) }
private val selectedDate: Calendar = Calendar.getInstance()
private val selectedButtons: MutableList<Button> = mutableListOf()
private val accessToken = GlobalApplication.prefs.getString("accessToken", "")

// 원래의 글자색 저장
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_wish_detail)

loadWishDetail("WISH002")
loadWishDetail("WISH002", accessToken)


}
private fun loadWishDetail(wishNo: String) {
private fun loadWishDetail(wishNo: String, accessToken: String) {
val retrofitAPI = RetrofitConnection.getInstance().create(WishService::class.java)
retrofitAPI.getWishDetail(wishNo).enqueue(object : retrofit2.Callback<WishItem> {
retrofitAPI.getWishDetail(wishNo, accessToken).enqueue(object : retrofit2.Callback<WishItem> {
override fun onResponse(call: Call<WishItem>, response: Response<WishItem>) {
// 성공 시 처리
val wishItem = response.body()
Expand Down
29 changes: 16 additions & 13 deletions app/src/main/java/com/wish/bunny/wish/WishDetailFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import android.view.ViewGroup
import android.widget.Button
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.wish.bunny.GlobalApplication
import com.wish.bunny.R
import com.wish.bunny.databinding.FragmentWishDetailBinding
import com.wish.bunny.util.RetrofitConnection
import com.wish.bunny.wish.WishService
import com.wish.bunny.wish.WishUpdateFragment
import com.wish.bunny.wish.domain.WishItem
import com.wish.bunny.wish.domain.WishMapResult
import retrofit2.Call
Expand All @@ -31,6 +33,8 @@ class WishDetailFragment : Fragment() {
private val selectedDate: Calendar = Calendar.getInstance()
private val selectedButtons: MutableList<Button> = mutableListOf()

//private val accessToken = GlobalApplication.prefs.getString("accessToken", "")
private val accessToken = "Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI2ZWE3NTFmOS1lNDhlLTQ1OWEtYjYwYi02MzFkMDM4ZmUwZmIiLCJpYXQiOjE3MDYyMjgzMDMsImV4cCI6MTcwODgyMDMwM30.x7mvX8xzWhd-lzB0xooHYIH9pSJfmsgzB7fe7tJhoUI"
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
Expand All @@ -45,22 +49,21 @@ class WishDetailFragment : Fragment() {
val wishNo = arguments?.getString("wishNo")

if (wishNo != null) {
Log.d("WishDetailFragment", "Received wishNo: $wishNo")
Log.d("WishDetailFragment", wishNo)

loadWishDetail(wishNo)
loadWishDetail(wishNo, accessToken)
view.findViewById<Button>(R.id.deleteBtn).setOnClickListener {
showConfirmationDialog(wishNo)
}
}

view.findViewById<Button>(R.id.updateBtn).setOnClickListener {
val newFragment = WishDetailFragment()
view.findViewById<Button>(R.id.updateBtn).setOnClickListener {
val newFragment = WishUpdateFragment()

val bundle = Bundle()
bundle.putString("wishNo", wishNo)
newFragment.arguments = bundle
val bundle = Bundle()
bundle.putString("wishNo", wishNo)
newFragment.arguments = bundle

replaceFragment(newFragment)
replaceFragment(newFragment)
}
}

}
Expand All @@ -71,9 +74,9 @@ class WishDetailFragment : Fragment() {
.addToBackStack(null)
.commit()
}
private fun loadWishDetail(wishNo: String) {
private fun loadWishDetail(wishNo: String, accessToken:String) {
val retrofitAPI = RetrofitConnection.getInstance().create(WishService::class.java)
retrofitAPI.getWishDetail(wishNo).enqueue(object : Callback<WishItem> {
retrofitAPI.getWishDetail(wishNo, "$accessToken").enqueue(object : Callback<WishItem> {
override fun onResponse(call: Call<WishItem>, response: Response<WishItem>) {
val wishItem = response.body()

Expand Down Expand Up @@ -140,7 +143,7 @@ class WishDetailFragment : Fragment() {
binding.content.text = wishItem.content
binding.hashtagButton1.text = '#' + wishItem.tagContents
binding.tvSelectedDate.text = wishItem.deadlineDt
// EditDeleteButtonShowYn(wishItem.writerYn)
EditDeleteButtonShowYn(wishItem.writerYn)
setCategroy(wishItem.category)
}

Expand Down
9 changes: 5 additions & 4 deletions app/src/main/java/com/wish/bunny/wish/WishList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class WishList : AppCompatActivity() {

if (wishMapResult != null) {
Log.d("WishList2", "불러오기 성공: ${wishMapResult.list.size} 개의 아이템")
updateUI(wishMapResult.list)

updateUI(wishMapResult.list, wishMapResult.writerYn)
Log.d("WishList2", wishMapResult.list.toString())
} else {
Log.d("WishList2", "서버 응답이 null입니다.")
Expand All @@ -53,8 +52,10 @@ class WishList : AppCompatActivity() {
})
}

private fun updateUI(wishItemList: List<WishItem>) {
adapter = CustomAdapter(this, wishItemList)
private fun updateUI(wishItemList: List<WishItem>, writerYn: String) {
// adapter = CustomAdapter(this, wishItemList, writerYn)

adapter = CustomAdapter(this, wishItemList, "N")
Log.d("wish Context",this.toString());
binding.wishListRecyclerView.adapter = adapter
binding.wishListRecyclerView.layoutManager = LinearLayoutManager(this)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/wish/bunny/wish/WishService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ interface WishService {


@GET("wish/{wishNo}")
fun getWishDetail(@Path("wishNo") wishNo: String): Call<WishItem>
fun getWishDetail(@Path("wishNo") wishNo: String, @Header("Authorization") accessToken: String): Call<WishItem>
/**
작성자: 김은솔
처리 내용: 위시리스트 완료처리
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/java/com/wish/bunny/wish/WishUpdateFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import java.util.Locale

class WishUpdateFragment : Fragment() {

//private val accessToken = GlobalApplication.prefs.getString("accessToken", "")
private val accessToken = "Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI2ZWE3NTFmOS1lNDhlLTQ1OWEtYjYwYi02MzFkMDM4ZmUwZmIiLCJpYXQiOjE3MDYyMjgzMDMsImV4cCI6MTcwODgyMDMwM30.x7mvX8xzWhd-lzB0xooHYIH9pSJfmsgzB7fe7tJhoUI"
private lateinit var btnOpenCalendar: ImageButton
private lateinit var tvSelectedDate: TextView
private lateinit var backButton: ImageButton
Expand Down Expand Up @@ -306,16 +308,16 @@ class WishUpdateFragment : Fragment() {

private fun loadWishDetail(wishNo: String) {
val retrofitAPI = RetrofitConnection.getInstance().create(WishService::class.java)
retrofitAPI.getWishDetail(wishNo).enqueue(object : Callback<WishItem> {
retrofitAPI.getWishDetail(wishNo, "$accessToken").enqueue(object : Callback<WishItem> {
override fun onResponse(call: Call<WishItem>, response: Response<WishItem>) {
val wishItem = response.body()

if (wishItem != null) {
updateUI(wishItem)
Log.d("wishItem", wishItem.toString())
//updateUI(wishItem)
Log.d("wishItem 수정", wishItem.toString())

} else {
Log.d("wishItem", "서버 응답이 null입니다.")
Log.d("wishItem 수정", "서버 응답이 null입니다.")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ data class WishMapResult(
val result: Objects,
val list : List<WishItem>,
val size: Int,
val udResult: Int
val udResult: Int,
var writerYn: String
)
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/active_circle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#DF646E"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M16.59,7.58L10,14.17l-3.59,-3.58L5,12l5,5 8,-8zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/>
</vector>

0 comments on commit 398a3cb

Please sign in to comment.