From 03c41957ef2842408d890acfe73485bb052e0e98 Mon Sep 17 00:00:00 2001 From: jung0115 Date: Sun, 11 Jun 2023 03:56:48 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]=20=EB=A7=88=EC=9D=B4=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80,=20=ED=94=84=EB=A1=9C=ED=95=84=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=20=EC=99=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nbit/Idear/mypage/AddProfileActivity.kt | 115 +++++++++++- .../Idear/mypage/mbtiAdapter/MbtiAdapter.kt | 89 ++++++++++ .../nbit/Idear/mypage/mbtiAdapter/MbtiItem.kt | 8 + .../moodKeywordAdapter/MoodKeywordAdapter.kt | 30 +++- .../moodKeywordAdapter/MoodKeywordItem.kt | 6 + .../main/res/drawable/shape_logout_btn.xml | 9 + .../res/drawable/shape_mood_profile_green.xml | 11 ++ .../main/res/drawable/shape_select_formal.xml | 15 ++ .../main/res/drawable/shape_select_mbti.xml | 11 ++ .../res/drawable/shape_toggle_mbti_border.xml | 12 ++ .../res/drawable/shape_unselect_formal.xml | 15 ++ .../main/res/drawable/shape_unselect_mbti.xml | 11 ++ .../main/res/layout/activity_add_profile.xml | 165 +++++++++++++++++- app/src/main/res/layout/activity_main.xml | 2 +- .../res/layout/item_mood_keyword_profile.xml | 1 + app/src/main/res/layout/item_toggle_mbti.xml | 56 ++++++ .../main/res/layout/main_include_drawer.xml | 32 ++-- app/src/main/res/values/strings.xml | 7 + 18 files changed, 568 insertions(+), 27 deletions(-) create mode 100644 app/src/main/java/com/nbit/Idear/mypage/mbtiAdapter/MbtiAdapter.kt create mode 100644 app/src/main/java/com/nbit/Idear/mypage/mbtiAdapter/MbtiItem.kt create mode 100644 app/src/main/java/com/nbit/Idear/mypage/moodKeywordAdapter/MoodKeywordItem.kt create mode 100644 app/src/main/res/drawable/shape_logout_btn.xml create mode 100644 app/src/main/res/drawable/shape_mood_profile_green.xml create mode 100644 app/src/main/res/drawable/shape_select_formal.xml create mode 100644 app/src/main/res/drawable/shape_select_mbti.xml create mode 100644 app/src/main/res/drawable/shape_toggle_mbti_border.xml create mode 100644 app/src/main/res/drawable/shape_unselect_formal.xml create mode 100644 app/src/main/res/drawable/shape_unselect_mbti.xml create mode 100644 app/src/main/res/layout/item_toggle_mbti.xml diff --git a/app/src/main/java/com/nbit/Idear/mypage/AddProfileActivity.kt b/app/src/main/java/com/nbit/Idear/mypage/AddProfileActivity.kt index 1f35eb8..56b4922 100644 --- a/app/src/main/java/com/nbit/Idear/mypage/AddProfileActivity.kt +++ b/app/src/main/java/com/nbit/Idear/mypage/AddProfileActivity.kt @@ -2,20 +2,133 @@ package com.nbit.Idear.mypage import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import android.view.View +import androidx.recyclerview.widget.GridLayoutManager +import androidx.recyclerview.widget.LinearLayoutManager import com.nbit.Idear.R import com.nbit.Idear.databinding.ActivityAddProfileBinding -import com.nbit.Idear.databinding.ActivityMyPageBinding +import com.nbit.Idear.mypage.mbtiAdapter.MbtiAdapter +import com.nbit.Idear.mypage.mbtiAdapter.MbtiItem +import com.nbit.Idear.mypage.moodKeywordAdapter.MoodKeywordAdapter +import com.nbit.Idear.mypage.moodKeywordAdapter.MoodKeywordItem // 프로필 추가 정보 class AddProfileActivity : AppCompatActivity() { // ViewBinding Setting lateinit var binding: ActivityAddProfileBinding + // 분위기 카테고리 recycler + private lateinit var moodKeywordItems: MutableList + private lateinit var moodKeywordAdapter: MoodKeywordAdapter + + // mbti recycler + private lateinit var mbtiItems: MutableList + private lateinit var mbtiAdapter: MbtiAdapter + + // 내용 입력 완료 + private var selectKeyword: Boolean = false + private var selectFormal: Boolean = false + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // ViewBinding Setting binding = ActivityAddProfileBinding.inflate(layoutInflater) setContentView(binding.root) + + // recyclerview 세팅 + initRecycler() + + moodKeywordItems = mutableListOf(MoodKeywordItem("깔끔한"), MoodKeywordItem("다정한"), + MoodKeywordItem("냉철한"), MoodKeywordItem("귀여운"), MoodKeywordItem("친근한"), MoodKeywordItem("발랄한"), + MoodKeywordItem("세련된"), MoodKeywordItem("공손한"), MoodKeywordItem("세심한"), MoodKeywordItem("기타")) + moodKeywordAdapter.items = moodKeywordItems + moodKeywordAdapter.notifyDataSetChanged() + + // 존댓말 선택 + binding.linearFormalTop.setOnClickListener(View.OnClickListener { + binding.linearFormalLow.setBackgroundResource(R.drawable.shape_unselect_formal) + binding.textFormalLow.setTextColor(getColor(R.color.idear_gray_800)) + + binding.linearFormalTop.setBackgroundResource(R.drawable.shape_select_formal) + binding.textFormalTop.setTextColor(getColor(R.color.white)) + + selectFormal = true + checkAllInput() + }) + + // 반말 선택 + binding.linearFormalLow.setOnClickListener(View.OnClickListener { + binding.linearFormalTop.setBackgroundResource(R.drawable.shape_unselect_formal) + binding.textFormalTop.setTextColor(getColor(R.color.idear_gray_800)) + + binding.linearFormalLow.setBackgroundResource(R.drawable.shape_select_formal) + binding.textFormalLow.setTextColor(getColor(R.color.white)) + + selectFormal = true + checkAllInput() + }) + + addMbti(MbtiItem("E", "I", true)) + addMbti(MbtiItem("N", "S", true)) + addMbti(MbtiItem("F", "T", true)) + addMbti(MbtiItem("P", "J", true)) + + // 추가하기 버튼 + binding.btnAddProfileDone.setOnClickListener { + if(selectFormal && selectKeyword) { + finish() + } + } + } + + // recyclerview 세팅 + private fun initRecycler() { + moodKeywordItems = mutableListOf() + moodKeywordAdapter = MoodKeywordAdapter( + this, + selectMoodKeyword = { + selectMoodKeyword() + } + ) + binding.recyclerMoodKeyword.layoutManager = GridLayoutManager(this, 5) + binding.recyclerMoodKeyword.adapter = moodKeywordAdapter + binding.recyclerMoodKeyword.isNestedScrollingEnabled = false + moodKeywordAdapter.items = moodKeywordItems + + mbtiItems = mutableListOf() + mbtiAdapter = MbtiAdapter( + this + ) + binding.recyclerToggleMbti.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false) + binding.recyclerToggleMbti.adapter = mbtiAdapter + binding.recyclerToggleMbti.isNestedScrollingEnabled = false + mbtiAdapter.items = mbtiItems + } + + private fun addMoodKeyword(item: MoodKeywordItem) { + moodKeywordItems.apply { + add(item) + } + moodKeywordAdapter.notifyDataSetChanged() + } + + private fun addMbti(item: MbtiItem) { + mbtiItems.apply { + add(item) + } + mbtiAdapter.notifyDataSetChanged() + } + + private fun checkAllInput() { + if(selectFormal && selectKeyword) { + binding.btnAddProfileDone.setBackgroundColor(getColor(R.color.idear_green)) + binding.btnAddProfileDone.setTextColor(getColor(R.color.white)) + } + } + + private fun selectMoodKeyword() { + selectKeyword = true + checkAllInput() } } \ No newline at end of file diff --git a/app/src/main/java/com/nbit/Idear/mypage/mbtiAdapter/MbtiAdapter.kt b/app/src/main/java/com/nbit/Idear/mypage/mbtiAdapter/MbtiAdapter.kt new file mode 100644 index 0000000..f65889c --- /dev/null +++ b/app/src/main/java/com/nbit/Idear/mypage/mbtiAdapter/MbtiAdapter.kt @@ -0,0 +1,89 @@ +package com.nbit.Idear.mypage.mbtiAdapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.core.content.ContextCompat.getColor +import androidx.recyclerview.widget.RecyclerView +import com.nbit.Idear.R +import com.nbit.Idear.databinding.ItemMoodKeywordProfileBinding +import com.nbit.Idear.databinding.ItemToggleMbtiBinding +import com.nbit.Idear.mypage.moodKeywordAdapter.MoodKeywordAdapter +import com.nbit.Idear.mypage.moodKeywordAdapter.MoodKeywordItem + +// mbti 토글 어댑터 +class MbtiAdapter ( + private val context: Context +) : + RecyclerView.Adapter(){ + + var items = mutableListOf() + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) : + MbtiAdapter.MbtiViewHolder { + + val view = LayoutInflater.from(context).inflate(R.layout.item_toggle_mbti, parent, false) + + return MbtiViewHolder(ItemToggleMbtiBinding.bind(view)) + } + + override fun getItemCount(): Int = items.size + + override fun onBindViewHolder(holder: MbtiAdapter.MbtiViewHolder, position: Int) { + holder.bind(items[position], position) + } + + inner class MbtiViewHolder(private val binding: ItemToggleMbtiBinding) : + RecyclerView.ViewHolder(binding.root) { + + fun bind(item: MbtiItem, position: Int) { + binding.textMbtiTopSelect.text = item.topMbti + binding.textMbtiTopUnselect.text = item.topMbti + + binding.textMbtiBottomSelect.text = item.bottomMbti + binding.textMbtiTopUnselect.text = item.bottomMbti + + // mbti 선택 안 됨 + if(item.unselect) { + binding.textMbtiTopSelect.setBackgroundResource(R.drawable.shape_unselect_mbti) + binding.textMbtiTopSelect.setTextColor(getColor(context, R.color.white)) + + binding.textMbtiBottomSelect.visibility = View.GONE + } + // 위쪽 mbti 선택됨 + else if(item.isSelectTop) { + binding.textMbtiTopSelect.setBackgroundResource(R.drawable.shape_select_mbti) + binding.textMbtiTopSelect.setTextColor(getColor(context, R.color.white)) + + binding.textMbtiTopSelect.visibility = View.VISIBLE + binding.textMbtiBottomSelect.visibility = View.GONE + } + // 아래쪽 mbti 선택됨 + else { + binding.textMbtiBottomSelect.setBackgroundResource(R.drawable.shape_select_mbti) + binding.textMbtiBottomSelect.setTextColor(getColor(context, R.color.white)) + + binding.textMbtiTopSelect.visibility = View.GONE + binding.textMbtiBottomSelect.visibility = View.VISIBLE + } + + binding.textMbtiTopUnselect.setOnClickListener(View.OnClickListener { + item.isSelectTop = true + select(position) + }) + + binding.textMbtiBottomUnselect.setOnClickListener(View.OnClickListener { + item.isSelectTop = false + select(position) + }) + } + } + + fun select(position: Int) { + for(i in 0..(items.size - 1)) { + items[i].unselect = false + } + notifyDataSetChanged() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/nbit/Idear/mypage/mbtiAdapter/MbtiItem.kt b/app/src/main/java/com/nbit/Idear/mypage/mbtiAdapter/MbtiItem.kt new file mode 100644 index 0000000..dc4adc7 --- /dev/null +++ b/app/src/main/java/com/nbit/Idear/mypage/mbtiAdapter/MbtiItem.kt @@ -0,0 +1,8 @@ +package com.nbit.Idear.mypage.mbtiAdapter + +data class MbtiItem ( + val topMbti: String, + val bottomMbti: String, + var isSelectTop: Boolean, + var unselect: Boolean = true, +) \ No newline at end of file diff --git a/app/src/main/java/com/nbit/Idear/mypage/moodKeywordAdapter/MoodKeywordAdapter.kt b/app/src/main/java/com/nbit/Idear/mypage/moodKeywordAdapter/MoodKeywordAdapter.kt index dade737..18b1317 100644 --- a/app/src/main/java/com/nbit/Idear/mypage/moodKeywordAdapter/MoodKeywordAdapter.kt +++ b/app/src/main/java/com/nbit/Idear/mypage/moodKeywordAdapter/MoodKeywordAdapter.kt @@ -11,11 +11,12 @@ import com.nbit.Idear.mypage.profileAdapter.ProfileListAdapter import com.nbit.Idear.mypage.profileAdapter.ProfileListItem class MoodKeywordAdapter ( - private val context: Context + private val context: Context, + private val selectMoodKeyword: () -> Unit ) : RecyclerView.Adapter(){ - var items = mutableListOf() + var items = mutableListOf() override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) : MoodKeywordAdapter.MoodKeywordViewHolder { @@ -29,13 +30,36 @@ class MoodKeywordAdapter ( override fun onBindViewHolder(holder: MoodKeywordAdapter.MoodKeywordViewHolder, position: Int) { holder.bind(items[position]) + + holder.itemView.setOnClickListener { + items[position].isSelected = true + allUncheck(position) + + selectMoodKeyword() + } } inner class MoodKeywordViewHolder(private val binding: ItemMoodKeywordProfileBinding) : RecyclerView.ViewHolder(binding.root) { - fun bind(item: ProfileListItem) { + fun bind(item: MoodKeywordItem) { + binding.textMoodKeyword.text = item.moodKeyword + + if(item.isSelected) { + binding.linearMoodKeyword.setBackgroundResource(R.drawable.shape_mood_profile_green) + } + else { + binding.linearMoodKeyword.setBackgroundResource(R.drawable.shape_mood_profile_gray) + } + } + } + fun allUncheck(position: Int) { + for(i in 0..(items.size - 1)) { + if(i != position) { + items[i].isSelected = false + } } + notifyDataSetChanged() } } \ No newline at end of file diff --git a/app/src/main/java/com/nbit/Idear/mypage/moodKeywordAdapter/MoodKeywordItem.kt b/app/src/main/java/com/nbit/Idear/mypage/moodKeywordAdapter/MoodKeywordItem.kt new file mode 100644 index 0000000..8a2505b --- /dev/null +++ b/app/src/main/java/com/nbit/Idear/mypage/moodKeywordAdapter/MoodKeywordItem.kt @@ -0,0 +1,6 @@ +package com.nbit.Idear.mypage.moodKeywordAdapter + +data class MoodKeywordItem ( + val moodKeyword: String, + var isSelected: Boolean = false, +) \ No newline at end of file diff --git a/app/src/main/res/drawable/shape_logout_btn.xml b/app/src/main/res/drawable/shape_logout_btn.xml new file mode 100644 index 0000000..867d9c7 --- /dev/null +++ b/app/src/main/res/drawable/shape_logout_btn.xml @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/shape_mood_profile_green.xml b/app/src/main/res/drawable/shape_mood_profile_green.xml new file mode 100644 index 0000000..466731d --- /dev/null +++ b/app/src/main/res/drawable/shape_mood_profile_green.xml @@ -0,0 +1,11 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/shape_select_formal.xml b/app/src/main/res/drawable/shape_select_formal.xml new file mode 100644 index 0000000..3fbe5fb --- /dev/null +++ b/app/src/main/res/drawable/shape_select_formal.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/shape_select_mbti.xml b/app/src/main/res/drawable/shape_select_mbti.xml new file mode 100644 index 0000000..466731d --- /dev/null +++ b/app/src/main/res/drawable/shape_select_mbti.xml @@ -0,0 +1,11 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/shape_toggle_mbti_border.xml b/app/src/main/res/drawable/shape_toggle_mbti_border.xml new file mode 100644 index 0000000..3553b69 --- /dev/null +++ b/app/src/main/res/drawable/shape_toggle_mbti_border.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/app/src/main/res/drawable/shape_unselect_formal.xml b/app/src/main/res/drawable/shape_unselect_formal.xml new file mode 100644 index 0000000..216f141 --- /dev/null +++ b/app/src/main/res/drawable/shape_unselect_formal.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/shape_unselect_mbti.xml b/app/src/main/res/drawable/shape_unselect_mbti.xml new file mode 100644 index 0000000..ed0edae --- /dev/null +++ b/app/src/main/res/drawable/shape_unselect_mbti.xml @@ -0,0 +1,11 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_add_profile.xml b/app/src/main/res/layout/activity_add_profile.xml index f8b3cde..4b2f25c 100644 --- a/app/src/main/res/layout/activity_add_profile.xml +++ b/app/src/main/res/layout/activity_add_profile.xml @@ -78,13 +78,176 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +