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

[Fix] #64 qa link detail #66

Merged
merged 7 commits into from
Aug 30, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ fun LinkDetailBottomSheet(
thumbnailPainter: Painter,
bookmark: Boolean,
openWebBrowserByClick: Boolean,
linkType: String,
pokitName: String,
dateString: String,
onHideBottomSheet: () -> Unit,
show: Boolean = false,
useRemind: Boolean = false,
onClickBookmark: (() -> Unit)? = null,
onClickRemoveLink: (() -> Unit)? = null,
onClickModifyLink: (() -> Unit)? = null,
Expand All @@ -63,23 +64,25 @@ fun LinkDetailBottomSheet(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
Image(
painter = painterResource(id = R.drawable.icon_24_bell),
contentDescription = null,
modifier = Modifier
.size(20.dp)
.background(
color = PokitTheme.colors.brand,
shape = CircleShape
)
.padding(2.dp),
colorFilter = ColorFilter.tint(PokitTheme.colors.inverseWh)
)
if (useRemind) {
Image(
painter = painterResource(id = R.drawable.icon_24_bell),
contentDescription = null,
modifier = Modifier
.size(20.dp)
.background(
color = PokitTheme.colors.brand,
shape = CircleShape
)
.padding(2.dp),
colorFilter = ColorFilter.tint(PokitTheme.colors.inverseWh)
)

Spacer(modifier = Modifier.width(4.dp))
Spacer(modifier = Modifier.width(4.dp))
}

Text(
text = linkType,
text = pokitName,
modifier = Modifier
.border(
width = 1.dp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private fun LinkDetailBottomSheetPreview() {
bookmark = true,
openWebBrowserByClick = false,
show = true,
linkType = "TEXT",
pokitName = "TEXT",
dateString = "2024.08.27",
onHideBottomSheet = { },
onClickBookmark = { },
Expand Down
2 changes: 1 addition & 1 deletion data/src/main/java/pokitmons/pokit/data/api/LinkApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ interface LinkApi {
): ModifyLinkResponse

@PUT("content/{contentId}/bookmark")
suspend fun cancelBookmark(@Path("contentId") contentId: Int)
suspend fun cancelBookmark(@Path("contentId") contentId: Int): Response<Unit>

@POST("content/{contentId}/bookmark")
suspend fun applyBookmark(@Path("contentId") contentId: Int): ApplyBookmarkResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ fun PokitScreen(
when (pokitOptionBottomSheetType) {
BottomSheetType.MODIFY -> {
ModifyBottomSheetContent(
onClickShare = {},
onClickModify = remember {
{
viewModel.hidePokitDetailRemoveBottomSheet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import pokitmons.pokit.domain.model.pokit.MAX_POKIT_COUNT
import pokitmons.pokit.domain.model.pokit.PokitsSort
import pokitmons.pokit.domain.usecase.link.DeleteLinkUseCase
import pokitmons.pokit.domain.usecase.link.GetLinksUseCase
import pokitmons.pokit.domain.usecase.link.SetBookmarkUseCase
import pokitmons.pokit.domain.usecase.pokit.DeletePokitUseCase
import pokitmons.pokit.domain.usecase.pokit.GetPokitCountUseCase
import pokitmons.pokit.domain.usecase.pokit.GetPokitsUseCase
Expand All @@ -41,6 +42,7 @@ class PokitViewModel @Inject constructor(
private val deletePokitUseCase: DeletePokitUseCase,
private val getPokitCountUseCase: GetPokitCountUseCase,
private val deleteLinkUseCase: DeleteLinkUseCase,
private val setBookmarkUseCase: SetBookmarkUseCase,
) : ViewModel() {

private val _sideEffect = MutableEventFlow<HomeSideEffect>()
Expand Down Expand Up @@ -321,6 +323,24 @@ class PokitViewModel @Inject constructor(
fun hideDetailLinkBottomSheet() {
_currentDetailShowLink.update { null }
}

fun toggleBookmark() {
val currentLink = _currentDetailShowLink.value ?: return
val currentLinkId = currentLink.id.toIntOrNull() ?: return
val applyBookmarked = !currentLink.bookmark

viewModelScope.launch {
val response = setBookmarkUseCase.setBookMarked(currentLinkId, applyBookmarked)
if (response is PokitResult.Success) {
val bookmarkChangedLink = currentLink.copy(bookmark = applyBookmarked)
linkPaging.modifyItem(bookmarkChangedLink)

if (currentLink.id == _currentDetailShowLink.value?.id) {
_currentDetailShowLink.update { bookmarkChangedLink }
}
}
}
}
}

sealed class Category {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ fun UnclassifiedScreen(
thumbnailPainter = rememberAsyncImagePainter(model = link.imageUrl),
bookmark = link.bookmark,
openWebBrowserByClick = true,
linkType = stringResource(link.linkType.textResourceId),
pokitName = link.pokitName,
dateString = link.dateString,
onHideBottomSheet = viewModel::hideDetailLinkBottomSheet,
show = true,
onClickBookmark = {}
onClickBookmark = viewModel::toggleBookmark
)
}

Expand All @@ -56,7 +56,6 @@ fun UnclassifiedScreen(
when (pokitOptionBottomSheetType) {
BottomSheetType.MODIFY -> {
ModifyBottomSheetContent(
onClickShare = {},
onClickModify = remember {
{
viewModel.hideLinkOptionBottomSheet()
Expand Down Expand Up @@ -93,7 +92,7 @@ fun UnclassifiedScreen(
key = { it.id }
) { unCategoryDetail ->
LinkCard(
item = unCategoryDetail.linkType,
item = unCategoryDetail.pokitName,
title = unCategoryDetail.title,
sub = unCategoryDetail.createdAt,
painter = rememberAsyncImagePainter(model = unCategoryDetail.imageUrl),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ fun RemindScreen(
when (pokitOptionBottomSheetType) {
BottomSheetType.MODIFY -> {
ModifyBottomSheetContent(
onClickShare = {},
onClickModify = remember {
{
viewModel.hideLinkOptionBottomSheet()
Expand Down Expand Up @@ -105,7 +104,7 @@ fun RemindScreen(
thumbnailPainter = rememberAsyncImagePainter(model = link.imageUrl),
bookmark = link.bookmark,
openWebBrowserByClick = true,
linkType = stringResource(link.linkType.textResourceId),
pokitName = link.pokitName,
dateString = link.dateString,
onHideBottomSheet = viewModel::hideDetailLinkBottomSheet,
show = true,
Expand Down Expand Up @@ -243,7 +242,7 @@ fun RemindScreen(
sub = "${favoriteContent.createdAt} • ${favoriteContent.domain}",
painter = rememberAsyncImagePainter(favoriteContent.thumbNail),
notRead = favoriteContent.isRead,
badgeText = favoriteContent.data,
badgeText = null,
onClickKebab = {
viewModel.showLinkOptionBottomSheet(remindResult = favoriteContent)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ class RemindViewModel @Inject constructor(
domainUrl = responseLink.domain,
imageUrl = _currentShowingLink.value?.imageUrl,
memo = responseLink.memo,
bookmark = responseLink.favorites
bookmark = responseLink.favorites,
pokitName = responseLink.categoryName
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ fun PokitDetailScreenContainer(
onClickLinkRemove = viewModel::deleteLink,
loadNextPokits = viewModel::loadNextPokits,
refreshPokits = viewModel::refreshPokits,
loadNextLinks = viewModel::loadNextLinks
loadNextLinks = viewModel::loadNextLinks,
onClickBookmark = viewModel::toggleBookmark
)
}

Expand Down Expand Up @@ -120,6 +121,7 @@ fun PokitDetailScreen(
loadNextPokits: () -> Unit = {},
refreshPokits: () -> Unit = {},
loadNextLinks: () -> Unit = {},
onClickBookmark: () -> Unit = {},
) {
Column(
modifier = Modifier.fillMaxSize()
Expand Down Expand Up @@ -195,8 +197,8 @@ fun PokitDetailScreen(
title = link.title,
sub = "${link.dateString} · ${link.domainUrl}",
painter = rememberAsyncImagePainter(link.imageUrl),
notRead = link.isRead,
badgeText = stringResource(id = link.linkType.textResourceId),
notRead = !link.isRead,
badgeText = link.pokitName,
onClickKebab = showLinkModifyBottomSheet,
onClickItem = onClickLink,
modifier = Modifier.padding(20.dp)
Expand All @@ -220,10 +222,11 @@ fun PokitDetailScreen(
thumbnailPainter = rememberAsyncImagePainter(state.currentLink.imageUrl),
bookmark = state.currentLink.bookmark,
openWebBrowserByClick = true,
linkType = stringResource(state.currentLink.linkType.textResourceId),
pokitName = state.currentLink.pokitName,
dateString = state.currentLink.dateString,
onHideBottomSheet = hideLinkDetailBottomSheet,
show = state.linkDetailBottomSheetVisible
show = state.linkDetailBottomSheetVisible,
onClickBookmark = onClickBookmark
)
}

Expand Down Expand Up @@ -261,7 +264,8 @@ fun PokitDetailScreen(
state = lazyColumnListState
) {
items(
items = pokitList
items = pokitList,
key = { it.id }
) { pokit ->
PokitList(
item = pokit,
Expand All @@ -281,7 +285,6 @@ fun PokitDetailScreen(
when (state.linkBottomSheetType) {
BottomSheetType.MODIFY -> {
ModifyBottomSheetContent(
onClickShare = {},
onClickModify = remember {
{
state.currentLink?.let { link ->
Expand Down Expand Up @@ -317,7 +320,6 @@ fun PokitDetailScreen(
when (state.pokitBottomSheetType) {
BottomSheetType.MODIFY -> {
ModifyBottomSheetContent(
onClickShare = {},
onClickModify = remember {
{
hidePokitModifyBottomSheet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import pokitmons.pokit.core.feature.navigation.args.PokitUpdateEvent
import pokitmons.pokit.domain.commom.PokitResult
import pokitmons.pokit.domain.model.link.LinksSort
import pokitmons.pokit.domain.usecase.link.DeleteLinkUseCase
import pokitmons.pokit.domain.usecase.link.GetLinkUseCase
import pokitmons.pokit.domain.usecase.link.GetLinksUseCase
import pokitmons.pokit.domain.usecase.link.SetBookmarkUseCase
import pokitmons.pokit.domain.usecase.pokit.DeletePokitUseCase
import pokitmons.pokit.domain.usecase.pokit.GetPokitUseCase
import pokitmons.pokit.domain.usecase.pokit.GetPokitsUseCase
Expand All @@ -39,6 +41,8 @@ class PokitDetailViewModel @Inject constructor(
private val getPokitUseCase: GetPokitUseCase,
private val deletePokitUseCase: DeletePokitUseCase,
private val deleteLinkUseCase: DeleteLinkUseCase,
private val setBookmarkUseCase: SetBookmarkUseCase,
private val getLinkUseCase: GetLinkUseCase,
savedStateHandle: SavedStateHandle,
) : ViewModel() {
private val pokitPaging = PokitPaging(
Expand Down Expand Up @@ -187,7 +191,22 @@ class PokitDetailViewModel @Inject constructor(
}

fun showLinkDetailBottomSheet(link: Link) {
_state.update { it.copy(currentLink = link, linkDetailBottomSheetVisible = true) }
_state.update {
it.copy(currentLink = link, linkDetailBottomSheetVisible = true)
}

viewModelScope.launch {
val response = getLinkUseCase.getLink(link.id.toInt())
if (response is PokitResult.Success && state.value.currentLink?.id == link.id && state.value.linkDetailBottomSheetVisible) {
_state.update { it.copy(currentLink = Link.fromDomainLink(response.result).copy(imageUrl = link.imageUrl, isRead = true)) }
}

val isReadChangedLink = linkPaging.pagingData.value
.find { it.id == link.id }
?.copy(isRead = true) ?: return@launch

linkPaging.modifyItem(isReadChangedLink)
}
}

fun hideLinkDetailBottomSheet() {
Expand Down Expand Up @@ -250,4 +269,28 @@ class PokitDetailViewModel @Inject constructor(
}
}
}

fun toggleBookmark() {
val currentLink = state.value.currentLink ?: return
val currentLinkId = currentLink.id.toIntOrNull() ?: return
val applyBookmarked = !currentLink.bookmark

viewModelScope.launch {
val response = setBookmarkUseCase.setBookMarked(currentLinkId, applyBookmarked)
if (response is PokitResult.Success) {
val bookmarkChangedLink = linkPaging.pagingData.value
.find { it.id == currentLink.id }
?.copy(bookmark = applyBookmarked) ?: return@launch
linkPaging.modifyItem(bookmarkChangedLink)

if (currentLink.id == state.value.currentLink?.id) {
_state.update { state ->
state.copy(
currentLink = bookmarkChangedLink
)
}
}
}
}
}
}
Loading
Loading