Skip to content

Commit

Permalink
[FEAT] 마이페이지, 프로필 추가 완
Browse files Browse the repository at this point in the history
  • Loading branch information
jung0115 committed Jun 10, 2023
1 parent 0b0d3ae commit 03c4195
Show file tree
Hide file tree
Showing 18 changed files with 568 additions and 27 deletions.
115 changes: 114 additions & 1 deletion app/src/main/java/com/nbit/Idear/mypage/AddProfileActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<MoodKeywordItem>
private lateinit var moodKeywordAdapter: MoodKeywordAdapter

// mbti recycler
private lateinit var mbtiItems: MutableList<MbtiItem>
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("세심한"), 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<MoodKeywordItem>()
moodKeywordAdapter = MoodKeywordAdapter(
this,
selectMoodKeyword = {
selectMoodKeyword()
}
)
binding.recyclerMoodKeyword.layoutManager = GridLayoutManager(this, 5)
binding.recyclerMoodKeyword.adapter = moodKeywordAdapter
binding.recyclerMoodKeyword.isNestedScrollingEnabled = false
moodKeywordAdapter.items = moodKeywordItems

mbtiItems = mutableListOf<MbtiItem>()
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()
}
}
89 changes: 89 additions & 0 deletions app/src/main/java/com/nbit/Idear/mypage/mbtiAdapter/MbtiAdapter.kt
Original file line number Diff line number Diff line change
@@ -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<MbtiAdapter.MbtiViewHolder>(){

var items = mutableListOf<MbtiItem>()

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()
}
}
Original file line number Diff line number Diff line change
@@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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<MoodKeywordAdapter.MoodKeywordViewHolder>(){

var items = mutableListOf<ProfileListItem>()
var items = mutableListOf<MoodKeywordItem>()

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) :
MoodKeywordAdapter.MoodKeywordViewHolder {
Expand All @@ -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()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.nbit.Idear.mypage.moodKeywordAdapter

data class MoodKeywordItem (
val moodKeyword: String,
var isSelected: Boolean = false,
)
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/shape_logout_btn.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<solid android:color="@color/idear_extra_light_green"/>
<corners
android:radius="8dp" />

</shape>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/shape_mood_profile_green.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<solid
android:color="@color/idear_green"/>

<corners
android:radius="8dp" />

</shape>
15 changes: 15 additions & 0 deletions app/src/main/res/drawable/shape_select_formal.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 높임말 선택 버튼 -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<solid
android:color="@color/idear_green"/>

<stroke android:width="1dp"
android:color="@color/idear_green"/>

<corners
android:radius="8dp" />

</shape>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/shape_select_mbti.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<solid
android:color="@color/idear_green"/>

<corners
android:radius="8dp" />

</shape>
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/shape_toggle_mbti_border.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<solid
android:color="@color/white"/>
<stroke android:width="1dp" android:color="@color/idear_gray_200"/>

<corners
android:radius="8dp" />

</shape>
15 changes: 15 additions & 0 deletions app/src/main/res/drawable/shape_unselect_formal.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 높임말 해제 버튼 -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<solid
android:color="@color/white"/>

<stroke android:width="1dp"
android:color="@color/idear_gray_500"/>

<corners
android:radius="8dp" />

</shape>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/shape_unselect_mbti.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<solid
android:color="@color/idear_gray_500"/>

<corners
android:radius="8dp" />

</shape>
Loading

0 comments on commit 03c4195

Please sign in to comment.