Fix ktlint issues

This commit is contained in:
Benoit Marty 2024-01-10 19:33:39 +01:00
parent 140a11cf77
commit a831f05f6e
100 changed files with 66 additions and 158 deletions

View file

@ -31,7 +31,6 @@ import javax.inject.Inject
class AndroidClipboardHelper @Inject constructor(
@ApplicationContext private val context: Context,
) : ClipboardHelper {
private val clipboardManager = requireNotNull(context.getSystemService<ClipboardManager>())
override fun copyPlainText(text: String) {

View file

@ -17,7 +17,6 @@
package io.element.android.libraries.androidutils.clipboard
class FakeClipboardHelper : ClipboardHelper {
var clipboardContents: Any? = null
override fun copyPlainText(text: String) {

View file

@ -26,7 +26,6 @@ internal class DefaultDiffCallback<T>(
private val newList: List<T>,
private val areItemsTheSame: (oldItem: T?, newItem: T?) -> Boolean,
) : DiffUtil.Callback() {
override fun getOldListSize(): Int {
return oldList.size
}

View file

@ -40,7 +40,6 @@ interface MutableDiffCache<E> : DiffCache<E> {
*
*/
class MutableListDiffCache<E>(private val mutableList: MutableList<E?> = ArrayList()) : MutableDiffCache<E> {
override fun removeAt(index: Int): E? {
return mutableList.removeAt(index)
}

View file

@ -36,7 +36,6 @@ interface DiffCacheInvalidator<T> {
* It invalidates the cache by setting values to null.
*/
class DefaultDiffCacheInvalidator<T> : DiffCacheInvalidator<T> {
override fun onChanged(position: Int, count: Int, cache: MutableDiffCache<T>) {
for (i in position until position + count) {
// Invalidate cache

View file

@ -36,7 +36,6 @@ class DiffCacheUpdater<ListItem, CachedItem>(
private val cacheInvalidator: DiffCacheInvalidator<CachedItem> = DefaultDiffCacheInvalidator(),
private val areItemsTheSame: (oldItem: ListItem?, newItem: ListItem?) -> Boolean,
) {
private val lock = Object()
private var prevOriginalList: List<ListItem> = emptyList()

View file

@ -27,7 +27,6 @@ import kotlin.contracts.contract
*/
@Stable
sealed interface AsyncAction<out T> {
/**
* Represents an uninitialized operation (i.e. yet to be run by the user).
*/

View file

@ -27,7 +27,6 @@ import kotlin.contracts.contract
*/
@Stable
sealed interface AsyncData<out T> {
/**
* Represents a failed operation.
*

View file

@ -25,7 +25,6 @@ import kotlinx.coroutines.flow.map
class HideOverlayBackPressHandler<NavTarget : Any> :
BaseBackPressHandlerStrategy<NavTarget, BackStack.State>() {
override val canHandleBackPressFlow: Flow<Boolean> by lazy {
navModel.elements.map(::areThereElements)
}

View file

@ -40,7 +40,6 @@ class Overlay<NavTarget : Any>(
savedStateMap = savedStateMap,
key = key,
) {
override val initialElements: NavElements<NavTarget, BackStack.State>
get() = emptyList()
}

View file

@ -24,7 +24,6 @@ import kotlinx.parcelize.Parcelize
@Parcelize
class Hide<T : Any> : OverlayOperation<T> {
override fun isApplicable(elements: BackStackElements<T>): Boolean =
elements.any { it.targetState == BackStack.State.ACTIVE }

View file

@ -29,7 +29,6 @@ import kotlinx.parcelize.RawValue
data class Show<T : Any>(
private val element: @RawValue T
) : OverlayOperation<T> {
override fun isApplicable(elements: BackStackElements<T>): Boolean =
element != elements.activeElement

View file

@ -84,7 +84,6 @@ class AsyncDataKtTest {
private class TestableMutableState<T>(
value: T
) : MutableState<T> {
@Suppress("ktlint:standard:property-naming")
private val _deque = ArrayDeque<T>(listOf(value))

View file

@ -21,7 +21,6 @@ package io.element.android.libraries.core.cache
* This class is not thread safe.
*/
class CircularCache<T : Any>(cacheSize: Int, factory: (Int) -> Array<T?>) {
companion object {
inline fun <reified T : Any> create(cacheSize: Int) = CircularCache(cacheSize) { Array<T?>(cacheSize) { null } }
}

View file

@ -26,20 +26,6 @@ inline fun <T> T.ooi(block: (T) -> Unit): T = also(block)
*/
fun CharSequence?.orEmpty() = this ?: ""
/**
* Check if a CharSequence is a phone number.
*/
/*
fun CharSequence.isMsisdn(): Boolean {
return try {
PhoneNumberUtil.getInstance().parse(ensurePrefix("+"), null)
true
} catch (e: NumberParseException) {
false
}
}
*/
/**
* Useful to append a String at the end of a filename but before the extension if any
* Ex:

View file

@ -23,7 +23,6 @@ package io.element.android.libraries.core.log.logger
* Timber.tag(loggerTag.value).v("My log message")
*/
open class LoggerTag(name: String, parentTag: LoggerTag? = null) {
object PushLoggerTag : LoggerTag("Push")
object NotificationLoggerTag : LoggerTag("Notification", PushLoggerTag)

View file

@ -20,7 +20,6 @@ import org.junit.Assert.assertEquals
import org.junit.Test
class BasicExtensionsTest {
@Test(expected = IllegalArgumentException::class)
fun `test ellipsize at 0`() {
"1234567890".ellipsize(0)

View file

@ -20,7 +20,6 @@ import com.google.common.truth.Truth.assertThat
import org.junit.Test
class ResultTest {
@Test
fun testFlatMap() {
val initial = Result.success("initial")

View file

@ -23,7 +23,6 @@ import io.element.android.libraries.matrix.test.A_THREAD_ID
import org.junit.Test
class DeepLinkCreatorTest {
@Test
fun room() {
val sut = DeepLinkCreator()

View file

@ -25,7 +25,6 @@ data class AvatarData(
val url: String? = null,
val size: AvatarSize,
) {
val initial by lazy {
(name?.takeIf { it.isNotBlank() } ?: id)
.let { dn ->

View file

@ -29,7 +29,6 @@ import io.element.android.libraries.designsystem.theme.components.TextButton
*/
@Immutable
sealed interface ButtonVisuals {
val action: () -> Unit
/**

View file

@ -29,7 +29,8 @@ import androidx.lifecycle.Lifecycle
* Inspired from https://stackoverflow.com/questions/68847559/how-can-i-detect-keyboard-opening-and-closing-in-jetpack-compose
*/
enum class Keyboard {
Opened, Closed
Opened,
Closed
}
// Note: it does not work as expected...

View file

@ -95,7 +95,6 @@ private fun PreferenceTopAppBar(
overflow = TextOverflow.Ellipsis
)
}
)
}

View file

@ -55,7 +55,7 @@ fun PreferenceTextField(
style: ListItemStyle = ListItemStyle.Default,
) {
var displayTextFieldDialog by rememberSaveable { mutableStateOf(false) }
val valueToDisplay = if (displayValue(value)) { value } else supportingText
val valueToDisplay = if (displayValue(value)) value else supportingText
ListItem(
modifier = modifier,

View file

@ -259,11 +259,14 @@ sealed interface IconSource {
}
enum class ButtonSize {
Medium, Large
Medium,
Large
}
internal enum class ButtonStyle {
Filled, Outlined, Text;
Filled,
Outlined,
Text;
@Composable
fun getColors(destructive: Boolean): ButtonColors = when (this) {

View file

@ -38,7 +38,8 @@ import io.element.android.libraries.designsystem.preview.PreviewGroup
fun FloatingActionButton(
onClick: () -> Unit,
modifier: Modifier = Modifier,
shape: Shape = CircleShape, // FloatingActionButtonDefaults.shape,
// FloatingActionButtonDefaults.shape
shape: Shape = CircleShape,
containerColor: Color = FloatingActionButtonDefaults.containerColor,
contentColor: Color = contentColorFor(containerColor),
elevation: FloatingActionButtonElevation = FloatingActionButtonDefaults.elevation(),

View file

@ -378,7 +378,6 @@ internal fun ListItemDisabledWithIconPreview() = PreviewItems.OneLineListItemPre
@Suppress("ModifierMissing")
private object PreviewItems {
@Composable
fun ThreeLinesListItemPreview(
modifier: Modifier = Modifier,

View file

@ -81,7 +81,6 @@ fun ListSupportingText(
}
object ListSupportingTextDefaults {
/** Specifies the padding to use for the supporting text. */
@Immutable
sealed interface Padding {

View file

@ -151,7 +151,6 @@ fun <T> SearchBar(
}
object ElementSearchBarDefaults {
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun inactiveColors() = SearchBarDefaults.colors(

View file

@ -37,7 +37,7 @@ fun Slider(
modifier: Modifier = Modifier,
enabled: Boolean = true,
valueRange: ClosedFloatingPointRange<Float> = 0f..1f,
/*@IntRange(from = 0)*/
// @IntRange(from = 0)
steps: Int = 0,
onValueChangeFinished: (() -> Unit)? = null,
colors: SliderColors = SliderDefaults.colors(),

View file

@ -282,11 +282,13 @@ private fun CustomStandardBottomSheet(
if (anchoredDraggableState.anchors.size > 1 && sheetSwipeEnabled) {
if (currentValue == SheetValue.PartiallyExpanded) {
expand(expandActionLabel) {
scope.launch { expand() }; true
scope.launch { expand() }
true
}
} else {
collapse(partialExpandActionLabel) {
scope.launch { partialExpand() }; true
scope.launch { partialExpand() }
true
}
}
if (!state.skipHiddenState) {
@ -314,7 +316,6 @@ private fun CustomStandardBottomSheet(
*/
@ExperimentalFoundationApi
class DraggableAnchorsConfig<T> {
internal val anchors = mutableMapOf<T, Float>()
/**
@ -344,7 +345,6 @@ internal fun <T : Any> DraggableAnchors(
): DraggableAnchors<T> = MapDraggableAnchors(DraggableAnchorsConfig<T>().apply(builder).anchors)
private class MapDraggableAnchors<T>(private val anchors: Map<T, Float>) : DraggableAnchors<T> {
override fun positionOf(value: T): Float = anchors[value] ?: Float.NaN
override fun hasAnchorFor(value: T) = anchors.containsKey(value)

View file

@ -51,7 +51,6 @@ constructor(
confirmValueChange: (SheetValue) -> Boolean = { true },
internal val skipHiddenState: Boolean = false,
) {
/**
* State of a sheet composable, such as [ModalBottomSheet]
*

View file

@ -30,7 +30,8 @@ import io.element.android.libraries.designsystem.theme.components.Snackbar
fun SnackbarHost(hostState: SnackbarHostState, modifier: Modifier = Modifier) {
androidx.compose.material3.SnackbarHost(hostState, modifier) { data ->
Snackbar(
modifier = Modifier.padding(12.dp), // Add default padding
// Add default padding
modifier = Modifier.padding(12.dp),
message = data.visuals.message,
action = data.visuals.actionLabel?.let { ButtonVisuals.Text(it, data::performAction) },
dismissAction = if (data.visuals.withDismissAction) {

View file

@ -22,7 +22,6 @@ import io.element.android.compound.theme.avatarColorsLight
import org.junit.Test
class AvatarColorsTest {
@Test
fun `ensure the size of the avatar color are equal for light and dark theme`() {
assertThat(avatarColorsDark.size).isEqualTo(avatarColorsLight.size)

View file

@ -22,7 +22,6 @@ import kotlinx.coroutines.test.runTest
import org.junit.Test
class SnackbarDispatcherTests {
@Test
fun `given an empty queue the flow emits a null item`() = runTest {
val snackbarDispatcher = SnackbarDispatcher()

View file

@ -33,7 +33,6 @@ class RandomSecretPassphraseProvider(
private val file: File,
private val secretSize: Int = 256,
) : PassphraseProvider {
override fun getPassphrase(): ByteArray {
val encryptedFile = EncryptedFileFactory(context).create(file)
return if (!file.exists()) {

View file

@ -36,7 +36,6 @@ internal class MapApplier(
val style: Style,
val symbolManager: SymbolManager,
) : AbstractApplier<MapNode>(MapNodeRoot) {
private val decorations = mutableListOf<MapNode>()
override fun onClear() {

View file

@ -42,7 +42,6 @@ internal class MapPropertiesNode(
cameraPositionState: CameraPositionState,
locationSettings: MapLocationSettings,
) : MapNode {
init {
map.locationComponent.activateLocationComponent(
LocationComponentActivationOptions.Builder(context, style)

View file

@ -34,7 +34,7 @@ object MatrixToConverter {
*/
fun convert(uri: Uri): Uri? {
val uriString = uri.toString()
val baseUrl = MatrixConfiguration.matrixToPermalinkBaseUrl
val baseUrl = MatrixConfiguration.MATRIX_TO_PERMALINK_BASE_URL
return when {
// URL is already a matrix.to

View file

@ -26,7 +26,7 @@ object PermalinkBuilder {
private const val ROOM_PATH = "room/"
private const val USER_PATH = "user/"
private val permalinkBaseUrl get() = (MatrixConfiguration.clientPermalinkBaseUrl ?: MatrixConfiguration.matrixToPermalinkBaseUrl).also {
private val permalinkBaseUrl get() = (MatrixConfiguration.clientPermalinkBaseUrl ?: MatrixConfiguration.MATRIX_TO_PERMALINK_BASE_URL).also {
var baseUrl = it
if (!baseUrl.endsWith("/")) {
baseUrl += "/"
@ -80,7 +80,7 @@ object PermalinkBuilder {
private fun escapeId(value: String) = value.replace("/", "%2F")
private fun isMatrixTo(): Boolean = permalinkBaseUrl.startsWith(MatrixConfiguration.matrixToPermalinkBaseUrl)
private fun isMatrixTo(): Boolean = permalinkBaseUrl.startsWith(MatrixConfiguration.MATRIX_TO_PERMALINK_BASE_URL)
}
sealed class PermalinkBuilderError : Throwable() {

View file

@ -136,7 +136,13 @@ fun AttachmentThumbnail(
@Parcelize
enum class AttachmentThumbnailType : Parcelable {
Image, Video, File, Audio, Location, Voice, Poll
Image,
Video,
File,
Audio,
Location,
Voice,
Poll,
}
@Parcelize

View file

@ -41,7 +41,6 @@ internal class CoilMediaFetcher(
private val mediaData: MediaRequestData?,
private val options: Options
) : Fetcher {
override suspend fun fetch(): FetchResult? {
if (mediaData?.source == null) return null
return when (mediaData.kind) {
@ -126,9 +125,7 @@ internal class CoilMediaFetcher(
class AvatarFactory(
private val context: Context,
private val client: MatrixClient
) :
Fetcher.Factory<AvatarData> {
) : Fetcher.Factory<AvatarData> {
override fun create(
data: AvatarData,
options: Options,

View file

@ -33,7 +33,6 @@ data class MediaRequestData(
val source: MediaSource?,
val kind: Kind
) {
sealed interface Kind {
data object Content : Kind
data class File(val body: String?, val mimeType: String) : Kind

View file

@ -26,7 +26,6 @@ import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class ToHtmlDocumentTest {
@Test
fun `toHtmlDocument - returns null if format is not HTML`() {
val body = FormattedBody(

View file

@ -28,7 +28,6 @@ import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class ToPlainTextTest {
@Test
fun `Document toPlainText - returns a plain text version of the document`() {
val document = Jsoup.parse(

View file

@ -25,7 +25,6 @@ import timber.log.Timber
internal class FormattedJsonHttpLogger(
private val level: HttpLoggingInterceptor.Level
) : HttpLoggingInterceptor.Logger {
companion object {
private const val INDENT_SPACE = 2
}

View file

@ -50,7 +50,7 @@ class PushersManager @Inject constructor(
pushGatewayNotifyRequest.execute(
PushGatewayNotifyRequest.Params(
url = "TODO", // unifiedPushHelper.getPushGateway() ?: return,
appId = PushConfig.pusher_app_id,
appId = PushConfig.PUSHER_APP_ID,
pushKey = "TODO", // unifiedPushHelper.getEndpointOrToken().orEmpty(),
eventId = TEST_EVENT_ID
)
@ -85,7 +85,7 @@ class PushersManager @Inject constructor(
): SetHttpPusherData =
SetHttpPusherData(
pushKey = pushKey,
appId = PushConfig.pusher_app_id,
appId = PushConfig.PUSHER_APP_ID,
profileTag = DEFAULT_PUSHER_FILE_TAG + "_" /* TODO + abs(activeSessionHolder.getActiveSession().myUserId.hashCode())*/,
lang = "en", // TODO localeProvider.current().language,
appDisplayName = buildMeta.applicationName,

View file

@ -38,7 +38,7 @@ class MarkAsReadActionFactory @Inject constructor(
private val clock: SystemClock,
) {
fun create(roomInfo: RoomEventGroupInfo): NotificationCompat.Action? {
if (!NotificationConfig.supportMarkAsReadAction) return null
if (!NotificationConfig.SUPPORT_MARK_AS_READ_ACTION) return null
val sessionId = roomInfo.sessionId.value
val roomId = roomInfo.roomId.value
val intent = Intent(context, NotificationBroadcastReceiver::class.java)

View file

@ -43,7 +43,7 @@ class QuickReplyActionFactory @Inject constructor(
private val clock: SystemClock,
) {
fun create(roomInfo: RoomEventGroupInfo, threadId: ThreadId?): NotificationCompat.Action? {
if (!NotificationConfig.supportQuickReplyAction) return null
if (!NotificationConfig.SUPPORT_QUICK_REPLY_ACTION) return null
val sessionId = roomInfo.sessionId
val roomId = roomInfo.roomId
return buildQuickReplyIntent(sessionId, roomId, threadId)?.let { replyPendingIntent ->