From 6656f304a29e98347c3c67ead46704107c6158fa Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Mon, 6 May 2024 11:06:53 +0200 Subject: [PATCH] Customization fixes --- Habitica/res/layout/shop_section_header.xml | 2 +- .../res/values-en-rGB/strings.sidebar.xml | 2 +- Habitica/res/values/strings.sidebar.xml | 2 +- Habitica/res/values/strings.xml | 1 + Habitica/res/values/styles.habitica.xml | 2 +- .../models/inventory/Customization.kt | 3 +- .../ui/fragments/NavigationDrawerFragment.kt | 8 -- .../ComposeAvatarCustomizationFragment.kt | 83 ++++++++++++------- .../habitica/ui/theme/HabiticaTheme.kt | 4 +- .../views/equipment/EquipmentOverviewView.kt | 10 +-- version.properties | 2 +- 11 files changed, 69 insertions(+), 50 deletions(-) diff --git a/Habitica/res/layout/shop_section_header.xml b/Habitica/res/layout/shop_section_header.xml index 1dd5c3fcc..0283570cc 100644 --- a/Habitica/res/layout/shop_section_header.xml +++ b/Habitica/res/layout/shop_section_header.xml @@ -28,7 +28,7 @@ android:id="@+id/switches_in_label" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:textColor="?tintedUiDetails" + android:textColor="?textColorTintedSecondary" android:gravity="center_vertical" android:layout_gravity="center_vertical" style="@style/Caption2" diff --git a/Habitica/res/values-en-rGB/strings.sidebar.xml b/Habitica/res/values-en-rGB/strings.sidebar.xml index 34335f9fd..8af9d6c74 100644 --- a/Habitica/res/values-en-rGB/strings.sidebar.xml +++ b/Habitica/res/values-en-rGB/strings.sidebar.xml @@ -6,7 +6,7 @@ Party Challenges Inventory - Avatar Customisation + Customize Avatar Equipment Pets & Mounts News diff --git a/Habitica/res/values/strings.sidebar.xml b/Habitica/res/values/strings.sidebar.xml index 39caaa647..1fa24fdfc 100644 --- a/Habitica/res/values/strings.sidebar.xml +++ b/Habitica/res/values/strings.sidebar.xml @@ -9,7 +9,7 @@ Subscription Challenges Inventory - Avatar Customization + Customize Avatar Avatar & Equipment Equipment Pets & Mounts diff --git a/Habitica/res/values/strings.xml b/Habitica/res/values/strings.xml index 452b7cdef..f5815e615 100644 --- a/Habitica/res/values/strings.xml +++ b/Habitica/res/values/strings.xml @@ -1509,6 +1509,7 @@ Head over to the Customization Shop to browse the many ways you can customize your avatar! Switches in %s Refresh for new items + Monthly Backgrounds You diff --git a/Habitica/res/values/styles.habitica.xml b/Habitica/res/values/styles.habitica.xml index 1a211fa9b..24ccb9622 100644 --- a/Habitica/res/values/styles.habitica.xml +++ b/Habitica/res/values/styles.habitica.xml @@ -104,7 +104,7 @@ diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Customization.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Customization.kt index 6bf69358b..3d4191ffc 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Customization.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/inventory/Customization.kt @@ -54,7 +54,8 @@ open class Customization : RealmObject(), BaseObject { if (this.type == "hair" && this.category == "color") { return "icon_color_hair_bangs_1_$identifier" } - return "icon_" + (getImageName(userSize, hairColor) ?: return null) + val name = (getImageName(userSize, hairColor) ?: return null) + return if (!name.startsWith("icon_")) "icon_$name" else name } fun getImageName( diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/NavigationDrawerFragment.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/NavigationDrawerFragment.kt index 0ccf882e5..04c9117da 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/NavigationDrawerFragment.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/NavigationDrawerFragment.kt @@ -258,13 +258,6 @@ class NavigationDrawerFragment : DialogFragment() { val shop = getItemWithIdentifier(SIDEBAR_SHOPS_SEASONAL) ?: return shop.pillText = context?.getString(R.string.open) - if (gearEvent?.isCurrentlyActive == true) { - shop.isVisible = true - shop.subtitle = - context?.getString(R.string.open_for, gearEvent.end?.getShortRemainingString()) - } else { - shop.isVisible = false - } adapter.updateItem(shop) } @@ -440,7 +433,6 @@ class NavigationDrawerFragment : DialogFragment() { SIDEBAR_SHOPS_SEASONAL, context.getString(R.string.seasonalShop), ) - seasonalShopEntry.isVisible = false items.add(seasonalShopEntry) items.add( HabiticaDrawerItem( diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/inventory/customization/ComposeAvatarCustomizationFragment.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/inventory/customization/ComposeAvatarCustomizationFragment.kt index ea3eb0a03..3bea14586 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/inventory/customization/ComposeAvatarCustomizationFragment.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/inventory/customization/ComposeAvatarCustomizationFragment.kt @@ -90,7 +90,7 @@ class CustomizationViewModel : ViewModel() { var type: String? = null var category: String? = null - val customizations = mutableStateListOf() + val items = mutableStateListOf() val activeCustomization = mutableStateOf(null) val userSize = mutableStateOf("slim") @@ -170,7 +170,7 @@ class ComposeAvatarCustomizationFragment : val hairColor by viewModel.hairColor val activeCustomization by viewModel.activeCustomization val avatar by userViewModel.user.observeAsState() - AvatarCustomizationView(avatar = avatar, configManager = configManager, viewModel.customizations, userSize, hairColor, type, stringResource(viewModel.typeNameId), activeCustomization) { customization -> + AvatarCustomizationView(avatar = avatar, configManager = configManager, viewModel.items, userSize, hairColor, type, stringResource(viewModel.typeNameId), activeCustomization) { customization -> lifecycleScope.launchCatching { if (customization.identifier?.isNotBlank() != true) { userRepository.useCustomization(type ?: "", category, activeCustomization ?: "") @@ -281,12 +281,12 @@ class ComposeAvatarCustomizationFragment : .combine(currentFilter) { customizations, filter -> Pair(customizations, filter) } .combine(ownedCustomizations) { pair, ownedCustomizations -> val ownedKeys = ownedCustomizations.map { it.key } - return@combine Pair(pair.first.filter { ownedKeys.contains(it.identifier) || ((it.price ?: 0) == 0 && type != "background") }, pair.second) + return@combine Pair(pair.first.filter { ownedKeys.contains(it.identifier) || ((it.price ?: 0) == 0 && (type != "background" || it.identifier.isNullOrEmpty())) }, pair.second) } .map { (customizations, filter) -> var displayedCustomizations = customizations if (filter.isFiltering) { - displayedCustomizations = mutableListOf() + displayedCustomizations = mutableListOf() for (customization in customizations) { if (shouldSkip(filter, customization)) continue displayedCustomizations.add(customization) @@ -299,8 +299,20 @@ class ComposeAvatarCustomizationFragment : } } .collect { customizations -> - viewModel.customizations.clear() - viewModel.customizations.addAll(customizations) + viewModel.items.clear() + if (type == "background") { + var lastSection = "" + customizations.forEach { background -> + val section = if (background.customizationSet?.startsWith("20") == true) requireContext().getString(R.string.monthly_backgrounds) else background.customizationSetName ?: "" + if (section != lastSection && background.customizationSet != "incentiveBackgrounds") { + viewModel.items.add(section) + lastSection = section + } + viewModel.items.add(background) + } + } else { + viewModel.items.addAll(customizations) + } } } } @@ -433,7 +445,7 @@ class ComposeAvatarCustomizationFragment : private fun AvatarCustomizationView( avatar: Avatar?, configManager: AppConfigManager, - customizations: List, + items: List, userSize: String, hairColor: String?, type: String?, @@ -480,29 +492,40 @@ private fun AvatarCustomizationView( modifier = Modifier.padding(10.dp), ) } - if (customizations.size > 1) { - items(customizations) { customization -> - Box( - contentAlignment = Alignment.Center, - modifier = + if (items.size > 1) { + items(items, span = { item -> if (item is Customization) GridItemSpan(1) else GridItemSpan(3) }) { item -> + if (item is Customization) { + Box( + contentAlignment = Alignment.Center, + modifier = Modifier .padding(4.dp) - .border(if (activeCustomization == customization.identifier) 2.dp else 0.dp, if (activeCustomization == customization.identifier) HabiticaTheme.colors.tintedUiMain else colorResource(R.color.transparent), RoundedCornerShape(8.dp)) + .border(if (activeCustomization == item.identifier) 2.dp else 0.dp, if (activeCustomization == item.identifier) HabiticaTheme.colors.tintedUiMain else colorResource(R.color.transparent), RoundedCornerShape(8.dp)) .size(76.dp) .clip(RoundedCornerShape(8.dp)) .clickable { - onSelect(customization) + onSelect(item) } .background(colorResource(id = R.color.window_background)), - ) { - if (customization.identifier.isNullOrBlank() || customization.identifier == "0") { - Image(painterResource(R.drawable.empty_slot), contentDescription = null, contentScale = ContentScale.None, modifier = Modifier.size(68.dp)) - } else { - PixelArtView( - imageName = customization.getIconName(userSize, hairColor), - Modifier.size(68.dp), - ) + ) { + if (item.identifier.isNullOrBlank() || item.identifier == "0") { + Image(painterResource(R.drawable.empty_slot), contentDescription = null, contentScale = ContentScale.None, modifier = Modifier.size(68.dp)) + } else { + PixelArtView( + imageName = item.getIconName(userSize, hairColor), + Modifier.size(68.dp), + ) + } } + } else if (item is String) { + Text( + item.uppercase(), + fontSize = 14.sp, + fontWeight = FontWeight.SemiBold, + color = colorResource(id = R.color.text_ternary), + textAlign = TextAlign.Center, + modifier = Modifier.padding(10.dp).padding(top = 16.dp), + ) } } } @@ -510,21 +533,23 @@ private fun AvatarCustomizationView( Column( horizontalAlignment = Alignment.CenterHorizontally, modifier = - Modifier.padding(top = 40.dp).clickable { + Modifier.padding(top = 56.dp).clickable { MainNavigationController.navigate(R.id.customizationsShopFragment) }, ) { Image( painterResource(if (type == "backgrounds") R.drawable.customization_background else R.drawable.customization_mix), null, - modifier = Modifier.padding(bottom = 12.dp), + modifier = Modifier.padding(bottom = 16.dp), ) - if (customizations.size <= 1) { - Text(stringResource(R.string.customizations_no_owned), fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = colorResource(R.color.text_secondary)) - Text(stringResource(R.string.customization_shop_check_out), fontSize = 13.sp, color = colorResource(R.color.text_ternary), textAlign = TextAlign.Center) + if (items.size <= 1) { + Text(stringResource(R.string.customizations_no_owned), fontSize = 16.sp, fontWeight = FontWeight.Bold, color = colorResource(R.color.text_secondary), + modifier = Modifier.padding(bottom = 2.dp)) + Text(stringResource(R.string.customization_shop_check_out), fontSize = 14.sp, color = colorResource(R.color.text_ternary), textAlign = TextAlign.Center) } else { - Text(stringResource(R.string.looking_for_more), fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = colorResource(R.color.text_secondary)) - Text(stringResource(R.string.customization_shop_more), fontSize = 13.sp, color = colorResource(R.color.text_ternary), textAlign = TextAlign.Center) + Text(stringResource(R.string.looking_for_more), fontSize = 16.sp, fontWeight = FontWeight.Bold, color = colorResource(R.color.text_secondary), + modifier = Modifier.padding(bottom = 2.dp)) + Text(stringResource(R.string.customization_shop_more), fontSize = 14.sp, color = colorResource(R.color.text_ternary), textAlign = TextAlign.Center) } } } diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/theme/HabiticaTheme.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/theme/HabiticaTheme.kt index ba7bbf556..38dc21f9c 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/theme/HabiticaTheme.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/theme/HabiticaTheme.kt @@ -57,9 +57,9 @@ fun HabiticaColors.contentBackgroundFor(task: Task?): Color { @Composable fun HabiticaColors.pixelArtBackground(hasIcon: Boolean): Color { return if (isSystemInDarkTheme()) { - colorResource(if (hasIcon) R.color.gray_200 else R.color.gray_5) + colorResource(if (hasIcon) R.color.gray_50 else R.color.gray_5) } else { - colorResource(if (hasIcon) R.color.content_background else R.color.content_background_offset) + colorResource(if (hasIcon) R.color.window_background else R.color.content_background_offset) } } diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/equipment/EquipmentOverviewView.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/equipment/EquipmentOverviewView.kt index 8e98fb78b..5deea4bc3 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/equipment/EquipmentOverviewView.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/views/equipment/EquipmentOverviewView.kt @@ -50,11 +50,11 @@ fun OverviewItem( horizontalAlignment = Alignment.CenterHorizontally, modifier = modifier - .width(70.dp), + .width(76.dp), ) { Box( Modifier - .size(70.dp) + .size(76.dp) .clip(MaterialTheme.shapes.small) .background(HabiticaTheme.colors.pixelArtBackground(hasIcon)), contentAlignment = Alignment.Center, @@ -66,7 +66,7 @@ fun OverviewItem( imageName = iconName, modifier = Modifier - .size(70.dp), + .size(76.dp), ) } else { Image(painterResource(R.drawable.empty_slot), null) @@ -75,7 +75,7 @@ fun OverviewItem( Text( text, style = HabiticaTheme.typography.caption2, - color = colorResource(R.color.text_ternary), + color = colorResource(R.color.text_secondary), textAlign = TextAlign.Center, modifier = Modifier.padding(top = 4.dp), ) @@ -297,7 +297,7 @@ fun AvatarCustomizationOverviewView( fun EquipmentOverviewItemPreview() { Column(Modifier.width(320.dp)) { Row( - modifier = Modifier.background(colorResource(id = R.color.equipment_overview_background)), + modifier = Modifier.background(colorResource(id = R.color.equipment_column_background)), horizontalArrangement = Arrangement.spacedBy(8.dp), ) { OverviewItem("Main-Hand", "shop_weapon_warrior_1") diff --git a/version.properties b/version.properties index 6204be24b..c09e6bb9c 100644 --- a/version.properties +++ b/version.properties @@ -1,2 +1,2 @@ NAME=4.3.7 -CODE=7591 \ No newline at end of file +CODE=7601 \ No newline at end of file