diff --git a/android/app/src/main/java/com/now/naaga/presentation/beginadventure/LocationDialogFragment.kt b/android/app/src/main/java/com/now/naaga/presentation/beginadventure/LocationDialogFragment.kt deleted file mode 100644 index 3eafb176f..000000000 --- a/android/app/src/main/java/com/now/naaga/presentation/beginadventure/LocationDialogFragment.kt +++ /dev/null @@ -1,73 +0,0 @@ -package com.now.naaga.presentation.beginadventure - -import android.content.Context -import android.content.Intent -import android.graphics.Color -import android.graphics.drawable.ColorDrawable -import android.net.Uri -import android.os.Build -import android.os.Bundle -import android.provider.Settings -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.view.WindowManager -import androidx.fragment.app.DialogFragment -import com.now.naaga.databinding.DialogLocationPermissionBinding -import kotlin.math.roundToInt - -class LocationDialogFragment : DialogFragment() { - private lateinit var binding: DialogLocationPermissionBinding - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle?, - ): View { - binding = DialogLocationPermissionBinding.inflate(layoutInflater) - dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) - return binding.root - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - setFragmentWidth() - binding.btnDialogLocationSetting.setOnClickListener { - goSetting() - dismiss() - } - } - - private fun setFragmentWidth() { - dialog?.window?.setLayout(getWidth(), convertDpToPx()) - } - - private fun getWidth(): Int { - val windowManager: WindowManager = - requireContext().getSystemService(Context.WINDOW_SERVICE) as WindowManager - - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - (windowManager.currentWindowMetrics.bounds.width() * WIDTH_PERCENTAGE).toInt() - } else { - (windowManager.defaultDisplay.width * WIDTH_PERCENTAGE).toInt() - } - } - - private fun convertDpToPx(): Int { - val density = requireContext().resources.displayMetrics.density - return (DP.toFloat() * density).roundToInt() - } - - private fun goSetting() { - val appDetailsIntent = Intent( - Settings.ACTION_APPLICATION_DETAILS_SETTINGS, - Uri.parse("package:${requireContext().packageName}"), - ).addCategory(Intent.CATEGORY_DEFAULT) - startActivity(appDetailsIntent) - } - - companion object { - const val WIDTH_PERCENTAGE = 0.83 - const val DP = 400 - } -} diff --git a/android/app/src/main/java/com/now/naaga/presentation/beginadventure/PolaroidDialog.kt b/android/app/src/main/java/com/now/naaga/presentation/beginadventure/PolaroidDialog.kt new file mode 100644 index 000000000..535d39ac4 --- /dev/null +++ b/android/app/src/main/java/com/now/naaga/presentation/beginadventure/PolaroidDialog.kt @@ -0,0 +1,66 @@ +package com.now.naaga.presentation.beginadventure + +import android.graphics.Color +import android.graphics.drawable.ColorDrawable +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.view.ViewGroup.LayoutParams.WRAP_CONTENT +import androidx.fragment.app.DialogFragment +import com.bumptech.glide.Glide +import com.now.naaga.databinding.DialogPolaroidBinding +import com.now.naaga.util.getWidthProportionalToDevice + +class PolaroidDialog : DialogFragment() { + private lateinit var binding: DialogPolaroidBinding + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle?, + ): View { + binding = DialogPolaroidBinding.inflate(layoutInflater) + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) + dialog?.setCanceledOnTouchOutside(false) + clickClose() + setSize() + setPhoto() + } + + private fun setPhoto() { + val photo: String? = arguments?.getString(PHOTO) + Glide.with(binding.ivImageDialogDestinationImage) + .load(photo) + .into(binding.ivImageDialogDestinationImage) + } + + private fun clickClose() { + binding.ivImageDialogClose.setOnClickListener { + dialog?.hide() + } + } + + private fun setSize() { + val dialogWidth = getWidthProportionalToDevice(requireContext(), WIDTH_RATE) + dialog?.window?.setLayout(dialogWidth, WRAP_CONTENT) + } + + companion object { + private const val WIDTH_RATE = 0.9f + private const val PHOTO = "PHOTO" + + fun makeDialog(photo: String): PolaroidDialog { + return PolaroidDialog().apply { + val bundle = Bundle() + bundle.putString(PHOTO, photo) + arguments = bundle + } + } + } +}