-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #269 from woowacourse-teams/AN/feature/253-setting…
…-inflate [설정 뷰] 설정 뷰 기능 작업
- Loading branch information
Showing
14 changed files
with
219 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
android/app/src/main/java/com/created/team201/presentation/setting/SettingActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
android/app/src/main/java/com/created/team201/presentation/setting/SettingClickListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
42 changes: 42 additions & 0 deletions
42
android/app/src/main/java/com/created/team201/presentation/setting/adapter/SettingAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...d/app/src/main/java/com/created/team201/presentation/setting/adapter/SettingViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
android/app/src/main/java/com/created/team201/presentation/setting/model/SettingType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
android/app/src/main/java/com/created/team201/presentation/setting/model/SettingUiModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters