-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…order [feature] 픽 목록 정렬 기준 추가
- Loading branch information
Showing
16 changed files
with
363 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
app/src/main/java/com/squirtles/musicroad/picklist/OrderBottomSheet.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package com.squirtles.musicroad.picklist | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.displayCutoutPadding | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.navigationBarsPadding | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.wrapContentHeight | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Check | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.HorizontalDivider | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.ModalBottomSheet | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.rememberModalBottomSheetState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.text.style.TextAlign | ||
import com.squirtles.domain.model.Order | ||
import com.squirtles.musicroad.R | ||
import com.squirtles.musicroad.common.Constants.DEFAULT_PADDING | ||
import com.squirtles.musicroad.ui.theme.Dark | ||
import com.squirtles.musicroad.ui.theme.Primary | ||
import com.squirtles.musicroad.ui.theme.White | ||
import kotlinx.coroutines.launch | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun OrderBottomSheet( | ||
isFavoritePicks: Boolean, | ||
currentOrder: Order, | ||
onDismissRequest: () -> Unit, | ||
onOrderClick: (Order) -> Unit, | ||
) { | ||
val sheetState = rememberModalBottomSheetState() | ||
val scope = rememberCoroutineScope() | ||
val orderList = listOf( | ||
stringResource(if (isFavoritePicks) R.string.latest_favorite_order else R.string.latest_create_order) to Order.LATEST, | ||
stringResource(if (isFavoritePicks) R.string.oldest_favorite_order else R.string.oldest_create_order) to Order.OLDEST, | ||
stringResource(R.string.favorite_count_desc) to Order.FAVORITE_DESC, | ||
) | ||
|
||
ModalBottomSheet( | ||
onDismissRequest = onDismissRequest, | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.wrapContentHeight() | ||
.displayCutoutPadding() | ||
.navigationBarsPadding(), | ||
sheetState = sheetState, | ||
containerColor = Dark, | ||
scrimColor = MaterialTheme.colorScheme.surface.copy(alpha = 0.32f), | ||
) { | ||
Column( | ||
modifier = Modifier.fillMaxWidth(), | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
orderList.forEach { (orderText, order) -> | ||
BottomSheetMenu( | ||
text = orderText, | ||
isSelected = currentOrder == order, | ||
) { | ||
scope | ||
.launch { | ||
if (currentOrder != order) { | ||
onOrderClick(order) | ||
} | ||
sheetState.hide() | ||
} | ||
.invokeOnCompletion { | ||
if (!sheetState.isVisible) { | ||
onDismissRequest() | ||
} | ||
} | ||
} | ||
} | ||
|
||
HorizontalDivider(color = White) | ||
BottomSheetMenu( | ||
text = stringResource(R.string.close_button_text), | ||
textAlign = TextAlign.Center, | ||
) { | ||
scope | ||
.launch { sheetState.hide() } | ||
.invokeOnCompletion { | ||
if (!sheetState.isVisible) { | ||
onDismissRequest() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun BottomSheetMenu( | ||
text: String, | ||
textAlign: TextAlign = TextAlign.Start, | ||
isSelected: Boolean = false, | ||
onClick: () -> Unit, | ||
) { | ||
Row( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.clickable { onClick() } | ||
.padding(DEFAULT_PADDING), | ||
horizontalArrangement = Arrangement.SpaceBetween, | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
Text( | ||
text = text, | ||
modifier = Modifier.weight(1f), | ||
color = if (isSelected) Primary else White, | ||
fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Normal, | ||
textAlign = textAlign, | ||
) | ||
|
||
if (isSelected) { | ||
Icon( | ||
imageVector = Icons.Default.Check, | ||
contentDescription = stringResource(R.string.selected_icon_description), | ||
tint = Primary | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
app/src/main/java/com/squirtles/musicroad/picklist/PickListType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.squirtles.musicroad.picklist | ||
|
||
enum class PickListType { | ||
FAVORITE, CREATED | ||
} |
5 changes: 3 additions & 2 deletions
5
app/src/main/java/com/squirtles/musicroad/picklist/PickListUiState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
package com.squirtles.musicroad.picklist | ||
|
||
import com.squirtles.domain.model.Order | ||
import com.squirtles.domain.model.Pick | ||
|
||
sealed class PickListUiState { | ||
data object Loading: PickListUiState() | ||
data class Success(val pickList: List<Pick>) : PickListUiState() | ||
data object Loading : PickListUiState() | ||
data class Success(val pickList: List<Pick>, val order: Order) : PickListUiState() | ||
data object Error : PickListUiState() | ||
} |
Oops, something went wrong.