Skip to content

Commit

Permalink
feat(study set): gán mark AI nếu như study set tạo từ AI
Browse files Browse the repository at this point in the history
- sửa các lỗi liên quan đến logic và giao diện
  • Loading branch information
nqmgaming committed Nov 27, 2024
1 parent aa6708e commit d055e92
Show file tree
Hide file tree
Showing 28 changed files with 263 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ data class StudySetFlashCardResponseDto(
val writeStatus: String = WriteStatus.NONE.status,
@SerializedName("isStarred")
val isStarred: Boolean,
@SerializedName("isAIGenerated")
val isAIGenerated: Boolean,
@SerializedName("createdAt")
val createdAt: String,
@SerializedName("updatedAt")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ fun StudySetFlashCardResponseDto.toModel() = StudySetFlashCardResponseModel(
writeStatus = writeStatus,
createdAt = createdAt,
updatedAt = updatedAt,
isStarred = isStarred
isStarred = isStarred,
isAIGenerated = isAIGenerated
)

fun StudySetFlashCardResponseModel.toDto() = StudySetFlashCardResponseDto(
Expand All @@ -34,5 +35,6 @@ fun StudySetFlashCardResponseModel.toDto() = StudySetFlashCardResponseDto(
writeStatus = writeStatus,
createdAt = createdAt,
updatedAt = updatedAt,
isStarred = isStarred
isStarred = isStarred,
isAIGenerated = isAIGenerated
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ data class StudySetFlashCardResponseModel(
val definitionImageURL: String? = null,
val hint: String? = null,
val explanation: String? = null,
val isAIGenerated: Boolean = false,
val rating: String = Rating.NOT_STUDIED.name,
val flipStatus: String = FlipCardStatus.NONE.name,
val quizStatus: String = QuizStatus.NONE.status,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
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.lazy.LazyColumn
Expand All @@ -17,15 +18,18 @@ import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.MaterialTheme.colorScheme
import androidx.compose.material3.MaterialTheme.typography
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.VerticalDivider
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
Expand Down Expand Up @@ -106,15 +110,35 @@ fun AddStudySetToClassItem(
}
}
)
Text(
studySet.subject?.name
?: SubjectModel.defaultSubjects[0].name,
style = MaterialTheme.typography.bodySmall.copy(
color = colorScheme.onSurface.copy(
alpha = 0.6f
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
Text(
text = studySet?.subject?.name ?: SubjectModel.defaultSubjects[0].name,
style = typography.bodySmall.copy(
color = colorScheme.onSurface.copy(alpha = 0.6f)
)
)
)
if(studySet?.isAIGenerated == true) {
VerticalDivider(
modifier = Modifier.height(12.dp)
)
Text(
stringResource(R.string.txt_ai_generated),
style = typography.bodySmall.copy(
color = colorScheme.onSurface.copy(alpha = 0.6f)
),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Icon(
painter = painterResource(R.drawable.ic_generative_ai),
contentDescription = stringResource(R.string.txt_ai_generated),
modifier = Modifier.size(16.dp)
)
}
}
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import androidx.compose.material3.TextFieldDefaults.colors
import androidx.compose.material3.VerticalDivider
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand All @@ -51,6 +52,11 @@ import com.pwhs.quickmem.core.data.enums.LanguageCode
import com.pwhs.quickmem.core.data.enums.QuestionType
import com.pwhs.quickmem.ui.theme.QuickMemTheme
import com.pwhs.quickmem.util.ads.AdsUtil
import com.revenuecat.purchases.CustomerInfo
import com.revenuecat.purchases.Purchases
import com.revenuecat.purchases.PurchasesError
import com.revenuecat.purchases.interfaces.ReceiveCustomerInfoCallback
import timber.log.Timber

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand All @@ -76,13 +82,32 @@ fun CreateStudySetAITab(
mutableStateOf(false)
}
val context = LocalContext.current
var customer: CustomerInfo? by remember { mutableStateOf(null) }
LaunchedEffect(key1 = true) {
Purchases.sharedInstance.getCustomerInfo(object : ReceiveCustomerInfoCallback {
override fun onError(error: PurchasesError) {
Timber.e("Error getting customer info: $error")
}

override fun onReceived(customerInfo: CustomerInfo) {
Timber.d("Customer info: $customerInfo")
customer = customerInfo
}

})
}
Scaffold(
floatingActionButton = {
if (title.isNotEmpty()) {
FloatingActionButton(
onClick = {
AdsUtil.rewardedAd(context) {
val isSubscribed = customer?.activeSubscriptions?.isNotEmpty() == true
if (isSubscribed) {
onCreateStudySet()
} else {
AdsUtil.rewardedAd(context) {
onCreateStudySet()
}
}
},
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
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.lazy.LazyColumn
Expand All @@ -17,15 +18,18 @@ import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.MaterialTheme.colorScheme
import androidx.compose.material3.MaterialTheme.typography
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.VerticalDivider
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
Expand Down Expand Up @@ -106,15 +110,35 @@ fun AddStudySetToFolderItem(
}
}
)
Text(
studySet.subject?.name
?: SubjectModel.defaultSubjects[0].name,
style = MaterialTheme.typography.bodySmall.copy(
color = colorScheme.onSurface.copy(
alpha = 0.6f
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
Text(
text = studySet?.subject?.name ?: SubjectModel.defaultSubjects[0].name,
style = typography.bodySmall.copy(
color = colorScheme.onSurface.copy(alpha = 0.6f)
)
)
)
if(studySet.isAIGenerated == true) {
VerticalDivider(
modifier = Modifier.height(12.dp)
)
Text(
stringResource(R.string.txt_ai_generated),
style = typography.bodySmall.copy(
color = colorScheme.onSurface.copy(alpha = 0.6f)
),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Icon(
painter = painterResource(R.drawable.ic_generative_ai),
contentDescription = stringResource(R.string.txt_ai_generated),
modifier = Modifier.size(16.dp)
)
}
}
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FabPosition
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LargeTopAppBar
Expand Down Expand Up @@ -269,7 +268,7 @@ private fun Home(
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp)
)
},
expandedHeight = 180.dp,
expandedHeight = 160.dp,
collapsedHeight = 56.dp,
title = {
Card(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
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.width
Expand All @@ -13,16 +14,20 @@ import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults.cardColors
import androidx.compose.material3.CardDefaults.elevatedCardElevation
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.MaterialTheme.colorScheme
import androidx.compose.material3.MaterialTheme.typography
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.VerticalDivider
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
Expand Down Expand Up @@ -92,12 +97,35 @@ fun StudySetHomeItem(
}
}
)
Text(
text = studySet?.subject?.name ?: SubjectModel.defaultSubjects[0].name,
style = typography.bodySmall.copy(
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f)
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
Text(
text = studySet?.subject?.name ?: SubjectModel.defaultSubjects[0].name,
style = typography.bodySmall.copy(
color = colorScheme.onSurface.copy(alpha = 0.6f)
)
)
)
if (studySet?.isAIGenerated == true) {
VerticalDivider(
modifier = Modifier.height(12.dp)
)
Text(
stringResource(R.string.txt_ai_generated),
style = typography.bodySmall.copy(
color = colorScheme.onSurface.copy(alpha = 0.6f)
),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Icon(
painter = painterResource(R.drawable.ic_generative_ai),
contentDescription = stringResource(R.string.txt_ai_generated),
modifier = Modifier.size(16.dp)
)
}
}
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ fun ListClassesScreen(
item {
if (classes.isNotEmpty()) {
SearchTextField(
modifier = Modifier.padding(horizontal = 16.dp),
searchQuery = searchQuery,
onSearchQueryChange = { searchQuery = it },
placeholder = stringResource(R.string.txt_search_classes),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ fun SearchTextField(
Box(
modifier = modifier
.fillMaxWidth()
.padding(horizontal = 16.dp)
) {
TextField(
value = searchQuery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ fun ListFolderScreen(
item {
if (folders.isNotEmpty()) {
SearchTextField(
modifier = Modifier.padding(horizontal = 16.dp),
searchQuery = searchQuery,
onSearchQueryChange = { searchQuery = it },
placeholder = stringResource(R.string.txt_search_folders),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ fun ListStudySetScreen(
LazyColumn {
item {
SearchTextField(
modifier = Modifier.padding(horizontal = 16.dp),
searchQuery = searchQuery,
onSearchQueryChange = { searchQuery = it },
placeholder = stringResource(R.string.txt_search_study_sets)
Expand Down
Loading

0 comments on commit d055e92

Please sign in to comment.