diff --git a/features/messages/impl/build.gradle.kts b/features/messages/impl/build.gradle.kts index f8377733a6..73360a0a25 100644 --- a/features/messages/impl/build.gradle.kts +++ b/features/messages/impl/build.gradle.kts @@ -34,6 +34,7 @@ dependencies { anvil(projects.anvilcodegen) api(projects.features.messages.api) implementation(projects.libraries.androidutils) + implementation(projects.libraries.androidtools.api) implementation(projects.libraries.core) implementation(projects.libraries.architecture) implementation(projects.libraries.matrix.api) @@ -64,6 +65,7 @@ dependencies { testImplementation(libs.molecule.runtime) testImplementation(libs.test.truth) testImplementation(libs.test.turbine) + testImplementation(projects.libraries.androidtools.test) testImplementation(projects.libraries.matrix.test) testImplementation(projects.libraries.dateformatter.test) testImplementation(projects.features.networkmonitor.test) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/local/AndroidLocalMediaFactory.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/local/AndroidLocalMediaFactory.kt index 7500f0d91e..c231825524 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/local/AndroidLocalMediaFactory.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/local/AndroidLocalMediaFactory.kt @@ -21,7 +21,7 @@ import android.net.Uri import androidx.core.net.toUri import com.squareup.anvil.annotations.ContributesBinding import io.element.android.features.messages.impl.timeline.util.FileExtensionExtractor -import io.element.android.features.messages.impl.timeline.util.FileSizeFormatter +import io.element.android.libraries.androidtools.api.FileSizeFormatter import io.element.android.libraries.androidutils.file.getFileName import io.element.android.libraries.androidutils.file.getFileSize import io.element.android.libraries.androidutils.file.getMimeType diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/factories/event/TimelineItemContentMessageFactory.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/factories/event/TimelineItemContentMessageFactory.kt index c99ab46ab1..db5ee8190e 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/factories/event/TimelineItemContentMessageFactory.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/factories/event/TimelineItemContentMessageFactory.kt @@ -25,8 +25,8 @@ import io.element.android.features.messages.impl.timeline.model.event.TimelineIt import io.element.android.features.messages.impl.timeline.model.event.TimelineItemUnknownContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemVideoContent import io.element.android.features.messages.impl.timeline.util.FileExtensionExtractor -import io.element.android.features.messages.impl.timeline.util.FileSizeFormatter import io.element.android.features.messages.impl.timeline.util.toHtmlDocument +import io.element.android.libraries.androidtools.api.FileSizeFormatter import io.element.android.libraries.core.mimetype.MimeTypes import io.element.android.libraries.matrix.api.timeline.item.event.EmoteMessageType import io.element.android.libraries.matrix.api.timeline.item.event.FileMessageType diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/fixtures/timelineItemsFactory.kt b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/fixtures/timelineItemsFactory.kt index beb37f8e51..6e2bf33477 100644 --- a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/fixtures/timelineItemsFactory.kt +++ b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/fixtures/timelineItemsFactory.kt @@ -32,7 +32,7 @@ import io.element.android.features.messages.impl.timeline.factories.virtual.Time import io.element.android.features.messages.impl.timeline.factories.virtual.TimelineItemVirtualFactory import io.element.android.features.messages.impl.timeline.groups.TimelineItemGrouper import io.element.android.features.messages.impl.timeline.util.FileExtensionExtractorWithoutValidation -import io.element.android.features.messages.timeline.FakeFileSizeFormatter +import io.element.android.libraries.androidtools.test.FakeFileSizeFormatter import io.element.android.libraries.dateformatter.test.FakeDaySeparatorFormatter import io.element.android.libraries.eventformatter.api.TimelineEventFormatter import io.element.android.libraries.matrix.api.timeline.item.event.EventTimelineItem diff --git a/libraries/androidtools/api/build.gradle.kts b/libraries/androidtools/api/build.gradle.kts new file mode 100644 index 0000000000..aeaec3ad30 --- /dev/null +++ b/libraries/androidtools/api/build.gradle.kts @@ -0,0 +1,23 @@ +/* + * 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("io.element.android-library") +} + +android { + namespace = "io.element.android.libraries.androidtools.api" +} diff --git a/libraries/androidtools/api/src/main/kotlin/io/element/android/libraries/androidtools/api/FileSizeFormatter.kt b/libraries/androidtools/api/src/main/kotlin/io/element/android/libraries/androidtools/api/FileSizeFormatter.kt new file mode 100644 index 0000000000..6c67d9a588 --- /dev/null +++ b/libraries/androidtools/api/src/main/kotlin/io/element/android/libraries/androidtools/api/FileSizeFormatter.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.androidtools.api + +interface FileSizeFormatter { + /** + * Formats a content size to be in the form of bytes, kilobytes, megabytes, etc. + */ + fun format(fileSize: Long): String +} diff --git a/libraries/androidtools/impl/build.gradle.kts b/libraries/androidtools/impl/build.gradle.kts new file mode 100644 index 0000000000..5b3b85036f --- /dev/null +++ b/libraries/androidtools/impl/build.gradle.kts @@ -0,0 +1,42 @@ +/* + * 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("io.element.android-library") + alias(libs.plugins.ksp) + alias(libs.plugins.anvil) +} + +anvil { + generateDaggerFactories.set(true) +} + +android { + namespace = "io.element.android.libraries.androidtools.impl" + + dependencies { + anvil(projects.anvilcodegen) + implementation(libs.dagger) + implementation(projects.libraries.di) + implementation(projects.anvilannotations) + + api(projects.libraries.androidtools.api) + + testImplementation(libs.test.junit) + testImplementation(libs.test.truth) + testImplementation(projects.libraries.androidtools.test) + } +} diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/util/FileSizeFormatter.kt b/libraries/androidtools/impl/src/main/kotlin/io/element/android/libraries/androidtools/impl/AndroidFileSizeFormatter.kt similarity index 82% rename from features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/util/FileSizeFormatter.kt rename to libraries/androidtools/impl/src/main/kotlin/io/element/android/libraries/androidtools/impl/AndroidFileSizeFormatter.kt index 4ede9b7f21..5a57c1d904 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/util/FileSizeFormatter.kt +++ b/libraries/androidtools/impl/src/main/kotlin/io/element/android/libraries/androidtools/impl/AndroidFileSizeFormatter.kt @@ -14,22 +14,16 @@ * limitations under the License. */ -package io.element.android.features.messages.impl.timeline.util +package io.element.android.libraries.androidtools.impl import android.content.Context import android.text.format.Formatter import com.squareup.anvil.annotations.ContributesBinding +import io.element.android.libraries.androidtools.api.FileSizeFormatter import io.element.android.libraries.di.AppScope import io.element.android.libraries.di.ApplicationContext import javax.inject.Inject -interface FileSizeFormatter { - /** - * Formats a content size to be in the form of bytes, kilobytes, megabytes, etc. - */ - fun format(fileSize: Long): String -} - @ContributesBinding(AppScope::class) class AndroidFileSizeFormatter @Inject constructor(@ApplicationContext private val context: Context) : FileSizeFormatter { override fun format(fileSize: Long): String { diff --git a/libraries/androidtools/test/build.gradle.kts b/libraries/androidtools/test/build.gradle.kts new file mode 100644 index 0000000000..8e045d6e01 --- /dev/null +++ b/libraries/androidtools/test/build.gradle.kts @@ -0,0 +1,27 @@ +/* + * 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("io.element.android-library") +} + +android { + namespace = "io.element.android.libraries.androidtools.test" + + dependencies { + api(projects.libraries.androidtools.api) + } +} diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/timeline/FakeFileSizeFormatter.kt b/libraries/androidtools/test/src/main/kotlin/io/element/android/libraries/androidtools/test/FakeFileSizeFormatter.kt similarity index 84% rename from features/messages/impl/src/test/kotlin/io/element/android/features/messages/timeline/FakeFileSizeFormatter.kt rename to libraries/androidtools/test/src/main/kotlin/io/element/android/libraries/androidtools/test/FakeFileSizeFormatter.kt index 4ff65b0146..d316510ec8 100644 --- a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/timeline/FakeFileSizeFormatter.kt +++ b/libraries/androidtools/test/src/main/kotlin/io/element/android/libraries/androidtools/test/FakeFileSizeFormatter.kt @@ -14,9 +14,9 @@ * limitations under the License. */ -package io.element.android.features.messages.timeline +package io.element.android.libraries.androidtools.test -import io.element.android.features.messages.impl.timeline.util.FileSizeFormatter +import io.element.android.libraries.androidtools.api.FileSizeFormatter class FakeFileSizeFormatter : FileSizeFormatter { override fun format(fileSize: Long): String {