Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 13 additions & 23 deletions app/src/main/java/com/nextcloud/ui/fileactions/ClientIntegration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@ package com.nextcloud.ui.fileactions

import android.content.Context
import android.content.Intent
import android.graphics.Canvas
import android.graphics.drawable.PictureDrawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.graphics.createBitmap
import androidx.core.graphics.drawable.toDrawable
import androidx.core.net.toUri
import androidx.lifecycle.lifecycleScope
import com.google.gson.Gson
Expand Down Expand Up @@ -81,31 +77,25 @@ class ClientIntegration(
}
text.text = endpoint.name

val px = DisplayUtils.convertDpToPixel(
context.resources.getDimension(R.dimen.iconized_single_line_item_icon_size),
context
)

if (endpoint.icon != null) {
sheet.lifecycleScope.launch(Dispatchers.IO) {
val client = OwnCloudClientManagerFactory.getDefaultSingleton()
.getNextcloudClientFor(user.toOwnCloudAccount(), context)

val drawable =
GlideHelper.getDrawable(context, client, client.baseUri.toString() + endpoint.icon)
?.mutate()

val px = DisplayUtils.convertDpToPixel(
context.resources.getDimension(R.dimen.iconized_single_line_item_icon_size),
context
)
val returnedBitmap =
createBitmap(drawable?.intrinsicWidth ?: px, drawable?.intrinsicHeight ?: px)

val canvas = Canvas(returnedBitmap)
canvas.drawPicture((drawable as PictureDrawable).picture)

val d = returnedBitmap.toDrawable(context.resources)

val tintedDrawable = viewThemeUtils.platform.tintDrawable(
val drawable = GlideHelper.fetchDrawable(
context,
d
)
client,
client.baseUri.toString() + endpoint.icon,
width = px,
height = px
)?.mutate()

val tintedDrawable = drawable?.let { viewThemeUtils.platform.tintDrawable(context, it) }

withContext(Dispatchers.Main) {
icon.setImageDrawable(tintedDrawable)
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/java/com/nextcloud/utils/GlideHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import com.nextcloud.common.NextcloudClient
import com.nextcloud.utils.LinkHelper.validateAndGetURL
import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.utils.svg.SvgSoftwareLayerSetter
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
* Utility object for loading images (including SVGs) using Glide.
Expand Down Expand Up @@ -178,6 +180,25 @@ object GlideHelper {
fun getDrawable(context: Context, client: NextcloudClient?, urlString: String?): Drawable? =
createRequestBuilder<Drawable>(context, client, urlString)?.submit()?.get()

@Suppress("TooGenericExceptionCaught")
suspend fun fetchDrawable(
context: Context,
client: NextcloudClient?,
urlString: String?,
width: Int = Target.SIZE_ORIGINAL,
height: Int = Target.SIZE_ORIGINAL
): Drawable? = withContext(Dispatchers.IO) {
try {
createRequestBuilder<Drawable>(context, client, urlString)
?.override(width, height)
?.submit()
?.get()
} catch (e: Exception) {
Log_OC.e("GlideHelper", "fetchDrawable failed", e)
null
}
}

fun <T> loadIntoTarget(
context: Context,
client: NextcloudClient?,
Expand Down
Loading