From 87656550c1ed560e4feb6f5130ad19a97d42ed54 Mon Sep 17 00:00:00 2001 From: YeonJeong Kim Date: Fri, 24 Nov 2023 12:59:21 +0900 Subject: [PATCH 1/4] :sparkles: Implement MySymbolSettingsScreen --- .../compose/settings/MainSettings.kt | 1 - .../compose/settings/MySymbolSettings.kt | 280 +++++++++++++++++- .../compose/settings/SettingsScreen.kt | 1 - frontend/app/src/main/res/values/strings.xml | 2 + 4 files changed, 274 insertions(+), 10 deletions(-) diff --git a/frontend/app/src/main/java/com/example/speechbuddy/compose/settings/MainSettings.kt b/frontend/app/src/main/java/com/example/speechbuddy/compose/settings/MainSettings.kt index 2c170644..023688fd 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/compose/settings/MainSettings.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/compose/settings/MainSettings.kt @@ -66,7 +66,6 @@ fun MainSettings( SettingsTextButton(text = stringResource(id = R.string.manage_symbols), onClick = { navController.navigate("my_symbol") }, - enabled = !isGuestMode ) SettingsTextButton( diff --git a/frontend/app/src/main/java/com/example/speechbuddy/compose/settings/MySymbolSettings.kt b/frontend/app/src/main/java/com/example/speechbuddy/compose/settings/MySymbolSettings.kt index c23bb201..50bacc03 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/compose/settings/MySymbolSettings.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/compose/settings/MySymbolSettings.kt @@ -1,38 +1,83 @@ package com.example.speechbuddy.compose.settings +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement 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.padding +import androidx.compose.foundation.lazy.grid.GridCells +import androidx.compose.foundation.lazy.grid.LazyVerticalGrid +import androidx.compose.foundation.lazy.grid.rememberLazyGridState +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.Card +import androidx.compose.material3.CardDefaults import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.getValue +import androidx.compose.runtime.livedata.observeAsState import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp +import androidx.hilt.navigation.compose.hiltViewModel import com.example.speechbuddy.R +import com.example.speechbuddy.compose.symbolselection.SymbolSearchTextField +import com.example.speechbuddy.compose.utils.ButtonUi +import com.example.speechbuddy.compose.utils.NoRippleInteractionSource +import com.example.speechbuddy.compose.utils.SymbolUi import com.example.speechbuddy.compose.utils.TopAppBarUi +import com.example.speechbuddy.ui.models.MySymbolSettingsDisplayMode +import com.example.speechbuddy.viewmodel.MySymbolSettingsViewModel +import androidx.compose.foundation.lazy.grid.items +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.size +import androidx.compose.material3.Checkbox +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.CheckboxDefaults +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.zIndex +import com.bumptech.glide.integration.compose.ExperimentalGlideComposeApi +import com.bumptech.glide.integration.compose.GlideImage +import com.example.speechbuddy.compose.utils.TitleUi +import com.example.speechbuddy.domain.models.Symbol +import com.example.speechbuddy.utils.Constants.Companion.DEFAULT_SYMBOL_COUNT +import com.example.speechbuddy.utils.Constants.Companion.DEFAULT_SYMBOL_IMAGE_PATH +import com.example.speechbuddy.utils.Constants.Companion.MAXIMUM_LINES_FOR_SYMBOL_TEXT @OptIn(ExperimentalMaterial3Api::class) @Composable fun MySymbolSettings( modifier: Modifier = Modifier, - onBackClick: () -> Unit, - bottomPaddingValues: PaddingValues + bottomPaddingValues: PaddingValues, + viewModel: MySymbolSettingsViewModel = hiltViewModel() ) { + val uiState by viewModel.uiState.collectAsState() + val symbols by viewModel.symbols.observeAsState(initial = emptyList()) + + val lazyGridState = rememberLazyGridState() + Surface( modifier = modifier.fillMaxSize() ) { Scaffold( topBar = { TopAppBarUi( - title = stringResource(id = R.string.settings), - onBackClick = onBackClick, - isBackClickEnabled = true + title = stringResource(id = R.string.settings) ) } ) { topPaddingValues -> @@ -44,12 +89,231 @@ fun MySymbolSettings( bottom = bottomPaddingValues.calculateBottomPadding() ) .padding(24.dp), - verticalArrangement = Arrangement.Center, + verticalArrangement = Arrangement.spacedBy(20.dp) + ) { + TitleUi(title = stringResource(id = R.string.manage_symbols)) + + SymbolSearchTextField( + value = viewModel.queryInput, + onValueChange = { viewModel.setQuery(it) } + ) + + Column ( + modifier = Modifier.weight(1f) + ) { + DisplayModeMenu( + currentDisplayMode = uiState.mySymbolSettingsDisplayMode, + onSelectDisplayMode = { viewModel.selectDisplayMode(it) } + ) + + LazyVerticalGrid( + columns = GridCells.Fixed(2), + modifier = Modifier + .fillMaxSize() + .background( + color = MaterialTheme.colorScheme.surfaceVariant, + shape = RoundedCornerShape(topEnd = 20.dp, bottomStart = 20.dp, bottomEnd = 20.dp) + ), + state = lazyGridState, + contentPadding = PaddingValues(16.dp), + verticalArrangement = Arrangement.spacedBy(16.dp), + horizontalArrangement = Arrangement.spacedBy(16.dp) + ) { + if (uiState.mySymbolSettingsDisplayMode == MySymbolSettingsDisplayMode.SYMBOL) { + items(symbols ?: emptyList()) { symbol -> + MySymbolUi( + symbol = symbol, + viewModel = viewModel + ) + } + } else { + items(symbols ?: emptyList()) { symbol -> + SymbolUi( + symbol = symbol, + onSelect = {}, + onFavoriteChange = { viewModel.updateFavorite(symbol, it) } + ) + } + } + } + } + if (uiState.mySymbolSettingsDisplayMode == MySymbolSettingsDisplayMode.SYMBOL) { + DeleteButtonUi( + text = stringResource(id = R.string.delete_my_symbol), + onClick = { viewModel.deleteCheckedSymbols() }, + isEnabled = viewModel.checkedSymbols.isNotEmpty() + ) + } + } + } + } +} + +data class DisplayModeItem( + val textResId: Int, + val displayMode: MySymbolSettingsDisplayMode, + val containerColor: Color, + val contentColor: Color +) + +@Composable +fun DisplayModeMenu( + currentDisplayMode: MySymbolSettingsDisplayMode, + onSelectDisplayMode: (MySymbolSettingsDisplayMode) -> Unit +) { + val displayModeItems = listOf( + DisplayModeItem( + R.string.my_symbol, + MySymbolSettingsDisplayMode.SYMBOL, + MaterialTheme.colorScheme.secondaryContainer, + MaterialTheme.colorScheme.onSecondaryContainer + ), + DisplayModeItem( + R.string.favorite, + MySymbolSettingsDisplayMode.FAVORITE, + MaterialTheme.colorScheme.errorContainer, + MaterialTheme.colorScheme.onErrorContainer + ) + ) + + Row { + displayModeItems.forEach { item -> + val selected = item.displayMode == currentDisplayMode + Card( + modifier = Modifier.clickable( + interactionSource = NoRippleInteractionSource(), + indication = null, + onClick = { onSelectDisplayMode(item.displayMode) }), + shape = RoundedCornerShape( + topStart = 10.dp, topEnd = 10.dp + ), + colors = CardDefaults.cardColors( + containerColor = + if (selected) MaterialTheme.colorScheme.surfaceVariant + else MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.5f) + ) + ) { + Card( + modifier = Modifier + .padding(8.dp), + shape = RoundedCornerShape(5.dp), + colors = CardDefaults.cardColors( + containerColor = + if (selected) item.containerColor + else item.containerColor.copy(alpha = 0.5f), + contentColor = + if (selected) item.contentColor + else item.contentColor.copy(alpha = 0.5f) + ) + ) { + Text( + text = stringResource(id = item.textResId), + modifier = Modifier.padding(horizontal = 10.dp, vertical = 4.dp) + ) + } + } + } + } +} + +@OptIn(ExperimentalGlideComposeApi::class) +@ExperimentalMaterial3Api +@Composable +fun MySymbolUi( + symbol: Symbol, + modifier: Modifier = Modifier, + viewModel: MySymbolSettingsViewModel +) { + val filepath = + if (symbol.id > DEFAULT_SYMBOL_COUNT) + LocalContext.current.filesDir.toString().plus("/") + else + DEFAULT_SYMBOL_IMAGE_PATH + + val isChecked = viewModel.checkedSymbols.contains(symbol) + + Card( + onClick = { viewModel.toggleSymbolChecked(symbol) }, + modifier = modifier.size(140.dp), + shape = RoundedCornerShape(10.dp), + colors = CardDefaults.cardColors( + containerColor = MaterialTheme.colorScheme.background + ) + ) { + Box( + contentAlignment = Alignment.TopEnd, + modifier = Modifier.fillMaxSize() + ) { + Box( + modifier = Modifier + .size(24.dp) + .padding(4.dp) + .border(1.dp, Color.Black) + ) { + Checkbox( + checked = isChecked, + onCheckedChange = { viewModel.toggleSymbolChecked(symbol) }, + modifier = Modifier + .fillMaxSize() + .zIndex(1f), + colors = CheckboxDefaults.colors( + checkedColor = Color.White, + uncheckedColor = Color.White, + checkmarkColor = Color.Black + ) + ) + } + + Column( + modifier = Modifier.fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally ) { - /* TODO */ - Text(text = "My Symbol Settings") + GlideImage( + model = filepath.plus("symbol_${symbol.id}.png"), + contentDescription = symbol.text, + modifier = Modifier.height(90.dp), + contentScale = ContentScale.FillHeight + ) + + Box( + modifier = Modifier + .fillMaxWidth() + .height(50.dp) + .background(color = MaterialTheme.colorScheme.secondaryContainer) + .padding(horizontal = 10.dp), + contentAlignment = Alignment.Center + ) { + Text( + text = symbol.text, + textAlign = TextAlign.Center, + maxLines = MAXIMUM_LINES_FOR_SYMBOL_TEXT, + style = MaterialTheme.typography.bodyMedium + ) + } } } } +} + +@Composable +fun DeleteButtonUi( + text: String, + onClick: () -> Unit, + modifier: Modifier = Modifier, + isEnabled: Boolean = true, +) { + Button( + onClick = onClick, + modifier = modifier + .fillMaxWidth() + .height(48.dp), + enabled = isEnabled, + shape = RoundedCornerShape(10.dp), + colors = ButtonDefaults.buttonColors( + containerColor = MaterialTheme.colorScheme.error, + contentColor = MaterialTheme.colorScheme.onError, + ) + ) { + Text(text = text, style = MaterialTheme.typography.titleMedium) + } } \ No newline at end of file diff --git a/frontend/app/src/main/java/com/example/speechbuddy/compose/settings/SettingsScreen.kt b/frontend/app/src/main/java/com/example/speechbuddy/compose/settings/SettingsScreen.kt index 0e3264e4..ac5391db 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/compose/settings/SettingsScreen.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/compose/settings/SettingsScreen.kt @@ -66,7 +66,6 @@ private fun SettingsScreenNavHost( } composable("my_symbol") { MySymbolSettings( - onBackClick = navigateToMain, bottomPaddingValues = bottomPaddingValues ) } diff --git a/frontend/app/src/main/res/values/strings.xml b/frontend/app/src/main/res/values/strings.xml index d0b76035..ac414150 100644 --- a/frontend/app/src/main/res/values/strings.xml +++ b/frontend/app/src/main/res/values/strings.xml @@ -124,6 +124,8 @@ 상징 목록 관리 + 삭제 + 내가 만든 상징 버전 정보 From 31704cb2daea5a7d0453e3011d3ecb139f04d829 Mon Sep 17 00:00:00 2001 From: YeonJeong Kim Date: Fri, 24 Nov 2023 13:00:05 +0900 Subject: [PATCH 2/4] :sparkles: Implement MySymbolSettings logic --- .../speechbuddy/data/local/SymbolDao.kt | 9 ++ .../repository/SymbolRepository.kt | 14 +++ .../ui/models/MySymbolSettingsUiState.kt | 10 ++ .../viewmodel/MySymbolSettingsViewModel.kt | 113 ++++++++++++++++++ 4 files changed, 146 insertions(+) create mode 100644 frontend/app/src/main/java/com/example/speechbuddy/ui/models/MySymbolSettingsUiState.kt create mode 100644 frontend/app/src/main/java/com/example/speechbuddy/viewmodel/MySymbolSettingsViewModel.kt diff --git a/frontend/app/src/main/java/com/example/speechbuddy/data/local/SymbolDao.kt b/frontend/app/src/main/java/com/example/speechbuddy/data/local/SymbolDao.kt index 130f118c..8b83dd7d 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/data/local/SymbolDao.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/data/local/SymbolDao.kt @@ -23,6 +23,12 @@ interface SymbolDao { @Query("SELECT * FROM symbols WHERE isFavorite = 1") fun getFavoriteSymbols(): Flow> + @Query("SELECT * FROM symbols WHERE isMine = 1") + fun getUserSymbols(): Flow> + + @Query("SELECT * FROM symbols WHERE isMine = 1 AND text LIKE '%' || :query || '%'") + fun getUserSymbolsByQuery(query: String): Flow> + @Query("SELECT * FROM symbols WHERE text LIKE '%' || :query || '%'") fun getSymbolsByQuery(query: String): Flow> @@ -49,4 +55,7 @@ interface SymbolDao { @Query("DELETE FROM symbols") suspend fun deleteAllSymbols() + + @Query("DELETE FROM symbols WHERE id = :symbolId") + suspend fun deleteSymbolById(symbolId: Int) } \ No newline at end of file diff --git a/frontend/app/src/main/java/com/example/speechbuddy/repository/SymbolRepository.kt b/frontend/app/src/main/java/com/example/speechbuddy/repository/SymbolRepository.kt index e18d1d7d..7724748d 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/repository/SymbolRepository.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/repository/SymbolRepository.kt @@ -68,6 +68,16 @@ class SymbolRepository @Inject constructor( symbolEntities.map { symbolEntity -> symbolMapper.mapToDomainModel(symbolEntity) } } + fun getUserSymbols(query: String) = + if (query.isBlank()) getAllUserSymbols() + else symbolDao.getUserSymbolsByQuery(query).map { symbolEntities -> + symbolEntities.map { symbolEntity -> symbolMapper.mapToDomainModel(symbolEntity) } + } + + private fun getAllUserSymbols() = symbolDao.getUserSymbols().map { symbolEntities -> + symbolEntities.map { symbolEntity -> symbolMapper.mapToDomainModel(symbolEntity) } + } + private fun getAllSymbols() = symbolDao.getSymbols().map { symbolEntities -> symbolEntities.map { symbolEntity -> symbolMapper.mapToDomainModel(symbolEntity) } } @@ -110,6 +120,10 @@ class SymbolRepository @Inject constructor( fun getNextSymbolId() = symbolDao.getLastSymbol().map { symbol -> symbol.id +1 } + suspend fun deleteSymbol(symbol: Symbol) { + symbolDao.deleteSymbolById(symbol.id) + } + fun clearAllMySymbols() { /* TODO: 내가 만든 상징들 모두 삭제 */ } diff --git a/frontend/app/src/main/java/com/example/speechbuddy/ui/models/MySymbolSettingsUiState.kt b/frontend/app/src/main/java/com/example/speechbuddy/ui/models/MySymbolSettingsUiState.kt new file mode 100644 index 00000000..7b32fdc2 --- /dev/null +++ b/frontend/app/src/main/java/com/example/speechbuddy/ui/models/MySymbolSettingsUiState.kt @@ -0,0 +1,10 @@ +package com.example.speechbuddy.ui.models + +data class MySymbolSettingsUiState( + val mySymbolSettingsDisplayMode: MySymbolSettingsDisplayMode = MySymbolSettingsDisplayMode.SYMBOL +) + +enum class MySymbolSettingsDisplayMode { + SYMBOL, + FAVORITE +} \ No newline at end of file diff --git a/frontend/app/src/main/java/com/example/speechbuddy/viewmodel/MySymbolSettingsViewModel.kt b/frontend/app/src/main/java/com/example/speechbuddy/viewmodel/MySymbolSettingsViewModel.kt new file mode 100644 index 00000000..716e878a --- /dev/null +++ b/frontend/app/src/main/java/com/example/speechbuddy/viewmodel/MySymbolSettingsViewModel.kt @@ -0,0 +1,113 @@ +package com.example.speechbuddy.viewmodel; + +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateListOf +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.example.speechbuddy.domain.models.Symbol +import com.example.speechbuddy.repository.SymbolRepository; +import com.example.speechbuddy.ui.models.MySymbolSettingsDisplayMode +import com.example.speechbuddy.ui.models.MySymbolSettingsUiState + +import javax.inject.Inject; + +import dagger.hilt.android.lifecycle.HiltViewModel; +import kotlinx.coroutines.Job +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.update +import kotlinx.coroutines.launch + +@HiltViewModel +class MySymbolSettingsViewModel @Inject internal constructor( + private val repository:SymbolRepository +) : ViewModel(){ + + private val _uiState = MutableStateFlow(MySymbolSettingsUiState()) + val uiState: StateFlow = _uiState.asStateFlow() + + private val _symbols = MutableLiveData>() + val symbols: LiveData> get() = _symbols + + private val _checkedSymbols = mutableStateListOf() + val checkedSymbols: List get() = _checkedSymbols + + var queryInput by mutableStateOf("") + private set + + private var getSymbolsJob: Job? = null + + init { + getSymbols() + } + + fun setQuery(input: String) { + queryInput = input + getSymbols(input) + } + + fun toggleSymbolChecked(symbol: Symbol) { + if (_checkedSymbols.contains(symbol)) { + _checkedSymbols.remove(symbol) + } else { + _checkedSymbols.add(symbol) + } + } + + fun updateFavorite(symbol: Symbol, value: Boolean) { + viewModelScope.launch { + repository.updateFavorite(symbol, value) + } + } + + fun selectDisplayMode(displayMode: MySymbolSettingsDisplayMode) { + _uiState.update { currentState -> + currentState.copy( + mySymbolSettingsDisplayMode = displayMode + ) + } + getSymbols() + } + + fun deleteCheckedSymbols() { + viewModelScope.launch { + val checkedSymbols = _checkedSymbols.toList() + for (symbol in checkedSymbols) { + repository.deleteSymbol(symbol) + } + _checkedSymbols.clear() + } + } + + private fun getSymbols(query: String? = null) { + getSymbolsJob?.cancel() + getSymbolsJob = viewModelScope.launch { + when (_uiState.value.mySymbolSettingsDisplayMode) { + MySymbolSettingsDisplayMode.SYMBOL -> { + if(query!=null){ + repository.getUserSymbols(query).collect{ symbols -> + _symbols.postValue(symbols) + } + } + else { + repository.getUserSymbols(queryInput).collect{ symbols -> + _symbols.postValue(symbols) + } + } + } + + MySymbolSettingsDisplayMode.FAVORITE -> { + repository.getFavoriteSymbols(queryInput).collect { symbols -> + _symbols.postValue(symbols) + } + } + } + } + } + +} From 506cb12943965dde743dd8f3073a02207a6c3ce0 Mon Sep 17 00:00:00 2001 From: YeonJeong Kim Date: Sun, 26 Nov 2023 15:04:49 +0900 Subject: [PATCH 3/4] :sparkles: Reflect symbol deletion to weight table --- .../speechbuddy/data/local/WeightRowDao.kt | 6 +++++ .../repository/WeightTableRepository.kt | 24 +++++++++++++++++++ .../viewmodel/MySymbolSettingsViewModel.kt | 3 +++ 3 files changed, 33 insertions(+) diff --git a/frontend/app/src/main/java/com/example/speechbuddy/data/local/WeightRowDao.kt b/frontend/app/src/main/java/com/example/speechbuddy/data/local/WeightRowDao.kt index 042be11d..02bfafec 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/data/local/WeightRowDao.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/data/local/WeightRowDao.kt @@ -24,4 +24,10 @@ interface WeightRowDao { @Query("DELETE FROM weighttable") suspend fun deleteAllWeightRows() + @Query("DELETE FROM weighttable WHERE id = :rowId") + suspend fun deleteWeightRowById(rowId: Int) + + @Query("SELECT COUNT(*) FROM weighttable WHERE id < :rowId") + suspend fun getCountOfRowsWithIdLessThan(rowId: Int): Int + } diff --git a/frontend/app/src/main/java/com/example/speechbuddy/repository/WeightTableRepository.kt b/frontend/app/src/main/java/com/example/speechbuddy/repository/WeightTableRepository.kt index 93fc6417..39d8ad63 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/repository/WeightTableRepository.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/repository/WeightTableRepository.kt @@ -1,5 +1,6 @@ package com.example.speechbuddy.repository +import android.util.Log import com.example.speechbuddy.data.local.SymbolDao import com.example.speechbuddy.data.local.WeightRowDao import com.example.speechbuddy.data.local.models.SymbolMapper @@ -104,6 +105,29 @@ class WeightTableRepository @Inject constructor( } } + fun updateWeightTableForDeletedSymbol(symbol: Symbol){ + CoroutineScope(Dispatchers.IO).launch { + val deletedSymbolIdx = weightRowDao.getCountOfRowsWithIdLessThan(symbol.id) + + val weightRows = mutableListOf() + weightRows.clear() + weightRows.addAll(fetchWeightRows()) + + // update existing weightRows + for(weightRow in weightRows){ + val newWeights = mutableListOf() + newWeights.addAll(weightRow.weights) + newWeights.removeAt(deletedSymbolIdx) + updateWeightRow(weightRow, newWeights) + } + + // delete weightRow for the deleted symbol + weightRowDao.deleteWeightRowById(symbol.id) + + allSymbols = getAllSymbols() + } + } + fun provideSuggestion(symbol: Symbol): Flow> = flow { val allSymbolList = allSymbols.first() val oneWeightRow = getWeightRowById(symbol.id).first() diff --git a/frontend/app/src/main/java/com/example/speechbuddy/viewmodel/MySymbolSettingsViewModel.kt b/frontend/app/src/main/java/com/example/speechbuddy/viewmodel/MySymbolSettingsViewModel.kt index 716e878a..c03ffb78 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/viewmodel/MySymbolSettingsViewModel.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/viewmodel/MySymbolSettingsViewModel.kt @@ -10,6 +10,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.example.speechbuddy.domain.models.Symbol import com.example.speechbuddy.repository.SymbolRepository; +import com.example.speechbuddy.repository.WeightTableRepository import com.example.speechbuddy.ui.models.MySymbolSettingsDisplayMode import com.example.speechbuddy.ui.models.MySymbolSettingsUiState @@ -25,6 +26,7 @@ import kotlinx.coroutines.launch @HiltViewModel class MySymbolSettingsViewModel @Inject internal constructor( + private val weightTableRepository: WeightTableRepository, private val repository:SymbolRepository ) : ViewModel(){ @@ -79,6 +81,7 @@ class MySymbolSettingsViewModel @Inject internal constructor( val checkedSymbols = _checkedSymbols.toList() for (symbol in checkedSymbols) { repository.deleteSymbol(symbol) + weightTableRepository.updateWeightTableForDeletedSymbol(symbol) } _checkedSymbols.clear() } From 6aab2131320b5406aee1c00f849249659a111e2f Mon Sep 17 00:00:00 2001 From: YeonJeong Kim Date: Wed, 29 Nov 2023 20:04:10 +0900 Subject: [PATCH 4/4] :bug: fix syntax bugs in SymbolRepository --- .../com/example/speechbuddy/repository/SymbolRepository.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/app/src/main/java/com/example/speechbuddy/repository/SymbolRepository.kt b/frontend/app/src/main/java/com/example/speechbuddy/repository/SymbolRepository.kt index 43b865a6..d0bc341a 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/repository/SymbolRepository.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/repository/SymbolRepository.kt @@ -85,6 +85,7 @@ class SymbolRepository @Inject constructor( private fun getAllUserSymbols() = symbolDao.getUserSymbols().map { symbolEntities -> symbolEntities.map { symbolEntity -> symbolMapper.mapToDomainModel(symbolEntity) } + } fun getSymbolsById(id: Int): Symbol { return runBlocking { symbolMapper.mapToDomainModel(symbolDao.getSymbolById(id).first()) } @@ -197,4 +198,4 @@ class SymbolRepository @Inject constructor( "Unknown error", null ) } -} +} \ No newline at end of file