Skip to content

Commit

Permalink
[UI] #83 검색/포킷 상세 화면에서 링크 리스트 내 북마크 표시여부가 보여지도록 수정, 검색 화면에서 북마크 변경이 안…
Browse files Browse the repository at this point in the history
…되었던 문제 수정
  • Loading branch information
l5x5l committed Nov 30, 2024
1 parent 1be1ea6 commit 3e21c9b
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ object LinkMapper {
alertYn = data.alertYn,
createdAt = data.createdAt,
isRead = data.isRead,
thumbnail = data.thumbNail
thumbnail = data.thumbNail,
favorites = data.isFavorite,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ data class GetLinksResponse(
val createdAt: String,
val isRead: Boolean,
val thumbNail: String,
val isFavorite: Boolean,
)

@Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package pokitmons.pokit.home.remind

import android.content.Context
import androidx.compose.foundation.background
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
Expand All @@ -19,7 +18,6 @@ import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
Expand All @@ -28,12 +26,10 @@ import coil.compose.rememberAsyncImagePainter
import com.strayalpaca.pokitdetail.R
import com.strayalpaca.pokitdetail.model.BottomSheetType
import pokitmons.pokit.core.feature.model.NetworkState
import pokitmons.pokit.core.feature.utils.ShareUrlLink
import pokitmons.pokit.core.ui.components.atom.loading.LoadingProgress
import pokitmons.pokit.core.ui.components.block.linkcard.LinkCard
import pokitmons.pokit.core.ui.components.template.bottomsheet.PokitBottomSheet
import pokitmons.pokit.core.ui.components.template.linkdetailbottomsheet.LinkDetailBottomSheet
import pokitmons.pokit.core.ui.components.template.modifybottomsheet.ModifyBottomSheetContent
import pokitmons.pokit.core.ui.components.template.pookiempty.EmptyPooki
import pokitmons.pokit.core.ui.components.template.pookierror.ErrorPooki
import pokitmons.pokit.core.ui.components.template.removeItemBottomSheet.TwoButtonBottomSheetContent
Expand All @@ -60,9 +56,6 @@ fun RemindScreen(
val currentDetailShowLink by viewModel.currentShowingLink.collectAsState()

val pokitOptionBottomSheetType by viewModel.pokitOptionBottomSheetType.collectAsState()
val currentSelectedLink by viewModel.currentSelectedLink.collectAsState()

val context: Context = LocalContext.current
val uriHandler = LocalUriHandler.current

val showTotalEmpty by remember {
Expand All @@ -79,23 +72,6 @@ fun RemindScreen(
show = pokitOptionBottomSheetType != null
) {
when (pokitOptionBottomSheetType) {
BottomSheetType.MODIFY -> {
ModifyBottomSheetContent(
onClickShare = {
ShareUrlLink(
context = context,
url = viewModel.currentShowingLink.value?.url ?: ""
)
},
onClickModify = remember {
{
viewModel.hideLinkOptionBottomSheet()
onNavigateToLinkModify(currentSelectedLink!!.id)
}
},
onClickRemove = viewModel::showLinkRemoveBottomSheet
)
}
BottomSheetType.REMOVE -> {
TwoButtonBottomSheetContent(
title = stringResource(id = R.string.title_remove_link),
Expand Down Expand Up @@ -235,7 +211,7 @@ fun RemindScreen(
},
onClickItem = {
uriHandler.openUri(unReadContent.data)
}
},
)
}
}
Expand Down Expand Up @@ -270,7 +246,7 @@ fun RemindScreen(
title = favoriteContent.title,
sub = "${favoriteContent.createdAt}${favoriteContent.domain}",
painter = rememberAsyncImagePainter(favoriteContent.thumbNail),
notRead = favoriteContent.isRead,
notRead = !favoriteContent.isRead,
badgeText = null,
onClickKebab = {
viewModel.showDetailLinkBottomSheet(remindResult = favoriteContent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,6 @@ class RemindViewModel @Inject constructor(
}
}

fun showLinkRemoveBottomSheet() {
_pokitOptionBottomSheetType.update {
BottomSheetType.REMOVE
}
}

fun showLinkRemoveBottomSheet(link: Link) {
_pokitOptionBottomSheetType.update {
BottomSheetType.REMOVE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ fun PokitDetailScreen(
onClickItem = {
uriHandler.openUri(link.url)
},
modifier = Modifier.padding(20.dp)
modifier = Modifier.padding(20.dp),
bookmark = link.bookmark
)

HorizontalDivider(
Expand Down
104 changes: 37 additions & 67 deletions feature/search/src/main/java/pokitmons/pokit/search/SearchScreen.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pokitmons.pokit.search

import android.content.Context
import android.content.Intent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -20,8 +19,7 @@ import pokitmons.pokit.core.feature.model.paging.PagingState
import pokitmons.pokit.core.feature.utils.ShareUrlLink
import pokitmons.pokit.core.ui.components.atom.loading.LoadingProgress
import pokitmons.pokit.core.ui.components.template.bottomsheet.PokitBottomSheet
import pokitmons.pokit.core.ui.components.template.linkdetailbottomsheet.LinkDetailBottomSheet
import pokitmons.pokit.core.ui.components.template.modifybottomsheet.ModifyBottomSheetContent
import pokitmons.pokit.core.ui.components.template.linkdetailbottomsheet.LinkDetailBottomSheetContent
import pokitmons.pokit.core.ui.components.template.pookiempty.EmptyPooki
import pokitmons.pokit.core.ui.components.template.pookierror.ErrorPooki
import pokitmons.pokit.core.ui.components.template.removeItemBottomSheet.TwoButtonBottomSheetContent
Expand All @@ -31,10 +29,10 @@ import pokitmons.pokit.search.components.filterbottomsheet.FilterBottomSheet
import pokitmons.pokit.search.components.recentsearchword.RecentSearchWord
import pokitmons.pokit.search.components.searchitemlist.SearchItemList
import pokitmons.pokit.search.components.toolbar.Toolbar
import pokitmons.pokit.search.model.BottomSheetType
import pokitmons.pokit.search.model.Filter
import pokitmons.pokit.search.model.FilterType
import pokitmons.pokit.search.model.Link
import pokitmons.pokit.search.model.LinkBottomSheetState
import pokitmons.pokit.search.model.SearchScreenState
import pokitmons.pokit.search.model.SearchScreenStep
import pokitmons.pokit.core.ui.R.string as coreString
Expand All @@ -54,32 +52,6 @@ fun SearchScreenContainer(

val context: Context = LocalContext.current

state.currentDetailLink?.let { link ->
LinkDetailBottomSheet(
title = link.title,
memo = link.memo,
bookmark = link.bookmark,
pokitName = link.pokitName,
dateString = link.dateString,
onHideBottomSheet = viewModel::hideLinkDetailBottomSheet,
show = state.showLinkDetailBottomSheet,
onClickShareLink = {
ShareUrlLink(
context = context,
url = state.currentDetailLink?.url ?: ""
)
},
onClickModifyLink = {
viewModel.hideLinkDetailBottomSheet()
onNavigateToLinkModify(link.id)
},
onClickRemoveLink = {
viewModel.showLinkRemoveBottomSheet(link)
},
onClickBookmark = viewModel::toggleBookmark
)
}

FilterBottomSheet(
filter = state.filter ?: Filter(),
firstShowType = state.firstBottomSheetFilterType,
Expand All @@ -93,48 +65,46 @@ fun SearchScreenContainer(
)

PokitBottomSheet(
onHideBottomSheet = viewModel::hideLinkModifyBottomSheet,
onHideBottomSheet = viewModel::hideLinkBottomSheet,
show = state.linkBottomSheetType != null
) {
if (state.linkBottomSheetType == BottomSheetType.MODIFY) {
ModifyBottomSheetContent(
onClickModify = remember {
{
state.currentTargetLink?.let { link ->
viewModel.hideLinkModifyBottomSheet()
onNavigateToLinkModify(link.id)
}
}
},
onClickRemove = remember {
{
state.currentTargetLink?.let { link ->
viewModel.showLinkRemoveBottomSheet(link)
state.linkBottomSheetType?.let { linkBottomSheetState ->
when(linkBottomSheetState) {
is LinkBottomSheetState.CheckRemove -> {
TwoButtonBottomSheetContent(
title = stringResource(id = R.string.title_remove_link),
subText = stringResource(id = R.string.sub_remove_link),
onClickLeftButton = viewModel::hideLinkBottomSheet,
onClickRightButton = {
viewModel.deleteLink()
viewModel.hideLinkBottomSheet()
}
}
},
onClickShare = remember {
{
val intent = Intent(Intent.ACTION_SEND_MULTIPLE).apply {
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, state.currentTargetLink?.url)
}
context.startActivity(Intent.createChooser(intent, "Pokit"))
}
)
}
)
}

if (state.linkBottomSheetType == BottomSheetType.REMOVE) {
TwoButtonBottomSheetContent(
title = stringResource(id = R.string.title_remove_link),
subText = stringResource(id = R.string.sub_remove_link),
onClickLeftButton = viewModel::hideLinkModifyBottomSheet,
onClickRightButton = {
viewModel.deleteLink()
viewModel.hideLinkModifyBottomSheet()
is LinkBottomSheetState.LinkDetail -> {
LinkDetailBottomSheetContent(
title = linkBottomSheetState.link.title,
memo = linkBottomSheetState.link.memo,
bookmark = linkBottomSheetState.link.bookmark,
pokitName = linkBottomSheetState.link.pokitName,
dateString = linkBottomSheetState.link.dateString,
onClickShareLink = {
ShareUrlLink(
context = context,
url = linkBottomSheetState.link.url
)
},
onClickModifyLink = {
viewModel.hideLinkBottomSheet()
onNavigateToLinkModify(linkBottomSheetState.link.id)
},
onClickRemoveLink = {
viewModel.showLinkRemoveBottomSheet(linkBottomSheetState.link)
},
onClickBookmark = viewModel::toggleBookmarkInBottomSheet
)
}
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import pokitmons.pokit.domain.usecase.search.GetRecentSearchWordsUseCase
import pokitmons.pokit.domain.usecase.search.GetUseRecentSearchWordsUseCase
import pokitmons.pokit.domain.usecase.search.RemoveRecentSearchWordUseCase
import pokitmons.pokit.domain.usecase.search.SetUseRecentSearchWordsUseCase
import pokitmons.pokit.search.model.BottomSheetType
import pokitmons.pokit.search.model.Filter
import pokitmons.pokit.search.model.FilterType
import pokitmons.pokit.search.model.Link
import pokitmons.pokit.search.model.LinkBottomSheetState
import pokitmons.pokit.search.model.Pokit
import pokitmons.pokit.search.model.SearchScreenState
import pokitmons.pokit.search.model.SearchScreenStep
Expand Down Expand Up @@ -233,47 +233,33 @@ class SearchViewModel @Inject constructor(
}
}

fun showLinkModifyBottomSheet(link: Link) {
_state.update { state ->
state.copy(
linkBottomSheetType = BottomSheetType.MODIFY,
currentTargetLink = link
)
}
}

fun showLinkRemoveBottomSheet(link: Link) {
_state.update { state ->
state.copy(
linkBottomSheetType = BottomSheetType.REMOVE,
showLinkDetailBottomSheet = false,
currentTargetLink = link
)
}
}

fun hideLinkModifyBottomSheet() {
_state.update { state ->
state.copy(
linkBottomSheetType = null,
currentTargetLink = null
linkBottomSheetType = LinkBottomSheetState.CheckRemove(link = link),
)
}
}

fun showLinkDetailBottomSheet(link: Link) {
_state.update { state ->
state.copy(
currentDetailLink = link,
showLinkDetailBottomSheet = true,
linkBottomSheetType = null
linkBottomSheetType = LinkBottomSheetState.LinkDetail(link = link),
)
}

viewModelScope.launch {
val response = getLinkUseCase.getLink(link.id.toInt())
if (response is PokitResult.Success && state.value.currentDetailLink?.id == link.id && state.value.showLinkDetailBottomSheet) {
_state.update { it.copy(currentDetailLink = Link.fromDomainLink(response.result).copy(imageUrl = link.imageUrl, isRead = true)) }
val currentBottomSheetState = state.value.linkBottomSheetType ?: return@launch

val currentShowDetailLinkBottomSheet = (currentBottomSheetState is LinkBottomSheetState.LinkDetail)
&& (currentBottomSheetState.link.id == link.id)

if (response is PokitResult.Success && currentShowDetailLinkBottomSheet) {
val responseLink = Link.fromDomainLink(response.result).copy(imageUrl = link.imageUrl, isRead = true)
_state.update {
it.copy(linkBottomSheetType = LinkBottomSheetState.LinkDetail(link = responseLink))
}
}

val isReadChangedLink = linkPaging.pagingData.value
Expand All @@ -284,11 +270,10 @@ class SearchViewModel @Inject constructor(
}
}

fun hideLinkDetailBottomSheet() {
fun hideLinkBottomSheet() {
_state.update { state ->
state.copy(
currentDetailLink = null,
showLinkDetailBottomSheet = false
linkBottomSheetType = null
)
}
}
Expand Down Expand Up @@ -338,27 +323,32 @@ class SearchViewModel @Inject constructor(
}
}

fun toggleBookmark() {
val currentLink = state.value.currentTargetLink ?: return
val currentLinkId = currentLink.id.toIntOrNull() ?: return
val applyBookmarked = !currentLink.bookmark
fun toggleBookmarkInBottomSheet() {
val currentState = state.value
val bottomSheetLink = currentState.linkBottomSheetType?.link ?: return
val bottomSheetLinkId = bottomSheetLink.id.toIntOrNull() ?: return
val applyBookmarked = !bottomSheetLink.bookmark

viewModelScope.launch {
val response = setBookmarkUseCase.setBookMarked(currentLinkId, applyBookmarked)
val response = setBookmarkUseCase.setBookMarked(bottomSheetLinkId, applyBookmarked)
if (response is PokitResult.Success) {
val bookmarkChangedLink = currentLink.copy(bookmark = applyBookmarked)
_state.update { state ->
state.copy(
currentDetailLink = bookmarkChangedLink
)
val bookmarkChangedLink = bottomSheetLink.copy(bookmark = applyBookmarked)

if (currentState.linkBottomSheetType is LinkBottomSheetState.LinkDetail) {
_state.update { state ->
state.copy(
linkBottomSheetType = LinkBottomSheetState.LinkDetail(link = bookmarkChangedLink)
)
}
}

linkPaging.modifyItem(bookmarkChangedLink)
}
}
}

fun deleteLink() {
val currentLinkId = state.value.currentTargetLink?.id?.toIntOrNull() ?: return
val currentLinkId = state.value.linkBottomSheetType?.link?.id?.toIntOrNull() ?: return
viewModelScope.launch {
val response = deleteLinkUseCase.deleteLink(currentLinkId)
if (response is PokitResult.Success) {
Expand Down
Loading

0 comments on commit 3e21c9b

Please sign in to comment.