Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[설정 뷰] 설정 뷰 기능 작업 #269

Merged
merged 5 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.created.team201.presentation.accountSetting

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.MenuItem
import com.created.team201.R
import com.created.team201.databinding.ActivityAccountSettingBinding
import com.created.team201.presentation.common.BindingActivity
Expand All @@ -9,5 +12,31 @@ class AccountSettingActivity :
BindingActivity<ActivityAccountSettingBinding>(R.layout.activity_account_setting) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

initActionBar()
}

private fun initActionBar() {
setSupportActionBar(binding.tbAccountSetting)
supportActionBar?.setHomeActionContentDescription(R.string.toolbar_back_text)
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_back)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean =
when (item.itemId) {
android.R.id.home -> {
finish()
true
}

else -> false
}

companion object {
fun getIntent(context: Context): Intent =
Intent(context, AccountSettingActivity::class.java).also {
it.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.fragment.app.viewModels
import com.created.team201.R
import com.created.team201.databinding.FragmentMyPageBinding
import com.created.team201.presentation.common.BindingFragment
import com.created.team201.presentation.setting.SettingActivity

class MyPageFragment : BindingFragment<FragmentMyPageBinding>(R.layout.fragment_my_page) {
private val myPageViewModel: MyPageViewModel by viewModels {
Expand All @@ -29,6 +30,7 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(R.layout.fragment_
when (it.itemId) {
R.id.menu_my_page_setting -> {
// 설정 뷰 이동
startActivity(SettingActivity.getIntent(requireContext()))
true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ProfileActivity : BindingActivity<ActivityProfileBinding>(R.layout.activit

private fun getDividerItemDecoration(): DividerItemDecoration {
val dividerItemDecoration = DividerItemDecoration(this, LinearLayout.VERTICAL)
ContextCompat.getDrawable(this, R.drawable.divider_study_list)?.let {
ContextCompat.getDrawable(this, R.drawable.divider_recyclerview_line)?.let {
dividerItemDecoration.setDrawable(it)
}
return dividerItemDecoration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,87 @@
package com.created.team201.presentation.setting

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.MenuItem
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.DividerItemDecoration
import com.created.team201.R
import com.created.team201.databinding.ActivitySettingBinding
import com.created.team201.presentation.accountSetting.AccountSettingActivity
import com.created.team201.presentation.common.BindingActivity
import com.created.team201.presentation.setting.adapter.SettingAdapter
import com.created.team201.presentation.setting.model.SettingType
import com.created.team201.presentation.setting.model.SettingUiModel

class SettingActivity : BindingActivity<ActivitySettingBinding>(R.layout.activity_setting) {
private val settingItems: List<SettingUiModel> by lazy {
resources.getStringArray(R.array.settingItems).mapIndexed { index, setting ->
SettingUiModel(index.toLong(), setting)
}
}

private val onSettingItemClick: SettingClickListener by lazy {
object : SettingClickListener {
override fun onClick(itemId: Long) {
when (SettingType.valueOf(itemId)) {
SettingType.NOTIFICATION -> {}
SettingType.ACCOUNT -> {
navigateToAccountSetting()
}

SettingType.POLICY -> {}
SettingType.LOGOUT -> {}
}
}
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

initActionBar()
initSettingRecyclerView()
}

private fun initActionBar() {
setSupportActionBar(binding.tbSetting)
supportActionBar?.setHomeActionContentDescription(R.string.toolbar_back_text)
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_back)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
}

private fun initSettingRecyclerView() {
binding.rvSetting.hasFixedSize()

val decoration = DividerItemDecoration(this, DividerItemDecoration.VERTICAL)
ContextCompat.getDrawable(this, R.drawable.divider_recyclerview_line)?.let {
decoration.setDrawable(it)
}

binding.rvSetting.addItemDecoration(decoration)
binding.rvSetting.adapter =
SettingAdapter(onSettingItemClick).also { it.submitList(settingItems) }
}

private fun navigateToAccountSetting() {
startActivity(AccountSettingActivity.getIntent(this))
}

override fun onOptionsItemSelected(item: MenuItem): Boolean =
when (item.itemId) {
android.R.id.home -> {
finish()
true
}

else -> false
}

companion object {
fun getIntent(context: Context): Intent =
Intent(context, SettingActivity::class.java).also {
it.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.created.team201.presentation.setting

interface SettingClickListener {
fun onClick(itemId: Long)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.created.team201.presentation.setting.adapter

import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import com.created.team201.presentation.setting.SettingClickListener
import com.created.team201.presentation.setting.model.SettingUiModel

class SettingAdapter(
private val settingClickListener: SettingClickListener
) : ListAdapter<SettingUiModel, SettingViewHolder>(SettingDiffUtil) {

init {
setHasStableIds(true)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SettingViewHolder {
return SettingViewHolder(parent, settingClickListener)
}

override fun onBindViewHolder(holder: SettingViewHolder, position: Int) {
holder.bind(getItem(position))
}

override fun getItemId(position: Int): Long = getItem(position).id

companion object {
private val SettingDiffUtil = object : DiffUtil.ItemCallback<SettingUiModel>() {
override fun areItemsTheSame(
oldItem: SettingUiModel,
newItem: SettingUiModel,
): Boolean =
oldItem.id == newItem.id

override fun areContentsTheSame(
oldItem: SettingUiModel,
newItem: SettingUiModel,
): Boolean =
oldItem == newItem
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.created.team201.presentation.setting.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.created.team201.R
import com.created.team201.databinding.ItemSettingBinding
import com.created.team201.presentation.setting.SettingClickListener
import com.created.team201.presentation.setting.model.SettingUiModel

class SettingViewHolder(
parent: ViewGroup,
settingClickListener: SettingClickListener
) : RecyclerView.ViewHolder(
LayoutInflater.from(parent.context).inflate(R.layout.item_setting, parent, false)
) {
private val binding = ItemSettingBinding.bind(itemView)

init {
itemView.setOnClickListener { settingClickListener.onClick(itemId) }
}

fun bind(setting: SettingUiModel) {
binding.tvSettingTitle.text = setting.title
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.created.team201.presentation.setting.model

enum class SettingType(val itemId: Long) {
NOTIFICATION(0L),
ACCOUNT(1L),
POLICY(2L),
LOGOUT(3L);

companion object {
fun valueOf(itemId: Long): SettingType =
when (itemId) {
0L -> NOTIFICATION
1L -> ACCOUNT
2L -> POLICY
3L -> LOGOUT
else -> throw IllegalArgumentException()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.created.team201.presentation.setting.model

data class SettingUiModel(
val id: Long,
val title: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class StudyListFragment : BindingFragment<FragmentStudyListBinding>(R.layout.fra

private fun setUpStudyListSettings() {
val dividerItemDecoration = DividerItemDecoration(context, VERTICAL)
getDrawable(requireContext(), R.drawable.divider_study_list)?.let {
getDrawable(requireContext(), R.drawable.divider_recyclerview_line)?.let {
dividerItemDecoration.setDrawable(it)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class StudyManageViewHolder(

private fun setUpStudyManageList() {
val dividerItemDecoration = DividerItemDecoration(parent.context, VERTICAL)
getDrawable(parent.context, R.drawable.divider_study_list)?.let {
getDrawable(parent.context, R.drawable.divider_recyclerview_line)?.let {
dividerItemDecoration.setDrawable(it)
}

Expand Down
8 changes: 8 additions & 0 deletions android/app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@
<item>@string/study_list_item_week_format</item>
</string-array>

<!-- 설정 뷰 -->
<string-array name="settingItems">
<item>@string/setting_item_notification_title</item>
<item>@string/setting_item_account_title</item>
<item>@string/setting_item_policy</item>
<item>@string/setting_item_logout</item>
</string-array>

</resources>
4 changes: 4 additions & 0 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@

<!-- 설정 뷰 -->
<string name="setting_toolbar_title">설정</string>
<string name="setting_item_notification_title">알림 설정</string>
<string name="setting_item_account_title">계정 관리</string>
<string name="setting_item_policy">정책 및 약관</string>
<string name="setting_item_logout">로그아웃</string>

<!-- 계정 관리 뷰 -->
<string name="accountSetting_toolbar_title">계정 관리</string>
Expand Down