From 27bf42c5f25b6d43844a91a6ed20fde2d7ea85c9 Mon Sep 17 00:00:00 2001 From: ganfra Date: Tue, 24 Jan 2023 17:38:57 +0100 Subject: [PATCH] Change/move some gradle modules to be better separated. Let core module be a kotlin lib. --- .idea/compiler.xml | 4 +- .idea/misc.xml | 2 +- features/login/build.gradle.kts | 2 - .../login/changeserver/ChangeServerView.kt | 2 +- .../features/login/root/LoginRootNode.kt | 2 +- .../features/login/root/LoginRootScreen.kt | 2 +- features/logout/build.gradle.kts | 1 - features/messages/build.gradle.kts | 2 - .../android/features/messages/MessagesView.kt | 2 +- .../messages/timeline/TimelineView.kt | 2 +- features/onboarding/build.gradle.kts | 1 - features/preferences/build.gradle.kts | 1 - features/rageshake/build.gradle.kts | 6 +- .../rageshake/bugreport/BugReportView.kt | 8 +- .../crash/ui/CrashDetectionScreen.kt | 7 +- .../detection/RageshakeDetectionEvents.kt | 2 +- .../detection/RageshakeDetectionPresenter.kt | 4 +- .../detection/RageshakeDetectionView.kt | 15 ++- .../rageshake/logs/VectorFileLogger.kt | 18 +-- .../rageshake/reporter/BugReporter.kt | 2 +- .../rageshake}/screenshot/Screenshot.kt | 4 +- .../rageshake/screenshot/ScreenshotHolder.kt | 2 +- features/roomlist/build.gradle.kts | 2 - .../android/features/roomlist/RoomListView.kt | 7 +- .../roomlist/components/RoomListTopBar.kt | 9 +- features/template/build.gradle.kts | 3 - gradle/libs.versions.toml | 1 + libraries/androidutils/.gitignore | 1 + libraries/androidutils/build.gradle.kts | 61 ++++++++++ libraries/androidutils/consumer-rules.pro | 0 libraries/androidutils/proguard-rules.pro | 21 ++++ .../androidutils/ExampleInstrumentedTest.kt | 40 +++++++ .../src/main/AndroidManifest.xml | 4 +- .../libraries/androidutils}/bitmap/Bitmap.kt | 2 +- .../androidutils/extensions/isEmail.kt | 24 ++++ .../androidutils}/file/compressFile.kt | 6 +- .../androidutils}/hardware/vibrator.kt | 2 +- .../androidutils}/ui/DimensionConverter.kt | 2 +- .../libraries/androidutils}/ui/View.kt | 2 +- .../src/main/res/values-ldrtl/integers.xml | 0 .../src/main/res/values/integers.xml | 0 .../libraries/androidutils/ExampleUnitTest.kt | 33 ++++++ libraries/core/build.gradle.kts | 15 ++- .../core/coroutine/CoroutineDispatchers.kt | 2 +- .../core/coroutine/TimingOperators.kt | 104 ------------------ .../android/libraries/core/coroutine/pmap.kt | 2 +- .../android/libraries/core/data/Try.kt | 8 +- .../core/extensions/BasicExtensions.kt | 8 -- libraries/coroutines/.gitignore | 1 + libraries/coroutines/build.gradle.kts | 30 +++++ .../components/form}/TextFieldLocalState.kt | 4 +- .../components/keyboard}/Keyboard.kt | 4 +- .../designsystem/utils}/LogCompositions.kt | 4 +- .../designsystem/utils}/OnLifecycleEvent.kt | 4 +- .../utils}/PairCombinedPreviewParameter.kt | 4 +- .../libraries/matrix/RustMatrixClient.kt | 1 - libraries/textcomposer/build.gradle.kts | 1 + .../textcomposer/RichTextComposerLayout.kt | 12 +- settings.gradle.kts | 1 + 59 files changed, 314 insertions(+), 202 deletions(-) rename {libraries/core/src/main/kotlin/io/element/android/libraries/core => features/rageshake/src/main/kotlin/io/element/android/features/rageshake}/screenshot/Screenshot.kt (96%) create mode 100644 libraries/androidutils/.gitignore create mode 100644 libraries/androidutils/build.gradle.kts create mode 100644 libraries/androidutils/consumer-rules.pro create mode 100644 libraries/androidutils/proguard-rules.pro create mode 100644 libraries/androidutils/src/androidTest/java/io/element/android/libraries/androidutils/ExampleInstrumentedTest.kt rename libraries/{core => androidutils}/src/main/AndroidManifest.xml (95%) rename libraries/{core/src/main/kotlin/io/element/android/libraries/core => androidutils/src/main/kotlin/io/element/android/libraries/androidutils}/bitmap/Bitmap.kt (93%) create mode 100644 libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/extensions/isEmail.kt rename libraries/{core/src/main/kotlin/io/element/android/libraries/core => androidutils/src/main/kotlin/io/element/android/libraries/androidutils}/file/compressFile.kt (93%) rename libraries/{core/src/main/kotlin/io/element/android/libraries/core => androidutils/src/main/kotlin/io/element/android/libraries/androidutils}/hardware/vibrator.kt (95%) rename libraries/{core/src/main/kotlin/io/element/android/libraries/core => androidutils/src/main/kotlin/io/element/android/libraries/androidutils}/ui/DimensionConverter.kt (96%) rename libraries/{core/src/main/kotlin/io/element/android/libraries/core => androidutils/src/main/kotlin/io/element/android/libraries/androidutils}/ui/View.kt (95%) rename libraries/{core => androidutils}/src/main/res/values-ldrtl/integers.xml (100%) rename libraries/{core => androidutils}/src/main/res/values/integers.xml (100%) create mode 100644 libraries/androidutils/src/test/java/io/element/android/libraries/androidutils/ExampleUnitTest.kt delete mode 100644 libraries/core/src/main/kotlin/io/element/android/libraries/core/coroutine/TimingOperators.kt create mode 100644 libraries/coroutines/.gitignore create mode 100644 libraries/coroutines/build.gradle.kts rename libraries/{core/src/main/kotlin/io/element/android/libraries/core/compose => designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/form}/TextFieldLocalState.kt (89%) rename libraries/{core/src/main/kotlin/io/element/android/libraries/core/compose => designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/keyboard}/Keyboard.kt (93%) rename libraries/{core/src/main/kotlin/io/element/android/libraries/core/compose => designsystem/src/main/kotlin/io/element/android/libraries/designsystem/utils}/LogCompositions.kt (91%) rename libraries/{core/src/main/kotlin/io/element/android/libraries/core/compose => designsystem/src/main/kotlin/io/element/android/libraries/designsystem/utils}/OnLifecycleEvent.kt (94%) rename libraries/{core/src/main/kotlin/io/element/android/libraries/core/compose => designsystem/src/main/kotlin/io/element/android/libraries/designsystem/utils}/PairCombinedPreviewParameter.kt (91%) diff --git a/.idea/compiler.xml b/.idea/compiler.xml index fb7f4a8a46..7d1c62f24e 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,8 @@ - + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 54d5acd7d7..55ded342f7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,7 +1,7 @@ - + diff --git a/features/login/build.gradle.kts b/features/login/build.gradle.kts index 13d386671c..c181d3b75e 100644 --- a/features/login/build.gradle.kts +++ b/features/login/build.gradle.kts @@ -34,14 +34,12 @@ anvil { dependencies { implementation(projects.anvilannotations) anvil(projects.anvilcodegen) - implementation(projects.libraries.di) implementation(projects.libraries.core) implementation(projects.libraries.architecture) implementation(projects.libraries.matrix) implementation(projects.libraries.designsystem) implementation(projects.libraries.elementresources) implementation(projects.libraries.testtags) - implementation(libs.appyx.core) implementation(projects.libraries.uiStrings) ksp(libs.showkase.processor) testImplementation(libs.test.junit) diff --git a/features/login/src/main/kotlin/io/element/android/features/login/changeserver/ChangeServerView.kt b/features/login/src/main/kotlin/io/element/android/features/login/changeserver/ChangeServerView.kt index b0ddd10efd..ce9700c8af 100644 --- a/features/login/src/main/kotlin/io/element/android/features/login/changeserver/ChangeServerView.kt +++ b/features/login/src/main/kotlin/io/element/android/features/login/changeserver/ChangeServerView.kt @@ -53,7 +53,7 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import io.element.android.libraries.architecture.Async -import io.element.android.libraries.core.compose.textFieldState +import io.element.android.libraries.designsystem.components.form.textFieldState import io.element.android.libraries.designsystem.components.VectorIcon import io.element.android.features.login.R import io.element.android.features.login.error.changeServerError diff --git a/features/login/src/main/kotlin/io/element/android/features/login/root/LoginRootNode.kt b/features/login/src/main/kotlin/io/element/android/features/login/root/LoginRootNode.kt index 87a1c3d248..6067171c46 100644 --- a/features/login/src/main/kotlin/io/element/android/features/login/root/LoginRootNode.kt +++ b/features/login/src/main/kotlin/io/element/android/features/login/root/LoginRootNode.kt @@ -29,7 +29,7 @@ import dagger.assisted.Assisted import dagger.assisted.AssistedInject import io.element.android.anvilannotations.ContributesNode import io.element.android.libraries.architecture.presenterConnector -import io.element.android.libraries.core.compose.OnLifecycleEvent +import io.element.android.libraries.designsystem.utils.OnLifecycleEvent import io.element.android.libraries.di.AppScope @ContributesNode(AppScope::class) diff --git a/features/login/src/main/kotlin/io/element/android/features/login/root/LoginRootScreen.kt b/features/login/src/main/kotlin/io/element/android/features/login/root/LoginRootScreen.kt index 04d8a474e2..c10a4ee454 100644 --- a/features/login/src/main/kotlin/io/element/android/features/login/root/LoginRootScreen.kt +++ b/features/login/src/main/kotlin/io/element/android/features/login/root/LoginRootScreen.kt @@ -58,7 +58,7 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp -import io.element.android.libraries.core.compose.textFieldState +import io.element.android.libraries.designsystem.components.form.textFieldState import io.element.android.features.login.error.loginError import io.element.android.libraries.testtags.TestTags import io.element.android.libraries.testtags.testTag diff --git a/features/logout/build.gradle.kts b/features/logout/build.gradle.kts index 71f4f78df4..e2df3becf4 100644 --- a/features/logout/build.gradle.kts +++ b/features/logout/build.gradle.kts @@ -33,7 +33,6 @@ anvil { dependencies { implementation(projects.anvilannotations) anvil(projects.anvilcodegen) - implementation(projects.libraries.di) implementation(projects.libraries.architecture) implementation(projects.libraries.core) implementation(projects.libraries.matrix) diff --git a/features/messages/build.gradle.kts b/features/messages/build.gradle.kts index f11c076f27..975c7b5c0e 100644 --- a/features/messages/build.gradle.kts +++ b/features/messages/build.gradle.kts @@ -33,14 +33,12 @@ anvil { dependencies { implementation(projects.anvilannotations) anvil(projects.anvilcodegen) - implementation(projects.libraries.di) implementation(projects.libraries.core) implementation(projects.libraries.architecture) implementation(projects.libraries.matrix) implementation(projects.libraries.matrixui) implementation(projects.libraries.designsystem) implementation(projects.libraries.textcomposer) - implementation(libs.appyx.core) implementation(libs.coil.compose) implementation(libs.datetime) implementation(libs.accompanist.flowlayout) diff --git a/features/messages/src/main/kotlin/io/element/android/features/messages/MessagesView.kt b/features/messages/src/main/kotlin/io/element/android/features/messages/MessagesView.kt index dbcf0011a4..b934c3ce67 100644 --- a/features/messages/src/main/kotlin/io/element/android/features/messages/MessagesView.kt +++ b/features/messages/src/main/kotlin/io/element/android/features/messages/MessagesView.kt @@ -56,7 +56,6 @@ import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp -import io.element.android.libraries.core.compose.LogCompositions import io.element.android.libraries.designsystem.components.avatar.Avatar import io.element.android.libraries.designsystem.components.avatar.AvatarData import io.element.android.features.messages.actionlist.ActionListEvents @@ -65,6 +64,7 @@ import io.element.android.features.messages.actionlist.model.TimelineItemAction import io.element.android.features.messages.timeline.model.TimelineItem import io.element.android.features.messages.textcomposer.MessageComposerView import io.element.android.features.messages.timeline.TimelineView +import io.element.android.libraries.designsystem.utils.LogCompositions import kotlinx.coroutines.launch import timber.log.Timber diff --git a/features/messages/src/main/kotlin/io/element/android/features/messages/timeline/TimelineView.kt b/features/messages/src/main/kotlin/io/element/android/features/messages/timeline/TimelineView.kt index c7d424db2e..378f4c83ee 100644 --- a/features/messages/src/main/kotlin/io/element/android/features/messages/timeline/TimelineView.kt +++ b/features/messages/src/main/kotlin/io/element/android/features/messages/timeline/TimelineView.kt @@ -58,7 +58,7 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.unit.dp import androidx.compose.ui.zIndex -import io.element.android.libraries.core.compose.PairCombinedPreviewParameter +import io.element.android.libraries.designsystem.utils.PairCombinedPreviewParameter import io.element.android.libraries.designsystem.components.avatar.Avatar import io.element.android.libraries.designsystem.components.avatar.AvatarData import io.element.android.features.messages.timeline.model.AggregatedReaction diff --git a/features/onboarding/build.gradle.kts b/features/onboarding/build.gradle.kts index 00f4503666..42282ffa8c 100644 --- a/features/onboarding/build.gradle.kts +++ b/features/onboarding/build.gradle.kts @@ -34,7 +34,6 @@ dependencies { implementation(projects.libraries.testtags) implementation(libs.accompanist.pager) implementation(libs.accompanist.pagerindicator) - implementation(libs.appyx.core) testImplementation(libs.test.junit) androidTestImplementation(libs.test.junitext) ksp(libs.showkase.processor) diff --git a/features/preferences/build.gradle.kts b/features/preferences/build.gradle.kts index 10b3f4917d..92dcb5b13d 100644 --- a/features/preferences/build.gradle.kts +++ b/features/preferences/build.gradle.kts @@ -34,7 +34,6 @@ anvil { dependencies { implementation(projects.anvilannotations) anvil(projects.anvilcodegen) - implementation(projects.libraries.di) implementation(projects.libraries.architecture) implementation(projects.libraries.core) implementation(projects.libraries.matrixui) diff --git a/features/rageshake/build.gradle.kts b/features/rageshake/build.gradle.kts index 16f529db26..ecb333289b 100644 --- a/features/rageshake/build.gradle.kts +++ b/features/rageshake/build.gradle.kts @@ -32,11 +32,11 @@ anvil { } dependencies { - implementation(projects.libraries.core) anvil(projects.anvilcodegen) - implementation(projects.libraries.di) - implementation(projects.libraries.architecture) implementation(projects.anvilannotations) + implementation(projects.libraries.androidutils) + implementation(projects.libraries.core) + implementation(projects.libraries.architecture) implementation(projects.libraries.designsystem) implementation(projects.libraries.elementresources) implementation(projects.libraries.uiStrings) diff --git a/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/bugreport/BugReportView.kt b/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/bugreport/BugReportView.kt index ba209f69bb..c9ee533344 100644 --- a/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/bugreport/BugReportView.kt +++ b/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/bugreport/BugReportView.kt @@ -51,10 +51,10 @@ import androidx.compose.ui.unit.sp import coil.compose.AsyncImage import coil.request.ImageRequest import io.element.android.libraries.architecture.Async -import io.element.android.libraries.core.compose.LogCompositions -import io.element.android.libraries.core.compose.textFieldState +import io.element.android.libraries.designsystem.components.form.textFieldState import io.element.android.libraries.designsystem.components.LabelledCheckbox import io.element.android.libraries.designsystem.components.dialogs.ErrorDialog +import io.element.android.libraries.designsystem.utils.LogCompositions import io.element.android.libraries.ui.strings.R as StringR @OptIn(ExperimentalMaterial3Api::class) @@ -111,7 +111,9 @@ fun BugReportView( .padding(horizontal = 16.dp, vertical = 16.dp), fontSize = 16.sp, ) - var descriptionFieldState by textFieldState(stateValue = state.formState.description) + var descriptionFieldState by textFieldState( + stateValue = state.formState.description + ) Column( // modifier = Modifier.weight(1f), ) { diff --git a/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/crash/ui/CrashDetectionScreen.kt b/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/crash/ui/CrashDetectionScreen.kt index b3b41ccd09..e3c58ab515 100644 --- a/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/crash/ui/CrashDetectionScreen.kt +++ b/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/crash/ui/CrashDetectionScreen.kt @@ -19,8 +19,8 @@ package io.element.android.features.rageshake.crash.ui import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview -import io.element.android.libraries.core.compose.LogCompositions import io.element.android.libraries.designsystem.components.dialogs.ConfirmationDialog +import io.element.android.libraries.designsystem.utils.LogCompositions import io.element.android.libraries.ui.strings.R as StringR @Composable @@ -28,7 +28,10 @@ fun CrashDetectionView( state: CrashDetectionState, onOpenBugReport: () -> Unit = { }, ) { - LogCompositions(tag = "Crash", msg = "CrashDetectionScreen") + LogCompositions( + tag = "Crash", + msg = "CrashDetectionScreen" + ) fun onPopupDismissed() { state.eventSink(CrashDetectionEvents.ResetAllCrashData) diff --git a/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/detection/RageshakeDetectionEvents.kt b/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/detection/RageshakeDetectionEvents.kt index 3030311674..9bc787d4ac 100644 --- a/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/detection/RageshakeDetectionEvents.kt +++ b/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/detection/RageshakeDetectionEvents.kt @@ -16,7 +16,7 @@ package io.element.android.features.rageshake.detection -import io.element.android.libraries.core.screenshot.ImageResult +import io.element.android.features.rageshake.screenshot.ImageResult sealed interface RageshakeDetectionEvents { object Dismiss : RageshakeDetectionEvents diff --git a/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/detection/RageshakeDetectionPresenter.kt b/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/detection/RageshakeDetectionPresenter.kt index de6f338b27..c91d584021 100644 --- a/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/detection/RageshakeDetectionPresenter.kt +++ b/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/detection/RageshakeDetectionPresenter.kt @@ -23,12 +23,12 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.saveable.rememberSaveable -import io.element.android.libraries.architecture.Presenter -import io.element.android.libraries.core.screenshot.ImageResult import io.element.android.features.rageshake.preferences.RageshakePreferencesEvents import io.element.android.features.rageshake.preferences.RageshakePreferencesPresenter import io.element.android.features.rageshake.rageshake.RageShake +import io.element.android.features.rageshake.screenshot.ImageResult import io.element.android.features.rageshake.screenshot.ScreenshotHolder +import io.element.android.libraries.architecture.Presenter import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import timber.log.Timber diff --git a/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/detection/RageshakeDetectionView.kt b/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/detection/RageshakeDetectionView.kt index a63c38d12e..6d7c5ee036 100644 --- a/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/detection/RageshakeDetectionView.kt +++ b/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/detection/RageshakeDetectionView.kt @@ -23,12 +23,12 @@ import androidx.compose.ui.platform.LocalView import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.lifecycle.Lifecycle -import io.element.android.libraries.core.compose.LogCompositions -import io.element.android.libraries.core.compose.OnLifecycleEvent -import io.element.android.libraries.core.hardware.vibrate -import io.element.android.libraries.core.screenshot.ImageResult -import io.element.android.libraries.core.screenshot.screenshot +import io.element.android.features.rageshake.screenshot.ImageResult +import io.element.android.features.rageshake.screenshot.screenshot +import io.element.android.libraries.androidutils.hardware.vibrate +import io.element.android.libraries.designsystem.utils.OnLifecycleEvent import io.element.android.libraries.designsystem.components.dialogs.ConfirmationDialog +import io.element.android.libraries.designsystem.utils.LogCompositions import io.element.android.libraries.ui.strings.R as StringR @Composable @@ -36,7 +36,10 @@ fun RageshakeDetectionView( state: RageshakeDetectionState, onOpenBugReport: () -> Unit = { }, ) { - LogCompositions(tag = "Rageshake", msg = "RageshakeDetectionScreen") + LogCompositions( + tag = "Rageshake", + msg = "RageshakeDetectionScreen" + ) val eventSink = state.eventSink val context = LocalContext.current OnLifecycleEvent { _, event -> diff --git a/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/logs/VectorFileLogger.kt b/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/logs/VectorFileLogger.kt index b7443e90bb..9ed2bc9354 100644 --- a/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/logs/VectorFileLogger.kt +++ b/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/logs/VectorFileLogger.kt @@ -19,17 +19,17 @@ package io.element.android.features.rageshake.logs import android.content.Context import android.util.Log import io.element.android.libraries.core.data.tryOrNull +import kotlinx.coroutines.DelicateCoroutinesApi +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import timber.log.Timber import java.io.File import java.io.PrintWriter import java.io.StringWriter import java.util.logging.FileHandler import java.util.logging.Level import java.util.logging.Logger -import kotlinx.coroutines.DelicateCoroutinesApi -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.launch -import timber.log.Timber /** * Will be planted in Timber. @@ -85,7 +85,9 @@ class VectorFileLogger( tryOrNull { file.delete() } } - fileHandler = tryOrNull("Failed to initialize FileLogger") { + fileHandler = tryOrNull( + onError = { Timber.e(it, "Failed to initialize FileLogger") } + ) { FileHandler( cacheDirectory.absolutePath + "/" + fileNamePrefix + ".%g.txt", maxLogSizeByte, @@ -134,7 +136,9 @@ class VectorFileLogger( * @return The list of files with logs. */ fun getLogFiles(): List { - return tryOrNull("## getLogFiles() failed") { + return tryOrNull( + onError = { Timber.e(it, "## getLogFiles() failed") } + ) { fileHandler ?.flush() ?.let { 0 until logRotationCount } diff --git a/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/reporter/BugReporter.kt b/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/reporter/BugReporter.kt index 3e495d613f..8aedf7b9be 100755 --- a/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/reporter/BugReporter.kt +++ b/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/reporter/BugReporter.kt @@ -19,7 +19,7 @@ package io.element.android.features.rageshake.reporter import android.content.Context import android.os.Build import io.element.android.libraries.core.extensions.toOnOff -import io.element.android.libraries.core.file.compressFile +import io.element.android.libraries.androidutils.file.compressFile import io.element.android.libraries.core.mimetype.MimeTypes import io.element.android.libraries.di.ApplicationContext import io.element.android.features.rageshake.R diff --git a/libraries/core/src/main/kotlin/io/element/android/libraries/core/screenshot/Screenshot.kt b/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/screenshot/Screenshot.kt similarity index 96% rename from libraries/core/src/main/kotlin/io/element/android/libraries/core/screenshot/Screenshot.kt rename to features/rageshake/src/main/kotlin/io/element/android/features/rageshake/screenshot/Screenshot.kt index c1e1a3be80..803c51f2da 100644 --- a/libraries/core/src/main/kotlin/io/element/android/libraries/core/screenshot/Screenshot.kt +++ b/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/screenshot/Screenshot.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 New Vector Ltd + * Copyright (c) 2023 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.element.android.libraries.core.screenshot +package io.element.android.features.rageshake.screenshot import android.app.Activity import android.graphics.Bitmap diff --git a/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/screenshot/ScreenshotHolder.kt b/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/screenshot/ScreenshotHolder.kt index d58a60dd4a..410c63b93a 100644 --- a/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/screenshot/ScreenshotHolder.kt +++ b/features/rageshake/src/main/kotlin/io/element/android/features/rageshake/screenshot/ScreenshotHolder.kt @@ -18,7 +18,7 @@ package io.element.android.features.rageshake.screenshot import android.content.Context import android.graphics.Bitmap -import io.element.android.libraries.core.bitmap.writeBitmap +import io.element.android.libraries.androidutils.bitmap.writeBitmap import io.element.android.libraries.di.AppScope import io.element.android.libraries.di.ApplicationContext import io.element.android.libraries.di.SingleIn diff --git a/features/roomlist/build.gradle.kts b/features/roomlist/build.gradle.kts index 2d23e891cc..fc0402eafc 100644 --- a/features/roomlist/build.gradle.kts +++ b/features/roomlist/build.gradle.kts @@ -34,13 +34,11 @@ dependencies { anvil(projects.anvilcodegen) implementation(projects.anvilannotations) - implementation(projects.libraries.di) implementation(projects.libraries.core) implementation(projects.libraries.architecture) implementation(projects.libraries.matrix) implementation(projects.libraries.matrixui) implementation(projects.libraries.designsystem) - implementation(libs.appyx.core) implementation(projects.libraries.elementresources) implementation(projects.libraries.uiStrings) implementation(libs.datetime) diff --git a/features/roomlist/src/main/kotlin/io/element/android/features/roomlist/RoomListView.kt b/features/roomlist/src/main/kotlin/io/element/android/features/roomlist/RoomListView.kt index 5b807f0dd0..0e7d8f410b 100644 --- a/features/roomlist/src/main/kotlin/io/element/android/features/roomlist/RoomListView.kt +++ b/features/roomlist/src/main/kotlin/io/element/android/features/roomlist/RoomListView.kt @@ -36,7 +36,6 @@ import androidx.compose.ui.input.nestedscroll.NestedScrollConnection import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.Velocity -import io.element.android.libraries.core.compose.LogCompositions import io.element.android.libraries.designsystem.components.avatar.AvatarData import io.element.android.features.roomlist.components.RoomListTopBar import io.element.android.features.roomlist.components.RoomSummaryRow @@ -44,6 +43,7 @@ import io.element.android.features.roomlist.model.RoomListEvents import io.element.android.features.roomlist.model.RoomListRoomSummary import io.element.android.features.roomlist.model.RoomListState import io.element.android.features.roomlist.model.stubbedRoomSummaries +import io.element.android.libraries.designsystem.utils.LogCompositions import io.element.android.libraries.matrix.core.RoomId import io.element.android.libraries.matrix.core.UserId import io.element.android.libraries.matrix.ui.model.MatrixUser @@ -103,7 +103,10 @@ fun RoomListView( } } val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior(appBarState) - LogCompositions(tag = "RoomListScreen", msg = "Content") + LogCompositions( + tag = "RoomListScreen", + msg = "Content" + ) val nestedScrollConnection = remember { object : NestedScrollConnection { diff --git a/features/roomlist/src/main/kotlin/io/element/android/features/roomlist/components/RoomListTopBar.kt b/features/roomlist/src/main/kotlin/io/element/android/features/roomlist/components/RoomListTopBar.kt index 8b5e4c4761..c7f077374f 100644 --- a/features/roomlist/src/main/kotlin/io/element/android/features/roomlist/components/RoomListTopBar.kt +++ b/features/roomlist/src/main/kotlin/io/element/android/features/roomlist/components/RoomListTopBar.kt @@ -52,9 +52,9 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.sp -import io.element.android.libraries.core.compose.LogCompositions -import io.element.android.libraries.core.compose.textFieldState import io.element.android.libraries.designsystem.components.avatar.Avatar +import io.element.android.libraries.designsystem.components.form.textFieldState +import io.element.android.libraries.designsystem.utils.LogCompositions import io.element.android.libraries.matrix.ui.model.MatrixUser import io.element.android.libraries.ui.strings.R as StringR @@ -66,7 +66,10 @@ fun RoomListTopBar( onOpenSettings: () -> Unit, scrollBehavior: TopAppBarScrollBehavior ) { - LogCompositions(tag = "RoomListScreen", msg = "TopBar") + LogCompositions( + tag = "RoomListScreen", + msg = "TopBar" + ) var searchWidgetStateIsOpened by rememberSaveable { mutableStateOf(false) } fun closeFilter() { diff --git a/features/template/build.gradle.kts b/features/template/build.gradle.kts index fea038bf14..47cf8f490c 100644 --- a/features/template/build.gradle.kts +++ b/features/template/build.gradle.kts @@ -35,7 +35,6 @@ dependencies { anvil(projects.anvilcodegen) implementation(projects.anvilannotations) - implementation(projects.libraries.di) implementation(projects.libraries.core) implementation(projects.libraries.architecture) implementation(projects.libraries.matrix) @@ -44,8 +43,6 @@ dependencies { implementation(projects.libraries.elementresources) implementation(projects.libraries.uiStrings) - implementation(libs.appyx.core) - testImplementation(libs.test.junit) testImplementation(libs.coroutines.test) testImplementation(libs.molecule.runtime) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8a6d27811e..92d50ac689 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -114,6 +114,7 @@ showkase_processor = { module = "com.airbnb.android:showkase-processor", version jsoup = { module = "org.jsoup:jsoup", version.ref = "jsoup" } appyx_core = { module = "com.bumble.appyx:core", version.ref = "appyx" } molecule-runtime = { module = "app.cash.molecule:molecule-runtime", version.ref = "molecule" } +timber = "com.jakewharton.timber:timber:5.0.1" # Di inject = "javax.inject:javax.inject:1" diff --git a/libraries/androidutils/.gitignore b/libraries/androidutils/.gitignore new file mode 100644 index 0000000000..42afabfd2a --- /dev/null +++ b/libraries/androidutils/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/libraries/androidutils/build.gradle.kts b/libraries/androidutils/build.gradle.kts new file mode 100644 index 0000000000..68881c2b57 --- /dev/null +++ b/libraries/androidutils/build.gradle.kts @@ -0,0 +1,61 @@ + +/* + * Copyright (c) 2023 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. + */ + +plugins { + id("com.android.library") + id("org.jetbrains.kotlin.android") +} + +android { + namespace = "io.element.android.libraries.androidutils" + compileSdk = 32 + + defaultConfig { + minSdk = 21 + targetSdk = 32 + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles("consumer-rules.pro") + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = "1.8" + } +} + +dependencies { + implementation(libs.timber) + implementation("androidx.core:core-ktx:1.7.0") + implementation("androidx.appcompat:appcompat:1.6.0") + implementation("com.google.android.material:material:1.7.0") + testImplementation("junit:junit:4.13.2") + androidTestImplementation("androidx.test.ext:junit:1.1.5") + androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") +} diff --git a/libraries/androidutils/consumer-rules.pro b/libraries/androidutils/consumer-rules.pro new file mode 100644 index 0000000000..e69de29bb2 diff --git a/libraries/androidutils/proguard-rules.pro b/libraries/androidutils/proguard-rules.pro new file mode 100644 index 0000000000..481bb43481 --- /dev/null +++ b/libraries/androidutils/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/libraries/androidutils/src/androidTest/java/io/element/android/libraries/androidutils/ExampleInstrumentedTest.kt b/libraries/androidutils/src/androidTest/java/io/element/android/libraries/androidutils/ExampleInstrumentedTest.kt new file mode 100644 index 0000000000..ce92608bfb --- /dev/null +++ b/libraries/androidutils/src/androidTest/java/io/element/android/libraries/androidutils/ExampleInstrumentedTest.kt @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 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.androidutils + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("io.element.android.libraries.androidutils.test", appContext.packageName) + } +} diff --git a/libraries/core/src/main/AndroidManifest.xml b/libraries/androidutils/src/main/AndroidManifest.xml similarity index 95% rename from libraries/core/src/main/AndroidManifest.xml rename to libraries/androidutils/src/main/AndroidManifest.xml index c7c3fad8ff..5a19e495ae 100644 --- a/libraries/core/src/main/AndroidManifest.xml +++ b/libraries/androidutils/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ - - diff --git a/libraries/core/src/main/kotlin/io/element/android/libraries/core/bitmap/Bitmap.kt b/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/bitmap/Bitmap.kt similarity index 93% rename from libraries/core/src/main/kotlin/io/element/android/libraries/core/bitmap/Bitmap.kt rename to libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/bitmap/Bitmap.kt index 3bb978f67d..f71fb1535e 100644 --- a/libraries/core/src/main/kotlin/io/element/android/libraries/core/bitmap/Bitmap.kt +++ b/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/bitmap/Bitmap.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.element.android.libraries.core.bitmap +package io.element.android.libraries.androidutils.bitmap import android.graphics.Bitmap import java.io.File diff --git a/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/extensions/isEmail.kt b/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/extensions/isEmail.kt new file mode 100644 index 0000000000..b47033286d --- /dev/null +++ b/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/extensions/isEmail.kt @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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.androidutils.extensions + +import android.util.Patterns + +/** + * Check if a CharSequence is an email. + */ +fun CharSequence.isEmail() = Patterns.EMAIL_ADDRESS.matcher(this).matches() diff --git a/libraries/core/src/main/kotlin/io/element/android/libraries/core/file/compressFile.kt b/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/file/compressFile.kt similarity index 93% rename from libraries/core/src/main/kotlin/io/element/android/libraries/core/file/compressFile.kt rename to libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/file/compressFile.kt index ff6fc22178..587c1aed75 100644 --- a/libraries/core/src/main/kotlin/io/element/android/libraries/core/file/compressFile.kt +++ b/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/file/compressFile.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 New Vector Ltd + * Copyright (c) 2023 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. @@ -14,11 +14,11 @@ * limitations under the License. */ -package io.element.android.libraries.core.file +package io.element.android.libraries.androidutils.file +import timber.log.Timber import java.io.File import java.util.zip.GZIPOutputStream -import timber.log.Timber /** * GZip a file. diff --git a/libraries/core/src/main/kotlin/io/element/android/libraries/core/hardware/vibrator.kt b/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/hardware/vibrator.kt similarity index 95% rename from libraries/core/src/main/kotlin/io/element/android/libraries/core/hardware/vibrator.kt rename to libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/hardware/vibrator.kt index e7f95a20d9..3e717ef6bf 100644 --- a/libraries/core/src/main/kotlin/io/element/android/libraries/core/hardware/vibrator.kt +++ b/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/hardware/vibrator.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.element.android.libraries.core.hardware +package io.element.android.libraries.androidutils.hardware import android.content.Context import android.os.Build diff --git a/libraries/core/src/main/kotlin/io/element/android/libraries/core/ui/DimensionConverter.kt b/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/ui/DimensionConverter.kt similarity index 96% rename from libraries/core/src/main/kotlin/io/element/android/libraries/core/ui/DimensionConverter.kt rename to libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/ui/DimensionConverter.kt index cde1a49cda..71fb1c7070 100644 --- a/libraries/core/src/main/kotlin/io/element/android/libraries/core/ui/DimensionConverter.kt +++ b/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/ui/DimensionConverter.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.element.android.libraries.core.ui +package io.element.android.libraries.androidutils.ui import android.content.res.Resources import android.util.TypedValue diff --git a/libraries/core/src/main/kotlin/io/element/android/libraries/core/ui/View.kt b/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/ui/View.kt similarity index 95% rename from libraries/core/src/main/kotlin/io/element/android/libraries/core/ui/View.kt rename to libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/ui/View.kt index 5d10fdd50a..0639f29d1f 100644 --- a/libraries/core/src/main/kotlin/io/element/android/libraries/core/ui/View.kt +++ b/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/ui/View.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.element.android.libraries.core.ui +package io.element.android.libraries.androidutils.ui import android.view.View import android.view.inputmethod.InputMethodManager diff --git a/libraries/core/src/main/res/values-ldrtl/integers.xml b/libraries/androidutils/src/main/res/values-ldrtl/integers.xml similarity index 100% rename from libraries/core/src/main/res/values-ldrtl/integers.xml rename to libraries/androidutils/src/main/res/values-ldrtl/integers.xml diff --git a/libraries/core/src/main/res/values/integers.xml b/libraries/androidutils/src/main/res/values/integers.xml similarity index 100% rename from libraries/core/src/main/res/values/integers.xml rename to libraries/androidutils/src/main/res/values/integers.xml diff --git a/libraries/androidutils/src/test/java/io/element/android/libraries/androidutils/ExampleUnitTest.kt b/libraries/androidutils/src/test/java/io/element/android/libraries/androidutils/ExampleUnitTest.kt new file mode 100644 index 0000000000..489e18e717 --- /dev/null +++ b/libraries/androidutils/src/test/java/io/element/android/libraries/androidutils/ExampleUnitTest.kt @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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.androidutils + +import org.junit.Test + +import org.junit.Assert.* + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} diff --git a/libraries/core/build.gradle.kts b/libraries/core/build.gradle.kts index 290ec420ba..ef4a882cb3 100644 --- a/libraries/core/build.gradle.kts +++ b/libraries/core/build.gradle.kts @@ -1,3 +1,4 @@ + /* * Copyright (c) 2022 New Vector Ltd * @@ -14,10 +15,18 @@ * limitations under the License. */ +// TODO: Remove once https://youtrack.jetbrains.com/issue/KTIJ-19369 is fixed +@Suppress("DSL_SCOPE_VIOLATION") plugins { - id("io.element.android-compose-library") + id("java-library") + alias(libs.plugins.kotlin.jvm) } -android { - namespace = "io.element.android.libraries.core" +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} + +dependencies { + implementation(libs.coroutines.core) } diff --git a/libraries/core/src/main/kotlin/io/element/android/libraries/core/coroutine/CoroutineDispatchers.kt b/libraries/core/src/main/kotlin/io/element/android/libraries/core/coroutine/CoroutineDispatchers.kt index 39e5e0dd51..a3f1586070 100644 --- a/libraries/core/src/main/kotlin/io/element/android/libraries/core/coroutine/CoroutineDispatchers.kt +++ b/libraries/core/src/main/kotlin/io/element/android/libraries/core/coroutine/CoroutineDispatchers.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 New Vector Ltd + * Copyright (c) 2023 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. diff --git a/libraries/core/src/main/kotlin/io/element/android/libraries/core/coroutine/TimingOperators.kt b/libraries/core/src/main/kotlin/io/element/android/libraries/core/coroutine/TimingOperators.kt deleted file mode 100644 index 68e92e0289..0000000000 --- a/libraries/core/src/main/kotlin/io/element/android/libraries/core/coroutine/TimingOperators.kt +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2022 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 android.os.SystemClock -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.channels.Channel -import kotlinx.coroutines.channels.ClosedReceiveChannelException -import kotlinx.coroutines.channels.ReceiveChannel -import kotlinx.coroutines.channels.produce -import kotlinx.coroutines.coroutineScope -import kotlinx.coroutines.delay -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.consumeAsFlow -import kotlinx.coroutines.flow.flow -import kotlinx.coroutines.isActive -import kotlinx.coroutines.selects.select - -@ExperimentalCoroutinesApi -fun Flow.chunk(durationInMillis: Long): Flow> { - require(durationInMillis > 0) { "Duration should be greater than 0" } - return flow { - coroutineScope { - val events = ArrayList() - val ticker = fixedPeriodTicker(durationInMillis) - try { - val upstreamValues = produce(capacity = Channel.CONFLATED) { - collect { value -> send(value) } - } - while (isActive) { - var hasTimedOut = false - select { - upstreamValues.onReceive { - events.add(it) - } - ticker.onReceive { - hasTimedOut = true - } - } - if (hasTimedOut && events.isNotEmpty()) { - emit(events.toList()) - events.clear() - } - } - } catch (e: ClosedReceiveChannelException) { - // drain remaining events - if (events.isNotEmpty()) emit(events.toList()) - } finally { - ticker.cancel() - } - } - } -} - -@ExperimentalCoroutinesApi -fun Flow.throttleFirst(windowDuration: Long): Flow = flow { - var windowStartTime = SystemClock.elapsedRealtime() - var emitted = false - collect { value -> - val currentTime = SystemClock.elapsedRealtime() - val delta = currentTime - windowStartTime - if (delta >= windowDuration) { - windowStartTime += delta / windowDuration * windowDuration - emitted = false - } - if (!emitted) { - emit(value) - emitted = true - } - } -} - -@ExperimentalCoroutinesApi -fun tickerFlow(scope: CoroutineScope, delayMillis: Long, initialDelayMillis: Long = delayMillis): Flow { - return scope.fixedPeriodTicker(delayMillis, initialDelayMillis).consumeAsFlow() -} - -@ExperimentalCoroutinesApi -private fun CoroutineScope.fixedPeriodTicker(delayMillis: Long, initialDelayMillis: Long = delayMillis): ReceiveChannel { - require(delayMillis >= 0) { "Expected non-negative delay, but has $delayMillis ms" } - require(initialDelayMillis >= 0) { "Expected non-negative initial delay, but has $initialDelayMillis ms" } - return produce(capacity = 0) { - delay(initialDelayMillis) - while (true) { - channel.send(Unit) - delay(delayMillis) - } - } -} diff --git a/libraries/core/src/main/kotlin/io/element/android/libraries/core/coroutine/pmap.kt b/libraries/core/src/main/kotlin/io/element/android/libraries/core/coroutine/pmap.kt index f823116898..178a5eef3a 100644 --- a/libraries/core/src/main/kotlin/io/element/android/libraries/core/coroutine/pmap.kt +++ b/libraries/core/src/main/kotlin/io/element/android/libraries/core/coroutine/pmap.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 New Vector Ltd + * Copyright (c) 2023 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. diff --git a/libraries/core/src/main/kotlin/io/element/android/libraries/core/data/Try.kt b/libraries/core/src/main/kotlin/io/element/android/libraries/core/data/Try.kt index 21e4bb7738..b91d249547 100644 --- a/libraries/core/src/main/kotlin/io/element/android/libraries/core/data/Try.kt +++ b/libraries/core/src/main/kotlin/io/element/android/libraries/core/data/Try.kt @@ -16,15 +16,11 @@ package io.element.android.libraries.core.data -import timber.log.Timber - -inline fun tryOrNull(message: String? = null, operation: () -> A): A? { +inline fun tryOrNull(noinline onError: ((Throwable) -> Unit)? = null, operation: () -> A): A? { return try { operation() } catch (any: Throwable) { - if (message != null) { - Timber.e("TAG", message, any) - } + onError?.invoke(any) null } } diff --git a/libraries/core/src/main/kotlin/io/element/android/libraries/core/extensions/BasicExtensions.kt b/libraries/core/src/main/kotlin/io/element/android/libraries/core/extensions/BasicExtensions.kt index 9ae50826c6..e5b9d3d06f 100644 --- a/libraries/core/src/main/kotlin/io/element/android/libraries/core/extensions/BasicExtensions.kt +++ b/libraries/core/src/main/kotlin/io/element/android/libraries/core/extensions/BasicExtensions.kt @@ -16,19 +16,11 @@ package io.element.android.libraries.core.extensions -import android.util.Patterns fun Boolean.toOnOff() = if (this) "ON" else "OFF" inline fun T.ooi(block: (T) -> Unit): T = also(block) -/** - * Check if a CharSequence is an email. - */ -fun CharSequence.isEmail() = Patterns.EMAIL_ADDRESS.matcher(this).matches() - -// fun CharSequence.isMatrixId() = MatrixPatterns.isUserId(this.toString()) - /** * Return empty CharSequence if the CharSequence is null. */ diff --git a/libraries/coroutines/.gitignore b/libraries/coroutines/.gitignore new file mode 100644 index 0000000000..42afabfd2a --- /dev/null +++ b/libraries/coroutines/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/libraries/coroutines/build.gradle.kts b/libraries/coroutines/build.gradle.kts new file mode 100644 index 0000000000..f9f12e0b09 --- /dev/null +++ b/libraries/coroutines/build.gradle.kts @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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. + */ +// TODO: Remove once https://youtrack.jetbrains.com/issue/KTIJ-19369 is fixed +@Suppress("DSL_SCOPE_VIOLATION") +plugins { + id("java-library") + alias(libs.plugins.kotlin.jvm) +} + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} + +dependencies { + implementation(libs.coroutines.core) +} diff --git a/libraries/core/src/main/kotlin/io/element/android/libraries/core/compose/TextFieldLocalState.kt b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/form/TextFieldLocalState.kt similarity index 89% rename from libraries/core/src/main/kotlin/io/element/android/libraries/core/compose/TextFieldLocalState.kt rename to libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/form/TextFieldLocalState.kt index c1a311492b..c7366dcfb7 100644 --- a/libraries/core/src/main/kotlin/io/element/android/libraries/core/compose/TextFieldLocalState.kt +++ b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/form/TextFieldLocalState.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 New Vector Ltd + * Copyright (c) 2023 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.element.android.libraries.core.compose +package io.element.android.libraries.designsystem.components.form import androidx.compose.runtime.Composable import androidx.compose.runtime.MutableState diff --git a/libraries/core/src/main/kotlin/io/element/android/libraries/core/compose/Keyboard.kt b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/keyboard/Keyboard.kt similarity index 93% rename from libraries/core/src/main/kotlin/io/element/android/libraries/core/compose/Keyboard.kt rename to libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/keyboard/Keyboard.kt index 4e66199845..1ebb67f75a 100644 --- a/libraries/core/src/main/kotlin/io/element/android/libraries/core/compose/Keyboard.kt +++ b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/keyboard/Keyboard.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 New Vector Ltd + * Copyright (c) 2023 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.element.android.libraries.core.compose +package io.element.android.libraries.designsystem.components.keyboard import androidx.compose.foundation.layout.ExperimentalLayoutApi import androidx.compose.foundation.layout.WindowInsets diff --git a/libraries/core/src/main/kotlin/io/element/android/libraries/core/compose/LogCompositions.kt b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/utils/LogCompositions.kt similarity index 91% rename from libraries/core/src/main/kotlin/io/element/android/libraries/core/compose/LogCompositions.kt rename to libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/utils/LogCompositions.kt index eff24198db..f6edd1a8fb 100644 --- a/libraries/core/src/main/kotlin/io/element/android/libraries/core/compose/LogCompositions.kt +++ b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/utils/LogCompositions.kt @@ -14,12 +14,12 @@ * limitations under the License. */ -package io.element.android.libraries.core.compose +package io.element.android.libraries.designsystem.utils import androidx.compose.runtime.Composable import androidx.compose.runtime.SideEffect import androidx.compose.runtime.remember -import io.element.android.libraries.core.BuildConfig +import io.element.android.libraries.designsystem.BuildConfig import timber.log.Timber // Note the inline function below which ensures that this function is essentially diff --git a/libraries/core/src/main/kotlin/io/element/android/libraries/core/compose/OnLifecycleEvent.kt b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/utils/OnLifecycleEvent.kt similarity index 94% rename from libraries/core/src/main/kotlin/io/element/android/libraries/core/compose/OnLifecycleEvent.kt rename to libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/utils/OnLifecycleEvent.kt index 51a117bacf..630434e060 100644 --- a/libraries/core/src/main/kotlin/io/element/android/libraries/core/compose/OnLifecycleEvent.kt +++ b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/utils/OnLifecycleEvent.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 New Vector Ltd + * Copyright (c) 2023 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.element.android.libraries.core.compose +package io.element.android.libraries.designsystem.utils import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect diff --git a/libraries/core/src/main/kotlin/io/element/android/libraries/core/compose/PairCombinedPreviewParameter.kt b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/utils/PairCombinedPreviewParameter.kt similarity index 91% rename from libraries/core/src/main/kotlin/io/element/android/libraries/core/compose/PairCombinedPreviewParameter.kt rename to libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/utils/PairCombinedPreviewParameter.kt index 253ee8fb5c..bf0a282f72 100644 --- a/libraries/core/src/main/kotlin/io/element/android/libraries/core/compose/PairCombinedPreviewParameter.kt +++ b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/utils/PairCombinedPreviewParameter.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 New Vector Ltd + * Copyright (c) 2023 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.element.android.libraries.core.compose +package io.element.android.libraries.designsystem.utils import androidx.compose.ui.tooling.preview.PreviewParameterProvider diff --git a/libraries/matrix/src/main/kotlin/io/element/android/libraries/matrix/RustMatrixClient.kt b/libraries/matrix/src/main/kotlin/io/element/android/libraries/matrix/RustMatrixClient.kt index 64b1cb4e34..b9631cd6ca 100644 --- a/libraries/matrix/src/main/kotlin/io/element/android/libraries/matrix/RustMatrixClient.kt +++ b/libraries/matrix/src/main/kotlin/io/element/android/libraries/matrix/RustMatrixClient.kt @@ -26,7 +26,6 @@ import io.element.android.libraries.matrix.room.MatrixRoom import io.element.android.libraries.matrix.room.RoomSummaryDataSource import io.element.android.libraries.matrix.room.RustMatrixRoom import io.element.android.libraries.matrix.room.RustRoomSummaryDataSource -import io.element.android.libraries.matrix.session.PreferencesSessionStore import io.element.android.libraries.matrix.session.SessionStore import io.element.android.libraries.matrix.session.sessionId import io.element.android.libraries.matrix.sync.SlidingSyncObserverProxy diff --git a/libraries/textcomposer/build.gradle.kts b/libraries/textcomposer/build.gradle.kts index 040a265f80..4b5f82f747 100644 --- a/libraries/textcomposer/build.gradle.kts +++ b/libraries/textcomposer/build.gradle.kts @@ -32,6 +32,7 @@ android { dependencies { implementation(projects.libraries.elementresources) implementation(projects.libraries.uiStrings) + implementation(projects.libraries.androidutils) implementation(projects.libraries.core) implementation(projects.libraries.matrix) implementation(libs.wysiwyg) diff --git a/libraries/textcomposer/src/main/kotlin/io/element/android/libraries/textcomposer/RichTextComposerLayout.kt b/libraries/textcomposer/src/main/kotlin/io/element/android/libraries/textcomposer/RichTextComposerLayout.kt index 86c1084f5d..2948685b74 100644 --- a/libraries/textcomposer/src/main/kotlin/io/element/android/libraries/textcomposer/RichTextComposerLayout.kt +++ b/libraries/textcomposer/src/main/kotlin/io/element/android/libraries/textcomposer/RichTextComposerLayout.kt @@ -40,14 +40,13 @@ import androidx.core.view.isInvisible import androidx.core.view.isVisible import androidx.core.view.updateLayoutParams import com.google.android.material.shape.MaterialShapeDrawable -import io.element.android.wysiwyg.EditorEditText -import io.element.android.wysiwyg.inputhandlers.models.InlineFormat -import io.element.android.libraries.core.ui.DimensionConverter -import io.element.android.libraries.core.ui.hideKeyboard -import io.element.android.libraries.core.ui.showKeyboard +import io.element.android.libraries.androidutils.ui.hideKeyboard +import io.element.android.libraries.androidutils.ui.showKeyboard import io.element.android.libraries.textcomposer.databinding.ComposerRichTextLayoutBinding import io.element.android.libraries.textcomposer.databinding.ViewRichTextMenuButtonBinding import io.element.android.libraries.textcomposer.tools.setTextIfDifferent +import io.element.android.wysiwyg.EditorEditText +import io.element.android.wysiwyg.inputhandlers.models.InlineFormat import uniffi.wysiwyg_composer.ActionState import uniffi.wysiwyg_composer.ComposerAction import io.element.android.element.resources.R as ElementR @@ -118,7 +117,8 @@ class RichTextComposerLayout @JvmOverloads constructor( } } - private val dimensionConverter = DimensionConverter(resources) + private val dimensionConverter = + io.element.android.libraries.androidutils.ui.DimensionConverter(resources) fun setFullScreen(isFullScreen: Boolean, animated: Boolean, manageKeyboard: Boolean) { if (!animated && views.composerLayout.layoutParams != null) { diff --git a/settings.gradle.kts b/settings.gradle.kts index 669bac4635..b85f5e6717 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -60,3 +60,4 @@ include(":anvilcodegen") include(":libraries:architecture") include(":libraries:matrixtest") include(":features:template") +include(":libraries:androidutils")