-
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.
Browse files
Browse the repository at this point in the history
Feat/#1 위시리스트 등록 화면 UI 구현
- Loading branch information
Showing
26 changed files
with
859 additions
and
22 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.wish.bunny.wish | ||
|
||
import android.content.Context | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.TextView | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.wish.bunny.R | ||
import com.wish.bunny.wish.domain.WishItem | ||
import java.time.LocalDate | ||
import java.time.format.DateTimeFormatter | ||
import java.time.temporal.ChronoUnit | ||
|
||
class CustomAdapter(private val context: Context, private val wishItemList: List<WishItem>) : | ||
RecyclerView.Adapter<CustomAdapter.ViewHolder>() { | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | ||
val view = LayoutInflater.from(context).inflate(R.layout.item_wish, parent, false) | ||
return ViewHolder(view) | ||
} | ||
|
||
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||
holder.bind(wishItemList[position]) | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return wishItemList.size | ||
} | ||
|
||
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | ||
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) | ||
|
||
fun bind(wishItem: WishItem) { | ||
content.text = wishItem.content | ||
dDay.text = calculateDDay(wishItem.deadlineDt) | ||
tag1.text = wishItem.tagContents | ||
//content.text = wishItem.wishNo | ||
// dDay 설정 등 필요한 데이터 설정 | ||
// 예시: dDay.text = "D-${calculateDDay(wishItem.deadlineDt)}" | ||
} | ||
|
||
private fun calculateDDay(deadlineDt: String): String { | ||
val dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd") | ||
val targetDate = LocalDate.parse(deadlineDt, dateFormatter) | ||
|
||
//현재날짜 | ||
val currentDate = LocalDate.now() | ||
|
||
//남은 일수 계산 | ||
val daysRemaining = ChronoUnit.DAYS.between(currentDate, targetDate) | ||
|
||
return "D-${daysRemaining.toString()}" | ||
} | ||
} | ||
} |
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,129 @@ | ||
package com.wish.bunny.wish | ||
|
||
import android.app.DatePickerDialog | ||
import android.graphics.Color | ||
import android.os.Bundle | ||
import android.text.Html | ||
import android.view.View | ||
import android.widget.Button | ||
import android.widget.TextView | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.core.content.ContextCompat | ||
import com.wish.bunny.R | ||
import java.text.SimpleDateFormat | ||
import java.util.Calendar | ||
import java.util.Locale | ||
|
||
class WishInsertActivity : AppCompatActivity() { | ||
private val btnOpenCalendar: Button by lazy { findViewById<Button>(R.id.btnOpenCalendar) } | ||
private val tvSelectedDate: TextView by lazy { findViewById<TextView>(R.id.tvSelectedDate) } | ||
private val selectedDate: Calendar = Calendar.getInstance() | ||
private val selectedButtons: MutableList<Button> = mutableListOf() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_insert) | ||
|
||
val button1: Button = findViewById(R.id.button1) | ||
val button2: Button = findViewById(R.id.button2) | ||
val button3: Button = findViewById(R.id.button3) | ||
|
||
val pinkColor = ContextCompat.getColor(this, R.color.pink) | ||
val changeTextColor = ContextCompat.getColor(this, R.color.white) | ||
val transparentColor = ContextCompat.getColor(this, R.color.ivory) | ||
val originalTextColor = ContextCompat.getColor(this, R.color.black) // 원래의 글자색 저장 | ||
|
||
button1.setOnClickListener { | ||
button1.setBackgroundColor(pinkColor) // 핑크색으로 변경 | ||
button1.setTextColor(changeTextColor) // 글자색을 원래대로 | ||
button2.setBackgroundColor(transparentColor) // 다른 버튼은 원래 색으로 | ||
button2.setTextColor(originalTextColor) | ||
button3.setBackgroundColor(transparentColor) | ||
button3.setTextColor(originalTextColor) | ||
} | ||
|
||
button2.setOnClickListener { | ||
button2.setBackgroundColor(pinkColor) | ||
button2.setTextColor(changeTextColor) // 글자색을 원래대로 | ||
button1.setBackgroundColor(transparentColor) // 다른 버튼은 원래 색으로 | ||
button1.setTextColor(originalTextColor) | ||
button3.setBackgroundColor(transparentColor) | ||
button3.setTextColor(originalTextColor) | ||
} | ||
|
||
button3.setOnClickListener { | ||
button3.setBackgroundColor(pinkColor) | ||
button3.setTextColor(changeTextColor) // 글자색을 원래대로 | ||
button1.setBackgroundColor(transparentColor) // 다른 버튼은 원래 색으로 | ||
button1.setTextColor(originalTextColor) | ||
button2.setBackgroundColor(transparentColor) | ||
button2.setTextColor(originalTextColor) | ||
} | ||
} | ||
|
||
// 클릭 이벤트 핸들러 | ||
fun onCalendarButtonClick(view: View) { | ||
openDatePickerDialog() | ||
} | ||
|
||
private fun openDatePickerDialog() { | ||
val datePickerDialog = DatePickerDialog( | ||
this, | ||
dateSetListener, | ||
selectedDate[Calendar.YEAR], | ||
selectedDate[Calendar.MONTH], | ||
selectedDate[Calendar.DAY_OF_MONTH] | ||
) | ||
datePickerDialog.show() | ||
} | ||
|
||
private val dateSetListener = | ||
DatePickerDialog.OnDateSetListener { _, year, month, dayOfMonth -> | ||
selectedDate[Calendar.YEAR] = year | ||
selectedDate[Calendar.MONTH] = month | ||
selectedDate[Calendar.DAY_OF_MONTH] = dayOfMonth | ||
updateSelectedDate() | ||
} | ||
|
||
private fun updateSelectedDate() { | ||
val dateFormat = SimpleDateFormat("yyyy년 MM월 dd일 EEEE까지", Locale.getDefault()) | ||
val formattedDate = dateFormat.format(selectedDate.time) | ||
tvSelectedDate.text = formattedDate | ||
} | ||
|
||
// 해시태그 버튼 클릭 이벤트 처리 | ||
fun onHashtagButtonClick(view: View) { | ||
val clickedButton = view as Button | ||
|
||
// 이미 선택된 버튼인지 확인 | ||
if (selectedButtons.contains(clickedButton)) { | ||
// 이미 선택된 경우, 선택 해제 | ||
selectedButtons.remove(clickedButton) | ||
updateButtonState(clickedButton, isSelected = false) | ||
} else { | ||
// 선택되지 않은 경우, 최대 선택 개수 확인 후 선택 | ||
if (selectedButtons.size < 2) { | ||
selectedButtons.add(clickedButton) | ||
updateButtonState(clickedButton, isSelected = true) | ||
} | ||
} | ||
} | ||
|
||
// 버튼의 선택 여부에 따라 상태 업데이트하는 함수 | ||
private fun updateButtonState(button: Button, isSelected: Boolean) { | ||
val pinkColor = ContextCompat.getColor(this, R.color.pink) | ||
val transparentColor = ContextCompat.getColor(this, R.color.ivory) | ||
|
||
button.isSelected = isSelected | ||
|
||
if (isSelected) { | ||
// 선택된 경우 | ||
button.setTextColor(Color.WHITE) | ||
button.setBackgroundColor(pinkColor) | ||
} else { | ||
// 선택 해제된 경우 | ||
button.setTextColor(Color.BLACK) | ||
button.setBackgroundColor(transparentColor) | ||
} | ||
} | ||
} |
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,86 @@ | ||
package com.wish.bunny.wish | ||
|
||
import android.os.Bundle | ||
import android.util.Log | ||
import android.widget.Toast | ||
import androidx.appcompat.app.AppCompatActivity | ||
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.sample.SampleService | ||
import com.wish.bunny.sample.domain.Sample | ||
import com.wish.bunny.wish.domain.Wish | ||
import com.wish.bunny.wish.domain.WishItem | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.GlobalScope | ||
import kotlinx.coroutines.launch | ||
import retrofit2.Call | ||
import retrofit2.Callback | ||
import retrofit2.Response | ||
|
||
|
||
class WishList : AppCompatActivity() { | ||
|
||
private lateinit var binding: ActivityWishListBinding | ||
private var adapter: CustomAdapter? = null | ||
// private var wishList = listOf<CustomAdapter.WishModel>() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = ActivityWishListBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
// setRecyclerView() | ||
loadWishList() //레트로핏 테스트 | ||
} | ||
private fun loadWishList(){ | ||
val retrofitAPI = RetrofitConnection.getInstance().create(WishService::class.java) | ||
retrofitAPI.getWishList().enqueue(object : Callback<List<WishItem>> { | ||
override fun onResponse(call: Call<List<WishItem>>, response: Response<List<WishItem>>) { | ||
// 성공 시 처리 | ||
val wishItemList = response.body() | ||
|
||
if (wishItemList != null) { | ||
Log.d("WishList", "불러오기 성공: ${wishItemList.size} 개의 아이템") | ||
updateUI(wishItemList) | ||
Log.d("WishList", wishItemList.toString()) | ||
|
||
} else { | ||
Log.d("WishList", "서버 응답이 null입니다.") | ||
} | ||
} | ||
|
||
override fun onFailure(call: Call<List<WishItem>>, t: Throwable) { | ||
Log.d("WishList", "불러오기 실패: ${t.message}") | ||
// TODO: 실패 시 처리 구현 | ||
} | ||
}) | ||
} | ||
|
||
|
||
private fun updateUI(wishItemList: List<WishItem>) { | ||
adapter = CustomAdapter(this, wishItemList) | ||
binding.wishListRecyclerView.adapter = adapter | ||
binding.wishListRecyclerView.layoutManager = LinearLayoutManager(this) | ||
} | ||
|
||
|
||
private fun getAllWishList(){ | ||
Thread{ | ||
// wishList = ArrayList(wishDAO.getAll()) | ||
setRecyclerView() | ||
}.start() | ||
} | ||
|
||
private fun setRecyclerView() { | ||
//adapter = CustomAdapter(this, wishList) | ||
binding.wishListRecyclerView.adapter = adapter | ||
binding.wishListRecyclerView.layoutManager = LinearLayoutManager(this) | ||
} | ||
|
||
override fun onRestart() { | ||
super.onRestart() | ||
//getAllWishList() | ||
} | ||
} |
Oops, something went wrong.