-
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.
Merge pull request #66 from snuhcs-course/feat/symbol-selection
�선택한 상징 목록 크게 보기 화면 구현
- Loading branch information
Showing
17 changed files
with
441 additions
and
158 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
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
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
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
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
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
176 changes: 176 additions & 0 deletions
176
...end/app/src/main/java/com/example/speechbuddy/compose/symbolselection/DisplayMaxScreen.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,176 @@ | ||
package com.example.speechbuddy.compose.symbolselection | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import android.content.ContextWrapper | ||
import android.content.pm.ActivityInfo | ||
import androidx.compose.foundation.BorderStroke | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.Row | ||
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.widthIn | ||
import androidx.compose.foundation.lazy.LazyRow | ||
import androidx.compose.foundation.lazy.items | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material3.Card | ||
import androidx.compose.material3.CardDefaults | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.DisposableEffect | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.layout.ContentScale | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.zIndex | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import com.bumptech.glide.integration.compose.ExperimentalGlideComposeApi | ||
import com.bumptech.glide.integration.compose.GlideImage | ||
import com.example.speechbuddy.R | ||
import com.example.speechbuddy.compose.utils.ButtonLevel | ||
import com.example.speechbuddy.compose.utils.ButtonUi | ||
import com.example.speechbuddy.domain.models.Symbol | ||
import com.example.speechbuddy.utils.Constants | ||
import com.example.speechbuddy.viewmodel.SymbolSelectionViewModel | ||
|
||
@Composable | ||
fun DisplayMaxScreen( | ||
onExit: () -> Unit, | ||
viewModel: SymbolSelectionViewModel = hiltViewModel() | ||
) { | ||
LockScreenOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) | ||
|
||
Surface( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.zIndex(Float.MAX_VALUE), | ||
color = MaterialTheme.colorScheme.background | ||
) { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(24.dp), | ||
verticalArrangement = Arrangement.spacedBy(20.dp, Alignment.CenterVertically), | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
Row( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.height(200.dp) | ||
.background(color = MaterialTheme.colorScheme.surface) | ||
.border( | ||
width = 1.dp, | ||
color = MaterialTheme.colorScheme.surfaceVariant, | ||
shape = RoundedCornerShape(24.dp) | ||
) | ||
) { | ||
Box( | ||
modifier = Modifier.fillMaxWidth(), | ||
contentAlignment = Alignment.CenterStart | ||
) { | ||
LazyRow( | ||
contentPadding = PaddingValues(20.dp), | ||
horizontalArrangement = Arrangement.spacedBy(20.dp) | ||
) { | ||
items(viewModel.selectedSymbols) { symbolItem -> | ||
DisplayMaxSymbolUi( | ||
symbol = symbolItem.symbol | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
ButtonUi( | ||
text = stringResource(id = R.string.exit), | ||
onClick = onExit, | ||
modifier = Modifier.widthIn(max = 312.dp), | ||
level = ButtonLevel.QUINARY | ||
) | ||
} | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalGlideComposeApi::class) | ||
@Composable | ||
fun DisplayMaxSymbolUi( | ||
symbol: Symbol | ||
) { | ||
val symbolImagePath = | ||
if (symbol.id > Constants.DEFAULT_SYMBOL_COUNT) | ||
LocalContext.current.filesDir.toString().plus("/") // needs to be modified | ||
else | ||
Constants.DEFAULT_SYMBOL_IMAGE_PATH | ||
|
||
Card( | ||
modifier = Modifier.size(160.dp), | ||
shape = RoundedCornerShape(20.dp), | ||
colors = CardDefaults.cardColors( | ||
containerColor = MaterialTheme.colorScheme.background | ||
), | ||
border = BorderStroke(width = 1.dp, color = MaterialTheme.colorScheme.onBackground) | ||
) { | ||
Box(contentAlignment = Alignment.TopEnd) { | ||
Column( | ||
modifier = Modifier.fillMaxSize(), | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
GlideImage( | ||
model = symbolImagePath.plus("symbol_${symbol.id}.png"), | ||
contentDescription = symbol.text, | ||
modifier = Modifier.height(104.dp), | ||
contentScale = ContentScale.FillHeight | ||
) | ||
|
||
Box( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.height(56.dp) | ||
.background(color = MaterialTheme.colorScheme.secondaryContainer) | ||
.padding(horizontal = 12.dp), | ||
contentAlignment = Alignment.Center | ||
) { | ||
Text( | ||
text = symbol.text, | ||
textAlign = TextAlign.Center, | ||
maxLines = Constants.MAXIMUM_LINES_FOR_SYMBOL_TEXT, | ||
style = MaterialTheme.typography.bodyLarge | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun LockScreenOrientation(orientation: Int) { | ||
val context = LocalContext.current | ||
DisposableEffect(orientation) { | ||
val activity = context.findActivity() ?: return@DisposableEffect onDispose {} | ||
val originalOrientation = activity.requestedOrientation | ||
activity.requestedOrientation = orientation | ||
onDispose { | ||
// restore original orientation when view disappears | ||
activity.requestedOrientation = originalOrientation | ||
} | ||
} | ||
} | ||
|
||
fun Context.findActivity(): Activity? = when (this) { | ||
is Activity -> this | ||
is ContextWrapper -> baseContext.findActivity() | ||
else -> null | ||
} |
Oops, something went wrong.