From 9617972a73b2818691ba26de293d62e39eefedb3 Mon Sep 17 00:00:00 2001 From: SeongHoonC <108349655+SeongHoonC@users.noreply.github.com> Date: Tue, 24 Oct 2023 17:49:03 +0900 Subject: [PATCH] =?UTF-8?q?[AN/USER]=20feat:=20=ED=99=88=20=ED=99=94?= =?UTF-8?q?=EB=A9=B4=EC=97=90=EC=84=9C=20=EB=92=A4=EB=A1=9C=EA=B0=80?= =?UTF-8?q?=EA=B8=B0=20=EB=88=84=EB=A5=B4=EB=A9=B4=20=EA=B3=A7=EB=B0=94?= =?UTF-8?q?=EB=A1=9C=20=EC=A2=85=EB=A3=8C=EB=90=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EB=8A=94=EB=8B=A4.=20(#588)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 홈화면 뒤로가기 상수 추가 * feat: 홈화면 뒤로가기 두 번 클릭 시 종료 --- .../presentation/ui/home/HomeActivity.kt | 20 +++++++++++++++++++ .../app/src/main/res/values/strings.xml | 1 + 2 files changed, 21 insertions(+) diff --git a/android/festago/app/src/main/java/com/festago/festago/presentation/ui/home/HomeActivity.kt b/android/festago/app/src/main/java/com/festago/festago/presentation/ui/home/HomeActivity.kt index 9b7fe0a8a..d4932ed32 100644 --- a/android/festago/app/src/main/java/com/festago/festago/presentation/ui/home/HomeActivity.kt +++ b/android/festago/app/src/main/java/com/festago/festago/presentation/ui/home/HomeActivity.kt @@ -4,6 +4,7 @@ import android.content.Context import android.content.Intent import android.os.Bundle import android.widget.Toast +import androidx.activity.addCallback import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.viewModels @@ -37,6 +38,7 @@ class HomeActivity : AppCompatActivity() { initView() initObserve() initResultLauncher() + initBackPressedDispatcher() } private fun initResultLauncher() { @@ -129,6 +131,22 @@ class HomeActivity : AppCompatActivity() { resultLauncher.launch(SignInActivity.getIntent(this)) } + private fun initBackPressedDispatcher() { + var backPressedTime = START_BACK_PRESSED_TIME + onBackPressedDispatcher.addCallback { + if ((System.currentTimeMillis() - backPressedTime) > FINISH_BACK_PRESSED_TIME) { + backPressedTime = System.currentTimeMillis() + Toast.makeText( + this@HomeActivity, + getString(R.string.home_back_pressed), + Toast.LENGTH_SHORT, + ).show() + } else { + finish() + } + } + } + private inline fun changeFragment() { val tag = T::class.java.name val fragmentTransaction = supportFragmentManager.beginTransaction() @@ -150,6 +168,8 @@ class HomeActivity : AppCompatActivity() { } companion object { + private const val START_BACK_PRESSED_TIME = 0L + private const val FINISH_BACK_PRESSED_TIME = 3000L fun getIntent(context: Context): Intent { return Intent(context, HomeActivity::class.java) } diff --git a/android/festago/app/src/main/res/values/strings.xml b/android/festago/app/src/main/res/values/strings.xml index 83cc4e6ff..384467101 100644 --- a/android/festago/app/src/main/res/values/strings.xml +++ b/android/festago/app/src/main/res/values/strings.xml @@ -39,6 +39,7 @@ 티켓 목록 마이페이지 알림 권한을 거부했습니다 :( + 한 번 더 누르면 앱이 종료됩니다 %1s ~ %1s