various fixes

This commit is contained in:
Phillip Thelen 2024-05-16 17:24:49 +02:00
parent 01a156c4b0
commit 5ad7ea11fd
13 changed files with 101 additions and 85 deletions

View file

@ -20,13 +20,8 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.DrawerState
import androidx.compose.material3.DrawerValue
import androidx.compose.material3.Scaffold
import androidx.compose.material3.ScaffoldState
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.material3.rememberScaffoldState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.mutableStateOf
@ -97,8 +92,6 @@ class BirthdayActivity : BaseActivity() {
@Inject
lateinit var configManager: AppConfigManager
val scaffoldState: ScaffoldState =
ScaffoldState(DrawerState(DrawerValue.Closed), SnackbarHostState())
private val isPurchasing = mutableStateOf(false)
private val price = mutableStateOf("")
private val hasGryphatrice = mutableStateOf(false)
@ -113,7 +106,6 @@ class BirthdayActivity : BaseActivity() {
setContent {
HabiticaTheme {
BirthdayActivityView(
scaffoldState,
isPurchasing.value,
hasGryphatrice.value,
hasEquipped.value,
@ -236,7 +228,6 @@ fun BirthdayTitle(text: String) {
@Composable
fun BirthdayActivityView(
scaffoldState: ScaffoldState,
isPurchasing: Boolean,
hasGryphatrice: Boolean,
hasEquipped: Boolean,
@ -264,7 +255,6 @@ fun BirthdayActivityView(
}
Scaffold(
scaffoldState = scaffoldState,
) { padding ->
Column(
horizontalAlignment = Alignment.CenterHorizontally,
@ -289,7 +279,7 @@ fun BirthdayActivityView(
MainNavigationController.navigateBack()
},
colors = ButtonDefaults.textButtonColors(contentColor = textColor),
elevation = ButtonDefaults.elevation(0.dp, 0.dp),
elevation = ButtonDefaults.buttonElevation(0.dp, 0.dp),
modifier = Modifier.align(Alignment.Start),
) {
Image(
@ -637,7 +627,6 @@ fun FourFreeItem(
@Preview(device = Devices.PIXEL_4, uiMode = UI_MODE_NIGHT_YES)
@Composable
private fun Preview() {
val scaffoldState = rememberScaffoldState()
BirthdayActivityView(scaffoldState, true, false, false, "", Date(), Date(), {
BirthdayActivityView(true, false, false, "", Date(), Date(), {
}, {}) {}
}

View file

@ -147,7 +147,7 @@ fun TaskSummaryView(viewModel: TaskSummaryViewModel) {
MainNavigationController.navigateBack()
},
colors = ButtonDefaults.textButtonColors(contentColor = darkestColor),
elevation = ButtonDefaults.elevation(0.dp, 0.dp),
elevation = ButtonDefaults.buttonElevation(0.dp, 0.dp),
) {
Image(
painterResource(R.drawable.arrow_back),

View file

@ -231,7 +231,7 @@ fun AvatarOverviewView(
) {
Text(
stringResource(R.string.avatar_size),
style = HabiticaTheme.typography.subtitle2,
style = HabiticaTheme.typography.titleMedium,
color = HabiticaTheme.colors.textSecondary,
)
Spacer(modifier = Modifier.weight(1f))
@ -263,13 +263,13 @@ fun AvatarOverviewView(
) {
Text(
stringResource(R.string.equipped),
style = HabiticaTheme.typography.subtitle2,
style = HabiticaTheme.typography.titleSmall,
color = HabiticaTheme.colors.textSecondary,
)
Spacer(modifier = Modifier.weight(1f))
Text(
stringResource(R.string.equip_automatically),
style = HabiticaTheme.typography.body2,
style = HabiticaTheme.typography.bodyMedium,
color = HabiticaTheme.colors.textPrimary,
)
Switch(checked = user?.preferences?.autoEquip == true, onCheckedChange = {
@ -287,13 +287,13 @@ fun AvatarOverviewView(
) {
Text(
stringResource(R.string.costume),
style = HabiticaTheme.typography.subtitle2,
style = HabiticaTheme.typography.titleSmall,
color = HabiticaTheme.colors.textSecondary,
)
Spacer(modifier = Modifier.weight(1f))
Text(
stringResource(R.string.wear_costume),
style = HabiticaTheme.typography.body2,
style = HabiticaTheme.typography.bodyMedium,
color = HabiticaTheme.colors.textPrimary,
)
Switch(checked = user?.preferences?.costume == true, onCheckedChange = {

View file

@ -174,6 +174,8 @@ class ComposeAvatarCustomizationFragment :
lifecycleScope.launchCatching {
if (customization.identifier?.isNotBlank() != true) {
userRepository.useCustomization(type ?: "", category, activeCustomization ?: "")
} else if (customization.identifier == activeCustomization && customization.type == "hair" && customization.category != "color") {
userRepository.useCustomization(type ?: "", category, "0")
} else if (customization.type == "background" && ownedCustomizations.value.firstOrNull { it.key == customization.identifier } == null) {
userRepository.unlockPath(customization)
userRepository.retrieveUser(false, true, true)
@ -292,6 +294,15 @@ class ComposeAvatarCustomizationFragment :
displayedCustomizations.add(customization)
}
}
if (type == "background") {
displayedCustomizations = displayedCustomizations.sortedBy {
when (it.customizationSet) {
"incentiveBackgrounds" -> 2
"timeTravelersBackground" -> 1
else -> 0
}
}
}
if (!filter.ascending) {
displayedCustomizations.reversed()
} else {
@ -538,7 +549,7 @@ private fun AvatarCustomizationView(
},
) {
Image(
painterResource(if (type == "backgrounds") R.drawable.customization_background else R.drawable.customization_mix),
painterResource(if (type == "background") R.drawable.customization_background else R.drawable.customization_mix),
null,
modifier = Modifier.padding(bottom = 16.dp),
)

View file

@ -123,8 +123,10 @@ class ComposeAvatarEquipmentFragment :
val avatar by userViewModel.user.observeAsState()
AvatarEquipmentView(avatar = avatar, configManager = configManager, viewModel.items, viewModel.type, stringResource(viewModel.typeNameId), activeEquipment) { equipment ->
lifecycleScope.launchCatching {
if (equipment.key?.isNotBlank() != true) {
inventoryRepository.equip(viewModel.type ?: "", activeEquipment ?: "")
if (equipment.key?.isNotBlank() != true && equipment.key != activeEquipment) {
inventoryRepository.equip(
if (userViewModel.user.value?.preferences?.costume == true) "costume" else "equipped",
activeEquipment ?: "")
} else {
inventoryRepository.equip(
equipment.type ?: "",
@ -247,7 +249,7 @@ private fun AvatarEquipmentView(
)
}
if (items.size > 1) {
items(items, span = { item -> if (item is Customization) GridItemSpan(1) else GridItemSpan(3) }) { item ->
items(items, span = { item -> if (item is Equipment) GridItemSpan(1) else GridItemSpan(3) }) { item ->
if (item is Equipment) {
Box(
contentAlignment = Alignment.Center,

View file

@ -25,6 +25,7 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
@ -143,7 +144,7 @@ class PartyInviteFragment : BaseFragment<FragmentComposeBinding>() {
}
}
@OptIn(ExperimentalFoundationApi::class)
@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class)
@Composable
fun PartyInviteView(
viewModel: PartyInviteViewModel,
@ -209,7 +210,7 @@ fun PartyInviteView(
}
},
colors = ButtonDefaults.textButtonColors(),
elevation = ButtonDefaults.elevation(0.dp),
elevation = ButtonDefaults.buttonElevation(0.dp),
contentPadding = PaddingValues(0.dp),
modifier =
Modifier
@ -239,11 +240,12 @@ fun PartyInviteView(
textStyle = TextStyle(fontSize = 16.sp),
placeholder = { Text(stringResource(R.string.username_or_email)) },
colors =
TextFieldDefaults.textFieldColors(
backgroundColor = Color.Transparent,
TextFieldDefaults.colors(
unfocusedContainerColor = Color.Transparent,
focusedContainerColor = Color.Transparent,
unfocusedIndicatorColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent,
textColor = HabiticaTheme.colors.textPrimary,
focusedTextColor = HabiticaTheme.colors.textPrimary,
),
modifier =
Modifier

View file

@ -21,11 +21,12 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ExperimentalMaterialApi
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Text
import androidx.compose.material3.pullrefresh.pullRefresh
import androidx.compose.material3.pullrefresh.rememberPullRefreshState
import androidx.compose.material3.pulltorefresh.PullToRefreshContainer
import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateMapOf
import androidx.compose.runtime.mutableStateOf
@ -33,6 +34,7 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
@ -176,7 +178,7 @@ fun InviteButton(
type = LoadingButtonType.DESTRUCTIVE,
colors =
ButtonDefaults.buttonColors(
backgroundColor = HabiticaTheme.colors.errorBackground,
containerColor = HabiticaTheme.colors.errorBackground,
contentColor = Color.White,
),
modifier = modifier,
@ -201,7 +203,7 @@ fun InviteButton(
}
}
@OptIn(ExperimentalMaterialApi::class, ExperimentalFoundationApi::class)
@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class)
@Composable
fun PartySeekingView(
viewModel: PartySeekingViewModel,
@ -209,23 +211,33 @@ fun PartySeekingView(
) {
val pageData = viewModel.seekingUsers.collectAsLazyPagingItems()
val refreshing by viewModel.isRefreshing
val pullRefreshState = rememberPullRefreshState(refreshing, { pageData.refresh() })
val pullRefreshState = rememberPullToRefreshState()
if (pullRefreshState.isRefreshing) {
LaunchedEffect(true) {
pageData.refresh()
}
}
if (!refreshing) {
LaunchedEffect(true) {
pullRefreshState.endRefresh()
}
}
val scope = rememberCoroutineScope()
Box(
modifier =
modifier
.fillMaxSize()
.pullRefresh(pullRefreshState),
modifier
.fillMaxSize()
.nestedScroll(pullRefreshState.nestedScrollConnection)
) {
LazyColumn {
item {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier =
Modifier
.fillMaxWidth()
.padding(top = 36.dp, bottom = 14.dp),
Modifier
.fillMaxWidth()
.padding(top = 36.dp, bottom = 14.dp),
) {
Text(
stringResource(R.string.find_more_members),
@ -241,9 +253,9 @@ fun PartySeekingView(
style = TextStyle(fontSize = 16.sp, fontWeight = FontWeight.Normal),
color = HabiticaTheme.colors.textSecondary,
modifier =
Modifier
.width(320.dp)
.align(alignment = Alignment.CenterHorizontally),
Modifier
.width(320.dp)
.align(alignment = Alignment.CenterHorizontally),
)
Image(
painterResource(R.drawable.looking_for_party_empty),
@ -257,9 +269,9 @@ fun PartySeekingView(
style = TextStyle(fontSize = 16.sp, fontWeight = FontWeight.Normal),
color = HabiticaTheme.colors.textSecondary,
modifier =
Modifier
.width(320.dp)
.align(alignment = Alignment.CenterHorizontally),
Modifier
.width(320.dp)
.align(alignment = Alignment.CenterHorizontally),
)
}
}
@ -276,9 +288,9 @@ fun PartySeekingView(
isInvited = viewModel.inviteStates[item.id]?.first ?: false,
configManager = viewModel.configManager,
modifier =
Modifier
.animateItemPlacement()
.padding(horizontal = 14.dp),
Modifier
.animateItemPlacement()
.padding(horizontal = 14.dp),
) { member ->
scope.launchCatching({
viewModel.inviteStates[member.id] = Pair(false, LoadingButtonState.FAILED)
@ -337,9 +349,9 @@ fun PartySeekingView(
item {
Box(
modifier =
Modifier
.fillMaxWidth()
.padding(12.dp),
Modifier
.fillMaxWidth()
.padding(12.dp),
contentAlignment = Alignment.Center,
) {
HabiticaCircularProgressView(indicatorSize = 32.dp)
@ -350,12 +362,17 @@ fun PartySeekingView(
else -> {}
}
}
HabiticaPullRefreshIndicator(
pageData.itemCount == 0,
refreshing,
pullRefreshState,
Modifier.align(Alignment.TopCenter),
)
PullToRefreshContainer(modifier = Modifier.align(Alignment.TopCenter),
state = pullRefreshState,
indicator = {
HabiticaPullRefreshIndicator(
pageData.itemCount == 0,
refreshing,
it,
Modifier.align(Alignment.TopCenter),
)
})
}
}

View file

@ -107,12 +107,12 @@ fun LabeledBar(
}
Column(modifier = Modifier.padding(start = animatedPadding.value)) {
LinearProgressIndicator(
progress = (animatedValue / cleanedMaxValue).toFloat(),
Modifier
progress = { (animatedValue / cleanedMaxValue).toFloat() },
modifier = Modifier
.fillMaxWidth()
.clip(CircleShape)
.height(barHeight),
backgroundColor = barColor,
trackColor = barColor,
color = color,
)
AnimatedVisibility(visible = !displayCompact) {

View file

@ -10,13 +10,11 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.ExperimentalMaterialApi
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.pullrefresh.PullRefreshState
import androidx.compose.material3.pullrefresh.pullRefresh
import androidx.compose.material3.pullrefresh.pullRefreshIndicatorTransform
import androidx.compose.material3.pullrefresh.rememberPullRefreshState
import androidx.compose.material3.pulltorefresh.PullToRefreshState
import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@ -26,16 +24,15 @@ import androidx.compose.ui.unit.dp
import com.habitrpg.android.habitica.ui.theme.colors
import com.habitrpg.common.habitica.theme.HabiticaTheme
import com.habitrpg.common.habitica.views.HabiticaCircularProgressView
import java.lang.Float.min
@OptIn(ExperimentalMaterialApi::class)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun HabiticaPullRefreshIndicator(
isInitial: Boolean,
isRefreshing: Boolean,
state: PullRefreshState,
state: PullToRefreshState,
modifier: Modifier = Modifier,
backgroundColor: Color = MaterialTheme.colors.surface,
backgroundColor: Color = MaterialTheme.colorScheme.surface,
scale: Boolean = true,
) {
AnimatedVisibility(
@ -50,11 +47,9 @@ fun HabiticaPullRefreshIndicator(
if (!isInitial) {
Surface(
modifier =
modifier
.pullRefreshIndicatorTransform(state, scale),
modifier,
shape = CircleShape,
color = backgroundColor,
elevation = if (isRefreshing) 6.dp else (min(1f, state.progress * 2) * 6f).dp,
) {
AnimatedVisibility(
visible = isRefreshing || state.progress > 0f,
@ -70,19 +65,19 @@ fun HabiticaPullRefreshIndicator(
Modifier
.border(1.dp, HabiticaTheme.colors.windowBackground, CircleShape)
.padding(4.dp)
.background(MaterialTheme.colors.surface, CircleShape),
.background(MaterialTheme.colorScheme.surface, CircleShape),
)
}
}
}
}
@OptIn(ExperimentalMaterialApi::class)
@OptIn(ExperimentalMaterial3Api::class)
@Preview
@Composable
private fun Preview() {
val state = rememberPullRefreshState(refreshing = true, onRefresh = { })
Box(Modifier.pullRefresh(state)) {
val state = rememberPullToRefreshState()
Box(Modifier) {
LazyColumn {
}
HabiticaPullRefreshIndicator(isInitial = false, isRefreshing = true, state = state)

View file

@ -420,8 +420,10 @@ class PurchaseDialog(
observable = { inventoryRepository.purchaseQuest(shopItem.key) }
} else if (shopItem.purchaseType == "debuffPotion") {
observable = { userRepository.useSkill(shopItem.key, null) }
} else if (shopItem.purchaseType == "customization" || shopItem.purchaseType == "background" || shopItem.purchaseType == "backgrounds" || shopItem.purchaseType == "customizationSet") {
} else if (shopItem.purchaseType == "background" || shopItem.purchaseType == "backgrounds") {
observable = { userRepository.unlockPath(item.unlockPath ?: "${item.pinType}.${item.key}", item.value) }
} else if (shopItem.purchaseType == "customization" || shopItem.purchaseType == "customizationSet") {
observable = { userRepository.unlockPath(item.path ?: item.unlockPath ?: "${item.pinType}.${item.key}", item.value) }
} else if (shopItem.purchaseType == "debuffPotion") {
observable = { userRepository.useSkill(shopItem.key, null) }
} else if (shopItem.purchaseType == "card") {
@ -473,9 +475,7 @@ class PurchaseDialog(
)
inventoryRepository.retrieveInAppRewards()
userRepository.retrieveUser(forced = true)
if (item.isTypeGear || item.currency == "hourglasses" || item.key == "gem") {
onShopNeedsRefresh?.invoke(item)
}
onShopNeedsRefresh?.invoke(item)
}
}

View file

@ -135,7 +135,7 @@ private fun IsAssignedIndicator(
label = "isAssigned",
transitionSpec = { tween(450, easing = FastOutLinearInEasing) },
) {
if (it) MaterialTheme.colors.primary else colorResource(id = R.color.transparent)
if (it) MaterialTheme.colorScheme.primary else colorResource(id = R.color.transparent)
}
val color =
transition.animateColor(
@ -149,7 +149,7 @@ private fun IsAssignedIndicator(
label = "isAssigned",
transitionSpec = { tween(450, easing = FastOutLinearInEasing) },
) {
if (it) MaterialTheme.colors.primary else colorResource(id = R.color.text_dimmed)
if (it) MaterialTheme.colorScheme.primary else colorResource(id = R.color.text_dimmed)
}
Image(
painterResource(R.drawable.ic_close_white_24dp),

View file

@ -148,7 +148,7 @@ private fun Preview() {
val selectedDown = remember { mutableStateOf(false) }
Box(
Modifier
.background(MaterialTheme.colors.background)
.background(MaterialTheme.colorScheme.background)
.width(300.dp)
.padding(8.dp),
) {

View file

@ -15,7 +15,7 @@ buildscript {
appcompat_version = '1.6.1'
coil_version = '2.4.0'
compose_version = '1.6.7'
compose_compiler = '1.5.12'
compose_compiler = '1.5.14'
core_ktx_version = '1.13.1'
coroutines_version = '1.7.3'
daggerhilt_version = '2.51.1'