diff --git a/android/app/src/main/java/com/created/team201/presentation/accountSetting/AccountSettingActivity.kt b/android/app/src/main/java/com/created/team201/presentation/accountSetting/AccountSettingActivity.kt index f6e97db96..0a53dfcec 100644 --- a/android/app/src/main/java/com/created/team201/presentation/accountSetting/AccountSettingActivity.kt +++ b/android/app/src/main/java/com/created/team201/presentation/accountSetting/AccountSettingActivity.kt @@ -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 @@ -9,5 +12,31 @@ class AccountSettingActivity : BindingActivity(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 + } } } diff --git a/android/app/src/main/java/com/created/team201/presentation/setting/SettingActivity.kt b/android/app/src/main/java/com/created/team201/presentation/setting/SettingActivity.kt index a0e855670..a86f4d3bf 100644 --- a/android/app/src/main/java/com/created/team201/presentation/setting/SettingActivity.kt +++ b/android/app/src/main/java/com/created/team201/presentation/setting/SettingActivity.kt @@ -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(R.layout.activity_setting) { + private val settingItems: List 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() { @@ -22,6 +49,16 @@ class SettingActivity : BindingActivity(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 -> { @@ -33,6 +70,9 @@ class SettingActivity : BindingActivity(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 + } } } diff --git a/android/app/src/main/java/com/created/team201/presentation/setting/SettingClickListener.kt b/android/app/src/main/java/com/created/team201/presentation/setting/SettingClickListener.kt new file mode 100644 index 000000000..af951a3ec --- /dev/null +++ b/android/app/src/main/java/com/created/team201/presentation/setting/SettingClickListener.kt @@ -0,0 +1,5 @@ +package com.created.team201.presentation.setting + +interface SettingClickListener { + fun onClick(itemId: Long) +} diff --git a/android/app/src/main/java/com/created/team201/presentation/setting/adapter/SettingAdapter.kt b/android/app/src/main/java/com/created/team201/presentation/setting/adapter/SettingAdapter.kt new file mode 100644 index 000000000..bfdc9ae6f --- /dev/null +++ b/android/app/src/main/java/com/created/team201/presentation/setting/adapter/SettingAdapter.kt @@ -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(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() { + override fun areItemsTheSame( + oldItem: SettingUiModel, + newItem: SettingUiModel, + ): Boolean = + oldItem.id == newItem.id + + override fun areContentsTheSame( + oldItem: SettingUiModel, + newItem: SettingUiModel, + ): Boolean = + oldItem == newItem + } + } +} diff --git a/android/app/src/main/java/com/created/team201/presentation/setting/adapter/SettingViewHolder.kt b/android/app/src/main/java/com/created/team201/presentation/setting/adapter/SettingViewHolder.kt new file mode 100644 index 000000000..d6b4295b4 --- /dev/null +++ b/android/app/src/main/java/com/created/team201/presentation/setting/adapter/SettingViewHolder.kt @@ -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 + } +} diff --git a/android/app/src/main/java/com/created/team201/presentation/setting/model/SettingType.kt b/android/app/src/main/java/com/created/team201/presentation/setting/model/SettingType.kt new file mode 100644 index 000000000..54f533e44 --- /dev/null +++ b/android/app/src/main/java/com/created/team201/presentation/setting/model/SettingType.kt @@ -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() + } + } +} diff --git a/android/app/src/main/java/com/created/team201/presentation/setting/model/SettingUiModel.kt b/android/app/src/main/java/com/created/team201/presentation/setting/model/SettingUiModel.kt new file mode 100644 index 000000000..e29b84f1f --- /dev/null +++ b/android/app/src/main/java/com/created/team201/presentation/setting/model/SettingUiModel.kt @@ -0,0 +1,6 @@ +package com.created.team201.presentation.setting.model + +data class SettingUiModel( + val id: Long, + val title: String +) diff --git a/android/app/src/main/res/values/arrays.xml b/android/app/src/main/res/values/arrays.xml index 5ad67f228..37cac432c 100644 --- a/android/app/src/main/res/values/arrays.xml +++ b/android/app/src/main/res/values/arrays.xml @@ -34,4 +34,12 @@ @string/study_list_item_week_format + + + @string/setting_item_notification_title + @string/setting_item_account_title + @string/setting_item_policy + @string/setting_item_logout + + diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index cb1dcb2db..b1145a12c 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -161,6 +161,10 @@ 설정 + 알림 설정 + 계정 관리 + 정책 및 약관 + 로그아웃 계정 관리