Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
Use Context instead of Application in AndroidResourcesHelper so…
Browse files Browse the repository at this point in the history
… it can be used with Paparazzi (LayoutLib does can't cas `applicationContext` to `Application`)
  • Loading branch information
jmartinesp committed Nov 30, 2023
1 parent 9daebca commit 9a480d5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ interface HtmlConverter {
mentionDisplayHandler: MentionDisplayHandler?,
isMention: ((text: String, url: String) -> Boolean)? = null,
): HtmlConverter {
val resourcesProvider =
AndroidResourcesHelper(context.applicationContext as Application)
val resourcesProvider = AndroidResourcesHelper(context)
return AndroidHtmlConverter(provideHtmlToSpansParser = { html ->
HtmlToSpansParser(
resourcesHelper = resourcesProvider,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.element.android.wysiwyg.utils

import android.app.Application
import android.content.Context
import android.util.DisplayMetrics
import androidx.annotation.ColorRes
import androidx.annotation.Dimension
Expand All @@ -21,18 +21,18 @@ internal interface ResourcesHelper {
* This class provides access to Android resources needed to convert HTML to spans.
*/
internal class AndroidResourcesHelper(
private val application: Application,
private val context: Context,
) : ResourcesHelper {

override fun getDisplayMetrics(): DisplayMetrics {
return application.resources.displayMetrics
return context.resources.displayMetrics
}

override fun dpToPx(dp: Int): Float {
return dp * getDisplayMetrics().density
}

override fun getColor(colorId: Int): Int {
return ResourcesCompat.getColor(application.resources, colorId, application.theme)
return ResourcesCompat.getColor(context.resources, colorId, context.theme)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class HtmlToSpansParserTest {
val app = RuntimeEnvironment.getApplication()
val styleConfig = createFakeStyleConfig()
return HtmlToSpansParser(
resourcesHelper = AndroidResourcesHelper(application = app),
resourcesHelper = AndroidResourcesHelper(context = app),
html = html,
styleConfig = styleConfig,
mentionDisplayHandler = mentionDisplayHandler,
Expand Down

0 comments on commit 9a480d5

Please sign in to comment.