Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.wafflestudio.siksha2.R
import com.wafflestudio.siksha2.databinding.DialogProfileImageBinding

class ImageBottomDialog(
private val onGallerySelected: () -> Unit,
private val onDefaultImageSelected: () -> Unit
) : BottomSheetDialogFragment() {
class ImageBottomDialog : BottomSheetDialogFragment() {

interface Listener {
fun onGallerySelected()
fun onDefaultImageSelected()
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BottomSheetDialogFragment는 함수 매개변수를 받고 있었기 때문에 리스너를 추가해서 해결했습니다.

private val listener: Listener?
get() = parentFragment as? Listener ?: activity as? Listener

override fun onCreateView(
inflater: LayoutInflater,
Expand All @@ -24,12 +29,12 @@ class ImageBottomDialog(
val binding = DialogProfileImageBinding.inflate(inflater, container, false)

binding.albumRow.setOnClickListener {
onGallerySelected()
listener?.onGallerySelected()
dismiss()
}

binding.defaultImageRow.setOnClickListener {
onDefaultImageSelected()
listener?.onDefaultImageSelected()
dismiss()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,12 @@ class DailyRestaurantFragment : Fragment() {
}

binding.menuFilter.setOnClickListener {
val filterDialog = FilterDialogFragment(FilterMode.FULL)
val filterDialog = FilterDialogFragment.newInstance(FilterMode.FULL)
filterDialog.show(parentFragmentManager, "FilterDialog")
}

binding.filterDistance.setOnClickListener {
val filterDialog = FilterDialogFragment(FilterMode.DISTANCE)
val filterDialog = FilterDialogFragment.newInstance(FilterMode.DISTANCE)
filterDialog.show(parentFragmentManager, "FilterDialog")

val permission = Manifest.permission.ACCESS_FINE_LOCATION
Expand All @@ -356,17 +356,17 @@ class DailyRestaurantFragment : Fragment() {
ContextCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED
) {
requestPermission {
val filterDialog = FilterDialogFragment(FilterMode.DISTANCE)
val filterDialog = FilterDialogFragment.newInstance(FilterMode.DISTANCE)
filterDialog.show(parentFragmentManager, "FilterDialog")
}
} else {
val filterDialog = FilterDialogFragment(FilterMode.DISTANCE)
val filterDialog = FilterDialogFragment.newInstance(FilterMode.DISTANCE)
filterDialog.show(parentFragmentManager, "FilterDialog")
}
}

binding.filterPrice.setOnClickListener {
val filterDialog = FilterDialogFragment(FilterMode.PRICE)
val filterDialog = FilterDialogFragment.newInstance(FilterMode.PRICE)
filterDialog.show(parentFragmentManager, "FilterDialog")
}

Expand All @@ -379,12 +379,12 @@ class DailyRestaurantFragment : Fragment() {
}

binding.filterRating.setOnClickListener {
val filterDialog = FilterDialogFragment(FilterMode.RATING)
val filterDialog = FilterDialogFragment.newInstance(FilterMode.RATING)
filterDialog.show(parentFragmentManager, "FilterDialog")
}

binding.filterCategory.setOnClickListener {
val filterDialog = FilterDialogFragment(FilterMode.CATEGORY)
val filterDialog = FilterDialogFragment.newInstance(FilterMode.CATEGORY)
filterDialog.show(parentFragmentManager, "FilterDialog")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,23 @@ import java.util.Locale
import javax.inject.Inject

@AndroidEntryPoint
class FilterDialogFragment(
private val mode: FilterMode
) : DialogFragment() {
class FilterDialogFragment() : DialogFragment() {
companion object {
private const val DEFAULT_MODE = "FULL"

fun newInstance(type: FilterMode): FilterDialogFragment {
return FilterDialogFragment().apply {
arguments = Bundle().apply {
putString(DEFAULT_MODE, type.name)
}
}
}
}
Comment on lines +39 to +49
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FilterDialog의 경우 enum class인 FilterMode만 받으면 되기 때문에 newInstance를 정의해 주어서 해결했습니다.


private val mode: FilterMode by lazy {
enumValueOf(requireArguments().getString(DEFAULT_MODE)!!)
}

@Inject
lateinit var mixpanelManager: MixpanelManager

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import kotlinx.coroutines.launch
import timber.log.Timber
import kotlin.properties.Delegates

class UserProfileFragment : Fragment() {
class UserProfileFragment : Fragment(), ImageBottomDialog.Listener {
private lateinit var binding: FragmentUserProfileBinding
private val settingViewModel: SettingViewModel by activityViewModels()

Expand Down Expand Up @@ -138,10 +138,7 @@ class UserProfileFragment : Fragment() {
}

private fun showImagePickerBottomDialog() {
val bottomSheetFragment = ImageBottomDialog(
onGallerySelected = { changeToGalleryImage() },
onDefaultImageSelected = { changeToDefaultImage() }
)
val bottomSheetFragment = ImageBottomDialog()
bottomSheetFragment.show(childFragmentManager, bottomSheetFragment.tag)
}

Expand Down Expand Up @@ -170,12 +167,12 @@ class UserProfileFragment : Fragment() {
imm.hideSoftInputFromWindow(binding.root.windowToken, 0)
}

private fun changeToGalleryImage() {
override fun onGallerySelected() {
pickImage.launch("image/*")
imageChanged = true
}

private fun changeToDefaultImage() {
override fun onDefaultImageSelected() {
settingViewModel.updateImageUri(null)
imageView.apply {
setImageResource(R.drawable.ic_rice_bowl)
Expand Down
Loading