diff options
author | Allan Wang <me@allanwang.ca> | 2018-01-07 04:44:18 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-07 04:44:18 -0500 |
commit | afe7437e0a0f6c315d383e0b6133b13a461c92af (patch) | |
tree | 3312b4841af831fe89a4a283fda306c490178961 /app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt | |
parent | 8aece5e3f9209d7c161410c304655f0aec2d6054 (diff) | |
download | frost-afe7437e0a0f6c315d383e0b6133b13a461c92af.tar.gz frost-afe7437e0a0f6c315d383e0b6133b13a461c92af.tar.bz2 frost-afe7437e0a0f6c315d383e0b6133b13a461c92af.zip |
Enhancement/debug (#605)
* Finalize debugger
* Add video logging
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt | 56 |
1 files changed, 52 insertions, 4 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt index 3cc10236..7fd2286c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt @@ -2,22 +2,24 @@ package com.pitchedapps.frost.web import android.annotation.SuppressLint import android.content.Context +import android.graphics.Bitmap import android.graphics.Color import android.util.AttributeSet import android.view.View -import android.webkit.CookieManager -import android.webkit.WebResourceRequest import android.webkit.WebView -import com.pitchedapps.frost.facebook.FB_USER_MATCHER import com.pitchedapps.frost.facebook.USER_AGENT_BASIC -import com.pitchedapps.frost.facebook.get +import com.pitchedapps.frost.injectors.CssAssets import com.pitchedapps.frost.injectors.CssHider import com.pitchedapps.frost.injectors.jsInject import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.Prefs +import com.pitchedapps.frost.utils.createFreshFile +import com.pitchedapps.frost.utils.iab.IS_FROST_PRO import com.pitchedapps.frost.utils.isFacebookUrl import org.jetbrains.anko.doAsync import org.jetbrains.anko.uiThread +import org.jetbrains.anko.withAlpha +import java.io.File /** * Created by Allan Wang on 2018-01-05. @@ -40,6 +42,31 @@ class DebugWebView @JvmOverloads constructor( settings.userAgentString = USER_AGENT_BASIC setLayerType(View.LAYER_TYPE_HARDWARE, null) webViewClient = DebugClient() + isDrawingCacheEnabled = true + } + + fun getScreenshot(output: File, callback: (Boolean) -> Unit) { + + if (!output.createFreshFile()) { + L.e { "Failed to create ${output.absolutePath} for debug screenshot" } + return callback(false) + } + doAsync { + var valid = true + try { + output.outputStream().use { + drawingCache.compress(Bitmap.CompressFormat.PNG, 100, it) + } + L.d { "Created screenshot at ${output.absolutePath}" } + } catch (e: Exception) { + L.e { "An error occurred ${e.message}" } + valid = false + } finally { + uiThread { + callback(valid) + } + } + } } private inner class DebugClient : BaseWebViewClient() { @@ -49,6 +76,27 @@ class DebugWebView @JvmOverloads constructor( onPageFinished(url) } + private fun injectBackgroundColor() { + setBackgroundColor( + if (url.isFacebookUrl) Prefs.bgColor.withAlpha(255) + else Color.WHITE) + } + + + override fun onPageCommitVisible(view: WebView, url: String?) { + super.onPageCommitVisible(view, url) + injectBackgroundColor() + if (url.isFacebookUrl) + view.jsInject( + CssAssets.ROUND_ICONS.maybe(Prefs.showRoundedIcons), + CssHider.CORE, + CssHider.COMPOSER.maybe(!Prefs.showComposer), + CssHider.PEOPLE_YOU_MAY_KNOW.maybe(!Prefs.showSuggestedFriends && IS_FROST_PRO), + CssHider.SUGGESTED_GROUPS.maybe(!Prefs.showSuggestedGroups && IS_FROST_PRO), + Prefs.themeInjector, + CssHider.NON_RECENT.maybe((url?.contains("?sk=h_chr") ?: false) + && Prefs.aggressiveRecents)) + } } }
\ No newline at end of file |