diff options
author | Allan Wang <me@allanwang.ca> | 2017-12-21 02:16:34 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-21 02:16:34 -0500 |
commit | d683cae6ffe644a9f63eea6cf3b7e59d2bde617b (patch) | |
tree | 517fe1d44c27084ccd87507d9804ba28f15c1647 /app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt | |
parent | 82f9aca96493316bc62008f2b3167d34a6029b38 (diff) | |
download | frost-d683cae6ffe644a9f63eea6cf3b7e59d2bde617b.tar.gz frost-d683cae6ffe644a9f63eea6cf3b7e59d2bde617b.tar.bz2 frost-d683cae6ffe644a9f63eea6cf3b7e59d2bde617b.zip |
Enhancement/fragment interface (#564)
* Begin fragment interfaces and themable contracts
* Prepare swiperefresh interface
* Snapshot
* Add compilable version
* Revamp once more
* Finalize layouts
* Cleanup
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt | 92 |
1 files changed, 0 insertions, 92 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt deleted file mode 100644 index f6d64ab7..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt +++ /dev/null @@ -1,92 +0,0 @@ -package com.pitchedapps.frost.web - -import android.annotation.SuppressLint -import android.content.Context -import android.graphics.Color -import android.os.Build -import android.support.v4.widget.SwipeRefreshLayout -import android.util.AttributeSet -import android.view.View -import android.widget.FrameLayout -import android.widget.ProgressBar -import ca.allanwang.kau.utils.* -import com.pitchedapps.frost.R -import com.pitchedapps.frost.facebook.FbItem -import com.pitchedapps.frost.facebook.USER_AGENT_BASIC -import com.pitchedapps.frost.utils.Prefs -import com.pitchedapps.frost.utils.frostDownload -import io.reactivex.android.schedulers.AndroidSchedulers - -/** - * Created by Allan Wang on 2017-06-01. - */ -class FrostWebView @JvmOverloads constructor( - context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0 -) : FrameLayout(context, attrs, defStyleAttr, defStyleRes), SwipeRefreshLayout.OnRefreshListener { - - val refresh: SwipeRefreshLayout by bindView(R.id.swipe_refresh) - val web: FrostWebViewCore by bindView(R.id.frost_webview_core) - val progress: ProgressBar by bindView(R.id.progress_bar) - - init { - inflate(getContext(), R.layout.swipe_webview, this) - progress.tint(Prefs.textColor.withAlpha(180)) - refresh.setColorSchemeColors(Prefs.iconColor) - refresh.setProgressBackgroundColorSchemeColor(Prefs.headerColor.withAlpha(255)) - web.progressObservable.observeOn(AndroidSchedulers.mainThread()).subscribe { - progress.invisibleIf(it == 100) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) progress.setProgress(it, true) - else progress.progress = it - } - web.refreshObservable.observeOn(AndroidSchedulers.mainThread()).subscribe { - refresh.isRefreshing = it - refresh.isEnabled = true - } - refresh.setOnRefreshListener(this) - addOnAttachStateChangeListener(object : OnAttachStateChangeListener { - override fun onViewDetachedFromWindow(v: View) { - web.visible() - } - - override fun onViewAttachedToWindow(v: View) {} - }) - } - - @SuppressLint("SetJavaScriptEnabled") - fun setupWebview(url: String, enum: FbItem? = null) { - with(web) { - baseUrl = url - baseEnum = enum - with(settings) { - javaScriptEnabled = true - if (url.shouldUseBasicAgent) - userAgentString = USER_AGENT_BASIC - allowFileAccess = true - textZoom = Prefs.webTextScaling - } - setLayerType(View.LAYER_TYPE_HARDWARE, null) - frostWebClient = baseEnum?.webClient?.invoke(this) ?: FrostWebViewClient(this) - webViewClient = frostWebClient - webChromeClient = FrostChromeClient(this) - addJavascriptInterface(FrostJSI(this), "Frost") - setBackgroundColor(Color.TRANSPARENT) - setDownloadListener(context::frostDownload) - } - } - - //Some urls have postJavascript injections so make sure we load the base url - override fun onRefresh() { - when (web.baseUrl) { - FbItem.MENU.url -> web.loadBaseUrl(true) - else -> web.reload(true) - } - } - - fun onBackPressed(): Boolean { - if (web.canGoBack()) { - web.goBack() - return true - } - return false - } -}
\ No newline at end of file |