Skip to content

Commit

Permalink
Merge branch 'feature/BDBD-513' into stage/sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
re4rk committed Feb 1, 2023
2 parents 6ec1e0e + d2209fb commit c98ddd5
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import retrofit2.http.Path

interface ProductEditorService {
@Multipart
@POST("product/getProductInfo/{productId}/modify")
@POST("product/modifyProductInfo/{productId}")
suspend fun postProductModification(
@Path("productId") productId: Long,
@PartMap productEditorInfo: Map<String, String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import com.fakedevelopers.presentation.ui.base.BaseFragment
import com.fakedevelopers.presentation.ui.productEditor.ProductEditorDto
import com.fakedevelopers.presentation.ui.util.DATE_PATTERN
import com.fakedevelopers.presentation.ui.util.repeatOnStarted
import com.orhanobut.logger.Logger
import dagger.hilt.android.AndroidEntryPoint
import org.threeten.bp.LocalDateTime
import org.threeten.bp.Period
Expand Down Expand Up @@ -78,8 +77,6 @@ class ProductDetailFragment : BaseFragment<FragmentProductDetailBinding>(
}

private fun navigateEditProduct(productDetailDto: ProductDetailDto) {
if (productDetailDto.productTitle.isBlank() || viewModel.productId == -1L) return

findNavController().navigate(
ProductDetailFragmentDirections.actionProductDetailFragmentToProductModificationFragment(
ProductEditorDto(viewModel.productId, productDetailDto),
Expand All @@ -89,7 +86,6 @@ class ProductDetailFragment : BaseFragment<FragmentProductDetailBinding>(
}

private fun setPagerCount(position: Int, totalCount: Int = productDetailAdapter.itemCount) {
Logger.i("$position $totalCount")
binding.textviewProductDetailPictureCount.text =
getString(R.string.product_detail_picture_count, position + 1, totalCount)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import androidx.core.content.PermissionChecker.checkCallingOrSelfPermission
import androidx.core.view.isVisible
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.ItemTouchHelper
import com.fakedevelopers.presentation.R
import com.fakedevelopers.presentation.databinding.FragmentProductEditorBinding
import com.fakedevelopers.presentation.ui.base.BaseFragment
Expand All @@ -28,6 +30,7 @@ import com.fakedevelopers.presentation.ui.productEditor.PriceTextWatcher.Compani
import com.fakedevelopers.presentation.ui.productEditor.PriceTextWatcher.Companion.MAX_EXPIRATION_TIME
import com.fakedevelopers.presentation.ui.productEditor.PriceTextWatcher.Companion.MAX_PRICE_LENGTH
import com.fakedevelopers.presentation.ui.productEditor.PriceTextWatcher.Companion.MAX_TICK_LENGTH
import com.fakedevelopers.presentation.ui.productModification.ProductModificationFragmentArgs
import com.fakedevelopers.presentation.ui.util.ApiErrorHandler
import com.fakedevelopers.presentation.ui.util.KeyboardVisibilityUtils
import com.fakedevelopers.presentation.ui.util.priceToLong
Expand All @@ -42,6 +45,8 @@ open class ProductEditorFragment : BaseFragment<FragmentProductEditorBinding>(
private lateinit var keyboardVisibilityUtils: KeyboardVisibilityUtils
protected lateinit var permissionLauncher: ActivityResultLauncher<String>

protected val args: ProductModificationFragmentArgs by navArgs()

protected val viewModel: ProductEditorViewModel by viewModels()
private val expirationFilter by lazy {
InputFilter { source, _, _, _, dstart, _ ->
Expand All @@ -61,6 +66,14 @@ open class ProductEditorFragment : BaseFragment<FragmentProductEditorBinding>(
super.onViewCreated(view, savedInstanceState)
binding.vm = viewModel

args.productEditorDto?.let {
viewModel.initState(it)
if (it.selectedImageInfo.uris.isNotEmpty()) {
ItemTouchHelper(DragAndDropCallback(viewModel.adapter))
.attachToRecyclerView(binding.recyclerProductEditor)
}
}

if (viewModel.category.isNotEmpty()) {
setCategory(viewModel.category)
}
Expand All @@ -85,15 +98,19 @@ open class ProductEditorFragment : BaseFragment<FragmentProductEditorBinding>(
}
}

protected open fun toPictureSelectFragment(permission: String) {
private fun toPictureSelectFragment(permission: String) {
val permissionCheck = checkCallingOrSelfPermission(requireContext(), permission)
if (permissionCheck == PermissionChecker.PERMISSION_GRANTED) {
findNavController().navigate(R.id.action_productRegistrationFragment_to_pictureSelectFragment)
navigatePictureSelectFragment()
} else {
permissionLauncher.launch(permission)
}
}

protected open fun navigatePictureSelectFragment() {
findNavController().navigate(R.id.action_productRegistrationFragment_to_pictureSelectFragment)
}

protected open fun initListener() {
// 가격 필터 등록
initEditTextFilter(binding.edittextProductEditorHopePrice, MAX_PRICE_LENGTH)
Expand Down Expand Up @@ -227,8 +244,8 @@ open class ProductEditorFragment : BaseFragment<FragmentProductEditorBinding>(

// 희망가 <= 최소 입찰가 인지 검사
protected fun checkPriceCondition(): Boolean {
val openingBid = viewModel.openingBid.value.priceToLong() ?: return false
val hopePrice = viewModel.hopePrice.value.priceToLong()
val openingBid = viewModel.openingBid.priceToLong() ?: return false
val hopePrice = viewModel.hopePrice.priceToLong()
if (hopePrice != null && hopePrice <= openingBid) {
sendSnackBar(getString(R.string.product_registration_error_minimum_bid))
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ class ProductEditorViewModel @Inject constructor(

var productId = 0L

val selectedImageInfo = SelectedImageInfo()
val title = MutableStateFlow("")
var editorToolbarTitle = ""
private val selectedImageInfo = SelectedImageInfo()

var title = ""
val content = MutableStateFlow("")
val hopePrice = MutableStateFlow("")
val openingBid = MutableStateFlow("")
val tick = MutableStateFlow("")
val expiration = MutableStateFlow("")
var hopePrice = ""
var openingBid = ""
var tick = ""
var expiration = ""

init {
requestProductCategory()
Expand Down Expand Up @@ -107,21 +109,21 @@ class ProductEditorViewModel @Inject constructor(
fun checkEditorCondition() {
viewModelScope.launch {
// 희망가, 호가, 만료 시간은 0이 되면 안됨
if (hopePrice.value == "0") {
hopePrice.emit("")
if (hopePrice == "0") {
hopePrice = ""
}
if (tick.value == "0") {
tick.emit("")
if (tick == "0") {
tick = ""
}
if (expiration.value == "0") {
expiration.emit("")
if (expiration == "0") {
expiration = ""
}
_condition.emit(
title.value.isNotEmpty() &&
(hopePrice.value.isEmpty() || hopePrice.value.priceToLong() != null) &&
openingBid.value.priceToLong() != null &&
tick.value.priceToInt() != null &&
expiration.value.toIntOrNull() != null &&
title.isNotEmpty() &&
(hopePrice.isEmpty() || hopePrice.priceToLong() != null) &&
openingBid.priceToLong() != null &&
tick.priceToInt() != null &&
expiration.toIntOrNull() != null &&
content.value.isNotEmpty()
)
}
Expand All @@ -136,7 +138,6 @@ class ProductEditorViewModel @Inject constructor(

fun requestProductModification(productId: Long) {
viewModelScope.launch {
println("hello")
val imageInfo = getMultipartList()
_productEditorResponse.emit(productModificationUseCase(productId, getProductEditorInfo(imageInfo)))
}
Expand All @@ -163,41 +164,41 @@ class ProductEditorViewModel @Inject constructor(
viewModelScope.launch {
categoryID = state.categoryId
adapter.submitList(selectedImageInfo.uris.toMutableList())
title.emit(state.title)
hopePrice.emit(state.hopePrice)
openingBid.emit(state.openingBid)
tick.emit(state.tick)
expiration.emit(state.expiration)
title = state.title
hopePrice = state.hopePrice
openingBid = state.openingBid
tick = state.tick
expiration = state.expiration
content.emit(state.content)
}
}

private fun getProductEditorInfo(imageInfo: List<MultipartBody.Part>): ProductEditorInfo {
val date = LocalDateTime.ofInstant(
Instant.ofEpochMilli(System.currentTimeMillis() + expiration.value.toInt() * 3600000),
Instant.ofEpochMilli(System.currentTimeMillis() + expiration.toInt() * 3600000),
ZoneId.of("Asia/Seoul")
)

return ProductEditorInfo(
content.value,
title.value,
title,
dateFormatter.format(date),
hopePrice.value.replace(",", ""),
openingBid.value.replace(",", ""),
hopePrice.replace(",", ""),
openingBid.replace(",", ""),
"0",
tick.value.replace(",", ""),
tick.replace(",", ""),
categoryID.toString(),
imageInfo
)
}

fun getProductEditorDto() = ProductEditorDto(
selectedImageInfo,
title.value,
hopePrice.value,
openingBid.value,
tick.value,
expiration.value,
title,
hopePrice,
openingBid,
tick,
expiration,
content.value,
categoryID
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@ package com.fakedevelopers.presentation.ui.productModification
import android.os.Bundle
import android.view.View
import androidx.activity.OnBackPressedCallback
import androidx.core.content.PermissionChecker
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.ItemTouchHelper
import com.fakedevelopers.presentation.R
import com.fakedevelopers.presentation.ui.productEditor.DragAndDropCallback
import com.fakedevelopers.presentation.ui.productEditor.ProductEditorFragment
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch

@AndroidEntryPoint
class ProductModificationFragment : ProductEditorFragment() {
private val args: ProductModificationFragmentArgs by navArgs()

override val backPressedCallback by lazy {
object : OnBackPressedCallback(true) {
Expand All @@ -28,15 +21,7 @@ class ProductModificationFragment : ProductEditorFragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.includeProductEditorToolbar.textviewToolbarTitle.text = getString(R.string.product_modification_title)
args.productEditorDto?.let {
viewModel.initState(it)
if (it.selectedImageInfo.uris.isNotEmpty()) {
ItemTouchHelper(DragAndDropCallback(viewModel.adapter))
.attachToRecyclerView(binding.recyclerProductEditor)
}
}

viewModel.editorToolbarTitle = "내 물건 수정"
viewModel.productId = args.productId
}

Expand All @@ -47,27 +32,15 @@ class ProductModificationFragment : ProductEditorFragment() {
if (viewModel.condition.value && checkPriceCondition()) {
sendSnackBar("게시글 수정 요청")
binding.includeProductEditorToolbar.buttonToolbarRegistration.isEnabled = false
lifecycleScope.launch {
viewModel.requestProductModification(viewModel.productId)
}
viewModel.requestProductModification(viewModel.productId)
}
}
}

override fun toPictureSelectFragment(permission: String) {
val permissionCheck =
PermissionChecker.checkCallingOrSelfPermission(requireContext(), permission)
if (permissionCheck == PermissionChecker.PERMISSION_GRANTED) {
findNavController().navigate(
ProductModificationFragmentDirections
.actionProductModificationFragmentToPictureSelectFragment(viewModel.getProductEditorDto())
)
} else {
permissionLauncher.launch(permission)
}
}

override fun onDestroyView() {
super.onDestroyView()
override fun navigatePictureSelectFragment() {
findNavController().navigate(
ProductModificationFragmentDirections
.actionProductModificationFragmentToPictureSelectFragment(viewModel.getProductEditorDto())
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@ package com.fakedevelopers.presentation.ui.productRegistration
import android.os.Bundle
import android.view.View
import androidx.activity.OnBackPressedCallback
import androidx.core.content.PermissionChecker
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.ItemTouchHelper
import com.fakedevelopers.presentation.R
import com.fakedevelopers.presentation.ui.productEditor.DragAndDropCallback
import com.fakedevelopers.presentation.ui.productEditor.ProductEditorFragment
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class ProductRegistrationFragment : ProductEditorFragment() {
private val args: ProductRegistrationFragmentArgs by navArgs()

override val backPressedCallback by lazy {
object : OnBackPressedCallback(true) {
Expand All @@ -26,18 +21,12 @@ class ProductRegistrationFragment : ProductEditorFragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

args.productEditorDto?.let {
viewModel.initState(it)
if (it.selectedImageInfo.uris.isNotEmpty()) {
ItemTouchHelper(DragAndDropCallback(viewModel.adapter))
.attachToRecyclerView(binding.recyclerProductEditor)
}
}
viewModel.editorToolbarTitle = "내 물건 등록"
}

override fun initListener() {
super.initListener()
// 게시글 등록 요청
binding.includeProductEditorToolbar.buttonToolbarRegistration.setOnClickListener {
if (viewModel.condition.value && checkPriceCondition()) {
sendSnackBar("게시글 등록 요청")
Expand All @@ -47,20 +36,10 @@ class ProductRegistrationFragment : ProductEditorFragment() {
}
}

override fun toPictureSelectFragment(permission: String) {
val permissionCheck =
PermissionChecker.checkCallingOrSelfPermission(requireContext(), permission)
if (permissionCheck == PermissionChecker.PERMISSION_GRANTED) {
findNavController().navigate(
ProductRegistrationFragmentDirections
.actionProductRegistrationFragmentToPictureSelectFragment(viewModel.getProductEditorDto())
)
} else {
permissionLauncher.launch(permission)
}
}

override fun onDestroyView() {
super.onDestroyView()
override fun navigatePictureSelectFragment() {
findNavController().navigate(
ProductRegistrationFragmentDirections
.actionProductRegistrationFragmentToPictureSelectFragment(viewModel.getProductEditorDto())
)
}
}
2 changes: 2 additions & 0 deletions presentation/src/main/res/layout/fragment_product_editor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:bind="http://schemas.android.com/apk/res-auto"
tools:context=".ui.productEditor.ProductEditorFragment">
<data>
<import type="android.view.View"/>
Expand All @@ -17,6 +18,7 @@
<include
android:id="@+id/include_product_editor_toolbar"
layout="@layout/toolbar_product_editor"
bind:title="@{vm.editorToolbarTitle}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand Down
Loading

0 comments on commit c98ddd5

Please sign in to comment.