Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

버튼 연속으로 눌러서 생기는 오류 수정 #212

Merged
merged 8 commits into from
Dec 11, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package app.priceguard.ui.additem
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.NavController
import androidx.navigation.NavDirections
import androidx.navigation.fragment.NavHostFragment
import app.priceguard.R
import app.priceguard.databinding.ActivityAddItemBinding
import app.priceguard.ui.additem.link.RegisterItemLinkFragmentDirections
import app.priceguard.ui.util.safeNavigate
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand Down Expand Up @@ -48,8 +47,4 @@ class AddItemActivity : AppCompatActivity() {
navController.safeNavigate(action)
}
}

private fun NavController.safeNavigate(direction: NavDirections) {
currentDestination?.getAction(direction.actionId)?.run { navigate(direction) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import android.view.ViewGroup
import androidx.activity.addCallback
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.navigation.NavController
import androidx.navigation.NavDirections
import androidx.navigation.fragment.findNavController
import app.priceguard.R
import app.priceguard.data.repository.product.ProductErrorState
import app.priceguard.data.repository.token.TokenRepository
import app.priceguard.databinding.FragmentRegisterItemLinkBinding
import app.priceguard.ui.home.HomeActivity
import app.priceguard.ui.util.lifecycle.repeatOnStarted
import app.priceguard.ui.util.safeNavigate
import app.priceguard.ui.util.showDialogWithLogout
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
Expand Down Expand Up @@ -132,10 +131,6 @@ class RegisterItemLinkFragment : Fragment() {
binding.tvRegisterItemError.text = message
}

private fun NavController.safeNavigate(direction: NavDirections) {
currentDestination?.getAction(direction.actionId)?.run { navigate(direction) }
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.net.Uri
import android.os.Bundle
import android.widget.Toast
import androidx.activity.addCallback
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import app.priceguard.R
Expand Down Expand Up @@ -32,6 +33,11 @@ class DetailActivity : AppCompatActivity(), ConfirmDialogFragment.OnDialogResult
private lateinit var binding: ActivityDetailBinding
private val productDetailViewModel: ProductDetailViewModel by viewModels()

private val activityResultLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
binding.btnDetailShare.isEnabled = true
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityDetailBinding.inflate(layoutInflater)
Expand Down Expand Up @@ -101,6 +107,7 @@ class DetailActivity : AppCompatActivity(), ConfirmDialogFragment.OnDialogResult
}

binding.btnDetailShare.setOnClickListener {
binding.btnDetailShare.isEnabled = false
val shareLink =
getString(R.string.share_link_template, productDetailViewModel.productCode)

Expand All @@ -112,7 +119,7 @@ class DetailActivity : AppCompatActivity(), ConfirmDialogFragment.OnDialogResult
}

val shareIntent = Intent.createChooser(sendIntent, null)
startActivity(shareIntent)
activityResultLauncher.launch(shareIntent)
}
}

Expand Down Expand Up @@ -270,14 +277,17 @@ class DetailActivity : AppCompatActivity(), ConfirmDialogFragment.OnDialogResult
}

private fun showConfirmationDialogForResult() {
val tag = "confirm_dialog_fragment_from_activity"
if (supportFragmentManager.findFragmentByTag(tag) != null) return

val dialogFragment = ConfirmDialogFragment()
val bundle = Bundle()
bundle.putString("title", getString(R.string.stop_tracking_confirm))
bundle.putString("message", getString(R.string.stop_tracking_detail))
bundle.putString("actionString", DialogConfirmAction.CUSTOM.name)
dialogFragment.arguments = bundle
dialogFragment.setOnDialogResultListener(this)
dialogFragment.show(supportFragmentManager, "confirm_dialog_fragment_from_fragment")
dialogFragment.show(supportFragmentManager, tag)
}

private fun showToast(message: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import app.priceguard.ui.intro.IntroActivity
import app.priceguard.ui.util.ConfirmDialogFragment
import app.priceguard.ui.util.lifecycle.repeatOnStarted
import app.priceguard.ui.util.openNotificationSettings
import app.priceguard.ui.util.safeNavigate
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
Expand Down Expand Up @@ -69,7 +70,7 @@ class MyPageFragment : Fragment(), ConfirmDialogFragment.OnDialogResultListener
}

Setting.THEME -> {
findNavController().navigate(R.id.action_myPageFragment_to_themeDialogFragment)
findNavController().safeNavigate(R.id.action_myPageFragment_to_themeDialogFragment)
}

Setting.LICENSE -> {
Expand Down Expand Up @@ -111,14 +112,17 @@ class MyPageFragment : Fragment(), ConfirmDialogFragment.OnDialogResultListener
}

private fun showConfirmationDialogForResult() {
val tag = "confirm_dialog_fragment_from_activity"
if (requireActivity().supportFragmentManager.findFragmentByTag(tag) != null) return

val dialogFragment = ConfirmDialogFragment()
val bundle = Bundle()
bundle.putString("title", getString(R.string.logout_confirm_title))
bundle.putString("message", getString(R.string.logout_confirm_message))
bundle.putString("actionString", DialogConfirmAction.CUSTOM.name)
dialogFragment.arguments = bundle
dialogFragment.setOnDialogResultListener(this)
dialogFragment.show(requireActivity().supportFragmentManager, "confirm_dialog_fragment_from_fragment")
dialogFragment.show(requireActivity().supportFragmentManager, tag)
}

private fun startIntroAndExitHome() {
Expand Down
18 changes: 15 additions & 3 deletions android/app/src/main/java/app/priceguard/ui/util/Dialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,47 @@ fun AppCompatActivity.showConfirmDialog(
message: String,
action: DialogConfirmAction = DialogConfirmAction.NOTHING
) {
val tag = "confirm_dialog_fragment_from_activity"
if (supportFragmentManager.findFragmentByTag(tag) != null) return

val dialogFragment = ConfirmDialogFragment()
val bundle = Bundle()
bundle.putString("title", title)
bundle.putString("message", message)
bundle.putString("actionString", action.name)
dialogFragment.arguments = bundle
dialogFragment.show(supportFragmentManager, "confirm_dialog_fragment_from_activity")
dialogFragment.show(supportFragmentManager, tag)
}

fun Fragment.showDialogWithAction(
title: String,
message: String,
action: DialogConfirmAction = DialogConfirmAction.NOTHING
) {
val tag = "confirm_dialog_fragment_from_activity"
if (requireActivity().supportFragmentManager.findFragmentByTag(tag) != null) return

val dialogFragment = ConfirmDialogFragment()
val bundle = Bundle()
bundle.putString("title", title)
bundle.putString("message", message)
bundle.putString("actionString", action.name)
dialogFragment.arguments = bundle
dialogFragment.show(requireActivity().supportFragmentManager, "confirm_dialog_fragment_from_fragment")
dialogFragment.show(requireActivity().supportFragmentManager, tag)
}

fun AppCompatActivity.showDialogWithLogout() {
val tag = "error_dialog_fragment_from_fragment"
if (supportFragmentManager.findFragmentByTag(tag) != null) return

val dialogFragment = ErrorDialogFragment()
dialogFragment.show(supportFragmentManager, "error_dialog_fragment_from_activity")
}

fun Fragment.showDialogWithLogout() {
val tag = "error_dialog_fragment_from_fragment"
if (requireActivity().supportFragmentManager.findFragmentByTag(tag) != null) return

val dialogFragment = ErrorDialogFragment()
dialogFragment.show(requireActivity().supportFragmentManager, "error_dialog_fragment_from_fragment")
dialogFragment.show(requireActivity().supportFragmentManager, tag)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package app.priceguard.ui.util

import androidx.navigation.NavController
import androidx.navigation.NavDirections

fun NavController.safeNavigate(direction: NavDirections) {
currentDestination?.getAction(direction.actionId)?.run { navigate(direction) }
}

fun NavController.safeNavigate(actionId: Int) {
currentDestination?.getAction(actionId)?.run { navigate(actionId) }
}