-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from WishBunny/feat/#4_wishList_select
Feat/#4 wish list select
- Loading branch information
Showing
12 changed files
with
591 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,84 @@ | ||
package com.wish.bunny.home | ||
|
||
import android.os.Bundle | ||
import androidx.fragment.app.Fragment | ||
import android.util.Log | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.Button | ||
import androidx.fragment.app.Fragment | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import com.wish.bunny.R | ||
import com.wish.bunny.databinding.ActivityWishListBinding | ||
import com.wish.bunny.retrofit.RetrofitConnection | ||
import com.wish.bunny.wish.CustomAdapter | ||
import com.wish.bunny.wish.WishService | ||
import com.wish.bunny.wish.domain.WishItem | ||
import com.wish.bunny.wish.domain.WishMapResult | ||
import retrofit2.Call | ||
import retrofit2.Callback | ||
import retrofit2.Response | ||
|
||
class HomeFragment : Fragment() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
} | ||
|
||
private lateinit var binding: ActivityWishListBinding | ||
private var adapter: CustomAdapter? = null | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
// Inflate the layout for this fragment | ||
return inflater.inflate(R.layout.fragment_home, container, false) | ||
binding = ActivityWishListBinding.inflate(inflater, container, false) | ||
return binding.root | ||
} | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
loadWishList() | ||
|
||
/* | ||
view.findViewById<Button>(R.id.rv_detail_btn).setOnClickListener { | ||
val detailFragment = WishDetailFragment(); | ||
replaceFragment(detailFragment) | ||
} | ||
*/ | ||
} | ||
|
||
private fun loadWishList() { | ||
val retrofitAPI = RetrofitConnection.getInstance().create(WishService::class.java) | ||
retrofitAPI.getWishList().enqueue(object : Callback<WishMapResult> { | ||
override fun onResponse(call: Call<WishMapResult>, response: Response<WishMapResult>) { | ||
val wishMapResult = response.body() | ||
|
||
if (wishMapResult != null) { | ||
Log.d("WishList", "불러오기 성공: ${wishMapResult.list.size} 개의 아이템") | ||
updateUI(wishMapResult.list) | ||
Log.d("WishList", wishMapResult.list.toString()) | ||
} else { | ||
Log.d("WishList", "서버 응답이 null입니다.") | ||
} | ||
} | ||
|
||
override fun onFailure(call: Call<WishMapResult>, t: Throwable) { | ||
Log.d("WishList", "불러오기 실패: ${t.message}") | ||
// TODO: 실패 시 처리 구현 | ||
} | ||
}) | ||
} | ||
|
||
private fun updateUI(wishItemList: List<WishItem>) { | ||
adapter = CustomAdapter(requireContext(), wishItemList) | ||
Log.d("wish Context", this.toString()) | ||
binding.wishListRecyclerView.adapter = adapter | ||
binding.wishListRecyclerView.layoutManager = LinearLayoutManager(requireContext()) | ||
} | ||
|
||
private fun replaceFragment(fragment: Fragment) { | ||
requireActivity().supportFragmentManager.beginTransaction() | ||
.replace(R.id.fragment_container, fragment) | ||
.addToBackStack(null) | ||
.commit() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
app/src/main/java/com/wish/bunny/wish/WishDetailFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package com.wish.bunny.home | ||
|
||
import android.os.Bundle | ||
import android.util.Log | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.Button | ||
import android.widget.TextView | ||
import androidx.core.content.ContextCompat | ||
import androidx.fragment.app.Fragment | ||
import com.wish.bunny.R | ||
import com.wish.bunny.databinding.FragmentWishDetailBinding | ||
import com.wish.bunny.retrofit.RetrofitConnection | ||
import com.wish.bunny.wish.WishService | ||
import com.wish.bunny.wish.domain.WishItem | ||
import retrofit2.Call | ||
import retrofit2.Callback | ||
import retrofit2.Response | ||
import java.text.SimpleDateFormat | ||
import java.util.* | ||
|
||
class WishDetailFragment : Fragment() { | ||
|
||
private var _binding: FragmentWishDetailBinding? = null | ||
private val binding get() = _binding!! | ||
|
||
private val selectedDate: Calendar = Calendar.getInstance() | ||
private val selectedButtons: MutableList<Button> = mutableListOf() | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
_binding = FragmentWishDetailBinding.inflate(inflater, container, false) | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
loadWishDetail("WISH002") | ||
} | ||
|
||
private fun loadWishDetail(wishNo: String) { | ||
val retrofitAPI = RetrofitConnection.getInstance().create(WishService::class.java) | ||
retrofitAPI.getWishDetail(wishNo).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()) | ||
|
||
} else { | ||
Log.d("wishItem", "서버 응답이 null입니다.") | ||
} | ||
} | ||
|
||
override fun onFailure(call: Call<WishItem>, t: Throwable) { | ||
Log.d("wishItem", "불러오기 실패: ${t.message}") | ||
// TODO: 실패 시 처리 구현 | ||
} | ||
}) | ||
} | ||
|
||
private fun updateUI(wishItem: WishItem) { | ||
binding.content.text = wishItem.content | ||
binding.hashtagButton1.text = '#' + wishItem.tagContents | ||
binding.tvSelectedDate.text = wishItem.deadlineDt | ||
EditDeleteButtonShowYn(wishItem.writerYn) | ||
setCategroy(wishItem.category) | ||
} | ||
|
||
private fun EditDeleteButtonShowYn(writerYn: String) { | ||
val editBtn = binding.updateBtn | ||
val deleteBtn = binding.deleteBtn | ||
|
||
if (writerYn.equals("Y")) { | ||
editBtn.visibility = View.VISIBLE | ||
deleteBtn.visibility = View.VISIBLE | ||
} else { | ||
editBtn.visibility = View.GONE | ||
deleteBtn.visibility = View.GONE | ||
} | ||
} | ||
|
||
private fun setCategroy(category: String) { | ||
val button1 = binding.button1 | ||
val button2 = binding.button2 | ||
val button3 = binding.button3 | ||
|
||
val pinkColor = ContextCompat.getColor(requireContext(), R.color.pink) | ||
val changeTextColor = ContextCompat.getColor(requireContext(), R.color.white) | ||
val transparentColor = ContextCompat.getColor(requireContext(), R.color.ivory) | ||
val originalTextColor = ContextCompat.getColor(requireContext(), R.color.black) | ||
|
||
when (category) { | ||
"go" -> { | ||
updateCategoryButton(button1, pinkColor, changeTextColor, transparentColor, originalTextColor) | ||
} | ||
"eat" -> { | ||
updateCategoryButton(button2, pinkColor, changeTextColor, transparentColor, originalTextColor) | ||
} | ||
else -> { | ||
updateCategoryButton(button3, pinkColor, changeTextColor, transparentColor, originalTextColor) | ||
} | ||
} | ||
} | ||
|
||
private fun updateCategoryButton( | ||
button: Button, | ||
pinkColor: Int, | ||
changeTextColor: Int, | ||
transparentColor: Int, | ||
originalTextColor: Int | ||
) { | ||
button.setBackgroundColor(pinkColor) | ||
button.setTextColor(changeTextColor) | ||
for (otherButton in listOf(binding.button1, binding.button2, binding.button3)) { | ||
if (otherButton != button) { | ||
otherButton.setBackgroundColor(transparentColor) | ||
otherButton.setTextColor(originalTextColor) | ||
} | ||
} | ||
} | ||
|
||
override fun onDestroyView() { | ||
super.onDestroyView() | ||
_binding = null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
app/src/main/java/com/wish/bunny/wish/item_wish_fragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.wish.bunny.wish | ||
|
||
import android.os.Bundle | ||
import androidx.fragment.app.Fragment | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import com.wish.bunny.R | ||
|
||
// TODO: Rename parameter arguments, choose names that match | ||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER | ||
private const val ARG_PARAM1 = "param1" | ||
private const val ARG_PARAM2 = "param2" | ||
|
||
/** | ||
* A simple [Fragment] subclass. | ||
* Use the [item_wish_fragment.newInstance] factory method to | ||
* create an instance of this fragment. | ||
*/ | ||
class item_wish_fragment : Fragment() { | ||
// TODO: Rename and change types of parameters | ||
private var param1: String? = null | ||
private var param2: String? = null | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
arguments?.let { | ||
param1 = it.getString(ARG_PARAM1) | ||
param2 = it.getString(ARG_PARAM2) | ||
} | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
// Inflate the layout for this fragment | ||
return inflater.inflate(R.layout.fragment_item_wish_fragment, container, false) | ||
} | ||
|
||
companion object { | ||
/** | ||
* Use this factory method to create a new instance of | ||
* this fragment using the provided parameters. | ||
* | ||
* @param param1 Parameter 1. | ||
* @param param2 Parameter 2. | ||
* @return A new instance of fragment item_wish_fragment. | ||
*/ | ||
// TODO: Rename and change types and number of parameters | ||
@JvmStatic | ||
fun newInstance(param1: String, param2: String) = | ||
item_wish_fragment().apply { | ||
arguments = Bundle().apply { | ||
putString(ARG_PARAM1, param1) | ||
putString(ARG_PARAM2, param2) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.