Skip to content

Commit

Permalink
refactor: 툴팁 윈도우 안정성 향상
Browse files Browse the repository at this point in the history
  • Loading branch information
junseo511 committed Dec 18, 2024
1 parent 16e0e1b commit 82ee749
Showing 1 changed file with 33 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,41 +199,46 @@ class NovelDetailActivity :
}

private fun setupTooltipBottomFramePosition() {
binding.ctlNovelDetail.viewTreeObserver.addOnGlobalLayoutListener(object :
ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
val layoutParams =
binding.viewNovelDetailTooltipFrameBottom.layoutParams as ConstraintLayout.LayoutParams
binding.ctlNovelDetail.viewTreeObserver.addOnPreDrawListener(object :
ViewTreeObserver.OnPreDrawListener {
override fun onPreDraw(): Boolean {
binding.ctlNovelDetail.viewTreeObserver.removeOnPreDrawListener(this)

val layoutParams = binding.viewNovelDetailTooltipFrameBottom.layoutParams as ConstraintLayout.LayoutParams
layoutParams.topMargin = binding.ctlNovelDetail.height
binding.viewNovelDetailTooltipFrameBottom.layoutParams = layoutParams
binding.ctlNovelDetail.viewTreeObserver.removeOnGlobalLayoutListener(this)

return true
}
})
}

private fun showTooltipWindow() {
tooltipPopupWindow = PopupWindow(
novelDetailToolTipBinding.root,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
true,
).apply {
novelDetailToolTipBinding.root.measure(
View.MeasureSpec.UNSPECIFIED,
View.MeasureSpec.UNSPECIFIED,
)
val anchorViewWidth = binding.tgNovelDetailReadStatus.measuredWidth
val popupWidth = novelDetailToolTipBinding.root.measuredWidth

val xOffset = (anchorViewWidth - popupWidth) / 2
val yOffset = 6.toIntPxFromDp()

showAsDropDown(binding.tgNovelDetailReadStatus, xOffset, yOffset)

novelDetailToolTipBinding.root.setOnClickListener { dismiss() }
this.setOnDismissListener {
novelDetailViewModel.updateIsFirstLaunched()
binding.tgNovelDetailReadStatus.clearChecked()
binding.tgNovelDetailReadStatus.post {
tooltipPopupWindow = PopupWindow(
novelDetailToolTipBinding.root,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
true,
).apply {
novelDetailToolTipBinding.root.measure(
View.MeasureSpec.UNSPECIFIED,
View.MeasureSpec.UNSPECIFIED,
)

val anchorViewWidth = binding.tgNovelDetailReadStatus.measuredWidth
val popupWidth = novelDetailToolTipBinding.root.measuredWidth
val xOffset = (anchorViewWidth - popupWidth) / 2
val yOffset = 6.toIntPxFromDp()

showAsDropDown(binding.tgNovelDetailReadStatus, xOffset, yOffset)

novelDetailToolTipBinding.root.setOnClickListener { dismiss() }

this.setOnDismissListener {
novelDetailViewModel.updateIsFirstLaunched()
binding.tgNovelDetailReadStatus.clearChecked()
}
}
}
}
Expand Down

0 comments on commit 82ee749

Please sign in to comment.