Merge pull request #3022 from element-hq/feature/bma/notificationSetting
Improve UX on notification setting changes
This commit is contained in:
commit
5dfd6b8193
10 changed files with 88 additions and 28 deletions
|
|
@ -125,6 +125,24 @@ suspend inline fun <T> MutableState<AsyncAction<T>>.runUpdatingState(
|
|||
resultBlock = resultBlock,
|
||||
)
|
||||
|
||||
/**
|
||||
* Run the given block and update the state accordingly, using only Loading and Failure states.
|
||||
* It's up to the caller to manage the Success state.
|
||||
*/
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
inline fun <T> MutableState<AsyncAction<T>>.runUpdatingStateNoSuccess(
|
||||
resultBlock: () -> Result<Unit>,
|
||||
): Result<Unit> {
|
||||
contract {
|
||||
callsInPlace(resultBlock, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
value = AsyncAction.Loading
|
||||
return resultBlock()
|
||||
.onFailure { failure ->
|
||||
value = AsyncAction.Failure(failure)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the specified [Result]-returning function [resultBlock]
|
||||
* encapsulating its progress and return value into an [AsyncAction] while
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) 2024 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.core.coroutine
|
||||
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlin.system.measureTimeMillis
|
||||
|
||||
fun suspendWithMinimumDuration(
|
||||
minimumDurationMillis: Long = 500,
|
||||
block: suspend () -> Unit
|
||||
) = suspend {
|
||||
val duration = measureTimeMillis {
|
||||
block()
|
||||
}
|
||||
delay(minimumDurationMillis - duration)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue