diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/base/BaseFragment.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/base/BaseFragment.kt index cf1b4518..e39bc178 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/base/BaseFragment.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/base/BaseFragment.kt @@ -84,7 +84,7 @@ abstract class BaseFragment( } fun showToastMessage(message: String) { - Toast.makeText(context, message, Toast.LENGTH_LONG).show() + Toast.makeText(context, message, Toast.LENGTH_SHORT).show() } fun showTwoButtonTitleDialog( diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/NavigationExtensions.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/NavigationExtensions.kt index 6480816a..dd69d6e6 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/NavigationExtensions.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/NavigationExtensions.kt @@ -1,6 +1,10 @@ package com.avengers.nibobnebob.presentation.ui +import android.app.Activity +import androidx.activity.OnBackPressedCallback +import androidx.fragment.app.FragmentActivity import androidx.navigation.NavController +import androidx.navigation.fragment.findNavController import com.avengers.nibobnebob.NavGraphDirections @@ -31,4 +35,12 @@ internal fun NavController.toMyPage() { internal fun NavController.toUserDetail(nickName: String) { val action = NavGraphDirections.globalToUserDetailFragment(nickName) navigate(action) +} + +internal fun customBack(activity : FragmentActivity, nav : NavController){ + activity.onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + nav.navigateUp() + } + }) } \ No newline at end of file diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/MainActivity.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/MainActivity.kt index 017c6623..70de496d 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/MainActivity.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/MainActivity.kt @@ -10,6 +10,7 @@ import android.provider.MediaStore import android.view.MotionEvent import android.view.View import android.view.inputmethod.InputMethodManager +import androidx.activity.OnBackPressedCallback import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.viewModels import androidx.core.app.ActivityCompat @@ -52,6 +53,7 @@ class MainActivity : BaseActivity(ActivityMainBinding::infl viewModel.events.collect{ when(it){ is MainEvents.OpenGallery -> onCheckStoragePermissions() + is MainEvents.FinishApp -> finish() } } } diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/MainViewModel.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/MainViewModel.kt index a6a8620d..dff2ce68 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/MainViewModel.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/MainViewModel.kt @@ -18,6 +18,7 @@ import javax.inject.Inject sealed class MainEvents{ data object OpenGallery: MainEvents() + data object FinishApp : MainEvents() } @HiltViewModel @@ -40,6 +41,12 @@ class MainViewModel @Inject constructor( } } + fun finishApp() { + viewModelScope.launch { + _events.emit(MainEvents.FinishApp) + } + } + fun setUriString(uri : String){ _image.value = uri } diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/follow/FollowFragment.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/follow/FollowFragment.kt index c8c95a7e..b1f2367f 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/follow/FollowFragment.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/follow/FollowFragment.kt @@ -1,5 +1,6 @@ package com.avengers.nibobnebob.presentation.ui.main.follow +import androidx.activity.OnBackPressedCallback import androidx.fragment.app.activityViewModels import androidx.fragment.app.viewModels import androidx.navigation.NavController @@ -24,6 +25,7 @@ class FollowFragment : BaseFragment(R.layout.fragment_fol binding.rvFollowList.adapter = FollowAdapter() binding.rvRecommendFriend.adapter = FollowAdapter() setTabSelectedListener() + finishApp() } override fun initNetworkView() { @@ -58,6 +60,20 @@ class FollowFragment : BaseFragment(R.layout.fragment_fol }) } + private fun finishApp(){ + var backPressTime = 0L + requireActivity().onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + if(System.currentTimeMillis() - backPressTime <= 2000) { + parentViewModel.finishApp() + } else{ + backPressTime = System.currentTimeMillis() + showToastMessage("뒤로가기 버튼을 한 번 더 누르면 종료됩니다.") + } + } + }) + } + private fun NavController.toFollowSearch() { val action = FollowFragmentDirections.actionFollowFragmentToFollowSearchFragment() navigate(action) diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/follow/search/FollowSearchFragment.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/follow/search/FollowSearchFragment.kt index 47620e8a..88135313 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/follow/search/FollowSearchFragment.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/follow/search/FollowSearchFragment.kt @@ -8,6 +8,7 @@ import com.avengers.nibobnebob.databinding.FragmentFollowSearchBinding import com.avengers.nibobnebob.presentation.base.BaseFragment import com.avengers.nibobnebob.presentation.customview.SelectRegionDialog import com.avengers.nibobnebob.presentation.ui.adjustKeyboard +import com.avengers.nibobnebob.presentation.ui.customBack import com.avengers.nibobnebob.presentation.ui.main.MainViewModel import com.avengers.nibobnebob.presentation.ui.main.follow.adapter.FollowSearchAdapter import com.avengers.nibobnebob.presentation.ui.toUserDetail @@ -25,6 +26,7 @@ class FollowSearchFragment : binding.rvFollowSearch.itemAnimator = null setEditText() viewModel.observeKeyword() + customBack(requireActivity(), findNavController()) } override fun initNetworkView() { diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/global/restaurantadd/AddMyRestaurantFragment.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/global/restaurantadd/AddMyRestaurantFragment.kt index 056bcd93..e692017e 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/global/restaurantadd/AddMyRestaurantFragment.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/global/restaurantadd/AddMyRestaurantFragment.kt @@ -7,6 +7,7 @@ import androidx.navigation.fragment.navArgs import com.avengers.nibobnebob.R import com.avengers.nibobnebob.databinding.FragmentAddMyRestaurantBinding import com.avengers.nibobnebob.presentation.base.BaseFragment +import com.avengers.nibobnebob.presentation.ui.customBack import com.avengers.nibobnebob.presentation.ui.main.MainViewModel import com.avengers.nibobnebob.presentation.ui.toHome import com.avengers.nibobnebob.presentation.ui.toMultiPart @@ -29,6 +30,7 @@ class AddMyRestaurantFragment : setSliderListener() setVisitMethodRadioListener() initImageObserver() + customBack(requireActivity(), findNavController()) } override fun initNetworkView() { diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/global/restaurantdetail/RestaurantDetailFragment.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/global/restaurantdetail/RestaurantDetailFragment.kt index 0bea70ec..df361e4e 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/global/restaurantdetail/RestaurantDetailFragment.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/global/restaurantdetail/RestaurantDetailFragment.kt @@ -9,6 +9,7 @@ import com.avengers.nibobnebob.R import com.avengers.nibobnebob.databinding.FragmentRestaurantDetailBinding import com.avengers.nibobnebob.presentation.base.BaseFragment import com.avengers.nibobnebob.presentation.customview.TwoButtonTitleDialog +import com.avengers.nibobnebob.presentation.ui.customBack import com.avengers.nibobnebob.presentation.ui.main.MainViewModel import com.avengers.nibobnebob.presentation.ui.main.global.restaurantdetail.adapter.RestaurantReviewAdapter import dagger.hilt.android.AndroidEntryPoint @@ -27,6 +28,7 @@ class RestaurantDetailFragment : binding.vm = viewModel viewModel.setRestaurantId(restaurantId) binding.rvReview.adapter = RestaurantReviewAdapter() + customBack(requireActivity(), findNavController()) } override fun initNetworkView() { diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/global/restaurantreview/RestaurantReviewsFragment.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/global/restaurantreview/RestaurantReviewsFragment.kt index d2557082..b57d72f3 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/global/restaurantreview/RestaurantReviewsFragment.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/global/restaurantreview/RestaurantReviewsFragment.kt @@ -1,6 +1,5 @@ package com.avengers.nibobnebob.presentation.ui.main.global.restaurantreview -import android.util.Log import androidx.appcompat.widget.PopupMenu import androidx.fragment.app.activityViewModels import androidx.fragment.app.viewModels @@ -10,6 +9,7 @@ import androidx.recyclerview.widget.RecyclerView import com.avengers.nibobnebob.R import com.avengers.nibobnebob.databinding.FragmentRestaurantReviewsBinding import com.avengers.nibobnebob.presentation.base.BaseFragment +import com.avengers.nibobnebob.presentation.ui.customBack import com.avengers.nibobnebob.presentation.ui.main.MainViewModel import com.avengers.nibobnebob.presentation.ui.main.global.restaurantdetail.adapter.RestaurantReviewAdapter import com.avengers.nibobnebob.presentation.util.Constants @@ -43,11 +43,11 @@ class RestaurantReviewsFragment : val isNotLoading = !viewModel.uiState.value.isLoading if (scrollBottom && hasNextPage && isNotLoading) { - Log.d("TEST", "end") viewModel.loadNextPage() } } }) + customBack(requireActivity(), findNavController()) } diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/global/userdetail/UserDetailFragment.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/global/userdetail/UserDetailFragment.kt index 6f38dcaa..0e4109cf 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/global/userdetail/UserDetailFragment.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/global/userdetail/UserDetailFragment.kt @@ -10,6 +10,7 @@ import com.avengers.nibobnebob.R import com.avengers.nibobnebob.databinding.FragmentUserDetailBinding import com.avengers.nibobnebob.presentation.base.BaseFragment import com.avengers.nibobnebob.presentation.customview.ImageDialog +import com.avengers.nibobnebob.presentation.ui.customBack import com.avengers.nibobnebob.presentation.ui.main.MainViewModel import com.avengers.nibobnebob.presentation.ui.main.global.userdetail.adapter.UserDetailRestaurantAdapter import dagger.hilt.android.AndroidEntryPoint @@ -26,6 +27,7 @@ class UserDetailFragment : BaseFragment(R.layout.frag binding.vm = viewModel viewModel.setNick(nickName) binding.rvRestaurant.adapter = UserDetailRestaurantAdapter() + customBack(requireActivity(), findNavController()) } @RequiresApi(Build.VERSION_CODES.O) diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/home/HomeFragment.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/home/HomeFragment.kt index e54a80b8..f43159f3 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/home/HomeFragment.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/home/HomeFragment.kt @@ -1,7 +1,9 @@ package com.avengers.nibobnebob.presentation.ui.main.home import android.Manifest +import androidx.activity.OnBackPressedCallback import androidx.activity.result.contract.ActivityResultContracts +import androidx.core.app.ActivityCompat import androidx.fragment.app.activityViewModels import androidx.fragment.app.viewModels import androidx.lifecycle.lifecycleScope @@ -9,6 +11,7 @@ import androidx.navigation.NavController import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs import com.avengers.nibobnebob.R +import com.avengers.nibobnebob.app.App import com.avengers.nibobnebob.databinding.FragmentHomeBinding import com.avengers.nibobnebob.presentation.base.BaseFragment import com.avengers.nibobnebob.presentation.customview.RecommendRestaurantDialog @@ -61,6 +64,7 @@ class HomeFragment : BaseFragment(R.layout.fragment_home), initMapView() binding.rvHomeFilter.adapter = HomeFilterAdapter() viewModel.setAddRestaurantId(restaurantId) + finishApp() } override fun initNetworkView() { @@ -258,6 +262,20 @@ class HomeFragment : BaseFragment(R.layout.fragment_home), markerList.clear() } + private fun finishApp(){ + var backPressTime = 0L + requireActivity().onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + if(System.currentTimeMillis() - backPressTime <= 2000) { + parentViewModel.finishApp() + } else{ + backPressTime = System.currentTimeMillis() + showToastMessage("뒤로가기 버튼을 한 번 더 누르면 종료됩니다.") + } + } + }) + } + private suspend fun addWishTest(id: Int, curState: Boolean): Boolean { return lifecycleScope.async { diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/home/search/RestaurantSearchFragment.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/home/search/RestaurantSearchFragment.kt index 9a38e627..3aefb1c6 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/home/search/RestaurantSearchFragment.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/home/search/RestaurantSearchFragment.kt @@ -19,6 +19,7 @@ import com.avengers.nibobnebob.R import com.avengers.nibobnebob.databinding.FragmentRestaurantSearchBinding import com.avengers.nibobnebob.presentation.base.BaseFragment import com.avengers.nibobnebob.presentation.ui.adjustKeyboard +import com.avengers.nibobnebob.presentation.ui.customBack import com.avengers.nibobnebob.presentation.ui.main.MainActivity import com.avengers.nibobnebob.presentation.ui.main.MainViewModel import com.avengers.nibobnebob.presentation.ui.main.home.adapter.HomeSearchAdapter @@ -43,6 +44,7 @@ class RestaurantSearchFragment : fetchCurrentLocation() view?.let { clearFocus(it) } initStateObserver() + customBack(requireActivity(), findNavController()) } override fun initNetworkView() { diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/home/search/RestaurantSearchMapFragment.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/home/search/RestaurantSearchMapFragment.kt index 5d233774..f74ac703 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/home/search/RestaurantSearchMapFragment.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/home/search/RestaurantSearchMapFragment.kt @@ -16,6 +16,7 @@ import com.avengers.nibobnebob.R import com.avengers.nibobnebob.databinding.FragmentRestaurantSearchMapBinding import com.avengers.nibobnebob.presentation.base.BaseFragment import com.avengers.nibobnebob.presentation.customview.RestaurantBottomSheet +import com.avengers.nibobnebob.presentation.ui.customBack import com.avengers.nibobnebob.presentation.ui.main.MainViewModel import com.avengers.nibobnebob.presentation.ui.main.home.model.UiRestaurantData import com.avengers.nibobnebob.presentation.ui.toAddRestaurant @@ -61,6 +62,7 @@ class RestaurantSearchMapFragment : override fun initView() { initMapView() initClickEvent() + customBack(requireActivity(), findNavController()) } override fun initNetworkView() {} diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/mypage/MyPageFragment.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/mypage/MyPageFragment.kt index 08539aa8..46897c86 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/mypage/MyPageFragment.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/mypage/MyPageFragment.kt @@ -3,6 +3,7 @@ package com.avengers.nibobnebob.presentation.ui.main.mypage import android.app.AlertDialog import android.content.Intent import android.os.Build +import androidx.activity.OnBackPressedCallback import androidx.annotation.RequiresApi import androidx.fragment.app.activityViewModels import androidx.fragment.app.viewModels @@ -27,7 +28,7 @@ class MyPageFragment : BaseFragment(R.layout.fragment_my_ override fun initView() { binding.svm = sharedViewModel binding.vm = viewModel - + finishApp() binding.tvWithdraw.setOnClickListener { @@ -91,6 +92,20 @@ class MyPageFragment : BaseFragment(R.layout.fragment_my_ } + private fun finishApp(){ + var backPressTime = 0L + requireActivity().onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + if(System.currentTimeMillis() - backPressTime <= 2000) { + parentViewModel.finishApp() + } else{ + backPressTime = System.currentTimeMillis() + showToastMessage("뒤로가기 버튼을 한 번 더 누르면 종료됩니다.") + } + } + }) + } + private fun NavController.toEditProfile() { val action = MyPageFragmentDirections.globalToEditProfileFragment() diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/mypage/edit/EditProfileFragment.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/mypage/edit/EditProfileFragment.kt index 790978b9..ebfbf6c0 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/mypage/edit/EditProfileFragment.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/mypage/edit/EditProfileFragment.kt @@ -1,13 +1,16 @@ package com.avengers.nibobnebob.presentation.ui.main.mypage.edit +import androidx.activity.OnBackPressedCallback import androidx.fragment.app.activityViewModels import androidx.fragment.app.viewModels import androidx.navigation.NavController import androidx.navigation.Navigation +import androidx.navigation.fragment.findNavController import com.avengers.nibobnebob.R import com.avengers.nibobnebob.databinding.FragmentEditProfileBinding import com.avengers.nibobnebob.presentation.base.BaseFragment import com.avengers.nibobnebob.presentation.customview.CalendarDatePicker +import com.avengers.nibobnebob.presentation.ui.customBack import com.avengers.nibobnebob.presentation.ui.main.MainViewModel import com.avengers.nibobnebob.presentation.ui.main.mypage.share.MyPageSharedUiEvent import com.avengers.nibobnebob.presentation.ui.main.mypage.share.MyPageSharedViewModel @@ -29,6 +32,7 @@ class EditProfileFragment : setDateBtnListener() initImageObserver() setGenderRadioListener() + customBack(requireActivity(), findNavController()) } override fun initNetworkView() { diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/mypage/mylist/MyRestaurantListFragment.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/mypage/mylist/MyRestaurantListFragment.kt index 228878a8..f62dcba5 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/mypage/mylist/MyRestaurantListFragment.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/mypage/mylist/MyRestaurantListFragment.kt @@ -9,6 +9,7 @@ import androidx.recyclerview.widget.RecyclerView import com.avengers.nibobnebob.R import com.avengers.nibobnebob.databinding.FragmentMyRestaurantListBinding import com.avengers.nibobnebob.presentation.base.BaseFragment +import com.avengers.nibobnebob.presentation.ui.customBack import com.avengers.nibobnebob.presentation.ui.main.MainViewModel import com.avengers.nibobnebob.presentation.ui.main.mypage.share.MyPageSharedUiEvent import com.avengers.nibobnebob.presentation.ui.main.mypage.share.MyPageSharedViewModel @@ -45,6 +46,7 @@ class MyRestaurantListFragment : } }) setFilterMenu() + customBack(requireActivity(), findNavController()) } override fun initNetworkView() { diff --git a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/mypage/wishlist/WishRestaurantListFragment.kt b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/mypage/wishlist/WishRestaurantListFragment.kt index d7de114e..5de96c0d 100644 --- a/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/mypage/wishlist/WishRestaurantListFragment.kt +++ b/Aos/app/src/main/java/com/avengers/nibobnebob/presentation/ui/main/mypage/wishlist/WishRestaurantListFragment.kt @@ -9,6 +9,7 @@ import androidx.recyclerview.widget.RecyclerView import com.avengers.nibobnebob.R import com.avengers.nibobnebob.databinding.FragmentWishRestaurantListBinding import com.avengers.nibobnebob.presentation.base.BaseFragment +import com.avengers.nibobnebob.presentation.ui.customBack import com.avengers.nibobnebob.presentation.ui.main.MainViewModel import com.avengers.nibobnebob.presentation.ui.main.mypage.share.MyPageSharedUiEvent import com.avengers.nibobnebob.presentation.ui.main.mypage.share.MyPageSharedViewModel @@ -47,6 +48,7 @@ class WishRestaurantListFragment : } }) setFilterMenu() + customBack(requireActivity(), findNavController()) } override fun initNetworkView() {