mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-17 03:09:00 +00:00
Invite fllow improvements
This commit is contained in:
parent
7b1311b9a5
commit
ba8bcfd86e
4 changed files with 42 additions and 18 deletions
|
|
@ -1388,6 +1388,7 @@
|
|||
<string name="rescinded">Rescinded</string>
|
||||
<string name="pending_invite">Pending Invite</string>
|
||||
<string name="invalid_input">Input invalid</string>
|
||||
<string name="username_requirements">Can only contain letters a-z, numbers, hyphens, or underscores</string>
|
||||
|
||||
<plurals name="you_x_others">
|
||||
<item quantity="zero">You</item>
|
||||
|
|
|
|||
|
|
@ -426,7 +426,10 @@ class AccountPreferenceFragment :
|
|||
it?.contains(" ") == false && it.length > 1 && it.length < 20 && !it.contains(regex)
|
||||
}) {
|
||||
lifecycleScope.launchCatching {
|
||||
userRepository.updateLoginName(it ?: "")
|
||||
val user = userRepository.updateLoginName(it ?: "")
|
||||
if (user == null) {
|
||||
userRepository.retrieveUser(false, forced = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -442,7 +445,7 @@ class AccountPreferenceFragment :
|
|||
val editText = view?.findViewById<ValidatingEditText>(R.id.edit_text)
|
||||
editText?.text = value
|
||||
editText?.validator = validator
|
||||
editText?.errorText = getString(R.string.invalid_input)
|
||||
editText?.errorText = getString(R.string.username_requirements)
|
||||
view?.findViewById<TextInputLayout>(R.id.input_layout)?.hint = title
|
||||
context?.let { context ->
|
||||
val dialog = HabiticaAlertDialog(context)
|
||||
|
|
|
|||
|
|
@ -246,6 +246,10 @@ fun PartyInviteView(
|
|||
inviteButtonState = LoadingButtonState.LOADING
|
||||
scope.launchCatching({
|
||||
inviteButtonState = LoadingButtonState.FAILED
|
||||
scope.launchCatching {
|
||||
delay(2.toDuration(DurationUnit.SECONDS))
|
||||
inviteButtonState = LoadingButtonState.CONTENT
|
||||
}
|
||||
}) {
|
||||
val responses = viewModel.sendInvites()
|
||||
if (responses?.isNotEmpty() == true) {
|
||||
|
|
@ -254,6 +258,8 @@ fun PartyInviteView(
|
|||
dismiss()
|
||||
} else {
|
||||
inviteButtonState = LoadingButtonState.FAILED
|
||||
delay(2.toDuration(DurationUnit.SECONDS))
|
||||
inviteButtonState = LoadingButtonState.CONTENT
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -4,6 +4,12 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.compose.animation.AnimatedContent
|
||||
import androidx.compose.animation.ExperimentalAnimationApi
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.with
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
|
|
@ -131,6 +137,7 @@ class PartySeekingFragment : BaseFragment<FragmentComposeBinding>() {
|
|||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalAnimationApi::class)
|
||||
@Composable
|
||||
fun InviteButton(
|
||||
state : LoadingButtonState,
|
||||
|
|
@ -138,24 +145,31 @@ fun InviteButton(
|
|||
modifier : Modifier = Modifier,
|
||||
isAlreadyInvited: Boolean = false,
|
||||
) {
|
||||
LoadingButton(state = state, onClick = onClick,
|
||||
type = if (isAlreadyInvited) LoadingButtonType.DESTRUCTIVE else LoadingButtonType.NORMAL,
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = if (isAlreadyInvited) HabiticaTheme.colors.errorBackground else HabiticaTheme.colors.tintedUiSub,
|
||||
contentColor = Color.White,
|
||||
), modifier = modifier, successContent = {
|
||||
if (isAlreadyInvited) {
|
||||
Text(stringResource(R.string.rescinded))
|
||||
AnimatedContent(
|
||||
transitionSpec = { fadeIn(animationSpec = tween(220, delayMillis = 90)) with
|
||||
fadeOut(animationSpec = tween(90)) },
|
||||
targetState = isAlreadyInvited) {isInvited ->
|
||||
if (isInvited) {
|
||||
LoadingButton(state = state, onClick = onClick,
|
||||
type = LoadingButtonType.DESTRUCTIVE,
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = HabiticaTheme.colors.errorBackground,
|
||||
contentColor = Color.White,
|
||||
), modifier = modifier, successContent = {
|
||||
Text(stringResource(R.string.rescinded))
|
||||
}) {
|
||||
Text(stringResource(R.string.rescind_invite))
|
||||
}
|
||||
} else {
|
||||
Text(stringResource(R.string.invited))
|
||||
}
|
||||
}) {
|
||||
if (isAlreadyInvited) {
|
||||
Text(stringResource(R.string.rescind_invite))
|
||||
} else {
|
||||
Text(stringResource(R.string.send_invite))
|
||||
LoadingButton(state = state, onClick = onClick,
|
||||
modifier = modifier, successContent = {
|
||||
Text(stringResource(R.string.invited))
|
||||
}) {
|
||||
Text(stringResource(R.string.send_invite))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterialApi::class, ExperimentalFoundationApi::class)
|
||||
|
|
@ -233,7 +247,7 @@ fun PartySeekingView(
|
|||
val response: Any? = if (isInvited) viewModel.rescindInvite(member) else viewModel.inviteUser(member)
|
||||
if (response != null) {
|
||||
viewModel.inviteStates[member.id] = Pair(isInvited, LoadingButtonState.SUCCESS)
|
||||
delay(4.toDuration(DurationUnit.SECONDS))
|
||||
delay(2500.toDuration(DurationUnit.MILLISECONDS))
|
||||
viewModel.inviteStates[member.id] = Pair(!isInvited, LoadingButtonState.CONTENT)
|
||||
} else {
|
||||
viewModel.inviteStates[member.id] = Pair(isInvited, LoadingButtonState.FAILED)
|
||||
|
|
|
|||
Loading…
Reference in a new issue