Skip to content

Commit

Permalink
Feat : 브리핑 상세 화면 API 연동
Browse files Browse the repository at this point in the history
  • Loading branch information
DongChyeon committed Jun 18, 2024
1 parent 507daef commit 3416e5f
Show file tree
Hide file tree
Showing 12 changed files with 314 additions and 93 deletions.
7 changes: 5 additions & 2 deletions app/src/main/java/com/dev/briefing/BriefingNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import store.newsbriefing.app.feature.bookmark.bookmarkScreen
import store.newsbriefing.app.feature.bookmark.navigateToBookmark
import store.newsbriefing.app.feature.home.homeScreen
import store.newsbriefing.app.feature.home.navigateToHome
import store.newsbriefing.app.feature.newsdetail.navigateToNewsDetail
import store.newsbriefing.app.feature.newsdetail.newsDetailScreen
import store.newsbriefing.app.feature.setting.navigateToSetting
import store.newsbriefing.app.feature.setting.settingScreen
Expand All @@ -26,13 +27,15 @@ fun BriefingNavHost(
homeScreen(
showSnackbar = appState::showSnackBar,
navigateToSettingRoute = appState.navController::navigateToSetting,
navigateToBookmarkRoute = appState.navController::navigateToBookmark
navigateToBookmarkRoute = appState.navController::navigateToBookmark,
navigateToNewsDetail = appState.navController::navigateToNewsDetail
)
bookmarkScreen(
showSnackbar = appState::showSnackBar
)
newsDetailScreen(
showSnackbar = appState::showSnackBar
showSnackbar = appState::showSnackBar,
navigateUp = appState.navController::navigateUp
)
settingScreen(
showSnackbar = appState::showSnackBar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ import store.newsbriefing.app.core.data.repository.ScrapRepository
import store.newsbriefing.app.core.data.repository.model.asExternalModel
import store.newsbriefing.app.core.model.Scrap
import store.newsbriefing.app.core.network.datasource.ScrapNetworkDataSource
import javax.inject.Inject

internal class DefaultScrapRepository(private val scrapNetworkDataSource: ScrapNetworkDataSource) :
ScrapRepository {
internal class DefaultScrapRepository @Inject constructor(
private val scrapNetworkDataSource: ScrapNetworkDataSource
) : ScrapRepository {
override fun getScrap(memberId: Long): Flow<List<Scrap>> = flow {
val scraps = scrapNetworkDataSource.getScrap(memberId).map { it.asExternalModel() }
emit(scraps)
}

override suspend fun setScrap(memberId: Long, articleId: Long) {
scrapNetworkDataSource.setScrap(memberId, articleId)
return scrapNetworkDataSource.setScrap(memberId, articleId)
}

override suspend fun unScrap(memberId: Long, articleId: Long){
val result = scrapNetworkDataSource.unScrap(memberId, articleId)
override suspend fun unScrap(memberId: Long, articleId: Long) {
return scrapNetworkDataSource.unScrap(memberId, articleId)
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package store.newsbriefing.app.core.data.repository.model

import store.newsbriefing.app.core.common.util.toZoneDateTime
import store.newsbriefing.app.core.model.BriefingArticle
import store.newsbriefing.app.core.model.BriefingArticleCategory
import store.newsbriefing.app.core.model.BriefingArticleRelated
import store.newsbriefing.app.core.model.BriefingArticleSummary
import store.newsbriefing.app.core.model.BriefingCategoryArticles
import store.newsbriefing.app.core.model.TimeOfDay
import store.newsbriefing.app.core.network.model.NetworkBriefingArticle
import store.newsbriefing.app.core.network.model.NetworkBriefingArticleRelated
import store.newsbriefing.app.core.network.model.NetworkBriefingArticleSummary
Expand All @@ -30,15 +31,15 @@ fun NetworkBriefingArticle.asExternalModel(): BriefingArticle {
title = title,
subtitle = subtitle,
content = content,
date = date.toZoneDateTime(),
date = date,
articles = articles.map { it.asExternalModel() },
isScrap = isScrap,
isBriefingOpen = isBriefingOpen,
isWarning = isWarning,
scrapCount = scrapCount,
gptModel = gptModel,
timeOfDay = timeOfDay,
type = type
timeOfDay = TimeOfDay.fromValue(timeOfDay),
category = BriefingArticleCategory.fromTypeName(type)
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package store.newsbriefing.app.core.model

import java.time.ZonedDateTime

data class BriefingArticle(
val id: Long,
val ranks: Int,
val title: String,
val subtitle: String,
val content: String,
val date: ZonedDateTime,
val date: String,
val articles: List<BriefingArticleRelated>,
val isScrap: Boolean,
val isBriefingOpen: Boolean,
val isWarning: Boolean,
val scrapCount: Int,
val gptModel: String,
val timeOfDay: String,
val type: String
val timeOfDay: TimeOfDay,
val category: BriefingArticleCategory
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package store.newsbriefing.app.core.model

enum class BriefingArticleCategory(val typeId: String) {
KOREA("KOREA"),
GLOBAL("GLOBAL"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ fun NavController.navigateToHome() {
fun NavGraphBuilder.homeScreen(
showSnackbar: (String) -> Unit,
navigateToBookmarkRoute: () -> Unit,
navigateToSettingRoute: () -> Unit
navigateToSettingRoute: () -> Unit,
navigateToNewsDetail: (String) -> Unit
) {
composable(
route = homeRoute
) {
HomeRoute(
showSnackbar = showSnackbar,
navigateToBookmarkRoute = navigateToBookmarkRoute,
navigateToSettingRoute = navigateToSettingRoute
navigateToSettingRoute = navigateToSettingRoute,
navigateToNewsDetail = navigateToNewsDetail
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ internal fun HomeRoute(
showSnackbar: (String) -> Unit,
navigateToBookmarkRoute: () -> Unit,
navigateToSettingRoute: () -> Unit,
navigateToNewsDetail: (String) -> Unit,
homeViewModel: HomeViewModel = hiltViewModel()
) {
val uiState by homeViewModel.uiState.collectAsStateWithLifecycle(
Expand All @@ -87,7 +88,8 @@ internal fun HomeRoute(
showSnackbar = showSnackbar,
loadBriefings = homeViewModel::loadBriefings,
navigateToBookmarkRoute = navigateToBookmarkRoute,
navigateToSettingRoute = navigateToSettingRoute
navigateToSettingRoute = navigateToSettingRoute,
navigateToNewsDetail = navigateToNewsDetail
)
}

Expand All @@ -112,7 +114,8 @@ internal fun HomeScreen(
loadBriefings: (BriefingArticleCategory, Boolean) -> Unit,
showSnackbar: (String) -> Unit = { },
navigateToBookmarkRoute: () -> Unit = { },
navigateToSettingRoute: () -> Unit = { }
navigateToSettingRoute: () -> Unit = { },
navigateToNewsDetail: (String) -> Unit
) {
Column(
modifier = Modifier
Expand Down Expand Up @@ -170,8 +173,8 @@ internal fun HomeScreen(
else -> emptyList()
}
} ?: emptyList()
) {

) { articleId ->
navigateToNewsDetail("$articleId")
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions feature/newsdetail/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ android {
}

dependencies {
implementation(projects.core.data)

api(projects.core.model)
api(projects.core.common)
api(projects.core.designsystem)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,50 @@
package store.newsbriefing.app.feature.newsdetail

import androidx.lifecycle.SavedStateHandle
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptionsBuilder
import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import java.net.URLDecoder
import java.net.URLEncoder
import kotlin.text.Charsets.UTF_8

private val URL_CHARACTER_ENCODING = UTF_8.name()

internal const val NEWS_ID_ARG = "newsId"
const val NewsDetailRoute = "news_detail_route"

fun NavController.navigateToNewsDetail() {
navigate(NewsDetailRoute)
internal class NewsDetailArgs(val newsId: String) {
constructor(savedStateHandle: SavedStateHandle) :
this(URLDecoder.decode(checkNotNull(savedStateHandle[NEWS_ID_ARG]), URL_CHARACTER_ENCODING))
}

fun NavController.navigateToNewsDetail(newsId: String, navOptions: NavOptionsBuilder.() -> Unit = {}) {
navigate(createNewsDetailRoute(newsId)) {
navOptions()
}
}

fun createNewsDetailRoute(newsId: String): String {
val encodedId = URLEncoder.encode(newsId, URL_CHARACTER_ENCODING)
return "$NewsDetailRoute/$encodedId"
}

fun NavGraphBuilder.newsDetailScreen(
showSnackbar: (String) -> Unit
showSnackbar: (String) -> Unit,
navigateUp: () -> Unit
) {
composable(
route = NewsDetailRoute
route = "${NewsDetailRoute}/{$NEWS_ID_ARG}",
arguments = listOf(
navArgument(NEWS_ID_ARG) { type = NavType.StringType },
),
) {
NewsDetailRoute(
showSnackbar = showSnackbar
showSnackbar = showSnackbar,
navigateUp = navigateUp
)
}
}
Loading

0 comments on commit 3416e5f

Please sign in to comment.