-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Communication
: Fix link rendering for attachments and show uploaded…
… images in chat (#109) Co-authored-by: Martin Felber <[email protected]>
- Loading branch information
1 parent
aafd80b
commit 9b6c193
Showing
16 changed files
with
379 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 0 additions & 61 deletions
61
...src/main/kotlin/de/tum/informatics/www1/artemis/native_app/core/ui/CourseImageProvider.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...lin/de/tum/informatics/www1/artemis/native_app/core/ui/remote_images/BaseImageProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package de.tum.informatics.www1.artemis.native_app.core.ui.remote_images | ||
|
||
import android.content.Context | ||
import coil.ImageLoader | ||
import coil.request.ImageRequest | ||
|
||
interface BaseImageProvider { | ||
fun createImageRequest( | ||
context: Context, | ||
imagePath: String, | ||
serverUrl: String, | ||
authorizationToken: String, | ||
memoryCacheKey: String? = null | ||
): ImageRequest | ||
|
||
fun createImageLoader(context: Context, authorizationToken: String): ImageLoader | ||
} |
36 changes: 36 additions & 0 deletions
36
...n/de/tum/informatics/www1/artemis/native_app/core/ui/remote_images/CourseImageProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package de.tum.informatics.www1.artemis.native_app.core.ui.remote_images | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.compositionLocalOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.graphics.painter.Painter | ||
import androidx.compose.ui.platform.LocalContext | ||
import coil.compose.rememberAsyncImagePainter | ||
|
||
val LocalCourseImageProvider = compositionLocalOf<CourseImageProvider> { DefaultCourseImageProvider } | ||
|
||
interface CourseImageProvider { | ||
@Composable | ||
fun rememberCourseImagePainter( | ||
courseIconPath: String, | ||
serverUrl: String, | ||
authorizationToken: String | ||
): Painter | ||
} | ||
|
||
private object DefaultCourseImageProvider : CourseImageProvider { | ||
private val imageProvider = DefaultImageProvider() | ||
|
||
@Composable | ||
override fun rememberCourseImagePainter( | ||
courseIconPath: String, | ||
serverUrl: String, | ||
authorizationToken: String | ||
): Painter { | ||
val context = LocalContext.current | ||
val imageRequest = remember { | ||
imageProvider.createImageRequest(context, courseIconPath, serverUrl, authorizationToken) | ||
} | ||
return rememberAsyncImagePainter(model = imageRequest) | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
.../de/tum/informatics/www1/artemis/native_app/core/ui/remote_images/DefaultImageProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package de.tum.informatics.www1.artemis.native_app.core.ui.remote_images | ||
|
||
import android.content.Context | ||
import coil.ImageLoader | ||
import coil.request.ImageRequest | ||
import io.ktor.http.HttpHeaders | ||
import io.ktor.http.URLBuilder | ||
import io.ktor.http.appendPathSegments | ||
|
||
class DefaultImageProvider : BaseImageProvider { | ||
override fun createImageRequest( | ||
context: Context, | ||
imagePath: String, | ||
serverUrl: String, | ||
authorizationToken: String, | ||
memoryCacheKey: String? | ||
): ImageRequest { | ||
val imageUrl = URLBuilder(serverUrl).appendPathSegments(imagePath).buildString() | ||
|
||
val builder = ImageRequest.Builder(context) | ||
.addHeader(HttpHeaders.Cookie, "jwt=$authorizationToken") | ||
.data(imageUrl) | ||
|
||
memoryCacheKey?.let { | ||
builder.memoryCacheKey(it) | ||
} | ||
return builder.build() | ||
} | ||
|
||
override fun createImageLoader( | ||
context: Context, | ||
authorizationToken: String | ||
): ImageLoader { | ||
return ImageLoader.Builder(context) | ||
.okHttpClient { | ||
okhttp3.OkHttpClient.Builder() | ||
.addInterceptor { chain -> | ||
val request = chain.request().newBuilder() | ||
.addHeader(HttpHeaders.Cookie, "jwt=$authorizationToken") | ||
.build() | ||
chain.proceed(request) | ||
} | ||
.build() | ||
} | ||
.build() | ||
} | ||
} |
Oops, something went wrong.