Skip to content

Commit

Permalink
#121 / 다이얼로그 프래그먼트 기본생성자 제거 밑 setLayoutSizeRatio 함수 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
l2zh committed Jan 28, 2024
1 parent f27a766 commit 004e3b7
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 36 deletions.
15 changes: 8 additions & 7 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion app/src/main/java/sopt/uni/presentation/IntroActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ class IntroActivity : AppCompatActivity() {
checkUserStatus()
}
}
appUpdateInfoTask.addOnFailureListener {exception ->
appUpdateInfoTask.addOnFailureListener { exception ->
Timber.tag("inappUpdate").e("업데이트 체크 실패: ${exception.message}")
showUpdateDialog()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import dagger.hilt.android.AndroidEntryPoint
import sopt.uni.R
import sopt.uni.data.datasource.local.SparkleStorage
import sopt.uni.databinding.TitleAction2DialogBinding
import sopt.uni.presentation.BindingDialogFragment
import sopt.uni.util.binding.BindingDialogFragment
import sopt.uni.util.extension.setOnSingleClickListener
import javax.inject.Inject

Expand All @@ -26,6 +26,7 @@ class UpdateDialogFragment :

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setLayoutSizeRatio(0.778f, 0.2f)

with(binding) {
dialogTitle.setText(getString(R.string.update_dialog_title))
Expand Down Expand Up @@ -56,7 +57,7 @@ class UpdateDialogFragment :
Log.e("update", it.resultCode.toString())
} else {
SparkleStorage.setUpdateAvailableBoolean(
UpdateDialogFragment.IS_UPDATE_AVAILABLE,
IS_UPDATE_AVAILABLE,
true,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ import sopt.uni.data.datasource.local.SparkleStorage
import sopt.uni.databinding.NoBodyAction2DialogBinding
import sopt.uni.databinding.TitleAction2DialogBinding
import sopt.uni.di.ServicePool
import sopt.uni.presentation.BindingDialogFragment
import sopt.uni.presentation.invite.NickNameActivity
import sopt.uni.presentation.login.LoginActivity
import sopt.uni.util.binding.BindingDialogFragment
import sopt.uni.util.extension.setOnSingleClickListener

class MypageAccountLogoutDialogFragment :
BindingDialogFragment<NoBodyAction2DialogBinding>(R.layout.no_body_action2_dialog) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setLayoutSizeRatio(0.778f, 0.16f)

with(binding) {
dialogTitle.setText(getString(R.string.logout_dialog_title))
Expand Down Expand Up @@ -47,6 +48,7 @@ class MypageAccountDeleteDialogFragment :

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setLayoutSizeRatio(0.778f, 0.22f)

with(binding) {
dialogTitle.setText(getString(R.string.delete_dialog_title))
Expand Down Expand Up @@ -77,6 +79,7 @@ class MypageAccountCoupleDisconnectDialogFragment :

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setLayoutSizeRatio(0.778f, 0.22f)

with(binding) {
dialogTitle.setText(getString(R.string.disconnect_dialog_title))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import android.os.Bundle
import android.view.View
import sopt.uni.R
import sopt.uni.databinding.DatepickerDialogBinding
import sopt.uni.presentation.BindingDialogFragment
import sopt.uni.util.binding.BindingDialogFragment
import sopt.uni.util.extension.setOnSingleClickListener
import java.util.Calendar

class MypageDatePickerDialogFragment :
BindingDialogFragment<DatepickerDialogBinding>(
R.layout.datepicker_dialog,
isWrapContent = true,
) {
private var listener: DatePickerDialogListener? = null

Expand All @@ -21,6 +20,7 @@ class MypageDatePickerDialogFragment :

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setLayoutSizeRatio(0.77f, 0.34f)

setMaxDate()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.os.Bundle
import android.view.View
import sopt.uni.R
import sopt.uni.databinding.TitleAction2DialogBinding
import sopt.uni.presentation.BindingDialogFragment
import sopt.uni.util.binding.BindingDialogFragment

class CreateShortGameDialogFragment :
BindingDialogFragment<TitleAction2DialogBinding>(R.layout.title_action2_dialog) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.os.Bundle
import android.view.View
import sopt.uni.R
import sopt.uni.databinding.TitleAction2DialogBinding
import sopt.uni.presentation.BindingDialogFragment
import sopt.uni.util.binding.BindingDialogFragment
import sopt.uni.util.extension.setOnSingleClickListener

class TimerDialogFragment :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.os.Bundle
import android.view.View
import sopt.uni.R
import sopt.uni.databinding.TitleAction2DialogBinding
import sopt.uni.presentation.BindingDialogFragment
import sopt.uni.util.binding.BindingDialogFragment
import sopt.uni.util.extension.setOnSingleClickListener

class NewWishDialogFragment :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.os.Bundle
import android.view.View
import sopt.uni.R
import sopt.uni.databinding.TitleAction2DialogBinding
import sopt.uni.presentation.BindingDialogFragment
import sopt.uni.util.binding.BindingDialogFragment

class UseWishDialogFragment :
BindingDialogFragment<TitleAction2DialogBinding>(R.layout.title_action2_dialog) {
Expand Down
38 changes: 22 additions & 16 deletions app/src/main/java/sopt/uni/util/binding/BindingDialogFragment.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package sopt.uni.presentation
package sopt.uni.util.binding

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand All @@ -10,21 +12,11 @@ import androidx.databinding.ViewDataBinding
import androidx.fragment.app.DialogFragment
import sopt.uni.R

abstract class BindingDialogFragment<B : ViewDataBinding>(
abstract class BindingDialogFragment<T : ViewDataBinding>(
@LayoutRes private val layoutRes: Int,
private val isWrapContent: Boolean = false,
) :
DialogFragment() {
private var _binding: B? = null
val binding get() = requireNotNull(_binding!!) { "${this::class.java.simpleName}에서 에러가 발생했습니다." }

override fun onStart() {
super.onStart()
val width = if (isWrapContent) ViewGroup.LayoutParams.WRAP_CONTENT else resources.getDimensionPixelSize(R.dimen.dialog_width)
val height = if (isWrapContent) ViewGroup.LayoutParams.WRAP_CONTENT else resources.getDimensionPixelSize(R.dimen.dialog_height)
dialog?.window?.setLayout(width, height)
dialog?.window?.setBackgroundDrawableResource(android.R.color.transparent)
}
) : DialogFragment() {
private var _binding: T? = null
protected val binding get() = _binding ?: error(getString(R.string.binding_error))

override fun onCreateView(
inflater: LayoutInflater,
Expand All @@ -35,8 +27,22 @@ abstract class BindingDialogFragment<B : ViewDataBinding>(
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
}

protected fun setLayoutSizeRatio(widthPercent: Float, heightPercent: Float) {
context?.resources?.displayMetrics?.let { metrics ->
binding.root.layoutParams.apply {
width = ((metrics.widthPixels * widthPercent).toInt())
height = ((metrics.heightPixels * heightPercent).toInt())
}
}
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
super.onDestroyView()
}
}
3 changes: 0 additions & 3 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
<dimen name="home_lightblue_background">158dp</dimen>
<dimen name="divider_width">49dp</dimen>
<dimen name="on_boarding_image">328dp</dimen>
<dimen name="dialog_width">300dp</dimen>
<dimen name="dialog_height">165dp</dimen>

<!-- Button -->
<dimen name="long_button_height">48dp</dimen>
</resources>
Expand Down

0 comments on commit 004e3b7

Please sign in to comment.