forked from boostcampwm-2022/android04-BEEP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issues boostcampwm-2022#287 feat: setting builder를 이용하여 유동적인 화면 구성
- Loading branch information
Showing
11 changed files
with
212 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
features/ui-setting/src/main/java/com/lighthouse/features/setting/ext/SettingGroupExt.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,9 @@ | ||
package com.lighthouse.features.setting.ext | ||
|
||
import com.lighthouse.features.setting.model.SettingGroup | ||
|
||
internal fun settingGroup(block: SettingGroup.Builder.() -> Unit): SettingGroup { | ||
val builder = SettingGroup.Builder() | ||
builder.block() | ||
return builder.build() | ||
} |
9 changes: 9 additions & 0 deletions
9
features/ui-setting/src/main/java/com/lighthouse/features/setting/ext/SettingItemExt.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,9 @@ | ||
package com.lighthouse.features.setting.ext | ||
|
||
import com.lighthouse.features.setting.model.SettingItem | ||
|
||
internal fun settingItems(block: SettingItem.Builder.() -> Unit): List<SettingItem> { | ||
val builder = SettingItem.Builder() | ||
builder.block() | ||
return builder.build() | ||
} |
35 changes: 35 additions & 0 deletions
35
features/ui-setting/src/main/java/com/lighthouse/features/setting/model/SettingGroup.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,35 @@ | ||
package com.lighthouse.features.setting.model | ||
|
||
import com.lighthouse.core.android.utils.resource.UIText | ||
|
||
internal class SettingGroup(val title: UIText?, val items: List<SettingItem>) { | ||
|
||
class Builder { | ||
private var title: UIText? = null | ||
private val items = ArrayList<SettingItem>() | ||
|
||
fun setTitle(title: UIText?) = apply { | ||
this.title = title | ||
} | ||
|
||
fun addItem(item: SettingItem) = apply { | ||
items.add(item) | ||
} | ||
|
||
fun addButton(menu: SettingMenu) = apply { | ||
addItem(SettingItem.Button(menu)) | ||
} | ||
|
||
fun addStateButton(menu: SettingMenu, state: UIText = UIText.Empty) = apply { | ||
addItem(SettingItem.StateButton(menu, state)) | ||
} | ||
|
||
fun addStateSwitch(menu: SettingMenu, state: Boolean = false) = apply { | ||
addItem(SettingItem.StateSwitch(menu, state)) | ||
} | ||
|
||
fun build(): SettingGroup { | ||
return SettingGroup(title, items.toList()) | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
features/ui-setting/src/main/java/com/lighthouse/features/setting/model/SettingItem.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,63 @@ | ||
package com.lighthouse.features.setting.model | ||
|
||
import com.lighthouse.core.android.utils.resource.UIText | ||
|
||
internal sealed class SettingItem { | ||
|
||
data class GroupHeader(val uiText: UIText) : SettingItem() | ||
|
||
object Divider : SettingItem() | ||
|
||
data class Button(val menu: SettingMenu) : SettingItem() | ||
|
||
data class StateButton(val menu: SettingMenu, val state: UIText) : SettingItem() | ||
|
||
data class StateSwitch(val menu: SettingMenu, val state: Boolean) : SettingItem() | ||
|
||
class Builder { | ||
private val groups = ArrayList<SettingGroup>() | ||
|
||
fun addGroup(group: SettingGroup) = apply { | ||
groups.add(group) | ||
} | ||
|
||
fun addItem(item: SettingItem) = apply { | ||
addGroup( | ||
SettingGroup.Builder() | ||
.addItem(item) | ||
.build() | ||
) | ||
} | ||
|
||
fun addButton(menu: SettingMenu) = apply { | ||
addItem(Button(menu)) | ||
} | ||
|
||
fun addStateButton(menu: SettingMenu, state: UIText = UIText.Empty) = apply { | ||
addItem(StateButton(menu, state)) | ||
} | ||
|
||
fun addStateSwitch(menu: SettingMenu, state: Boolean = false) = apply { | ||
addItem(StateSwitch(menu, state)) | ||
} | ||
|
||
fun build(): List<SettingItem> { | ||
val list = ArrayList<SettingItem>() | ||
|
||
for (group in groups) { | ||
if (group.title != null) { | ||
list.add(GroupHeader(group.title)) | ||
} | ||
|
||
group.items.forEachIndexed { index, item -> | ||
list.add(item) | ||
if (index < group.items.lastIndex) { | ||
list.add(Divider) | ||
} | ||
} | ||
} | ||
|
||
return list.toList() | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
features/ui-setting/src/main/java/com/lighthouse/features/setting/model/SettingMenu.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.lighthouse.features.setting.model | ||
|
||
import com.lighthouse.core.android.utils.resource.UIText | ||
import com.lighthouse.features.setting.R | ||
|
||
internal enum class SettingMenu(val uiText: UIText) { | ||
|
||
USED_GIFTICON(UIText.StringResource(R.string.used_gifticon)), | ||
IMMINENT_NOTIFICATION(UIText.StringResource(R.string.setting_imminent_notification)), | ||
SECURITY(UIText.StringResource(R.string.setting_security)), | ||
LOCATION(UIText.StringResource(R.string.setting_location_permission)), | ||
SIGN_IN(UIText.StringResource(R.string.user_sign_in)), | ||
SIGN_OUT(UIText.StringResource(R.string.user_sign_out)), | ||
WITHDRAWAL(UIText.StringResource(R.string.user_withdrawal)), | ||
COFFEE(UIText.StringResource(R.string.etc_coffee)), | ||
TERMS_OF_USE(UIText.StringResource(R.string.etc_terms_of_use)), | ||
PERSONAL_INFO_POLICY(UIText.StringResource(R.string.etc_personal_info_policy)), | ||
OPEN_SOURCE_LICENSE(UIText.StringResource(R.string.etc_open_source_license)) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</layout> |
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,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</layout> |
9 changes: 9 additions & 0 deletions
9
features/ui-setting/src/main/res/layout/item_group_header.xml
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,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</layout> |
9 changes: 9 additions & 0 deletions
9
features/ui-setting/src/main/res/layout/item_state_button.xml
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,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</layout> |
9 changes: 9 additions & 0 deletions
9
features/ui-setting/src/main/res/layout/item_state_switch.xml
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,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</layout> |