From 99832c6a5071011883ef1d616c06e8f638890c06 Mon Sep 17 00:00:00 2001 From: Nguyen Quang Minh Date: Thu, 19 Dec 2024 21:48:42 +0700 Subject: [PATCH] =?UTF-8?q?refactor:=20t=E1=BA=A1o=20view=20chung=20cho=20?= =?UTF-8?q?hint=20v=C3=A0=20explanation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flashcard/component/ExplanationCard.kt | 68 +++++++++++++ .../app/flashcard/component/HintCard.kt | 67 +++++++++++++ .../flashcard/create/CreateFlashCardScreen.kt | 99 +++---------------- .../app/flashcard/edit/EditFlashCardScreen.kt | 99 +++---------------- 4 files changed, 159 insertions(+), 174 deletions(-) create mode 100644 app/src/main/java/com/pwhs/quickmem/presentation/app/flashcard/component/ExplanationCard.kt create mode 100644 app/src/main/java/com/pwhs/quickmem/presentation/app/flashcard/component/HintCard.kt diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/flashcard/component/ExplanationCard.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/flashcard/component/ExplanationCard.kt new file mode 100644 index 00000000..3688d749 --- /dev/null +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/flashcard/component/ExplanationCard.kt @@ -0,0 +1,68 @@ +package com.pwhs.quickmem.presentation.app.flashcard.component + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Clear +import androidx.compose.material3.Card +import androidx.compose.material3.CardDefaults +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme.colorScheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import com.pwhs.quickmem.R + +@Composable +fun ExplanationCard( + modifier: Modifier = Modifier, + explanation: String, + onExplanationChanged: (String) -> Unit, + onShowExplanationClicked: (Boolean) -> Unit +) { + Card( + modifier = modifier + .fillMaxWidth() + .padding(16.dp), + elevation = CardDefaults.elevatedCardElevation( + defaultElevation = 5.dp, + focusedElevation = 8.dp + ), + colors = CardDefaults.cardColors( + containerColor = colorScheme.surface + ), + ) { + Box( + contentAlignment = Alignment.Center + ) { + Column( + modifier = Modifier.padding(16.dp) + ) { + FlashCardTextField( + value = explanation, + onValueChange = onExplanationChanged, + hint = stringResource(R.string.txt_explanation) + ) + } + + IconButton( + onClick = { + onShowExplanationClicked(false) + onExplanationChanged("") + }, + modifier = Modifier.align(Alignment.TopEnd) + ) { + Icon( + imageVector = Icons.Filled.Clear, + contentDescription = stringResource(R.string.txt_close), + ) + } + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/flashcard/component/HintCard.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/flashcard/component/HintCard.kt new file mode 100644 index 00000000..0d76e0a5 --- /dev/null +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/flashcard/component/HintCard.kt @@ -0,0 +1,67 @@ +package com.pwhs.quickmem.presentation.app.flashcard.component + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Clear +import androidx.compose.material3.Card +import androidx.compose.material3.CardDefaults +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme.colorScheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import com.pwhs.quickmem.R + +@Composable +fun HintCard( + modifier: Modifier = Modifier, + hint: String, + onHintChanged: (String) -> Unit, + onShowHintClicked: (Boolean) -> Unit +) { + Card( + modifier = modifier + .fillMaxWidth() + .padding(16.dp), + elevation = CardDefaults.elevatedCardElevation( + defaultElevation = 5.dp, + focusedElevation = 8.dp + ), + colors = CardDefaults.cardColors( + containerColor = colorScheme.surface + ), + ) { + Box( + contentAlignment = Alignment.Center + ) { + Column( + modifier = Modifier.padding(16.dp) + ) { + FlashCardTextField( + value = hint, + onValueChange = onHintChanged, + hint = stringResource(R.string.txt_hint) + ) + } + + IconButton( + onClick = { + onShowHintClicked(false) + onHintChanged("") + }, + modifier = Modifier.align(Alignment.TopEnd) + ) { + Icon( + imageVector = Icons.Filled.Clear, + contentDescription = stringResource(R.string.txt_close), + ) + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/flashcard/create/CreateFlashCardScreen.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/flashcard/create/CreateFlashCardScreen.kt index dd2fcb18..d68e2fc5 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/flashcard/create/CreateFlashCardScreen.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/flashcard/create/CreateFlashCardScreen.kt @@ -3,20 +3,12 @@ package com.pwhs.quickmem.presentation.app.flashcard.create import android.net.Uri import android.widget.Toast import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.Clear -import androidx.compose.material3.Card -import androidx.compose.material3.CardDefaults import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.HorizontalDivider -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton -import androidx.compose.material3.MaterialTheme.colorScheme import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.material3.rememberModalBottomSheetState @@ -47,11 +39,12 @@ import com.pwhs.quickmem.R import com.pwhs.quickmem.domain.model.pixabay.SearchImageResponseModel import com.pwhs.quickmem.presentation.ads.BannerAds import com.pwhs.quickmem.presentation.app.flashcard.component.CardSelectImage -import com.pwhs.quickmem.presentation.app.flashcard.component.FlashCardTextField +import com.pwhs.quickmem.presentation.app.flashcard.component.ExplanationCard import com.pwhs.quickmem.presentation.app.flashcard.component.FlashCardTextFieldContainer import com.pwhs.quickmem.presentation.app.flashcard.component.FlashCardTopAppBar import com.pwhs.quickmem.presentation.app.flashcard.component.FlashcardBottomSheet import com.pwhs.quickmem.presentation.app.flashcard.component.FlashcardSelectImageBottomSheet +import com.pwhs.quickmem.presentation.app.flashcard.component.HintCard import com.pwhs.quickmem.presentation.component.LoadingOverlay import com.pwhs.quickmem.ui.theme.QuickMemTheme import com.pwhs.quickmem.util.ImageCompressor @@ -298,89 +291,21 @@ fun CreateFlashCard( item { if (showHint) { - Card( - modifier = Modifier - .fillMaxWidth() - .padding(16.dp), - elevation = CardDefaults.elevatedCardElevation( - defaultElevation = 5.dp, - focusedElevation = 8.dp - ), - colors = CardDefaults.cardColors( - containerColor = colorScheme.surface - ), - ) { - Box( - contentAlignment = Alignment.Center - ) { - Column( - modifier = Modifier.padding(16.dp) - ) { - FlashCardTextField( - value = hint, - onValueChange = onHintChanged, - hint = stringResource(R.string.txt_hint) - ) - } - - IconButton( - onClick = { - onShowHintClicked(false) - onHintChanged("") - }, - modifier = Modifier.align(Alignment.TopEnd) - ) { - Icon( - imageVector = Icons.Filled.Clear, - contentDescription = stringResource(R.string.txt_close), - ) - } - } - } + HintCard( + hint = hint, + onHintChanged = onHintChanged, + onShowHintClicked = onShowHintClicked + ) } } item { if (showExplanation) { - Card( - modifier = Modifier - .fillMaxWidth() - .padding(16.dp), - elevation = CardDefaults.elevatedCardElevation( - defaultElevation = 5.dp, - focusedElevation = 8.dp - ), - colors = CardDefaults.cardColors( - containerColor = colorScheme.surface - ), - ) { - Box( - contentAlignment = Alignment.Center - ) { - Column( - modifier = Modifier.padding(16.dp) - ) { - FlashCardTextField( - value = explanation, - onValueChange = onExplanationChanged, - hint = stringResource(R.string.txt_explanation) - ) - } - - IconButton( - onClick = { - onShowExplanationClicked(false) - onExplanationChanged("") - }, - modifier = Modifier.align(Alignment.TopEnd) - ) { - Icon( - imageVector = Icons.Filled.Clear, - contentDescription = stringResource(R.string.txt_close), - ) - } - } - } + ExplanationCard( + explanation = explanation, + onExplanationChanged = onExplanationChanged, + onShowExplanationClicked = onShowExplanationClicked + ) } } diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/flashcard/edit/EditFlashCardScreen.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/flashcard/edit/EditFlashCardScreen.kt index 14dc28fe..a99b9535 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/flashcard/edit/EditFlashCardScreen.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/flashcard/edit/EditFlashCardScreen.kt @@ -3,20 +3,12 @@ package com.pwhs.quickmem.presentation.app.flashcard.edit import android.net.Uri import android.widget.Toast import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.Clear -import androidx.compose.material3.Card -import androidx.compose.material3.CardDefaults import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.HorizontalDivider -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton -import androidx.compose.material3.MaterialTheme.colorScheme import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.material3.rememberModalBottomSheetState @@ -47,11 +39,12 @@ import com.pwhs.quickmem.R import com.pwhs.quickmem.domain.model.pixabay.SearchImageResponseModel import com.pwhs.quickmem.presentation.ads.BannerAds import com.pwhs.quickmem.presentation.app.flashcard.component.CardSelectImage -import com.pwhs.quickmem.presentation.app.flashcard.component.FlashCardTextField +import com.pwhs.quickmem.presentation.app.flashcard.component.ExplanationCard import com.pwhs.quickmem.presentation.app.flashcard.component.FlashCardTextFieldContainer import com.pwhs.quickmem.presentation.app.flashcard.component.FlashCardTopAppBar import com.pwhs.quickmem.presentation.app.flashcard.component.FlashcardBottomSheet import com.pwhs.quickmem.presentation.app.flashcard.component.FlashcardSelectImageBottomSheet +import com.pwhs.quickmem.presentation.app.flashcard.component.HintCard import com.pwhs.quickmem.presentation.component.LoadingOverlay import com.pwhs.quickmem.ui.theme.QuickMemTheme import com.pwhs.quickmem.util.ImageCompressor @@ -303,89 +296,21 @@ fun CreateFlashCard( item { if (showHint || hint.isNotEmpty()) { - Card( - modifier = Modifier - .fillMaxWidth() - .padding(16.dp), - elevation = CardDefaults.elevatedCardElevation( - defaultElevation = 5.dp, - focusedElevation = 8.dp - ), - colors = CardDefaults.cardColors( - containerColor = colorScheme.surface - ), - ) { - Box( - contentAlignment = Alignment.Center - ) { - Column( - modifier = Modifier.padding(16.dp) - ) { - FlashCardTextField( - value = hint, - onValueChange = onHintChanged, - hint = stringResource(R.string.txt_hint) - ) - } - - IconButton( - onClick = { - onShowHintClicked(false) - onHintChanged("") - }, - modifier = Modifier.align(Alignment.TopEnd) - ) { - Icon( - imageVector = Icons.Filled.Clear, - contentDescription = "Close", - ) - } - } - } + HintCard( + hint = hint, + onHintChanged = onHintChanged, + onShowHintClicked = onShowHintClicked + ) } } item { if (showExplanation || explanation.isNotEmpty()) { - Card( - modifier = Modifier - .fillMaxWidth() - .padding(16.dp), - elevation = CardDefaults.elevatedCardElevation( - defaultElevation = 5.dp, - focusedElevation = 8.dp - ), - colors = CardDefaults.cardColors( - containerColor = colorScheme.surface - ), - ) { - Box( - contentAlignment = Alignment.Center - ) { - Column( - modifier = Modifier.padding(16.dp) - ) { - FlashCardTextField( - value = explanation, - onValueChange = onExplanationChanged, - hint = stringResource(R.string.txt_explanation) - ) - } - - IconButton( - onClick = { - onShowExplanationClicked(false) - onExplanationChanged("") - }, - modifier = Modifier.align(Alignment.TopEnd) - ) { - Icon( - imageVector = Icons.Filled.Clear, - contentDescription = "Close", - ) - } - } - } + ExplanationCard( + explanation = explanation, + onExplanationChanged = onExplanationChanged, + onShowExplanationClicked = onShowExplanationClicked + ) } }