Skip to content

Commit

Permalink
feat: Setting 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
inseonyun committed Aug 8, 2023
1 parent 0dad5d5 commit e84f602
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 1 deletion.
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,13 +6,40 @@ import android.os.Bundle
import android.view.MenuItem
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() {
Expand All @@ -22,6 +49,16 @@ class SettingActivity : BindingActivity<ActivitySettingBinding>(R.layout.activit
supportActionBar?.setDisplayHomeAsUpEnabled(true)
}

private fun initSettingRecyclerView() {
binding.rvSetting.hasFixedSize()
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 -> {
Expand All @@ -33,6 +70,9 @@ class SettingActivity : BindingActivity<ActivitySettingBinding>(R.layout.activit
}

companion object {
fun getIntent(context: Context): Intent = Intent(context, SettingActivity::class.java)
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
)
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 @@ -34,4 +34,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 @@ -161,6 +161,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

0 comments on commit e84f602

Please sign in to comment.