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

키워드 모아보기 모듈화 #280

Merged
merged 2 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ dependencies {
implementation(project(":feature:setting"))
implementation(project(":feature:splash"))
implementation(project(":feature:register"))
implementation(project(":feature:keyword-collection"))

implementation(libs.core.ktx)
implementation(libs.lifecycle)
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/team/ppac/navigation/FarmemeNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import team.ppac.mypage.navigation.navigateToMyPage
import team.ppac.recommendation.navigation.RECOMMENDATION_ROUTE
import team.ppac.recommendation.navigation.navigateToRecommendation
import team.ppac.recommendation.navigation.recommendationScreen
import team.ppac.search.detail.navigation.navigateToSearchDetail
import team.ppac.search.detail.navigation.searchDetailScreen
import team.ppac.feature.keyword_collection.navigation.navigateToKeywordCollection
import team.ppac.feature.keyword_collection.navigation.keywordCollectionScreen
import team.ppac.search.main.navigation.navigateToSearch
import team.ppac.search.main.navigation.searchScreen
import team.ppac.search.result.navigation.navigateToSearchResult
Expand Down Expand Up @@ -44,10 +44,10 @@ fun FarmemeNavHost(
)
searchScreen(
analyticsHelper = analyticsHelper,
navigateToSearchDetail = { navController.navigateToSearchDetail(it) },
navigateToKeywordCollection = { navController.navigateToKeywordCollection(it) },
navigateToSearchResult = { navController.navigateToSearchResult(it) }
)
searchDetailScreen(
keywordCollectionScreen(
analyticsHelper = analyticsHelper,
navigateBack = { navController.popBackStack() },
navigateToMemeDetail = navigateToDetail
Expand Down
1 change: 1 addition & 0 deletions core/common/android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ android {

dependencies {
implementation(project(":core:designsystem"))
implementation(project(":core:domain"))

implementation(libs.kotlin.coroutines.android)
implementation(libs.kotlin.coroutines.core)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package team.ppac.search.detail.component
package team.ppac.common.android.component.empty

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package team.ppac.search.detail.component
package team.ppac.common.android.component.paging

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
Expand All @@ -23,7 +23,7 @@ import team.ppac.common.android.util.showSkeleton
import team.ppac.designsystem.foundation.FarmemeRadius

@Composable
internal fun SearchDetailLoadingContent(
fun PagingItemsLoadingContent(
modifier: Modifier = Modifier,
isLoading: Boolean,
) {
Expand Down Expand Up @@ -81,9 +81,9 @@ internal fun SearchDetailLoadingContent(

@Preview
@Composable
private fun SearchDetailLoadingContentPreview() {
private fun PagingItemsLoadingContentPreview() {
Box(modifier = Modifier.background(Color.White)) {
SearchDetailLoadingContent(
PagingItemsLoadingContent(
modifier = Modifier.fillMaxSize(),
isLoading = true
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package team.ppac.search.detail.component
package team.ppac.common.android.component.paging

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.offset
Expand All @@ -7,18 +7,22 @@ import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridItemSpan
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.paging.LoadState
import androidx.paging.PagingData
import androidx.paging.compose.LazyPagingItems
import androidx.paging.compose.collectAsLazyPagingItems
import androidx.paging.compose.itemKey
import kotlinx.coroutines.flow.emptyFlow
import team.ppac.common.android.component.FarmemeMemeItem
import team.ppac.search.detail.model.SearchResultUiModel
import team.ppac.domain.model.Meme

@Composable
fun SearchDetailResultContent(
fun PagingMemesContent(
modifier: Modifier = Modifier,
totalItemCount: Int,
searchResults: LazyPagingItems<SearchResultUiModel>,
pagingItems: LazyPagingItems<Meme>,
onMemeClick: (String) -> Unit,
onCopyClick: (String, String) -> Unit,
) {
Expand All @@ -32,25 +36,25 @@ fun SearchDetailResultContent(
SearchDetailResultHeader(totalCount = totalItemCount)
}
items(
count = searchResults.itemCount,
key = searchResults.itemKey(SearchResultUiModel::memeId)
count = pagingItems.itemCount,
key = pagingItems.itemKey(Meme::id)
) { index ->
val searchResult = searchResults[index] ?: return@items
val searchResult = pagingItems[index] ?: return@items

with(searchResult) {
FarmemeMemeItem(
modifier = Modifier.offset(y = (-20).dp),
memeId = memeId,
memeTitle = memeTitle,
lolCount = lolCount,
memeId = id,
memeTitle = title,
lolCount = reactionCount,
imageUrl = imageUrl,
onMemeClick = onMemeClick,
onCopyClick = { onCopyClick(memeId, memeTitle) },
onCopyClick = { onCopyClick(id, title) },
)
}
}

searchResults.apply {
pagingItems.apply {
when {
loadState.append is LoadState.NotLoading && loadState.append.endOfPaginationReached -> {
item(span = StaggeredGridItemSpan.FullLine) {
Expand All @@ -60,4 +64,15 @@ fun SearchDetailResultContent(
}
}
}
}

@Preview
@Composable
private fun PagingMemesContentPreview() {
PagingMemesContent(
totalItemCount = 10,
pagingItems = emptyFlow<PagingData<Meme>>().collectAsLazyPagingItems(),
onMemeClick = {},
onCopyClick = { _, _ -> }
)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package team.ppac.search.detail.component
package team.ppac.common.android.component.paging

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package team.ppac.search.detail.component
package team.ppac.common.android.component.paging

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.fillMaxWidth
Expand Down
1 change: 1 addition & 0 deletions feature/keyword-collection/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
50 changes: 50 additions & 0 deletions feature/keyword-collection/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.dagger.hilt)
alias(libs.plugins.kotlin.kapt)
}

android {
namespace = "team.ppac.feature.keyword_collection"
compileSdk = libs.versions.compileSdk.get().toInt()

defaultConfig {
minSdk = libs.versions.minSdk.get().toInt()
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get()
}
kotlinOptions {
jvmTarget = "17"
}
}

dependencies {
implementation(project(":core:common:android"))
implementation(project(":core:common:kotlin"))
implementation(project(":core:domain"))
implementation(project(":core:designsystem"))
implementation(project(":core:error-handling"))
implementation(project(":core:analytics"))

implementation(platform(libs.compose.bom))
implementation(libs.bundles.compose)
implementation(libs.bundles.lifecycle)
implementation(libs.appcompat)
implementation(libs.core.ktx)
implementation(libs.kotlin.coroutines.android)
implementation(libs.timber)
implementation(libs.hilt.android)
implementation(libs.kotlinx.collections.immutable)
kapt(libs.hilt.compiler)
implementation(libs.paging.runtime)
implementation(libs.paging.compose)
}
4 changes: 4 additions & 0 deletions feature/keyword-collection/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package team.ppac.search.detail
package team.ppac.feature.keyword_collection

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
Expand All @@ -21,15 +19,14 @@ import team.ppac.analytics.action.SearchDetailAction
import team.ppac.analytics.type.ScreenType
import team.ppac.common.android.base.BaseComposable
import team.ppac.common.android.util.ComposableLifecycle
import team.ppac.search.detail.mvi.SearchDetailIntent
import team.ppac.search.detail.mvi.SearchDetailSideEffect
import timber.log.Timber
import team.ppac.feature.keyword_collection.mvi.KeywordCollectionIntent
import team.ppac.feature.keyword_collection.mvi.KeywordCollectionSideEffect

@Composable
internal fun SearchDetailRoute(
internal fun KeywordCollectionRoute(
modifier: Modifier = Modifier,
analyticsHelper: AnalyticsHelper,
viewModel: SearchDetailViewModel = hiltViewModel(),
viewModel: KeywordCollectionViewModel = hiltViewModel(),
navigateBack: () -> Unit,
navigateToMemeDetail: (String) -> Unit,
) {
Expand All @@ -55,13 +52,13 @@ internal fun SearchDetailRoute(
LaunchedEffect(key1 = viewModel) {
viewModel.sideEffect.collect { sideEffect ->
when (sideEffect) {
is SearchDetailSideEffect.NavigateToMemeDetail ->
is KeywordCollectionSideEffect.NavigateToMemeDetail ->
navigateToMemeDetail(sideEffect.memeId)
}
}
}

SearchDetailScreen(
KeywordCollectionScreen(
modifier = modifier,
uiState = uiState,
handleLoadStates = viewModel::handleLoadErrorStates,
Expand All @@ -85,9 +82,9 @@ internal fun SearchDetailRoute(
}
)

viewModel.intent(SearchDetailIntent.ClickMeme(memeId))
viewModel.intent(KeywordCollectionIntent.ClickMeme(memeId))
},
onRetryClick = { viewModel.intent(SearchDetailIntent.ClickErrorRetry) },
onRetryClick = { viewModel.intent(KeywordCollectionIntent.ClickErrorRetry) },
onCopyClick = { memeId, memeTitle ->
analyticsHelper.reportAction(
action = SearchDetailAction.CLICK_COPY,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package team.ppac.search.detail
package team.ppac.feature.keyword_collection

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
Expand All @@ -13,28 +13,28 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.LayoutDirection
import androidx.paging.LoadStates
import team.ppac.common.android.component.empty.EmptyResultContent
import team.ppac.common.android.component.paging.PagingMemesContent
import team.ppac.common.android.component.error.FarmemeErrorScreen
import team.ppac.common.android.extension.collectPagingItemsWithHandleState
import team.ppac.designsystem.FarmemeTheme
import team.ppac.designsystem.component.scaffold.FarmemeScaffold
import team.ppac.designsystem.component.tabbar.TabBarHeight
import team.ppac.designsystem.component.toolbar.FarmemeBackToolBar
import team.ppac.search.detail.component.EmptyResultContent
import team.ppac.search.detail.component.SearchDetailLoadingContent
import team.ppac.search.detail.component.SearchDetailResultContent
import team.ppac.search.detail.mvi.SearchDetailUiState
import team.ppac.common.android.component.paging.PagingItemsLoadingContent
import team.ppac.feature.keyword_collection.mvi.KeywordCollectionUiState

@Composable
internal fun SearchDetailScreen(
internal fun KeywordCollectionScreen(
modifier: Modifier = Modifier,
uiState: SearchDetailUiState,
uiState: KeywordCollectionUiState,
handleLoadStates: (LoadStates) -> Unit,
onBackClick: () -> Unit,
onMemeClick: (String) -> Unit,
onRetryClick: () -> Unit,
onCopyClick: (String, String) -> Unit,
) {
val searchResults = uiState.searchResults.collectPagingItemsWithHandleState(handleLoadStates)
val memes = uiState.memes.collectPagingItemsWithHandleState(handleLoadStates)

when {
uiState.isError -> {
Expand Down Expand Up @@ -72,7 +72,7 @@ internal fun SearchDetailScreen(

when {
uiState.isLoading -> {
SearchDetailLoadingContent(
PagingItemsLoadingContent(
modifier = Modifier.fillMaxSize(),
isLoading = uiState.isLoading
)
Expand All @@ -85,9 +85,9 @@ internal fun SearchDetailScreen(
if (uiState.totalMemeCount == 0) {
EmptyResultContent()
} else {
SearchDetailResultContent(
PagingMemesContent(
totalItemCount = uiState.totalMemeCount,
searchResults = searchResults,
pagingItems = memes,
onMemeClick = onMemeClick,
onCopyClick = onCopyClick,
)
Expand All @@ -103,8 +103,8 @@ internal fun SearchDetailScreen(
@Preview
@Composable
private fun SearchDetailScreenPreview() {
SearchDetailScreen(
uiState = SearchDetailUiState.INITIAL_STATE,
KeywordCollectionScreen(
uiState = KeywordCollectionUiState.INITIAL_STATE,
handleLoadStates = {},
onBackClick = {},
onMemeClick = {},
Expand Down
Loading
Loading