Skip to content
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
8 changes: 4 additions & 4 deletions app/src/main/java/com/hmoa/app/navigation/NavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@ fun SetUpNavGraph(

/** magazine 모듈 */
magazineMain(
onNavHome = navController::navigateToHome,
onNavPerfumeDesc = navController::navigateToPerfume,
onNavCommunityDesc = navController::navigateToCommunityDescriptionRoute,
onNavMagazineDesc = navController::navigateToMagazineDesc
navHome = navController::navigateToHome,
navPerfumeDesc = navController::navigateToPerfume,
navCommunityDesc = navController::navigateToCommunityDescriptionRoute,
navMagazineDesc = navController::navigateToMagazineDesc
)
magazineDesc(
navBack = navController::navigateToBack,
Expand Down
12 changes: 12 additions & 0 deletions feature-hpedia/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ android {
buildFeatures {
compose = true
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>() {
compilerOptions.freeCompilerArgs.addAll(
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=${project.buildDir.absolutePath}/compose_metrics",
)
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>() {
compilerOptions.freeCompilerArgs.addAll(
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=${project.buildDir.absolutePath}/compose_reports",
)
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import com.hmoa.feature_community.Screen.CommunityHomeRoute

@Composable
fun HPediaRoute(
navHPediaSearch: (String) -> Unit,
navHPediaSearch: (keyword: String) -> Unit,
navCommunityDesc: (befRoute: CommunityRoute, communityId: Int) -> Unit,
navCommunityGraph: () -> Unit,
navLogin: () -> Unit
Expand All @@ -45,7 +45,7 @@ fun HPediaRoute(

@Composable
fun HPediaScreen(
navHPediaSearch: (String) -> Unit,
navHPediaSearch: (keyword: String) -> Unit,
navCommunityDesc: (communityRoute: CommunityRoute, communityId: Int) -> Unit,
navCommunityGraph: () -> Unit,
onErrorHandleLoginAgain: () -> Unit,
Expand All @@ -61,9 +61,7 @@ fun HPediaScreen(
.padding(horizontal = 16.dp)
) {
HPediaScreenTitle("HPedia")
SelectSearchType(
navHPediaSearch = navHPediaSearch
)
SelectSearchType(navHPediaSearch = navHPediaSearch)
}
Spacer(Modifier.height(27.dp))
CommunityHomeRoute(
Expand Down Expand Up @@ -91,9 +89,7 @@ fun HPediaScreenTitle(title: String) {
}

@Composable
fun SelectSearchType(
navHPediaSearch: (String) -> Unit
) {
fun SelectSearchType(navHPediaSearch: (keyword: String) -> Unit) {
val data = listOf(
listOf("용어", "Top notes\n탑노트란?"),
listOf("노트", "woody\n우디"),
Expand All @@ -117,9 +113,7 @@ fun SelectSearchType(
.fillMaxHeight()
.weight(1f)
.background(color = Color.Black, shape = RectangleShape)
.clickable {
navHPediaSearch(data[0])
}
.clickable {navHPediaSearch(data[0])}
.padding(16.dp)
) {
Text(
Expand All @@ -134,9 +128,7 @@ fun SelectSearchType(
style = textStyle
)
}
if (idx != 2) {
Spacer(Modifier.width(8.dp))
}
if (idx != 2) {Spacer(Modifier.width(8.dp))}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.hmoa.feature_hpedia.Screen

import android.util.Log
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
Expand All @@ -14,6 +13,8 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand All @@ -27,9 +28,11 @@ import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.paging.compose.LazyPagingItems
import androidx.paging.compose.collectAsLazyPagingItems
import com.hmoa.core_designsystem.component.TopBar
import com.hmoa.core_common.ErrorUiState
import com.hmoa.core_designsystem.R
import com.hmoa.core_designsystem.component.ErrorUiSetView
import com.hmoa.core_designsystem.component.SearchTopBar
import com.hmoa.core_designsystem.component.TopBar
import com.hmoa.core_model.response.NoteDefaultResponseDto
import com.hmoa.core_model.response.PerfumerDefaultResponseDto
import com.hmoa.core_model.response.TermDefaultResponseDto
Expand All @@ -39,23 +42,26 @@ import com.hmoa.feature_hpedia.ViewModel.HPediaSearchViewModel
fun HPediaSearchRoute(
type : String?,
navBack : () -> Unit,
navHPediaDesc : (Int, String) -> Unit,
navHPediaDesc : (hpediaId: Int, type: String) -> Unit,
viewModel : HPediaSearchViewModel = hiltViewModel()
){
viewModel.setType(type)

val errState by viewModel.errorUiState.collectAsStateWithLifecycle()
val topBarState = viewModel.topBarState.collectAsStateWithLifecycle()
val searchWord = viewModel.searchWord.collectAsStateWithLifecycle()
val type = viewModel.type.collectAsStateWithLifecycle()
val result = viewModel.communityPagingSource().collectAsLazyPagingItems()
val onClearWord = remember<() -> Unit> {{viewModel.updateSearchWord("")}}

HPediaSearchScreen(
errState = errState,
type = type.value,
topBarState = topBarState.value,
onChagneTopBarState = { viewModel.updateTopBarState(it) },
onChagneTopBarState = viewModel::updateTopBarState,
searchWord = searchWord.value,
onChangeSearchWord = { viewModel.updateSearchWord(it) },
onClearWord = { viewModel.updateSearchWord("") },
onChangeSearchWord = viewModel::updateSearchWord,
onClearWord = onClearWord,
onClickSearch = { },
termResult = if(type.value == "용어") (result as LazyPagingItems<TermDefaultResponseDto>) else null,
noteResult = if(type.value == "노트") (result as LazyPagingItems<NoteDefaultResponseDto>) else null,
Expand All @@ -67,51 +73,60 @@ fun HPediaSearchRoute(

@Composable
fun HPediaSearchScreen(
errState: ErrorUiState,
type : String?,
topBarState : Boolean,
onChagneTopBarState : (Boolean) -> Unit,
onChagneTopBarState : (topBarState: Boolean) -> Unit,
searchWord : String,
onChangeSearchWord : (String) -> Unit,
onChangeSearchWord : (keyword: String) -> Unit,
onClearWord : () -> Unit,
onClickSearch : () -> Unit,
termResult : LazyPagingItems<TermDefaultResponseDto>? = null,
noteResult : LazyPagingItems<NoteDefaultResponseDto>? = null,
perfumerResult : LazyPagingItems<PerfumerDefaultResponseDto>? = null,
navBack: () -> Unit,
navHPediaDesc: (Int, String) -> Unit
navHPediaDesc: (hpediaId: Int, type: String) -> Unit
){
Column(
modifier = Modifier
.fillMaxSize()
.background(color = Color.White)
){
HPediaEventTopBar(
type = type ?: "Null Type",
topBarState = topBarState,
onChagneTopBarState = onChagneTopBarState,
searchWord = searchWord,
onChangeSearchWord = onChangeSearchWord,
onClearWord = onClearWord,
onClickSearch = onClickSearch,
navBack = navBack
)
HPediaSearchResult(
type = type ?: "Null Type",
termResult = termResult,
noteResult = noteResult,
perfumerResult = perfumerResult,
navHPediaDesc = navHPediaDesc
if (errState is ErrorUiState.ErrorData && errState.isValidate()){
ErrorUiSetView(
onLoginClick = navBack,
errorUiState = errState,
onCloseClick = navBack
)
} else {
Column(
modifier = Modifier
.fillMaxSize()
.background(color = Color.White)
){
HPediaEventTopBar(
type = type ?: "Null Type",
topBarState = topBarState,
onChagneTopBarState = onChagneTopBarState,
searchWord = searchWord,
onChangeSearchWord = onChangeSearchWord,
onClearWord = onClearWord,
onClickSearch = onClickSearch,
navBack = navBack
)
HPediaSearchResult(
type = type ?: "Null Type",
termResult = termResult,
noteResult = noteResult,
perfumerResult = perfumerResult,
navHPediaDesc = navHPediaDesc
)
}
}
}

@Composable
fun HPediaEventTopBar(
type : String,
topBarState : Boolean,
onChagneTopBarState : (Boolean) -> Unit,
onChagneTopBarState : (topBarState: Boolean) -> Unit,
searchWord : String,
onChangeSearchWord : (String) -> Unit,
onChangeSearchWord : (keyword: String) -> Unit,
onClearWord : () -> Unit,
onClickSearch : () -> Unit,
navBack : () -> Unit
Expand All @@ -127,12 +142,10 @@ fun HPediaEventTopBar(
} else {
TopBar(
title = type,
navIcon = painterResource(com.hmoa.core_designsystem.R.drawable.ic_back),
navIcon = painterResource(R.drawable.ic_back),
onNavClick = navBack,
menuIcon = painterResource(com.hmoa.core_designsystem.R.drawable.ic_search),
onMenuClick = {
onChagneTopBarState(true)
}
menuIcon = painterResource(R.drawable.ic_search),
onMenuClick = {onChagneTopBarState(true)}
)
}
}
Expand All @@ -143,13 +156,16 @@ fun HPediaSearchResult(
termResult : LazyPagingItems<TermDefaultResponseDto>? = null,
noteResult : LazyPagingItems<NoteDefaultResponseDto>? = null,
perfumerResult : LazyPagingItems<PerfumerDefaultResponseDto>? = null,
navHPediaDesc: (Int, String) -> Unit
navHPediaDesc: (hpediaId: Int, type: String) -> Unit
){
LazyColumn(
modifier = Modifier.fillMaxSize()
){
if(termResult != null){
items(termResult.itemSnapshotList){
items(
items = termResult.itemSnapshotList,
key = {it!!.termId}
){
if (it != null){
HPediaResultItem(
type = type,
Expand All @@ -162,7 +178,10 @@ fun HPediaSearchResult(
}
}
else if (noteResult != null) {
items(noteResult.itemSnapshotList){
items(
items = noteResult.itemSnapshotList,
key = {it!!.noteId}
){
if (it != null){
HPediaResultItem(
type = type,
Expand All @@ -175,8 +194,10 @@ fun HPediaSearchResult(
}
}
else if (perfumerResult != null){
Log.d("HOTFIX", "perfumers : ${perfumerResult.itemSnapshotList}")
items(perfumerResult.itemSnapshotList){
items(
items = perfumerResult.itemSnapshotList,
key = {it!!.perfumerId}
){
if (it != null){
HPediaResultItem(
type = type,
Expand All @@ -197,15 +218,13 @@ fun HPediaResultItem(
id : Int,
koTitle : String,
engTitle : String,
navHPediaDesc: (Int, String) -> Unit
navHPediaDesc: (hpediaId: Int, type: String) -> Unit
){
Row(
modifier = Modifier
.fillMaxWidth()
.height(50.dp)
.clickable {
navHPediaDesc(id, type)
}
.clickable { navHPediaDesc(id, type) }
.padding(horizontal = 16.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.hmoa.core_common.ErrorUiState
import com.hmoa.core_domain.repository.SearchRepository
import com.hmoa.feature_community.ViewModel.PAGE_SIZE
import com.hmoa.feature_hpedia.SearchResultPagingSource
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import javax.inject.Inject

Expand All @@ -33,29 +38,42 @@ class HPediaSearchViewModel @Inject constructor(
private val _topBarState = MutableStateFlow(false)
val topBarState get() = _topBarState.asStateFlow()

//err 상태
private val _errState = MutableStateFlow<String?>(null)
val errState get() = _errState.asStateFlow()

private var expiredTokenErrorState = MutableStateFlow<Boolean>(false)
private var wrongTypeTokenErrorState = MutableStateFlow<Boolean>(false)
private var unLoginedErrorState = MutableStateFlow<Boolean>(false)
private var generalErrorState = MutableStateFlow<Pair<Boolean, String?>>(Pair(false, null))
val errorUiState: StateFlow<ErrorUiState> = combine(
expiredTokenErrorState,
wrongTypeTokenErrorState,
unLoginedErrorState,
generalErrorState
) { expiredTokenError, wrongTypeTokenError, unknownError, generalError ->
ErrorUiState.ErrorData(
expiredTokenError = expiredTokenError,
wrongTypeTokenError = wrongTypeTokenError,
unknownError = unknownError,
generalError = generalError
)
}.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5_000),
initialValue = ErrorUiState.Loading
)

//type 설정
fun setType(newType : String?){
if (newType == null) {
_errState.update{ "Type is NULL" }
} else {
_type.update{ newType }
generalErrorState.update{ Pair(true, "해당 글에 오류가 발생했습니다") }
return
}
_type.update{ newType }
}

//상단바 상태 수정
fun updateTopBarState(state : Boolean) {
_topBarState.update{ state }
}
fun updateTopBarState(state : Boolean) { _topBarState.update{ state } }

//검색어 변경
fun updateSearchWord(newSearchWord : String){
_searchWord.update{ newSearchWord }
}
fun updateSearchWord(newSearchWord : String){ _searchWord.update{ newSearchWord } }

//paging데이터 외부 노출
fun communityPagingSource() : Flow<PagingData<Any>> = Pager(
Expand Down
Loading
Loading