Skip to content

Commit

Permalink
#162 / 백 버튼 누를떄 다이얼로그 띄우기
Browse files Browse the repository at this point in the history
  • Loading branch information
l2zh committed Dec 19, 2023
1 parent 3d873b9 commit 33e79ec
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions app/src/main/java/sopt/uni/presentation/timer/TimerStartActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sopt.uni.presentation.timer

import android.os.Bundle
import androidx.activity.OnBackPressedCallback
import dagger.hilt.android.AndroidEntryPoint
import sopt.uni.R
import sopt.uni.data.datasource.local.SparkleStorage
Expand All @@ -11,12 +12,23 @@ import sopt.uni.util.extension.setOnSingleClickListener
@AndroidEntryPoint
class TimerStartActivity : BindingActivity<ActivityTimerBinding>(R.layout.activity_timer) {

private val onBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
exitTimer()
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(binding.root)

setBackButton()
setTimerFragment()
finishTimer()
}

private fun finishTimer() {
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
}

private fun setTimerFragment() {
Expand All @@ -36,16 +48,20 @@ class TimerStartActivity : BindingActivity<ActivityTimerBinding>(R.layout.activi

private fun setBackButton() {
binding.btnTimerBack.setOnSingleClickListener {
val currentFragment = supportFragmentManager.findFragmentById(R.id.fcv_timer)

if (currentFragment is TimerSettingFragment) {
finish()
} else {
TimerDialogFragment().show(
supportFragmentManager,
TIMER_DIALOG_TAG,
)
}
exitTimer()
}
}

private fun exitTimer() {
val currentFragment = supportFragmentManager.findFragmentById(R.id.fcv_timer)

if (currentFragment is TimerSettingFragment) {
finish()
} else {
TimerDialogFragment().show(
supportFragmentManager,
TIMER_DIALOG_TAG,
)
}
}

Expand Down

0 comments on commit 33e79ec

Please sign in to comment.