Skip to content

Commit

Permalink
fix: #406
Browse files Browse the repository at this point in the history
  • Loading branch information
FunkyMuse committed Jan 22, 2024
1 parent 89336a2 commit 0cb79bb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
alias(libs.plugins.ksp).apply(false)
alias(libs.plugins.test).apply(false)
alias(libs.plugins.spotless).apply(false)
alias(libs.plugins.dokka).apply(false)
alias(libs.plugins.dokka)
}

val Project.composeMetricsDir get() = layout.buildDirectory.asFile.get().absolutePath + "/compose_metrics"
Expand Down
11 changes: 3 additions & 8 deletions common/src/main/java/com/funkymuse/common/InMemoryCache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,12 @@ object InMemoryCache {
/**
* get the saved value addressed by the key
*/
fun get(key: String): Any? = map[key]
operator fun get(key: String): Any? = map[key]

/**
* check if have the value on the Given Key
*/
fun have(key: String) = map.containsKey(key)

/**
* check if have the value on the Given Key
*/
fun contains(key: String) = have(key)
fun contains(key: String) = map.containsKey(key)

/**
* Clear all the InMemoryCache
Expand All @@ -55,7 +50,7 @@ object InMemoryCache {
/**
* get Saved Data from memory, null if it os not exists
*/
fun <T> getFromMemory(key: String): T? = InMemoryCache.get(key) as? T
fun <T> getFromMemory(key: String): T? = InMemoryCache[key] as? T


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ object DefaultUserAgent {
var ua: String
try {
val constructor = WebSettings::class.java.getDeclaredConstructor(
Context::class.java, WebView::class.java)
Context::class.java, WebView::class.java
)
constructor.isAccessible = true
try {
val settings = constructor.newInstance(context, null)
Expand All @@ -29,18 +30,18 @@ object DefaultUserAgent {
}

@SuppressLint("NewApi")
private fun getWebSettingsDefaultUserAgent(context: Context): String {
return WebSettings.getDefaultUserAgent(context)
}
fun getWebSettingsDefaultUserAgent(context: Context): String =
WebSettings.getDefaultUserAgent(context)

@SuppressLint("PrivateApi")
private fun getUserAgent(context: Context): String {
fun getUserAgent(context: Context): String {
var userAgent: String
try {
@Suppress("UNCHECKED_CAST")
val clz = Class.forName("android.webkit.WebSettingsClassic") as Class<out WebSettings>
val constructor = clz.getDeclaredConstructor(
Context::class.java, Class.forName("android.webkit.WebViewClassic"))
Context::class.java, Class.forName("android.webkit.WebViewClassic")
)
constructor.isAccessible = true
try {
val settings = constructor.newInstance(context, null)
Expand Down

0 comments on commit 0cb79bb

Please sign in to comment.