Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into fix/#330-calendar_…
Browse files Browse the repository at this point in the history
…touch_area
  • Loading branch information
boiledEgg-s committed Jan 12, 2025
2 parents 02f1a2f + 86e087f commit ede4275
Show file tree
Hide file tree
Showing 24 changed files with 190 additions and 149 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package com.terning.core.designsystem.util

import com.terning.core.designsystem.extension.currentMonth
import com.terning.core.designsystem.extension.currentYear
import java.util.Calendar

object CalendarDefaults {
const val START_YEAR = 2010
const val END_YEAR = 2030
val END_YEAR =
if (Calendar.getInstance().currentMonth >= 10) Calendar.getInstance().currentYear + 1
else Calendar.getInstance().currentYear
const val START_MONTH = 1
const val END_MONTH = 12
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package com.terning.data.search.datasource
import com.terning.core.network.BaseResponse
import com.terning.data.search.dto.request.SearchRequestDto
import com.terning.data.search.dto.response.SearchAnnouncementResponseDto
import com.terning.data.search.dto.response.SearchBannersResponseDto
import com.terning.data.search.dto.response.SearchResultResponseDto

interface SearchDataSource {
suspend fun getSearch(request: SearchRequestDto): BaseResponse<SearchResultResponseDto>
suspend fun getSearchViews(): BaseResponse<SearchAnnouncementResponseDto>
suspend fun getSearchScraps(): BaseResponse<SearchAnnouncementResponseDto>
suspend fun getSearchBanners(): BaseResponse<SearchBannersResponseDto>
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.terning.core.network.BaseResponse
import com.terning.data.search.datasource.SearchDataSource
import com.terning.data.search.dto.request.SearchRequestDto
import com.terning.data.search.dto.response.SearchAnnouncementResponseDto
import com.terning.data.search.dto.response.SearchBannersResponseDto
import com.terning.data.search.dto.response.SearchResultResponseDto
import com.terning.data.search.service.SearchService
import javax.inject.Inject
Expand All @@ -26,4 +27,7 @@ class SearchDataSourceImpl @Inject constructor(

override suspend fun getSearchScraps(): BaseResponse<SearchAnnouncementResponseDto> =
searchService.getSearchScrapsList()

override suspend fun getSearchBanners(): BaseResponse<SearchBannersResponseDto> =
searchService.getSearchBannerList()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.terning.data.search.dto.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class SearchBannersResponseDto(
@SerialName("banners")
val banners: List<BannerDto>,
) {
@Serializable
data class BannerDto(
@SerialName("imageUrl")
val imageUrl: String,
@SerialName("link")
val link: String,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.terning.data.search.mapper

import com.terning.data.search.dto.response.SearchBannersResponseDto
import com.terning.domain.search.entity.SearchBanner

fun SearchBannersResponseDto.toSearchBannerList(): List<SearchBanner> {
return banners.map {
SearchBanner(
imageUrl = it.imageUrl,
url = it.link,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package com.terning.data.search.repositoryimpl

import com.terning.data.search.datasource.SearchDataSource
import com.terning.data.search.dto.request.SearchRequestDto
import com.terning.data.search.mapper.toSearchBannerList
import com.terning.data.search.mapper.toSearchPopularAnnouncementList
import com.terning.data.search.mapper.toSearchResultList
import com.terning.domain.search.entity.SearchBanner
import com.terning.domain.search.entity.SearchPopularAnnouncement
import com.terning.domain.search.entity.SearchResult
import com.terning.domain.search.repository.SearchRepository
Expand Down Expand Up @@ -39,4 +41,9 @@ class SearchRepositoryImpl @Inject constructor(
runCatching {
searchDataSource.getSearchScraps().result.toSearchPopularAnnouncementList()
}

override suspend fun getSearchBannersList(): Result<List<SearchBanner>> =
kotlin.runCatching {
searchDataSource.getSearchBanners().result.toSearchBannerList()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.terning.data.search.service

import com.terning.core.network.BaseResponse
import com.terning.data.search.dto.response.SearchAnnouncementResponseDto
import com.terning.data.search.dto.response.SearchBannersResponseDto
import com.terning.data.search.dto.response.SearchResultResponseDto
import retrofit2.http.GET
import retrofit2.http.Query
Expand All @@ -20,4 +21,7 @@ interface SearchService {

@GET("api/v1/search/scraps")
suspend fun getSearchScrapsList(): BaseResponse<SearchAnnouncementResponseDto>

@GET("api/v1/search/banners")
suspend fun getSearchBannerList(): BaseResponse<SearchBannersResponseDto>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.terning.domain.search.entity

data class SearchBanner(
val imageRes: Int,
val url: String
val imageUrl: String,
val url: String,
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.terning.domain.search.repository

import com.terning.domain.search.entity.SearchBanner
import com.terning.domain.search.entity.SearchPopularAnnouncement
import com.terning.domain.search.entity.SearchResult

Expand All @@ -10,6 +11,8 @@ interface SearchRepository {
page: Int,
size: Int,
): Result<List<SearchResult>>

suspend fun getSearchViewsList(): Result<List<SearchPopularAnnouncement>>
suspend fun getSearchScrapsList(): Result<List<SearchPopularAnnouncement>>
suspend fun getSearchBannersList(): Result<List<SearchBanner>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fun StartFilteringScreen(
onStartClick = onStartClick,
onLaterClick = onLaterClick
)
Spacer(modifier = Modifier.height((24 * screenHeight).dp))
Spacer(modifier = Modifier.height((16 * screenHeight).dp))
}
}

Expand All @@ -133,7 +133,7 @@ private fun ButtonAnimation(
cornerRadius = 10.dp,
modifier = Modifier.padding(horizontal = 24.dp)
)
Spacer(modifier = Modifier.height(12.dp))
Spacer(modifier = Modifier.height(20.dp))
Text(
text = stringResource(R.string.start_filtering_later),
style = TerningTheme.typography.detail3.copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,22 @@ private fun rememberPickerState() = remember { PickerState() }
internal fun HomeYearMonthPicker(
chosenYear: Int?,
chosenMonth: Int?,
onYearChosen: (Int?, Boolean) -> Unit,
onMonthChosen: (Int?, Boolean) -> Unit,
onYearChosen: (Int?) -> Unit,
onMonthChosen: (Int?) -> Unit,
isYearNull: Boolean,
isMonthNull: Boolean,
yearsList: ImmutableList<String>,
monthsList: ImmutableList<String>,
isInitialNullState: Boolean,
modifier: Modifier = Modifier,
) {
val yearPickerState = rememberPickerState()
val monthPickerState = rememberPickerState()

var isInitialSelection by remember { mutableStateOf(isInitialNullState) }

val startYearIndex =
if (isYearNull) yearsList.lastIndex else yearsList.indexOf("${chosenYear ?: "-"}")
if (isYearNull) yearsList.lastIndex else yearsList.indexOf("${chosenYear ?: NULL_DATE}")
.takeIf { it >= 0 } ?: yearsList.lastIndex
val startMonthIndex =
if (isMonthNull) monthsList.lastIndex else monthsList.indexOf("${chosenMonth ?: "-"}")
if (isMonthNull) monthsList.lastIndex else monthsList.indexOf("${chosenMonth ?: NULL_DATE}")
.takeIf { it >= 0 } ?: monthsList.lastIndex

Row(
Expand All @@ -91,10 +88,9 @@ internal fun HomeYearMonthPicker(
items = yearsList,
startIndex = startYearIndex,
onItemSelected = { year ->
if (year == NULL_DATE && !isInitialSelection) isInitialSelection = true
onYearChosen(
if (year == NULL_DATE) null else year.dropLast(1).toInt(),
isInitialSelection
if (year == NULL_DATE) null
else year.dropLast(1).toInt()
)
}
)
Expand All @@ -105,10 +101,9 @@ internal fun HomeYearMonthPicker(
items = monthsList,
startIndex = startMonthIndex,
onItemSelected = { month ->
if (month == NULL_DATE && !isInitialSelection) isInitialSelection = true
onMonthChosen(
if (month == NULL_DATE) null else month.dropLast(1).toInt(),
isInitialSelection
if (month == NULL_DATE) null
else month.dropLast(1).toInt()
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,15 @@ internal fun PlanFilteringScreen(
var isYearNull by remember { mutableStateOf(currentFilteringInfo.startYear == 0 || currentFilteringInfo.startYear == null) }
var isMonthNull by remember { mutableStateOf(currentFilteringInfo.startMonth == 0 || currentFilteringInfo.startMonth == null) }

var isInitialNullState by remember { mutableStateOf(false) }

val yearsList by remember(isYearNull) {
mutableStateOf(
if (isYearNull || isInitialNullState) years + NULL_DATE
if (isYearNull) years + NULL_DATE
else years
)
}
val monthsList by remember(isMonthNull) {
mutableStateOf(
if (isMonthNull || isInitialNullState) months + NULL_DATE
if (isMonthNull) months + NULL_DATE
else months
)
}
Expand Down Expand Up @@ -133,27 +131,24 @@ internal fun PlanFilteringScreen(
HomeYearMonthPicker(
chosenYear = currentFilteringInfo.startYear,
chosenMonth = currentFilteringInfo.startMonth,
onYearChosen = { year, isInitialSelection ->
onYearChosen = { year ->
updateStartYear(year)
if (year != null) {
updateIsCheckBoxChecked(false)
isYearNull = false
isInitialNullState = isInitialSelection
}
},
onMonthChosen = { month, isInitialSelection ->
onMonthChosen = { month ->
updateStartMonth(month)
if (month != null) {
updateIsCheckBoxChecked(false)
isMonthNull = false
isInitialNullState = isInitialSelection
}
},
isYearNull = isYearNull,
isMonthNull = isMonthNull,
yearsList = yearsList.toImmutableList(),
monthsList = monthsList.toImmutableList(),
isInitialNullState = isInitialNullState
)

Row(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import androidx.browser.customtabs.CustomTabsIntent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
Expand All @@ -30,22 +30,26 @@ import com.terning.core.designsystem.state.UiState
import com.terning.core.designsystem.theme.Black
import com.terning.core.designsystem.theme.TerningTheme
import com.terning.core.designsystem.theme.White
import com.terning.domain.search.entity.SearchBanner
import com.terning.domain.search.entity.SearchPopularAnnouncement
import com.terning.feature.search.R
import com.terning.feature.search.search.component.ImageSlider
import com.terning.feature.search.search.component.InternListType
import com.terning.feature.search.search.component.SearchInternList
import okhttp3.internal.toImmutableList
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList

@Composable
fun SearchRoute(
modifier: Modifier,
paddingValues: PaddingValues,
navigateToSearchProcess: () -> Unit,
navigateToIntern: (Long) -> Unit,
viewModel: SearchViewModel = hiltViewModel(),
) {
val lifecycleOwner = LocalLifecycleOwner.current
val context = LocalContext.current

val bannerState by viewModel.bannerState.collectAsStateWithLifecycle(lifecycleOwner = lifecycleOwner)
val viewState by viewModel.viewState.collectAsStateWithLifecycle(lifecycleOwner = lifecycleOwner)
val scrapState by viewModel.scrapState.collectAsStateWithLifecycle(lifecycleOwner = lifecycleOwner)

Expand All @@ -54,32 +58,38 @@ fun SearchRoute(
LaunchedEffect(key1 = true) {
viewModel.getSearchViews()
viewModel.getSearchScraps()
viewModel.getSearchBanners()
}

LaunchedEffect(viewModel.sideEffect, lifecycleOwner) {
viewModel.sideEffect.flowWithLifecycle(lifecycle = lifecycleOwner.lifecycle)
.collect { sideEffect ->
when (sideEffect) {
is SearchSideEffect.Toast -> {
is SearchSideEffect.ShowToast -> {
sideEffect.message
}
}
}
}

val bannerList = when (bannerState.searchBannersList) {
is UiState.Success -> (bannerState.searchBannersList as UiState.Success<List<SearchBanner>>).data.toImmutableList()
else -> emptyList<SearchBanner>().toImmutableList()
}

val searchViewsList = when (viewState.searchViewsList) {
is UiState.Success -> (viewState.searchViewsList as UiState.Success<List<com.terning.domain.search.entity.SearchPopularAnnouncement>>).data.toImmutableList()
else -> emptyList()
is UiState.Success -> (viewState.searchViewsList as UiState.Success<List<SearchPopularAnnouncement>>).data.toImmutableList()
else -> emptyList<SearchPopularAnnouncement>().toImmutableList()
}

val searchScrapsList = when (scrapState.searchScrapsList) {
is UiState.Success -> (scrapState.searchScrapsList as UiState.Success<List<com.terning.domain.search.entity.SearchPopularAnnouncement>>).data.toImmutableList()
else -> emptyList()
is UiState.Success -> (scrapState.searchScrapsList as UiState.Success<List<SearchPopularAnnouncement>>).data.toImmutableList()
else -> emptyList<SearchPopularAnnouncement>().toImmutableList()
}

SearchScreen(
modifier = modifier,
bannerList = SearchViewModel.bannerList,
paddingValues = paddingValues,
bannerList = bannerList,
searchViewsList = searchViewsList,
searchScrapsList = searchScrapsList,
navigateToSearchProcess = {
Expand All @@ -96,25 +106,25 @@ fun SearchRoute(
name = "quest_banner"
)
CustomTabsIntent.Builder().build()
.launchUrl(context, SearchViewModel.bannerList[pageIndex].url.toUri())
.launchUrl(context, bannerList[pageIndex].url.toUri())
}
)
}

@Composable
fun SearchScreen(
modifier: Modifier = Modifier,
bannerList: List<com.terning.domain.search.entity.SearchBanner>,
searchViewsList: List<com.terning.domain.search.entity.SearchPopularAnnouncement>,
searchScrapsList: List<com.terning.domain.search.entity.SearchPopularAnnouncement>,
paddingValues: PaddingValues,
bannerList: ImmutableList<SearchBanner>,
searchViewsList: ImmutableList<SearchPopularAnnouncement>,
searchScrapsList: ImmutableList<SearchPopularAnnouncement>,
navigateToSearchProcess: () -> Unit,
navigateToIntern: (Long) -> Unit,
onAdvertisementClick: (Int) -> Unit,
) {
Column(
modifier = modifier
.fillMaxSize()
modifier = Modifier
.background(White)
.padding(paddingValues)
) {
TerningImage(
painter = R.drawable.ic_terning_logo_typo,
Expand Down Expand Up @@ -145,7 +155,7 @@ fun SearchScreen(
LazyColumn {
item {
ImageSlider(
images = bannerList,
searchBanners = bannerList,
onAdvertisementClick = onAdvertisementClick,
)

Expand Down
Loading

0 comments on commit ede4275

Please sign in to comment.