Merge pull request #1436 from vector-im/feature/bma/mutableIntFloat

Mutable int float
This commit is contained in:
Benoit Marty 2023-09-26 18:31:36 +02:00 committed by GitHub
commit 8e24d5991c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 31 additions and 26 deletions

View file

@ -21,7 +21,7 @@ import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
@ -64,7 +64,7 @@ fun StaticMapView(
contentAlignment = Alignment.Center
) {
val context = LocalContext.current
var retryHash by remember { mutableStateOf(0) }
var retryHash by remember { mutableIntStateOf(0) }
val builder = remember { StaticMapUrlBuilder(context) }
val painter = rememberAsyncImagePainter(
model = if (constraints.isZero) {

View file

@ -18,6 +18,7 @@ package io.element.android.features.login.impl.screens.waitlistscreen
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
@ -58,14 +59,14 @@ class WaitListPresenter @AssistedInject constructor(
mutableStateOf(Async.Uninitialized)
}
val attemptNumber: MutableState<Int> = remember { mutableStateOf(0) }
val attemptNumber = remember { mutableIntStateOf(0) }
fun handleEvents(event: WaitListEvents) {
when (event) {
WaitListEvents.AttemptLogin -> {
// Do not attempt to login on first resume of the View.
attemptNumber.value++
if (attemptNumber.value > 1) {
attemptNumber.intValue++
if (attemptNumber.intValue > 1) {
coroutineScope.loginAttempt(formState, loginAction)
}
}

View file

@ -21,6 +21,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
@ -59,7 +60,7 @@ class MediaViewerPresenter @AssistedInject constructor(
@Composable
override fun present(): MediaViewerState {
val coroutineScope = rememberCoroutineScope()
var loadMediaTrigger by remember { mutableStateOf(0) }
var loadMediaTrigger by remember { mutableIntStateOf(0) }
val mediaFile: MutableState<MediaFile?> = remember {
mutableStateOf(null)
}

View file

@ -147,7 +147,7 @@ fun TimelineItemEventRow(
}
if (canReply) {
val state: SwipeableActionsState = rememberSwipeableActionsState()
val offset = state.offset.value
val offset = state.offset.floatValue
val swipeThresholdPx = 40.dp.toPx()
val thresholdCrossed = abs(offset) > swipeThresholdPx
SwipeSensitivity(3f) {

View file

@ -17,9 +17,11 @@
package io.element.android.features.rageshake.impl.bugreport
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableFloatState
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
@ -43,27 +45,27 @@ class BugReportPresenter @Inject constructor(
) : Presenter<BugReportState> {
private class BugReporterUploadListener(
private val sendingProgress: MutableState<Float>,
private val sendingProgress: MutableFloatState,
private val sendingAction: MutableState<Async<Unit>>
) : BugReporterListener {
override fun onUploadCancelled() {
sendingProgress.value = 0f
sendingProgress.floatValue = 0f
sendingAction.value = Async.Uninitialized
}
override fun onUploadFailed(reason: String?) {
sendingProgress.value = 0f
sendingProgress.floatValue = 0f
sendingAction.value = Async.Failure(Exception(reason))
}
override fun onProgress(progress: Int) {
sendingProgress.value = progress.toFloat() / 100
sendingProgress.floatValue = progress.toFloat() / 100
sendingAction.value = Async.Loading()
}
override fun onUploadSucceed(reportUrl: String?) {
sendingProgress.value = 0f
sendingProgress.floatValue = 0f
sendingAction.value = Async.Success(Unit)
}
}
@ -80,7 +82,7 @@ class BugReportPresenter @Inject constructor(
.collectAsState(initial = "")
val sendingProgress = remember {
mutableStateOf(0f)
mutableFloatStateOf(0f)
}
val sendingAction: MutableState<Async<Unit>> = remember {
mutableStateOf(Async.Uninitialized)
@ -107,7 +109,7 @@ class BugReportPresenter @Inject constructor(
copy(sendScreenshot = event.sendScreenshot)
}
BugReportEvents.ClearError -> {
sendingProgress.value = 0f
sendingProgress.floatValue = 0f
sendingAction.value = Async.Uninitialized
}
}
@ -115,7 +117,7 @@ class BugReportPresenter @Inject constructor(
return BugReportState(
hasCrashLogs = crashInfo.isNotEmpty(),
sendingProgress = sendingProgress.value,
sendingProgress = sendingProgress.floatValue,
sending = sendingAction.value,
formState = formState.value,
screenshotUri = screenshotUri.value,