Skip to content

Commit

Permalink
Merge pull request #246 from Team-HMH/feat/add_popup
Browse files Browse the repository at this point in the history
[feat/add_popup]: νŒμ—…κ΄€λ ¨ ν”Œλ‘œμš° μˆ˜μ •
  • Loading branch information
jihyun0v0 authored Sep 8, 2024
2 parents 9d4a5d0 + 0573627 commit 37d75bb
Show file tree
Hide file tree
Showing 8 changed files with 296 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.annotation.DrawableRes
import androidx.core.view.isGone
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
import com.hmh.hamyeonham.common.R
import com.hmh.hamyeonham.common.context.dialogWidthPercent
import com.hmh.hamyeonham.common.databinding.DialogCommonOneButtonBinding
import com.hmh.hamyeonham.common.view.setOnSingleClickListener
Expand Down Expand Up @@ -52,6 +53,7 @@ class OneButtonCommonDialog : DialogFragment() {
val description = arguments?.getString(DESCRIPTION)
val iconRes = arguments?.getInt(ICON_RES)
val confirmButtonText = arguments?.getString(CONFIRM_BUTTON_TEXT, "")
val setBlueButton = arguments?.getBoolean(BLUE_BUTTON, false) ?: false

with(binding) {
tvDialogTitle.text = title
Expand All @@ -60,6 +62,8 @@ class OneButtonCommonDialog : DialogFragment() {
ivDialogIcon.isGone = true
}
tvConfirmButton.text = confirmButtonText
if (setBlueButton)
tvConfirmButton.setBackgroundResource(R.drawable.shape_blue_purple_button_radius6)
}
}

Expand All @@ -82,20 +86,23 @@ class OneButtonCommonDialog : DialogFragment() {
const val DESCRIPTION = "description"
const val ICON_RES = "iconRes"
const val CONFIRM_BUTTON_TEXT = "confirmButtonText"
const val BLUE_BUTTON = "blueButton"


fun newInstance(
title: String,
description: String? = null,
@DrawableRes iconRes: Int? = null,
confirmButtonText: String,
setBlueButton: Boolean = false
): OneButtonCommonDialog {
return OneButtonCommonDialog().apply {
arguments = Bundle().apply {
putString(TITLE, title)
putString(DESCRIPTION, description)
iconRes?.let { putInt(ICON_RES, it) }
putString(CONFIRM_BUTTON_TEXT, confirmButtonText)
putBoolean(BLUE_BUTTON, setBlueButton)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.DrawableRes
import androidx.core.view.isGone
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
import com.hmh.hamyeonham.common.context.dialogWidthPercent
Expand Down Expand Up @@ -53,12 +55,21 @@ class TwoButtonCommonDialog : DialogFragment() {
private fun initViews() {
val title = arguments?.getString(TITLE, "")
val description = arguments?.getString(DESCRIPTION)
val iconRes = arguments?.getInt(OneButtonCommonDialog.ICON_RES, 0)
val confirmButtonText = arguments?.getString(CONFIRM_BUTTON_TEXT, "")
val dismissButtonText = arguments?.getString(DISMISS_BUTTON_TEXT, "")
val hideIcon = arguments?.getBoolean(HIDE_ICON) ?: false

with(binding) {
tvDialogTitle.text = title
tvDialogDescription.text = description
if (hideIcon)
ivDialogIcon.isGone = true
else {
iconRes?.let {
ivDialogIcon.setImageResource(it)
} ?: run { ivDialogIcon.isGone = true }
}
tvConfirmButton.text = confirmButtonText
tvDismissButton.text = dismissButtonText
}
Expand Down Expand Up @@ -87,11 +98,14 @@ class TwoButtonCommonDialog : DialogFragment() {
const val DESCRIPTION = "description"
const val CONFIRM_BUTTON_TEXT = "confirmButtonText"
const val DISMISS_BUTTON_TEXT = "dismissButtonText"
const val ICON_RES = "iconRes"
const val HIDE_ICON = "hideIcon"


fun newInstance(
title: String,
description: String? = null,
@DrawableRes iconRes: Int? = null,
confirmButtonText: String,
dismissButtonText: String
): TwoButtonCommonDialog {
Expand All @@ -100,6 +114,7 @@ class TwoButtonCommonDialog : DialogFragment() {
putString(TITLE, title)
putString(DESCRIPTION, description)
putString(CONFIRM_BUTTON_TEXT, confirmButtonText)
iconRes?.let { putInt(ICON_RES, it) } ?: run { putBoolean(HIDE_ICON, true) }
putString(DISMISS_BUTTON_TEXT, dismissButtonText)
}
}
Expand Down
3 changes: 1 addition & 2 deletions core/common/src/main/res/layout/dialog_common_one_button.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="12dp"
android:layout_marginTop="9dp"
android:layout_marginTop="6dp"
android:ellipsize="end"
android:gravity="center"
android:maxLines="2"
android:textAppearance="?textAppearanceBodyMedium"
app:layout_constraintBottom_toTopOf="@+id/tv_confirm_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_dialog_title"
Expand Down
15 changes: 11 additions & 4 deletions core/common/src/main/res/layout/dialog_common_two_button.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,26 @@
android:id="@+id/tv_dialog_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="12dp"
android:layout_marginTop="9dp"
android:layout_marginTop="6dp"
android:ellipsize="end"
android:gravity="center"
android:maxLines="2"
android:textAppearance="?textAppearanceBodyMedium"
app:layout_constraintBottom_toTopOf="@+id/tv_confirm_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_dialog_title"
app:layout_constraintVertical_bias="0.2"
tools:text="μ±Œλ¦°μ§€λ₯Ό λ“±λ‘ν•˜λ©΄ 포인트λ₯Ό 얻을 수 μžˆμ–΄μš”" />

<ImageView
android:id="@+id/iv_dialog_icon"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_marginTop="22dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_dialog_description" />

<TextView
android:id="@+id/tv_confirm_button"
android:layout_width="0dp"
Expand All @@ -56,7 +63,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/tv_dismiss_button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_dialog_description"
app:layout_constraintTop_toBottomOf="@id/iv_dialog_icon"
tools:text="확인" />

<TextView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import com.hmh.hamyeonham.common.dialog.OneButtonCommonDialog
import com.hmh.hamyeonham.common.amplitude.AmplitudeUtils
import com.hmh.hamyeonham.common.view.viewBinding
import com.hmh.hamyeonham.feature.challenge.R
import com.hmh.hamyeonham.feature.challenge.databinding.ActivityNewChallengeBinding
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
Expand Down Expand Up @@ -52,7 +54,7 @@ class NewChallengeActivity : AppCompatActivity() {
binding.vpNewChallenge.run {
when (currentItem) {
FRAGMENT.PERIODSELECTION.position -> currentItem = FRAGMENT.TIMESELECTION.position
FRAGMENT.TIMESELECTION.position -> finishWithResults()
FRAGMENT.TIMESELECTION.position -> showChallengeCreatedDialog()
}
}
}
Expand All @@ -63,6 +65,20 @@ class NewChallengeActivity : AppCompatActivity() {
}.launchIn(lifecycleScope)
}

private fun showChallengeCreatedDialog() {
OneButtonCommonDialog.newInstance(
title = getString(R.string.dialog_title_challengecreated),
description = getString(R.string.dialog_description_challengecreated),
iconRes = R.drawable.ic_challengecreated_120,
confirmButtonText = getString(R.string.dialog_button_challengecreated),
setBlueButton = true
).apply {
setConfirmButtonClickListener {
finishWithResults()
}
}.showAllowingStateLoss(supportFragmentManager, OneButtonCommonDialog.TAG)
}

private fun finishWithResults() {
val intent = Intent().apply {
putExtra(PERIOD, viewModel.state.value.goalDate)
Expand Down
Loading

0 comments on commit 37d75bb

Please sign in to comment.