Skip to content

Commit

Permalink
[#8] 기본 다이얼로그 추가
Browse files Browse the repository at this point in the history
- 타이틀과 하단 버튼만을 구성하고 있는 CustomContentDialogFragment 추가
- 각종 레이아웃 및 drawable 추가
- 테마로 중복코드 해소
  • Loading branch information
ethan-223 committed Apr 19, 2022
1 parent 1dcc182 commit ffcab83
Show file tree
Hide file tree
Showing 12 changed files with 253 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.moyerun.moyeorun_android.common.dialog

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.moyerun.moyeorun_android.R
import com.moyerun.moyeorun_android.common.extension.getStringFromArgument
import com.moyerun.moyeorun_android.common.extension.putStringToArgument
import com.moyerun.moyeorun_android.databinding.DialogCustomContentBinding

abstract class CustomContentDialogFragment : BaseDialogFragment() {

final override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
return DialogCustomContentBinding.inflate(inflater, container, false).apply {
contentCustomDialog.addView(
onCreateContentView(
inflater,
contentCustomDialog,
savedInstanceState
)
)
}.root
}

final override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val binding = DialogCustomContentBinding.bind(view)
binding.headerTextDialog.textDialogHeader.text = getStringFromArgument(ARG_TITLE)
with(binding.footerTextDialog) {
buttonNegativeDialogFooter.text =
getStringFromArgument(ARG_LABEL_NEGATIVE, getString(R.string.cancel))
buttonPositiveDialogFooter.text =
getStringFromArgument(ARG_LABEL_POSITIVE, getString(R.string.ok))

buttonNegativeDialogFooter.setOnClickListener {
onNegativeClick()
dismissAllowingStateLoss()
}

buttonPositiveDialogFooter.setOnClickListener {
onPositiveClick()
dismissAllowingStateLoss()
}
}
onContentViewCreated(view, savedInstanceState)
}

abstract fun onCreateContentView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View

abstract fun onContentViewCreated(view: View, savedInstanceState: Bundle?)

protected open fun onPositiveClick() { }

protected open fun onNegativeClick() { }

protected fun setTitle(title: String?) {
putStringToArgument(ARG_TITLE, title)
}

protected fun setPositiveLabel(label: String?) {
putStringToArgument(ARG_LABEL_POSITIVE, label)
}

protected fun setNegativeLabel(label: String?) {
putStringToArgument(ARG_LABEL_NEGATIVE, label)
}

companion object {
private const val ARG_TITLE = "title"
private const val ARG_LABEL_NEGATIVE = "negativeLabel"
private const val ARG_LABEL_POSITIVE = "positiveLabel"
}
}
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/round_background_12.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--Todo: 스타일 처리-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="12dp" />
<solid android:color="#ffffff" />
</shape>
</item>
</layer-list>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/round_background_4.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--Todo: 컬러 스타일 처리-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="4dp" />
<solid android:color="#ffffff" />
</shape>
</item>
</layer-list>
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/round_border_background_4.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<stroke
android:width="1dp"
android:color="#BDBEC1" />
<corners android:radius="4dp" />
<solid android:color="#ffffff" />
</shape>
</item>
</layer-list>
32 changes: 32 additions & 0 deletions app/src/main/res/layout/dialog_custom_content.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
style="@style/Dialog.Background"
android:orientation="vertical">

<include
android:id="@+id/header_text_dialog"
layout="@layout/dialog_header_text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<View style="@style/Dialog.Divider" />

<!-- 커스텀 컨텐츠가 들어올 레이아웃 -->
<FrameLayout
android:id="@+id/content_custom_dialog"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<include
android:id="@+id/footer_text_dialog"
layout="@layout/dialog_footer_two_button"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</LinearLayout>

</FrameLayout>
28 changes: 28 additions & 0 deletions app/src/main/res/layout/dialog_footer_two_button.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingHorizontal="@dimen/padding_dialog_common"
android:paddingBottom="@dimen/padding_dialog_common">

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/button_negative_dialog_footer"
style="@style/Dialog.Button.Negative"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="4.5dp"
android:layout_weight="1"
tools:text="Negative" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/button_positive_dialog_footer"
style="@style/Dialog.Button.Positive"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="4.5dp"
android:layout_weight="1"
tools:text="Positive" />

</LinearLayout>
16 changes: 16 additions & 0 deletions app/src/main/res/layout/dialog_header_text.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="@dimen/padding_dialog_common"
android:paddingVertical="21dp">

<TextView
android:id="@+id/text_dialog_header"
style="@style/Dialog.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="다이얼로그 제목" />

</FrameLayout>
3 changes: 3 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
<color name="text_gray">#828282</color>
<color name="text_hint_gray">#A9A9A9</color>

<!-- Line colors -->
<color name="line_dialog_divider">#EBECEF</color>

</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="padding_dialog_common">17dp</dimen>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<resources>
<string name="app_name">MoyeoRun-android</string>

<!-- common string -->
<string name="cancel">취소</string>
<string name="ok">확인</string>

</resources>
50 changes: 50 additions & 0 deletions app/src/main/res/values/styles_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Dialog" />

<style name="Dialog.Divider">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">1dp</item>
<item name="android:background">@color/line_dialog_divider</item>
</style>

<style name="Dialog.Background">
<item name="android:layout_width">297dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">@drawable/round_background_12</item>
</style>

<style name="Dialog.Title">
<item name="android:textColor">@color/text_default_black</item>
<item name="android:textSize">22dp</item>
<item name="android:textStyle">bold</item>
<item name="android:layout_gravity">center</item>
<item name="android:gravity">center</item>
</style>

<style name="Dialog.Content">
<item name="android:layout_gravity">center</item>
<item name="android:gravity">center</item>
<item name="android:textColor">@color/text_default_black</item>
<item name="android:textSize">18dp</item>
</style>

<style name="Dialog.Button">
<item name="android:minWidth">0dp</item>
<item name="android:minHeight">0dp</item>
<item name="android:paddingTop">16dp</item>
<item name="android:paddingBottom">16dp</item>
<item name="android:textSize">16dp</item>
</style>

<style name="Dialog.Button.Negative">
<item name="android:background">@drawable/round_border_background_4</item>
<item name="android:textColor">@color/text_default_black</item>
</style>

<style name="Dialog.Button.Positive">
<item name="android:background">@drawable/round_background_4</item>
<item name="android:backgroundTint">@color/main_blue</item>
<item name="android:textColor">@color/main_white</item>
</style>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
<item name="android:textColorHint">@color/text_hint_gray</item>
<item name="android:textSize">18dp</item>
</style>

</resources>

0 comments on commit ffcab83

Please sign in to comment.