Skip to content

Commit

Permalink
fix(ui):sửa lỗi giao diện
Browse files Browse the repository at this point in the history
- sửa lỗi giao diện màn study set detail
- bổ sung logic tính toán coin
  • Loading branch information
nqmgaming committed Dec 14, 2024
1 parent 0c1623a commit f2fceb0
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 72 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/navEditor.xmlc
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
local.properties
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ android {
try {
file(rootProject.file("local.properties")).inputStream()
.use { localProperties.load(it) }
} catch (e: Exception) {
} catch (_: Exception) {
println("local.properties not found, using default values")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand All @@ -35,25 +32,19 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import coil.compose.AsyncImage
import com.pwhs.quickmem.R
import com.pwhs.quickmem.domain.model.classes.GetClassDetailResponseModel
import com.pwhs.quickmem.presentation.ads.BannerAds
import com.pwhs.quickmem.presentation.app.settings.component.SettingCard
import com.pwhs.quickmem.presentation.app.settings.component.SettingItem
import com.pwhs.quickmem.presentation.app.settings.component.SettingTitleSection
import com.pwhs.quickmem.presentation.component.LoadingOverlay
import com.pwhs.quickmem.util.ads.AdsUtil.interstitialAds
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.annotation.RootGraph
import com.ramcosta.composedestinations.generated.NavGraphs
import com.ramcosta.composedestinations.generated.destinations.ClassDetailScreenDestination
import com.ramcosta.composedestinations.generated.destinations.UserDetailScreenDestination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
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
import com.pwhs.quickmem.R

@Destination<RootGraph>(
navArgs = JoinClassArgs::class
Expand Down Expand Up @@ -92,8 +83,10 @@ fun JoinClassScreen(
}

JoinClassUiEvent.UnAuthorized -> {
Toast.makeText(context,
context.getString(R.string.txt_unauthorized), Toast.LENGTH_SHORT).show()
Toast.makeText(
context,
context.getString(R.string.txt_unauthorized), Toast.LENGTH_SHORT
).show()
navigator.navigate(NavGraphs.root) {
popUpTo(NavGraphs.root) {
saveState = false
Expand All @@ -104,8 +97,10 @@ fun JoinClassScreen(
}

JoinClassUiEvent.NotFound -> {
Toast.makeText(context,
context.getString(R.string.txt_class_not_found), Toast.LENGTH_SHORT).show()
Toast.makeText(
context,
context.getString(R.string.txt_class_not_found), Toast.LENGTH_SHORT
).show()
navigator.navigate(NavGraphs.root) {
popUpTo(NavGraphs.root) {
saveState = false
Expand Down Expand Up @@ -152,21 +147,6 @@ fun JoinClass(
onBackHome: () -> Unit = {},
onOwnerClick: () -> Unit = {}
) {
var customer: CustomerInfo? by remember { mutableStateOf(null) }
val context = LocalContext.current
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(
topBar = {
CenterAlignedTopAppBar(
Expand Down Expand Up @@ -199,7 +179,7 @@ fun JoinClass(
modifier = Modifier.padding(16.dp)
) {
SettingItem(
title = "Name",
title = stringResource(R.string.txt_title),
subtitle = classDetailResponseModel?.title ?: "",
showArrow = false
)
Expand Down Expand Up @@ -244,12 +224,7 @@ fun JoinClass(

item {
Button(
onClick = {
val isSubscribed = customer?.activeSubscriptions?.isNotEmpty() == true
interstitialAds(context, isSubscribed) {
onJoinClass()
}
},
onClick = onJoinClass,
modifier = Modifier.padding(16.dp)
) {
Text(text = stringResource(R.string.txt_join_class))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
Expand All @@ -56,7 +57,6 @@ import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.annotation.RootGraph
import com.ramcosta.composedestinations.generated.destinations.StudySetDetailScreenDestination
import com.ramcosta.composedestinations.generated.destinations.UserDetailScreenDestination
import com.ramcosta.composedestinations.generated.destinations.UserDetailScreenDestination.invoke
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.revenuecat.purchases.CustomerInfo

Expand Down Expand Up @@ -87,6 +87,7 @@ fun ExploreScreen(
Toast.LENGTH_SHORT
).show()
}

is ExploreUiEvent.Error -> {
Toast.makeText(
context,
Expand Down Expand Up @@ -164,7 +165,7 @@ fun Explore(
onDifficultyLevelChange: (DifficultyLevel) -> Unit = {},
onCreateStudySet: () -> Unit = {},
onEarnCoins: () -> Unit = {},
@StringRes errorMessage: Int? = null,
@StringRes errorMessage: Int? = null,
coins: Int = 0,
customerInfo: CustomerInfo? = null,
) {
Expand All @@ -174,7 +175,7 @@ fun Explore(
stringResource(R.string.txt_top_streak),
)
val context = LocalContext.current

var isGettingAds by rememberSaveable { mutableStateOf(false) }

Scaffold(
modifier = modifier,
Expand All @@ -195,7 +196,7 @@ fun Explore(
) {
Icon(
imageVector = Icons.Default.Refresh,
contentDescription = "Refresh",
contentDescription = stringResource(R.string.txt_refresh),
)
}
} else {
Expand All @@ -216,22 +217,25 @@ fun Explore(
)
Image(
painter = painterResource(id = R.drawable.ic_coin),
contentDescription = "Coins",
contentDescription = stringResource(R.string.txt_coin),
modifier = Modifier.size(24.dp),
contentScale = ContentScale.Crop
)
if (customerInfo?.activeSubscriptions?.isNotEmpty() == false) {
Icon(
imageVector = Icons.Default.Add,
contentDescription = "Add",
contentDescription = stringResource(R.string.txt_add),
tint = colorScheme.primary,
modifier = Modifier
.size(24.dp)
.clickable {
isGettingAds = true
AdsUtil.rewardedInterstitialAd(
context,
onEarnCoins
)
) {
onEarnCoins()
isGettingAds = false
}
},
)
}
Expand Down Expand Up @@ -312,7 +316,7 @@ fun Explore(
)
}
}
LoadingOverlay(isLoading = isLoading)
LoadingOverlay(isLoading = isLoading || isGettingAds)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,14 @@ class ExploreViewModel @Inject constructor(
)
}
if (_uiState.value.customerInfo?.activeSubscriptions?.isNotEmpty() == false) {
updateCoins(coinAction = CoinAction.SUBTRACT)
updateCoins(
coinAction = CoinAction.SUBTRACT,
coin = when (uiState.value.numberOfFlashcards) {
in 1..10 -> 1
in 11..20 -> 2
else -> 3
}
)
}
_uiEvent.send(
ExploreUiEvent.CreatedStudySet(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,26 @@ fun CreateStudySetAITab(
) {
Icon(
painter = painterResource(R.drawable.ic_sparkling),
contentDescription = stringResource(R.string.txt_create_study_set_with_ai_minus_one),
contentDescription = "Create",
)
Text(
text = when (isPlus) {
false -> stringResource(R.string.txt_create_study_set_with_ai_minus_one)
false -> when (numberOfFlashcards) {
in 1..10 -> stringResource(
R.string.txt_create_study_set_ai_now,
1
)

in 11..20 -> stringResource(
R.string.txt_create_study_set_ai_now,
2
)

else -> {
stringResource(R.string.txt_create_study_set_ai_now, 3)
}
}

else -> stringResource(
R.string.txt_create_study_set_with_ai,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,26 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import coil.compose.AsyncImage
import coil.request.ImageRequest
import com.pwhs.quickmem.R
import com.pwhs.quickmem.presentation.component.ShowImageDialog

@Composable
fun calculateDynamicFontSize(text: String): androidx.compose.ui.unit.TextUnit {
fun calculateDynamicFontSize(text: String): TextUnit {
return when {
text.length <= 20 -> 24.sp
text.length <= 50 -> 20.sp
else -> 16.sp
text.length <= 100 -> 18.sp
text.length <= 150 -> 16.sp
text.length <= 200 -> 14.sp
else -> 12.sp
}
}

Expand Down Expand Up @@ -136,6 +142,7 @@ fun StudySetFlipCard(
style = MaterialTheme.typography.bodyMedium.copy(
fontSize = frontTextSize,
color = colorScheme.onBackground,
fontWeight = FontWeight.Normal,
textAlign = when {
backImage != null -> TextAlign.Start
else -> TextAlign.Center
Expand All @@ -149,7 +156,10 @@ fun StudySetFlipCard(
backImage?.let {
if (it.isNotEmpty()) {
AsyncImage(
model = it,
model = ImageRequest.Builder(LocalContext.current)
.data(it)
.error(R.drawable.ic_image_error)
.build(),
contentDescription = null,
modifier = Modifier
.width(100.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.pwhs.quickmem.presentation.app.study_set.detail.progress

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
Expand Down Expand Up @@ -113,6 +114,9 @@ fun ProgressTabScreen(
)
}
}
item {
Spacer(modifier = Modifier.padding(60.dp))
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values-vi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@
<string name="txt_bronze_medal">Huy chương đồng</string>
<string name="txt_top_10_highest_streak_leaderboard">Bảng xếp hạng 10 chuỗi thành tích cao nhất</string>
<string name="txt_streak_leaderboard_motivation">Duy trì chuỗi để leo bảng xếp hạng!</string>
<string name="txt_create_study_set_with_ai_minus_one">Tạo (-1)</string>
<string name="txt_warning_ai_not_gen">Cảnh báo: AI có thể không tạo thẻ học chính xác hoặc đầy đủ. Hãy kiểm tra lại nếu bạn thấy cần thiết.</string>
<string name="txt_title_required">Tiêu đề (bắt buộc)</string>
<string name="txt_description_optional">Mô tả (tùy chọn)</string>
Expand Down Expand Up @@ -616,4 +615,7 @@
<string name="txt_please_login_again">Vui lòng đăng nhập lại!</string>
<string name="txt_failed_to_mark_notification_as_read">Đánh dấu thông báo là đã đọc thất bại</string>
<string name="txt_failed_to_load_notifications">Tải thông báo thất bại</string>
<string name="txt_refresh">Tải lại</string>
<string name="txt_coin">Xu</string>
<string name="txt_create_study_set_ai_now">Tạo (-%1$s)</string>
</resources>
4 changes: 3 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@
<string name="txt_bronze_medal">Bronze Medal</string>
<string name="txt_top_10_highest_streak_leaderboard">Top 10 highest streak leaderboard</string>
<string name="txt_streak_leaderboard_motivation">Keep up the streak to climb the leaderboard!</string>
<string name="txt_create_study_set_with_ai_minus_one">Create (-1)</string>
<string name="txt_warning_ai_not_gen">Warning: AI may not generate accurate or complete flashcards. Please review if unsure.</string>
<string name="txt_title_required">Title (required)</string>
<string name="txt_description_optional">Description (optional)</string>
Expand Down Expand Up @@ -619,4 +618,7 @@
<string name="txt_please_login_again">Please login again!</string>
<string name="txt_failed_to_mark_notification_as_read">Failed to mark notification as read</string>
<string name="txt_failed_to_load_notifications">Failed to load notifications</string>
<string name="txt_refresh">Refresh</string>
<string name="txt_coin">Coin</string>
<string name="txt_create_study_set_ai_now">Create (-%1$s)</string>
</resources>
Loading

0 comments on commit f2fceb0

Please sign in to comment.