Skip to content

Commit

Permalink
[FEATURE] #79 즐겨찾기/안읽음 링크 목록 화면 세부 구현 및 화면 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
l5x5l committed Nov 16, 2024
1 parent 6b2d8da commit 378af64
Show file tree
Hide file tree
Showing 17 changed files with 345 additions and 25 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ dependencies {
implementation(project(":feature:search"))
implementation(project(":feature:settings"))
implementation(project(":feature:home"))
implementation(project(":feature:linklist"))

// hilt
implementation(libs.hilt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,12 @@ object EditNickname {
object Alarm {
val route: String = "alarm"
}

object LinkList {
val route: String = "linklist"
val linkListTypeArg = "type"
val routeWithArgs = "$route/{$linkListTypeArg}"
var arguments = listOf(
navArgument(linkListTypeArg) { defaultValue = "bookmark" },
)
}
20 changes: 19 additions & 1 deletion app/src/main/java/pokitmons/pokit/navigation/RootNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import pokitmons.pokit.alarm.AlarmViewModel
import pokitmons.pokit.home.HomeScreen
import pokitmons.pokit.home.pokit.PokitViewModel
import pokitmons.pokit.keyword.KeywordScreen
import pokitmons.pokit.linklist.LinkListScreenContainer
import pokitmons.pokit.linklist.LinkListViewModel
import pokitmons.pokit.login.LoginScreen
import pokitmons.pokit.nickname.InputNicknameScreen
import pokitmons.pokit.search.SearchScreenContainer
Expand Down Expand Up @@ -188,7 +190,9 @@ fun RootNavHost(
onNavigateAddPokit = { navHostController.navigate(AddPokit.route) },
onNavigateToLinkModify = { navHostController.navigate("${AddLink.route}?${AddLink.linkIdArg}=$it") },
onNavigateToPokitModify = { navHostController.navigate("${AddPokit.route}?${AddPokit.pokitIdArg}=$it") },
onNavigateToAlarm = { navHostController.navigate(Alarm.route) }
onNavigateToAlarm = { navHostController.navigate(Alarm.route) },
onNavigateToUnreadLinkList = { navHostController.navigate("${LinkList.route}/unread") },
onNavigateToBookmarkLinkList = { navHostController.navigate("${LinkList.route}/bookmark") }
)
}

Expand All @@ -202,5 +206,19 @@ fun RootNavHost(
}
)
}

composable(
route = LinkList.routeWithArgs,
arguments = LinkList.arguments
) {
val viewModel: LinkListViewModel = hiltViewModel()
LinkListScreenContainer(
viewModel = viewModel,
onBackPressed = navHostController::popBackStack,
onNavigateToLinkModify = { linkId ->
navHostController.navigate("${AddLink.route}?${AddLink.linkIdArg}=$linkId")
}
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import javax.inject.Inject

class RemindDataSourceImpl @Inject constructor(private val remindApi: RemindApi) : RemindDataSource {
override suspend fun getUnreadContents(remindRequest: RemindRequest): RemindResponse {
return remindApi.getUnreadContents()
return remindApi.getUnreadContents(size = remindRequest.size, page = remindRequest.page, sort = remindRequest.sort.value)
}

override suspend fun getUnreadContentsCount(): UnreadContentCountResponse {
Expand All @@ -22,7 +22,7 @@ class RemindDataSourceImpl @Inject constructor(private val remindApi: RemindApi)
}

override suspend fun getBookmarkContents(remindRequest: RemindRequest): RemindResponse {
return remindApi.getBookmarkContents()
return remindApi.getBookmarkContents(size = remindRequest.size, page = remindRequest.page, sort = remindRequest.sort.value)
}

override suspend fun getBookmarkContentsCount(): BookmarkContentCountResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RemindRepositoryImpl @Inject constructor(private val remindDataSource: Rem
sort: PokitsSort,
): PokitResult<List<RemindResult>> {
return runCatching {
val response = remindDataSource.getUnreadContents(RemindRequest())
val response = remindDataSource.getUnreadContents(RemindRequest(size = size, page = page, sort = sort))
val remindResponse = RemindMapper.mapperToRemind(response)
PokitResult.Success(remindResponse)
}.getOrElse { throwable ->
Expand Down Expand Up @@ -57,7 +57,7 @@ class RemindRepositoryImpl @Inject constructor(private val remindDataSource: Rem
sort: PokitsSort,
): PokitResult<List<RemindResult>> {
return runCatching {
val response = remindDataSource.getBookmarkContents(RemindRequest())
val response = remindDataSource.getBookmarkContents(RemindRequest(size = size, page = page, sort = sort))
val remindResponse = RemindMapper.mapperToRemind(response)
PokitResult.Success(remindResponse)
}.getOrElse { throwable ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package pokitmons.pokit.domain.usecase.home.remind

import pokitmons.pokit.domain.commom.PokitResult
import pokitmons.pokit.domain.model.home.remind.RemindResult
import pokitmons.pokit.domain.model.pokit.PokitsSort
import pokitmons.pokit.domain.repository.home.remind.RemindRepository
import javax.inject.Inject

class BookMarkContentsUseCase @Inject constructor(private val remindRepository: RemindRepository) {
suspend fun getBookmarkContents(): PokitResult<List<RemindResult>> {
return remindRepository.getBookmarkContents()
suspend fun getBookmarkContents(sort: PokitsSort = PokitsSort.RECENT): PokitResult<List<RemindResult>> {
return remindRepository.getBookmarkContents(sort = sort)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package pokitmons.pokit.domain.usecase.home.remind

import pokitmons.pokit.domain.commom.PokitResult
import pokitmons.pokit.domain.model.home.remind.RemindResult
import pokitmons.pokit.domain.model.pokit.PokitsSort
import pokitmons.pokit.domain.repository.home.remind.RemindRepository
import javax.inject.Inject

class UnReadContentsUseCase @Inject constructor(private val remindRepository: RemindRepository) {
suspend fun getUnreadContents(): PokitResult<List<RemindResult>> {
return remindRepository.getUnReadContents()
suspend fun getUnreadContents(sort: PokitsSort = PokitsSort.RECENT): PokitResult<List<RemindResult>> {
return remindRepository.getUnReadContents(sort = sort)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ fun HomeScreen(
onNavigateToLinkModify: (String) -> Unit,
onNavigateToPokitModify: (String) -> Unit,
onNavigateToAlarm: () -> Unit,
onNavigateToBookmarkLinkList: () -> Unit,
onNavigateToUnreadLinkList: () -> Unit,
) {
val sheetState = rememberModalBottomSheetState()
val scope = rememberCoroutineScope()
Expand Down Expand Up @@ -194,7 +196,9 @@ fun HomeScreen(
is ScreenType.Remind -> {
RemindScreen(
modifier = Modifier.padding(padding),
onNavigateToLinkModify = onNavigateToLinkModify
onNavigateToLinkModify = onNavigateToLinkModify,
onNavigateToUnreadLinkList = onNavigateToUnreadLinkList,
onNavigateToBookmarkLinkList = onNavigateToBookmarkLinkList
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ fun RemindScreen(
modifier: Modifier = Modifier,
viewModel: RemindViewModel = hiltViewModel(),
onNavigateToLinkModify: (String) -> Unit,
onNavigateToBookmarkLinkList: () -> Unit,
onNavigateToUnreadLinkList: () -> Unit,
) {
val unreadContents = viewModel.unReadContents.collectAsState()
val unreadContentsState by viewModel.unreadContentNetworkState.collectAsState()
Expand Down Expand Up @@ -207,7 +209,10 @@ fun RemindScreen(
Spacer(modifier = Modifier.height(32.dp))

if ((unreadContentsState == NetworkState.IDLE && unreadContents.value.isNotEmpty())) {
RemindSection(title = "한번도 읽지 않았어요") {
RemindSection(
title = "한번도 읽지 않았어요",
onClickButton = onNavigateToUnreadLinkList
) {
Spacer(modifier = Modifier.height(16.dp))
Column(
modifier = Modifier,
Expand All @@ -234,7 +239,10 @@ fun RemindScreen(
Spacer(modifier = Modifier.height(32.dp))
}

RemindSection(title = "즐겨찾기 링크만 모았어요") {
RemindSection(
title = "즐겨찾기 링크만 모았어요",
onClickButton = onNavigateToBookmarkLinkList
) {
Spacer(modifier = Modifier.height(12.dp))

when (bookmarkContentState) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,53 @@
package pokitmons.pokit.home.remind

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import pokitmons.pokit.core.ui.R
import pokitmons.pokit.core.ui.theme.PokitTheme

@Composable
fun RemindSection(
title: String,
onClickButton: (() -> Unit)? = null,
content: @Composable () -> Unit,
) {
Column {
Text(
text = title,
style = PokitTheme.typography.title2
)
Column(
modifier = Modifier.fillMaxWidth()
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = title,
style = PokitTheme.typography.title2
)

onClickButton?.let {
IconButton(
modifier = Modifier
.size(28.dp),
onClick = it
) {
Icon(
painter = painterResource(id = R.drawable.icon_24_arrow_right),
contentDescription = "close filter bottomSheet"
)
}
}
}
content()
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package pokitmons.pokit.linklist

import android.content.Context
import android.content.Intent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand All @@ -19,10 +21,13 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
Expand All @@ -31,19 +36,43 @@ import pokitmons.pokit.core.feature.model.paging.PagingState
import pokitmons.pokit.core.ui.components.atom.loading.LoadingProgress
import pokitmons.pokit.core.ui.components.block.linkcard.LinkCard
import pokitmons.pokit.core.ui.components.block.toolbar.Toolbar
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.pookiempty.EmptyPooki
import pokitmons.pokit.core.ui.components.template.pookierror.ErrorPooki
import pokitmons.pokit.core.ui.components.template.removeItemBottomSheet.TwoButtonBottomSheetContent
import pokitmons.pokit.core.ui.theme.PokitTheme
import pokitmons.pokit.core.ui.utils.noRippleClickable
import pokitmons.pokit.linklist.model.BottomSheetType
import pokitmons.pokit.linklist.model.Link
import pokitmons.pokit.linklist.model.LinkListScreenState
import pokitmons.pokit.core.ui.R.string as CoreString
import pokitmons.pokit.core.ui.R.drawable as CoreDrawable

@Composable
fun LinkListScreenContainer(

viewModel: LinkListViewModel,
onBackPressed: () -> Unit,
onNavigateToLinkModify: (String) -> Unit,
) {
val state by viewModel.state.collectAsState()
val linkList by viewModel.linkList.collectAsState()
val linkListState by viewModel.linkListState.collectAsState()

LinkListScreen(
state = state,
onBackPressed = onBackPressed,
loadNextLinkList = viewModel::loadNextLinks,
toggleSort = viewModel::toggleSort,
linkList = linkList,
linkListState = linkListState,
showLinkDetailBottomSheet = viewModel::showLinkDetailBottomSheet,
showCheckLinkRemoveBottomSheet = viewModel::showCheckLinkRemoveBottomSheet,
hideBottomSheet = viewModel::hideBottomSheet,
onClickLinkRemove = viewModel::removeLink,
onClickModifyLink = onNavigateToLinkModify,
onClickBookmark = viewModel::toggleBookmark
)

}

Expand All @@ -55,6 +84,12 @@ fun LinkListScreen(
linkListState: PagingState = PagingState.IDLE,
loadNextLinkList: () -> Unit,
toggleSort: () -> Unit,
showLinkDetailBottomSheet: (Link) -> Unit,
showCheckLinkRemoveBottomSheet: () -> Unit,
hideBottomSheet: () -> Unit,
onClickLinkRemove: () -> Unit,
onClickModifyLink: (String) -> Unit,
onClickBookmark: () -> Unit,
) {
Column(
modifier = Modifier
Expand Down Expand Up @@ -151,7 +186,6 @@ fun LinkListScreen(
) {
items(
items = linkList,
key = { it.id }
) { link ->
LinkCard(
item = link,
Expand All @@ -160,8 +194,8 @@ fun LinkListScreen(
painter = rememberAsyncImagePainter(link.imageUrl),
notRead = !link.isRead,
badgeText = link.pokitName,
onClickKebab = {},
onClickItem = {},
onClickKebab = showLinkDetailBottomSheet,
onClickItem = showLinkDetailBottomSheet,
modifier = Modifier.padding(20.dp)
)

Expand All @@ -174,6 +208,57 @@ fun LinkListScreen(
}
}
}

val context: Context = LocalContext.current
val link = state.bottomSheetInfo?.link ?: Link()
LinkDetailBottomSheet(
title = link.title,
memo = link.memo,
url = link.url,
thumbnailPainter = rememberAsyncImagePainter(link.imageUrl),
bookmark = link.bookmark,
openWebBrowserByClick = true,
pokitName = link.pokitName,
dateString = link.dateString,
onHideBottomSheet = hideBottomSheet,
show = state.bottomSheetInfo?.type == BottomSheetType.DETAIL,
onClickShareLink = {
val intent = Intent(Intent.ACTION_SEND_MULTIPLE).apply {
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, link.url)
}
context.startActivity(Intent.createChooser(intent, "Pokit"))
},
onClickModifyLink = {
hideBottomSheet()
onClickModifyLink(link.id)
},
onClickRemoveLink = {
showCheckLinkRemoveBottomSheet()
},
onClickBookmark = onClickBookmark
)



PokitBottomSheet(
onHideBottomSheet = hideBottomSheet,
show = state.bottomSheetInfo?.type == BottomSheetType.CHECK_REMOVE
) {
TwoButtonBottomSheetContent(
title = stringResource(id = R.string.title_remove_link),
subText = stringResource(id = R.string.sub_remove_link),
onClickLeftButton = hideBottomSheet,
onClickRightButton = remember {
{
onClickLinkRemove()
hideBottomSheet()
}
}
)
}


}
}

Loading

0 comments on commit 378af64

Please sign in to comment.