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 089cbe2 commit 431138b
Show file tree
Hide file tree
Showing 16 changed files with 348 additions and 149 deletions.
11 changes: 7 additions & 4 deletions app/src/main/java/com/dev/briefing/BriefingNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import androidx.navigation.compose.NavHost
import store.newsbriefing.app.feature.auth.signInRoute
import store.newsbriefing.app.feature.auth.signInScreen
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.newsDetailScreen
import store.newsbriefing.app.feature.setting.navigateToSetting
import store.newsbriefing.app.feature.setting.settingScreen

@Composable
Expand All @@ -22,7 +24,9 @@ fun BriefingNavHost(
startDestination = signInRoute
) {
homeScreen(
showSnackbar = appState::showSnackBar
showSnackbar = appState::showSnackBar,
navigateToSettingRoute = appState.navController::navigateToSetting,
navigateToBookmarkRoute = appState.navController::navigateToBookmark
)
bookmarkScreen(
showSnackbar = appState::showSnackBar
Expand All @@ -35,8 +39,7 @@ fun BriefingNavHost(
)
signInScreen(
showSnackBar = appState::showSnackBar,
navigateToHome = {
appState.navController.navigateToHome()
})
navigateToHome = appState.navController::navigateToHome
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ package store.newsbriefing.app.core.data.repository
import kotlinx.coroutines.flow.Flow
import store.newsbriefing.app.core.model.BriefingArticle
import store.newsbriefing.app.core.model.BriefingArticleCategory
import store.newsbriefing.app.core.model.BriefingArticleSummary
import store.newsbriefing.app.core.model.TimeOfDay
import java.time.LocalDate
import store.newsbriefing.app.core.model.BriefingCategoryArticles

interface BriefingRepository {
suspend fun getBriefingArticleSummaries(
briefingArticleCategory: BriefingArticleCategory,
dateLocalDate: LocalDate?,
timeOfDay: TimeOfDay?
): Flow<List<BriefingArticleSummary>>
briefingArticleCategory: BriefingArticleCategory
): Flow<BriefingCategoryArticles>

suspend fun getBriefingArticle(articleId: Long): Flow<BriefingArticle>
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,22 @@ import store.newsbriefing.app.core.data.repository.BriefingRepository
import store.newsbriefing.app.core.data.repository.model.asExternalModel
import store.newsbriefing.app.core.model.BriefingArticle
import store.newsbriefing.app.core.model.BriefingArticleCategory
import store.newsbriefing.app.core.model.BriefingArticleSummary
import store.newsbriefing.app.core.model.TimeOfDay
import store.newsbriefing.app.core.model.BriefingCategoryArticles
import store.newsbriefing.app.core.network.datasource.BriefingNetworkDataSource
import java.time.LocalDate
import javax.inject.Inject

internal class DefaultBriefingRepository(
internal class DefaultBriefingRepository @Inject constructor(
private val briefingNetworkDataSource: BriefingNetworkDataSource
) : BriefingRepository {
override suspend fun getBriefingArticleSummaries(
briefingArticleCategory: BriefingArticleCategory,
dateLocalDate: LocalDate?,
timeOfDay: TimeOfDay?
): Flow<List<BriefingArticleSummary>> = flow {
): Flow<BriefingCategoryArticles> = flow {
val summaries = briefingNetworkDataSource.getBriefingArticleSummaries(
briefingArticleCategory,
dateLocalDate,
timeOfDay
null,
null
)
emit(summaries.map {
it.asExternalModel()
})
emit(summaries.asExternalModel())
}

override suspend fun getBriefingArticle(articleId: Long): Flow<BriefingArticle> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,24 @@ import store.newsbriefing.app.core.common.util.toZoneDateTime
import store.newsbriefing.app.core.model.BriefingArticle
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.network.model.NetworkBriefingArticle
import store.newsbriefing.app.core.network.model.NetworkBriefingArticleRelated
import store.newsbriefing.app.core.network.model.NetworkBriefingArticleSummary
import store.newsbriefing.app.core.network.model.NetworkBriefingCategoryArticles
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

fun NetworkBriefingCategoryArticles.asExternalModel(): BriefingCategoryArticles {
val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.getDefault())
val parsedDate = dateFormat.parse(createdAt) ?: Date()

return BriefingCategoryArticles(
createdAt = parsedDate,
briefings = briefings.map { it.asExternalModel() }
)
}

fun NetworkBriefingArticle.asExternalModel(): BriefingArticle {
return BriefingArticle(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package store.newsbriefing.app.core.model

import java.util.Date

data class BriefingCategoryArticles(
val createdAt: Date,
val briefings: List<BriefingArticleSummary>
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package store.newsbriefing.app.core.network.datasource
import store.newsbriefing.app.core.model.BriefingArticleCategory
import store.newsbriefing.app.core.model.TimeOfDay
import store.newsbriefing.app.core.network.model.NetworkBriefingArticle
import store.newsbriefing.app.core.network.model.NetworkBriefingArticleSummary
import store.newsbriefing.app.core.network.model.NetworkBriefingCategoryArticles
import java.time.LocalDate

interface BriefingNetworkDataSource {
suspend fun getBriefingArticleSummaries(
briefingArticleCategory: BriefingArticleCategory,
dateLocalDate: LocalDate?,
timeOfDay: TimeOfDay?
): List<NetworkBriefingArticleSummary>
): NetworkBriefingCategoryArticles

suspend fun getBriefingArticle(articleId: Long): NetworkBriefingArticle
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package store.newsbriefing.app.core.network.model

import com.google.gson.annotations.SerializedName

data class NetworkBriefingCategoryArticles(
@SerializedName("createdAt")
val createdAt: String,
@SerializedName("briefings")
val briefings: List<NetworkBriefingArticleSummary>
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import store.newsbriefing.app.core.model.BriefingArticleCategory
import store.newsbriefing.app.core.model.TimeOfDay
import store.newsbriefing.app.core.network.datasource.BriefingNetworkDataSource
import store.newsbriefing.app.core.network.model.NetworkBriefingArticle
import store.newsbriefing.app.core.network.model.NetworkBriefingArticleSummary
import store.newsbriefing.app.core.network.model.NetworkBriefingCategoryArticles
import store.newsbriefing.app.core.network.model.RetrofitCommonResponse
import java.time.LocalDate
import java.time.format.DateTimeFormatter
Expand All @@ -21,7 +21,7 @@ private interface RetrofitBriefingApi {
@Query("type") type: String,
@Query("date") date: String?,
@Query("timeOfDay") timeOfDay: String?
): RetrofitCommonResponse<List<NetworkBriefingArticleSummary>>
): RetrofitCommonResponse<NetworkBriefingCategoryArticles>

@GET("briefings/{id}")
suspend fun getBriefingArticle(@Path("id") id: Long): RetrofitCommonResponse<NetworkBriefingArticle>
Expand All @@ -39,7 +39,7 @@ internal class RetrofitBriefingNetworkDataSource @Inject constructor(
briefingArticleCategory: BriefingArticleCategory,
dateLocalDate: LocalDate?,
timeOfDay: TimeOfDay?
): List<NetworkBriefingArticleSummary> {
): NetworkBriefingCategoryArticles {
return api.getBriefingArticleSummaries(
type = briefingArticleCategory.typeId,
date = dateLocalDate?.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ComposeCompilerApi
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -31,15 +26,13 @@ import androidx.compose.ui.unit.sp
import androidx.credentials.CredentialManager
import androidx.credentials.GetCredentialRequest
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.google.android.libraries.identity.googleid.GetGoogleIdOption
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import store.newsbriefing.app.core.designsystem.theme.BriefingTheme
import store.newsbriefing.app.core.ui.BuildConfig
import store.newsbriefing.app.feature.auth.R
import java.util.UUID
import kotlin.math.sign

private fun createGoogleIdOption(): GetGoogleIdOption {
return GetGoogleIdOption.Builder()
Expand All @@ -51,7 +44,11 @@ private fun createGoogleIdOption(): GetGoogleIdOption {
}

@Composable
fun SignInRoute(showSnackBar : (String) -> Unit, navigateToMain : () -> Unit, signInViewModel: SignInViewModel = hiltViewModel()) {
fun SignInRoute(
showSnackBar : (String) -> Unit,
navigateToMain : () -> Unit,
signInViewModel: SignInViewModel = hiltViewModel()
) {
val context = LocalContext.current
val composeCoroutine = rememberCoroutineScope()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
package store.newsbriefing.app.feature.auth.signIn

import android.content.Context
import android.util.Log
import androidx.credentials.CredentialManager
import androidx.credentials.CustomCredential
import androidx.credentials.GetCredentialRequest
import androidx.credentials.GetCredentialResponse
import androidx.credentials.exceptions.GetCredentialException
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.google.android.libraries.identity.googleid.GetGoogleIdOption
import com.google.android.libraries.identity.googleid.GoogleIdTokenCredential
import com.google.android.libraries.identity.googleid.GoogleIdTokenParsingException
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import store.newsbriefing.app.core.common.util.BriefingLogger
import store.newsbriefing.app.core.common.util.EventFlow
import store.newsbriefing.app.core.common.util.MutableEventFlow
import store.newsbriefing.app.core.common.util.asEventFlow
import store.newsbriefing.app.core.data.repository.MemberRepository
import store.newsbriefing.app.core.domain.SignInWithSocialProviderUseCase
import store.newsbriefing.app.core.model.MemberToken
import store.newsbriefing.app.core.model.SocialProvider
import store.newsbriefing.app.core.ui.BuildConfig
import java.util.UUID
import javax.inject.Inject

sealed class SignInEvent {
Expand Down Expand Up @@ -69,5 +57,4 @@ class SignInViewModel @Inject constructor(
}
}


}
2 changes: 2 additions & 0 deletions feature/home/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,8 +1,25 @@
package store.newsbriefing.app.feature.home

enum class HomeCategory(val title: String) {
SOCIETY("사회"),
SCIENCE("과학"),
GLOBAL("글로벌"),
ECONOMY("경제")
import store.newsbriefing.app.core.model.BriefingArticleCategory

enum class HomeCategory(
val title: Int,
val category: BriefingArticleCategory
) {
SOCIETY(
R.string.tab_society,
BriefingArticleCategory.SOCIAL
),
SCIENCE(
R.string.tab_science,
BriefingArticleCategory.SCIENCE
),
GLOBAL(
R.string.tab_global,
BriefingArticleCategory.GLOBAL
),
ECONOMY(
R.string.tab_economy,
BriefingArticleCategory.ECONOMY
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package store.newsbriefing.app.feature.home

import androidx.compose.runtime.Composable
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
Expand All @@ -12,15 +11,17 @@ fun NavController.navigateToHome() {
}

fun NavGraphBuilder.homeScreen(
showSnackbar: (String) -> Unit
showSnackbar: (String) -> Unit,
navigateToBookmarkRoute: () -> Unit,
navigateToSettingRoute: () -> Unit
) {
composable(
route = homeRoute
) {
HomeRoute(
showSnackbar = showSnackbar,
navigateToBookmarkRoute = { },
navigateToSettingRoute = { }
navigateToBookmarkRoute = navigateToBookmarkRoute,
navigateToSettingRoute = navigateToSettingRoute
)
}
}
Loading

0 comments on commit 431138b

Please sign in to comment.