Changes after review
This commit is contained in:
parent
1b054aca5b
commit
97efff8aa4
14 changed files with 130 additions and 63 deletions
|
|
@ -19,6 +19,7 @@ package io.element.android.x.architecture
|
|||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import com.bumble.appyx.core.node.Node
|
||||
import io.element.android.x.di.DaggerComponentOwner
|
||||
|
||||
inline fun <reified T : Any> Node.bindings() = bindings(T::class.java)
|
||||
inline fun <reified T : Any> Context.bindings() = bindings(T::class.java)
|
||||
|
|
@ -27,7 +28,7 @@ fun <T : Any> Context.bindings(klass: Class<T>): T {
|
|||
// search dagger components in the context hierarchy
|
||||
return generateSequence(this) { (it as? ContextWrapper)?.baseContext }
|
||||
.plus(applicationContext)
|
||||
.filterIsInstance<io.element.android.x.di.DaggerComponentOwner>()
|
||||
.filterIsInstance<DaggerComponentOwner>()
|
||||
.map { it.daggerComponent }
|
||||
.flatMap { if (it is Collection<*>) it else listOf(it) }
|
||||
.filterIsInstance(klass)
|
||||
|
|
@ -38,7 +39,7 @@ fun <T : Any> Context.bindings(klass: Class<T>): T {
|
|||
fun <T : Any> Node.bindings(klass: Class<T>): T {
|
||||
// search dagger components in node hierarchy
|
||||
return generateSequence(this, Node::parent)
|
||||
.filterIsInstance<io.element.android.x.di.DaggerComponentOwner>()
|
||||
.filterIsInstance<DaggerComponentOwner>()
|
||||
.map { it.daggerComponent }
|
||||
.flatMap { if (it is Collection<*>) it else listOf(it) }
|
||||
.filterIsInstance(klass)
|
||||
|
|
|
|||
|
|
@ -16,9 +16,7 @@
|
|||
|
||||
package io.element.android.x.matrix.media
|
||||
|
||||
import io.element.android.x.matrix.MatrixClient
|
||||
import org.matrix.rustcomponents.sdk.MediaSource
|
||||
import org.matrix.rustcomponents.sdk.mediaSourceFromUrl
|
||||
|
||||
interface MediaResolver {
|
||||
|
||||
|
|
@ -39,23 +37,3 @@ interface MediaResolver {
|
|||
|
||||
suspend fun resolve(meta: Meta): ByteArray?
|
||||
}
|
||||
|
||||
internal class RustMediaResolver(private val client: MatrixClient) : MediaResolver {
|
||||
|
||||
override suspend fun resolve(url: String?, kind: MediaResolver.Kind): ByteArray? {
|
||||
if (url.isNullOrEmpty()) return null
|
||||
val mediaSource = mediaSourceFromUrl(url)
|
||||
return resolve(MediaResolver.Meta(mediaSource, kind))
|
||||
}
|
||||
|
||||
override suspend fun resolve(meta: MediaResolver.Meta): ByteArray? {
|
||||
return when (meta.kind) {
|
||||
is MediaResolver.Kind.Content -> client.loadMediaContentForSource(meta.source)
|
||||
is MediaResolver.Kind.Thumbnail -> client.loadMediaThumbnailForSource(
|
||||
meta.source,
|
||||
meta.kind.width.toLong(),
|
||||
meta.kind.height.toLong()
|
||||
)
|
||||
}.getOrNull()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.x.matrix.media
|
||||
|
||||
import io.element.android.x.matrix.MatrixClient
|
||||
import org.matrix.rustcomponents.sdk.mediaSourceFromUrl
|
||||
|
||||
internal class RustMediaResolver(private val client: MatrixClient) : MediaResolver {
|
||||
|
||||
override suspend fun resolve(url: String?, kind: MediaResolver.Kind): ByteArray? {
|
||||
if (url.isNullOrEmpty()) return null
|
||||
val mediaSource = mediaSourceFromUrl(url)
|
||||
return resolve(MediaResolver.Meta(mediaSource, kind))
|
||||
}
|
||||
|
||||
override suspend fun resolve(meta: MediaResolver.Meta): ByteArray? {
|
||||
return when (meta.kind) {
|
||||
is MediaResolver.Kind.Content -> client.loadMediaContentForSource(meta.source)
|
||||
is MediaResolver.Kind.Thumbnail -> client.loadMediaThumbnailForSource(
|
||||
meta.source,
|
||||
meta.kind.width.toLong(),
|
||||
meta.kind.height.toLong()
|
||||
)
|
||||
}.getOrNull()
|
||||
}
|
||||
}
|
||||
30
libraries/matrixtest/build.gradle.kts
Normal file
30
libraries/matrixtest/build.gradle.kts
Normal file
|
|
@ -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("io.element.android-library")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "io.element.android.x.libraries.matrix.test"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(project(":libraries:matrix"))
|
||||
api(libs.coroutines.core)
|
||||
}
|
||||
18
libraries/matrixtest/src/main/AndroidManifest.xml
Normal file
18
libraries/matrixtest/src/main/AndroidManifest.xml
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<manifest/>
|
||||
|
|
@ -14,15 +14,16 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.element.android.x.matrix
|
||||
package io.element.android.x.libraries.matrixtest
|
||||
|
||||
import io.element.android.x.matrix.MatrixClient
|
||||
import io.element.android.x.matrix.core.RoomId
|
||||
import io.element.android.x.matrix.core.SessionId
|
||||
import io.element.android.x.matrix.core.UserId
|
||||
import io.element.android.x.matrix.media.FakeMediaResolver
|
||||
import io.element.android.x.libraries.matrixtest.media.FakeMediaResolver
|
||||
import io.element.android.x.matrix.media.MediaResolver
|
||||
import io.element.android.x.matrix.room.FakeMatrixRoom
|
||||
import io.element.android.x.matrix.room.InMemoryRoomSummaryDataSource
|
||||
import io.element.android.x.libraries.matrixtest.room.FakeMatrixRoom
|
||||
import io.element.android.x.libraries.matrixtest.room.InMemoryRoomSummaryDataSource
|
||||
import io.element.android.x.matrix.room.MatrixRoom
|
||||
import io.element.android.x.matrix.room.RoomSummaryDataSource
|
||||
import org.matrix.rustcomponents.sdk.MediaSource
|
||||
|
|
@ -14,7 +14,9 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.element.android.x.matrix.media
|
||||
package io.element.android.x.libraries.matrixtest.media
|
||||
|
||||
import io.element.android.x.matrix.media.MediaResolver
|
||||
|
||||
class FakeMediaResolver : MediaResolver {
|
||||
override suspend fun resolve(url: String?, kind: MediaResolver.Kind): ByteArray? {
|
||||
|
|
@ -14,11 +14,12 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.element.android.x.matrix.room
|
||||
package io.element.android.x.libraries.matrixtest.room
|
||||
|
||||
import io.element.android.x.matrix.core.EventId
|
||||
import io.element.android.x.matrix.core.RoomId
|
||||
import io.element.android.x.matrix.timeline.FakeMatrixTimeline
|
||||
import io.element.android.x.matrix.room.MatrixRoom
|
||||
import io.element.android.x.libraries.matrixtest.timeline.FakeMatrixTimeline
|
||||
import io.element.android.x.matrix.timeline.MatrixTimeline
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.emptyFlow
|
||||
|
|
@ -14,8 +14,10 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.element.android.x.matrix.room
|
||||
package io.element.android.x.libraries.matrixtest.room
|
||||
|
||||
import io.element.android.x.matrix.room.RoomSummary
|
||||
import io.element.android.x.matrix.room.RoomSummaryDataSource
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.emptyFlow
|
||||
|
||||
|
|
@ -14,9 +14,11 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.element.android.x.matrix.timeline
|
||||
package io.element.android.x.libraries.matrixtest.timeline
|
||||
|
||||
import io.element.android.x.matrix.core.EventId
|
||||
import io.element.android.x.matrix.timeline.MatrixTimeline
|
||||
import io.element.android.x.matrix.timeline.MatrixTimelineItem
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.emptyFlow
|
||||
import org.matrix.rustcomponents.sdk.TimelineListener
|
||||
|
|
@ -24,7 +26,7 @@ import org.matrix.rustcomponents.sdk.TimelineListener
|
|||
class FakeMatrixTimeline : MatrixTimeline {
|
||||
|
||||
override var callback: MatrixTimeline.Callback?
|
||||
get() = TODO("Not yet implemented")
|
||||
get() = null
|
||||
set(value) {}
|
||||
|
||||
override val hasMoreToLoad: Boolean
|
||||
|
|
@ -38,9 +40,7 @@ class FakeMatrixTimeline : MatrixTimeline {
|
|||
return Result.success(Unit)
|
||||
}
|
||||
|
||||
override fun addListener(timelineListener: TimelineListener) {
|
||||
//
|
||||
}
|
||||
override fun addListener(timelineListener: TimelineListener) = Unit
|
||||
|
||||
override fun initialize() = Unit
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue