-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…mend #299 [feat] 추천한/추천받은 책 삭제
- Loading branch information
Showing
42 changed files
with
438 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/sopt/peekabookaos/domain/usecase/DeleteRecommendUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.sopt.peekabookaos.domain.usecase | ||
|
||
import com.sopt.peekabookaos.domain.repository.RecommendRepository | ||
import javax.inject.Inject | ||
|
||
class DeleteRecommendUseCase @Inject constructor( | ||
private val recommendRepository: RecommendRepository | ||
) { | ||
suspend operator fun invoke(recommendId: Int) = recommendRepository.deleteRecommend(recommendId) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
app/src/main/java/com/sopt/peekabookaos/presentation/recommend/RecommendDeleteDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.sopt.peekabookaos.presentation.recommend | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.view.WindowManager | ||
import androidx.fragment.app.DialogFragment | ||
import androidx.fragment.app.activityViewModels | ||
import com.sopt.peekabookaos.R | ||
import com.sopt.peekabookaos.databinding.DialogRecommendDeleteBinding | ||
import com.sopt.peekabookaos.util.UiEvent | ||
import com.sopt.peekabookaos.util.extensions.getSerializableCompat | ||
import com.sopt.peekabookaos.util.extensions.repeatOnStarted | ||
import timber.log.Timber | ||
|
||
class RecommendDeleteDialog : DialogFragment() { | ||
private var _binding: DialogRecommendDeleteBinding? = null | ||
private val binding get() = _binding ?: error(getString(R.string.binding_error)) | ||
|
||
private val recommendViewModel by activityViewModels<RecommendViewModel>() | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
_binding = DialogRecommendDeleteBinding.inflate(inflater, container, false) | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
isCancelable = true | ||
initLayout() | ||
initWarningDialogContent() | ||
initConfirmBtnClickListener() | ||
initCancelBtnClickListener() | ||
collectUiEvent() | ||
} | ||
|
||
private fun collectUiEvent() { | ||
repeatOnStarted { | ||
recommendViewModel.uiEvent.collect { uiEvent -> | ||
when (uiEvent) { | ||
UiEvent.IDLE -> {} | ||
UiEvent.SUCCESS -> { | ||
recommendViewModel.getRecommend() | ||
dismiss() | ||
} | ||
|
||
UiEvent.ERROR -> { | ||
dismiss() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun initLayout() { | ||
val ratio = 0.89 | ||
val layoutParams = requireNotNull(dialog).window!!.attributes | ||
layoutParams.width = (resources.displayMetrics.widthPixels * ratio).toInt() | ||
layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT | ||
requireNotNull(dialog).window!!.attributes = layoutParams | ||
} | ||
|
||
private fun initWarningDialogContent() { | ||
val recommendType = arguments?.getSerializableCompat(RECOMMEND_TYPE) as? RecommendType | ||
?: Timber.e(getString(R.string.null_point_exception_warning_dialog_argument)) | ||
with(binding) { | ||
type = when (recommendType as RecommendType) { | ||
RecommendType.RECOMMENDED -> | ||
RecommendDeleteDialogContent().getRecommended(requireContext()) | ||
|
||
RecommendType.RECOMMENDING -> | ||
RecommendDeleteDialogContent().getRecommending(requireContext()) | ||
} | ||
} | ||
} | ||
|
||
private fun initConfirmBtnClickListener() { | ||
binding.btnRecommendDeleteDialogConfirm.setOnClickListener { | ||
recommendViewModel.deleteRecommend() | ||
} | ||
} | ||
|
||
private fun initCancelBtnClickListener() { | ||
binding.btnRecommendDeleteDialogCancel.setOnClickListener { | ||
dismiss() | ||
} | ||
} | ||
|
||
override fun onDestroyView() { | ||
super.onDestroyView() | ||
_binding = null | ||
} | ||
|
||
companion object { | ||
const val DIALOG_TYPE = "recommendDeleteDialog" | ||
const val RECOMMEND_TYPE = "recommendType" | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...rc/main/java/com/sopt/peekabookaos/presentation/recommend/RecommendDeleteDialogContent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.sopt.peekabookaos.presentation.recommend | ||
|
||
import android.content.Context | ||
import com.sopt.peekabookaos.R | ||
|
||
data class RecommendDeleteDialogContent( | ||
val title: String = "", | ||
val content: String = "" | ||
) { | ||
fun getRecommended(context: Context): RecommendDeleteDialogContent = | ||
RecommendDeleteDialogContent( | ||
title = context.getString(R.string.recommend_recommended_delete_dialog_title), | ||
content = context.getString(R.string.recommend_recommended_delete_dialog_content) | ||
) | ||
|
||
fun getRecommending(context: Context): RecommendDeleteDialogContent = | ||
RecommendDeleteDialogContent( | ||
title = context.getString(R.string.recommend_recommending_delete_dialog_title), | ||
content = context.getString(R.string.recommend_recommending_delete_dialog_content) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
app/src/main/java/com/sopt/peekabookaos/presentation/recommend/RecommendType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.sopt.peekabookaos.presentation.recommend | ||
|
||
enum class RecommendType { | ||
RECOMMENDED, RECOMMENDING | ||
} |
71 changes: 68 additions & 3 deletions
71
app/src/main/java/com/sopt/peekabookaos/presentation/recommend/RecommendViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.