Skip to content

Commit

Permalink
Merge pull request #12 from WishBunny/feat/#1
Browse files Browse the repository at this point in the history
Feat/#1 위시리스트 등록 화면 UI 구현
  • Loading branch information
sangeun99 authored Jan 23, 2024
2 parents 5c4cc90 + f753439 commit 5723c7b
Show file tree
Hide file tree
Showing 26 changed files with 859 additions and 22 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.11.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.ar.sceneform:filament-android:1.17.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
Expand Down
35 changes: 19 additions & 16 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
xmlns:tools="http://schemas.android.com/tools">
<!-- 인터넷 사용 권한 설정 -->
<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:name=".GlobalApplication"
android:allowBackup="true"
Expand All @@ -18,31 +20,32 @@
tools:targetApi="31">
<activity
android:name=".sample.SampleActivity"
android:exported="true">
<!-- <intent-filter>
<action android:name="android.intent.action.MAIN" />
android:exported="false">
<!-- <intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter> -->
</intent-filter>-->
</activity>
<activity
android:name=".home.LoginActivity"
android:exported="true">
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
android:exported="false">
<!-- <intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>-->
</activity>
<activity
android:name=".MainActivity"
android:name=".wish.WishList"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.kakao.sdk.auth.AuthCodeHandlerActivity"
android:name=".MainActivity"
android:exported="true">

<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/wish/bunny/GlobalApplication.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.wish.bunny

import android.app.Application
import com.kakao.sdk.common.KakaoSdk
import com.wish.bunny.BuildConfig.NATIVE_APP_KEY
/*import com.kakao.sdk.common.KakaoSdk
import com.wish.bunny.BuildConfig.NATIVE_APP_KEY*/

/**
작성자: 엄상은
Expand All @@ -12,6 +12,6 @@ class GlobalApplication : Application() {
override fun onCreate() {
super.onCreate()
// Kakao SDK 초기화
KakaoSdk.init(this, "${NATIVE_APP_KEY}")
// KakaoSdk.init(this, "${NATIVE_APP_KEY}")
}
}
8 changes: 6 additions & 2 deletions app/src/main/java/com/wish/bunny/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.wish.bunny

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.google.android.material.bottomnavigation.BottomNavigationView
import androidx.appcompat.app.AppCompatActivity
import android.util.Log
import com.kakao.sdk.common.util.Utility
import com.wish.bunny.databinding.ActivityMainBinding
import com.wish.bunny.friend.FriendFragment
import com.wish.bunny.home.HomeFragment
Expand All @@ -13,6 +15,8 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater) // 뷰 바인딩
setContentView(binding.root)
var keyhash = Utility.getKeyHash(this)
Log.d("MainActivity", keyhash)

binding.bottomNavi.run { setOnNavigationItemSelectedListener {
when(it.itemId) {
Expand Down
58 changes: 58 additions & 0 deletions app/src/main/java/com/wish/bunny/wish/CustomAdapter.kt
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()}"
}
}
}
129 changes: 129 additions & 0 deletions app/src/main/java/com/wish/bunny/wish/WishInsert.kt
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)
}
}
}
86 changes: 86 additions & 0 deletions app/src/main/java/com/wish/bunny/wish/WishList.kt
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()
}
}
Loading

0 comments on commit 5723c7b

Please sign in to comment.