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

[feat] #182 link category change #184

Merged
merged 6 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
@@ -0,0 +1,6 @@
package designsystem.components.bottomsheet

enum class BottomSheetType {
LINK,
CLIP,
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ class LinkMindBottomSheet(context: Context) {
window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
binding.etvBottomSheet.editText.requestFocus()
}
}

fun setBottomSheetType(bottomSheetType: BottomSheetType) {
binding.etvBottomSheet.apply {
throttleAfterTextChanged {
handleTextChange()
handleTextChange(bottomSheetType)
}

onClickTextClear {
Expand All @@ -43,6 +45,7 @@ class LinkMindBottomSheet(context: Context) {
}
}
}

fun setBottomSheetHint(@StringRes textId: Int) {
binding.etvBottomSheet.editText.setHint(textId)
}
Expand All @@ -62,8 +65,8 @@ class LinkMindBottomSheet(context: Context) {
}
}

fun handleTextChange() {
val isError = showErrorMsg()
private fun handleTextChange(bottomSheetType: BottomSheetType) {
val isError = showErrorMsg(bottomSheetType)
binding.apply {
tvBottomSheetErrorText.isVisible = isError
if (isError) binding.etvBottomSheet.editText.filters = arrayOf(InputFilter.LengthFilter(16))
Expand All @@ -76,7 +79,18 @@ class LinkMindBottomSheet(context: Context) {
fun setTitle(@StringRes textId: Int) {
binding.tvBottomSheetTitle.setText(textId)
}
fun showErrorMsg(): Boolean = binding.etvBottomSheet.editText.text.length > 15 || binding.etvBottomSheet.editText.text.isEmpty()

fun showErrorMsg(bottomSheetType: BottomSheetType): Boolean {
return when (bottomSheetType) {
BottomSheetType.LINK -> {
binding.etvBottomSheet.editText.text.isEmpty()
}

BottomSheetType.CLIP -> {
binding.etvBottomSheet.editText.text.length > 15 || binding.etvBottomSheet.editText.text.isEmpty()
}
}
}

fun setErroMsg(@StringRes textId: Int) {
binding.tvBottomSheetErrorText.setText(textId)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.timer.model
package org.sopt.model.timer

import org.sopt.model.category.Category

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package org.sopt.remote.link.api

import org.sopt.network.model.response.base.BaseResponse
import org.sopt.remote.link.request.RequestIsReadDto
import org.sopt.remote.link.request.RequestPatchCategoryDto
import org.sopt.remote.link.request.RequestPatchTitleDto
import org.sopt.remote.link.request.RequestWriteDto
import org.sopt.remote.link.response.ResponseIsReadDto
import org.sopt.remote.link.response.ResponsePatchCategoryDto
import org.sopt.remote.link.response.ResponsePatchTitleDto
import retrofit2.http.Body
import retrofit2.http.DELETE
Expand All @@ -19,6 +21,7 @@ interface LinkService {
const val ISREAD = "is-read"
const val SAVE = "save"
const val TITLE = "title"
const val CATEGORY = "category"
}

@POST("/$TOAST/$SAVE")
Expand All @@ -34,4 +37,7 @@ interface LinkService {

@PATCH("/$TOAST/$TITLE")
suspend fun patchLinkTitle(@Body requestPatchTitleDto: RequestPatchTitleDto): BaseResponse<ResponsePatchTitleDto>

@PATCH("/$TOAST/$CATEGORY")
suspend fun patchToastCategory(@Body requestPatchCategoryDto: RequestPatchCategoryDto): BaseResponse<ResponsePatchCategoryDto>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.sopt.remote.link.datasource
import org.sopt.data.link.datasource.RemoteLinkDataSource
import org.sopt.remote.link.api.LinkService
import org.sopt.remote.link.request.RequestIsReadDto
import org.sopt.remote.link.request.RequestPatchCategoryDto
import org.sopt.remote.link.request.RequestPatchTitleDto
import org.sopt.remote.link.request.RequestWriteDto
import javax.inject.Inject
Expand Down Expand Up @@ -37,4 +38,12 @@ class RemoteLinkDataSourceImpl @Inject constructor(
title = title,
),
).data!!.updatedTitle

override suspend fun patchLinkCategory(toastId: Long, categoryId: Long): Long =
linkService.patchToastCategory(
RequestPatchCategoryDto(
toastId = toastId,
categoryId = categoryId,
),
).data!!.categoryId
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.sopt.remote.link.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class RequestPatchCategoryDto(
@SerialName("toastId")
val toastId: Long,
@SerialName("categoryId")
val categoryId: Long,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.sopt.remote.link.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ResponsePatchCategoryDto(
@SerialName("categoryId")
val categoryId: Long,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ interface RemoteLinkDataSource {
suspend fun postSaveLink(linkUrl: String, categoryId: Long?): Int
suspend fun deleteLink(toastId: Long): Int
suspend fun patchReadLink(toastId: Long, isRead: Boolean): Boolean

suspend fun patchLinkTitle(toastId: Long, title: String): String
suspend fun patchLinkCategory(toastId: Long, categoryId: Long): Long
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ class LinkRepoImpl @Inject constructor(

override suspend fun patchLinkTitle(toastId: Long, title: String): Result<String> =
runCatching { remoteCategoryDataSource.patchLinkTitle(toastId, title) }

override suspend fun patchToastCategory(toastId: Long, categoryId: Long): Result<Long> =
runCatching { remoteCategoryDataSource.patchLinkCategory(toastId, categoryId) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ interface LinkRepository {
suspend fun postSaveLink(linkUrl: String, categoryId: Long?): Result<Int>
suspend fun deleteLink(toastId: Long): Result<Int>
suspend fun patchReadLink(toastId: Long, isRead: Boolean): Result<Boolean>

suspend fun patchLinkTitle(toastId: Long, title: String): Result<String>
suspend fun patchToastCategory(toastId: Long, categoryId: Long): Result<Long>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.sopt.domain.link.usecase

import org.sopt.domain.link.repository.LinkRepository
import javax.inject.Inject

class PatchLinkCategoryUseCase @Inject constructor(
private val linkRepository: LinkRepository,
) {
suspend operator fun invoke(param: Param): Result<Long> = linkRepository.patchToastCategory(
toastId = param.toastId,
categoryId = param.categoryId,
)

data class Param(
val toastId: Long,
val categoryId: Long,
)
}
Original file line number Diff line number Diff line change
@@ -1,48 +1,76 @@
package org.sopt.clip

import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.core.view.isVisible
import org.sopt.clip.databinding.FragmentDeleteLinkBottomSheetBinding
import org.sopt.ui.base.BindingBottomSheetDialogFragment
import org.sopt.ui.view.onThrottleClick

class DeleteLinkBottomSheetFragment() :
BindingBottomSheetDialogFragment<FragmentDeleteLinkBottomSheetBinding>({ FragmentDeleteLinkBottomSheetBinding.inflate(it) }) {
var id: Int? = null
var clipId: Long? = null
var isFullClipSize: Boolean? = null
private var handleDelete: () -> Unit = {}
private var handleChange: () -> Unit = {}
private var handleModify: () -> Unit = {}
private var isClipListEmptySnackBar: () -> Unit = {}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
clipId = arguments?.getLong("clipId")
isFullClipSize = arguments?.getBoolean("isFullClipSize")
}

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

if (clipId?.toInt() == 0) {
binding.tvDeleteLinkChange.isVisible = false
}

binding.ivDeleteLinkBottomSheetClose.setOnClickListener {
dismiss()
}
binding.tvDeleteLinkDelete.onThrottleClick {
Log.d("test", "test")
handleDelete.invoke()
dismiss()
}

binding.tvDeleteLinkChange.onThrottleClick {
if (isFullClipSize == true) {
handleChange.invoke()
} else {
isClipListEmptySnackBar.invoke()
}
dismiss()
}

binding.tvDeleteLinkModify.onThrottleClick {
handleModify.invoke()
dismiss()
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
id = arguments?.getInt("id")
}

companion object {
fun newInstance(id: Int, handleDeleteButton: () -> Unit, handleModifyButton: () -> Unit): DeleteLinkBottomSheetFragment {
fun newInstance(
clipId: Long,
isFullClipSize: Boolean,
isClipListEmpty: () -> Unit,
handleDeleteButton: () -> Unit,
handleChangeButton: () -> Unit,
handleModifyButton: () -> Unit,
): DeleteLinkBottomSheetFragment {
val args = Bundle().apply {
putInt("id", id)
putLong("clipId", clipId)
putBoolean("isFullClipSize", isFullClipSize)
}
return DeleteLinkBottomSheetFragment().apply {
arguments = args
handleDelete = handleDeleteButton
handleChange = handleChangeButton
handleModify = handleModifyButton
isClipListEmptySnackBar = isClipListEmpty
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions feature/clip/src/main/java/org/sopt/clip/clip/ClipFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.fragment.app.viewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.navigation.fragment.findNavController
import dagger.hilt.android.AndroidEntryPoint
import designsystem.components.bottomsheet.BottomSheetType
import designsystem.components.bottomsheet.LinkMindBottomSheet
import designsystem.components.toast.linkMindSnackBar
import kotlinx.coroutines.flow.launchIn
Expand Down Expand Up @@ -115,6 +116,7 @@ class ClipFragment : BindingFragment<FragmentClipBinding>({ FragmentClipBinding.
val addClipBottomSheet = LinkMindBottomSheet(requireContext())
addClipBottomSheet.show()
addClipBottomSheet.apply {
setBottomSheetType(BottomSheetType.CLIP)
setBottomSheetHint(org.sopt.mainfeature.R.string.clip_new_clip_info)
setTitle(org.sopt.mainfeature.R.string.clip_add_clip)
setErroMsg(org.sopt.mainfeature.R.string.error_clip_length)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.sopt.clip.clipchange

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.ListAdapter
import org.sopt.clip.databinding.ItemClipChangeBinding
import org.sopt.model.timer.Clip
import org.sopt.ui.view.ItemDiffCallback

class ClipChangeAdapter(
private val onClick: (Clip, Int) -> Unit,
private val context: Context,
) : ListAdapter<Clip, ClipChangeViewHolder>(DiffUtil) {
var selectedPosition = -1
override fun onBindViewHolder(holder: ClipChangeViewHolder, position: Int) {
holder.onBind(getItem(position), position) { clip, position ->
selectItemByPosition(position, clip)
onClick(clip, position)
}

if (position == 0) {
val disMissClickColor = ContextCompat.getColor(context, org.sopt.mainfeature.R.color.neutrals400)
holder.binding.ivItemClipChange.setColorFilter(disMissClickColor)
holder.binding.tvItemClipChangeName.setTextColor(disMissClickColor)
holder.binding.tvItemClipChangeCount.setTextColor(disMissClickColor)
holder.binding.root.isEnabled = false
}
}

private fun selectItemByPosition(position: Int, clip: Clip) {
if (selectedPosition != position) {
if (selectedPosition != -1) {
getItem(selectedPosition).isSelected = false
notifyItemChanged(selectedPosition)
}
clip.isSelected = true
selectedPosition = position
} else {
clip.isSelected = !clip.isSelected
if (!clip.isSelected) {
selectedPosition = -1
}
}
notifyItemChanged(position)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ClipChangeViewHolder {
return ClipChangeViewHolder(
ItemClipChangeBinding.inflate(LayoutInflater.from(parent.context), parent, false),
context,
)
}

companion object {
private val DiffUtil = ItemDiffCallback<Clip>(
onItemsTheSame = { old, new -> old == new },
Copy link
Contributor

Choose a reason for hiding this comment

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

id

onContentsTheSame = { old, new -> old == new },
)
}
}
Loading
Loading