From b10a745c7f0f46f4f014e1ba7fa71172d7442b83 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 8 Jul 2017 03:03:55 -0400 Subject: Dev-1.1.7 (#39) - feature overload + context menu * Address some crashlytics issues * Add text scaling * Kau fixes and cleanup * WIP formatter * Create in house url formatter * Update context menu * Update themes * Test proguard without R * Implement sharing and clean up context menu * Disable viewpager swipe on long press * Test keeping lib strings * Update changelog and proguard --- .../kotlin/com/pitchedapps/frost/web/FrostJSI.kt | 21 +++-- .../pitchedapps/frost/web/FrostWebContextMenu.kt | 100 --------------------- .../com/pitchedapps/frost/web/FrostWebView.kt | 6 +- .../pitchedapps/frost/web/FrostWebViewClient.kt | 2 +- .../com/pitchedapps/frost/web/FrostWebViewCore.kt | 6 +- .../pitchedapps/frost/web/FrostWebViewSearch.kt | 6 +- 6 files changed, 25 insertions(+), 116 deletions(-) delete mode 100644 app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebContextMenu.kt (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt index 68163333..3340e7d2 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt @@ -2,8 +2,10 @@ package com.pitchedapps.frost.web import android.content.Context import android.webkit.JavascriptInterface +import ca.allanwang.kau.logging.KL import com.pitchedapps.frost.MainActivity import com.pitchedapps.frost.dbflow.CookieModel +import com.pitchedapps.frost.facebook.formattedFbUrl import com.pitchedapps.frost.utils.* import io.reactivex.subjects.Subject @@ -11,7 +13,7 @@ import io.reactivex.subjects.Subject /** * Created by Allan Wang on 2017-06-01. */ -class FrostJSI(val context: Context, val webView: FrostWebViewCore, val contextMenu: FrostWebContextMenu) { +class FrostJSI(val context: Context, val webView: FrostWebViewCore) { val headerObservable: Subject? = (context as? MainActivity)?.headerBadgeObservable @@ -33,8 +35,17 @@ class FrostJSI(val context: Context, val webView: FrostWebViewCore, val contextM } @JavascriptInterface - fun contextMenu(url: String) { - contextMenu.post { contextMenu.show(url) } + fun contextMenu(url: String, text: String) { + webView.post { webView.context.showWebContextMenu(WebContext(url.formattedFbUrl, text)) } + } + + /** + * Get notified when a stationary long click starts or ends + * This will be used to toggle the main activities viewpager swipe + */ + @JavascriptInterface + fun longClick(start: Boolean) { + (webView.context as? MainActivity)?.viewPager?.enableSwipe = !start } @JavascriptInterface @@ -44,12 +55,12 @@ class FrostJSI(val context: Context, val webView: FrostWebViewCore, val contextM @JavascriptInterface fun emit(flag: Int) { - webView.post { webView.frostWebClient!!.emit(flag) } + webView.post { webView.frostWebClient.emit(flag) } } @JavascriptInterface fun handleHtml(html: String) { - webView.post { webView.frostWebClient!!.handleHtml(html) } + webView.post { webView.frostWebClient.handleHtml(html) } } @JavascriptInterface diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebContextMenu.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebContextMenu.kt deleted file mode 100644 index e0aa5ebd..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebContextMenu.kt +++ /dev/null @@ -1,100 +0,0 @@ -package com.pitchedapps.frost.web - -import android.content.Context -import android.support.constraint.ConstraintLayout -import android.support.constraint.ConstraintSet -import android.text.method.ScrollingMovementMethod -import android.util.AttributeSet -import android.widget.TextView -import ca.allanwang.kau.logging.KL -import ca.allanwang.kau.utils.* -import com.pitchedapps.frost.R -import com.pitchedapps.frost.utils.Prefs - -/** - * Created by Allan Wang on 2017-07-06. - */ -class FrostWebContextMenu @JvmOverloads constructor( - context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 -) : ConstraintLayout(context, attrs, defStyleAttr) { - - var url = "" - - val urlHolder = TextView(context, attrs, defStyleAttr) - - init { - layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT) - elevation = 20f - setBackgroundColor(0x80000000.toInt()) - gone() - - val tc = Prefs.textColor - val bg = Prefs.bgColor.colorToForeground(0.1f).withAlpha(255) - - urlHolder.apply { - isVerticalScrollBarEnabled = true - movementMethod = ScrollingMovementMethod() - maxHeight = 60.dpToPx - } - addView(urlHolder) - - //collection of items in our menu and their click event - val data = arrayOf( - R.string.copy_link to { context.copyToClipboard(url) } - ) - - //add views and extract ids - val views = data.map { - (textId, onClick) -> - val tv = TextView(context).apply { - text = context.string(textId) - setOnClickListener({ onClick(); close() }) - } - addView(tv) - tv - }.toMutableList() - - views.add(0, urlHolder) - - val ids = views.mapIndexed { index, textView -> - textView.apply { - id = 74329 + index //totally arbitrary - setTextColor(tc) - setBackgroundColor(bg) - } - KL.d("ID ${textView.text}") - textView.id - } - - //clone to set only after ids are set - val set = ConstraintSet() - set.clone(this) - - ids.forEach { - set.connect(it, ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START, 16) - set.connect(it, ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END, 16) - } - - - set.createVerticalChain(ConstraintSet.PARENT_ID, ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM, - ids.toIntArray(), null, ConstraintSet.CHAIN_PACKED) - - set.applyTo(this) - setOnClickListener { - close() - } - } - - fun close() { - transitionAuto() - gone() - } - - fun show(url: String) { - this.url = url - urlHolder.text = this.url - transitionAuto() - visible() - } - -} \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt index 64bdf888..5583c63d 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt @@ -28,7 +28,6 @@ class FrostWebView @JvmOverloads constructor( 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) - val contextMenu: FrostWebContextMenu by bindView(R.id.context_menu) init { inflate(getContext(), R.layout.swipe_webview, this) @@ -55,7 +54,7 @@ class FrostWebView @JvmOverloads constructor( @SuppressLint("SetJavaScriptEnabled") fun setupWebview(url: String, enum: FbTab? = null) { - with (web) { + with(web) { baseUrl = url baseEnum = enum with(settings) { @@ -63,12 +62,13 @@ class FrostWebView @JvmOverloads constructor( userAgentString = com.pitchedapps.frost.facebook.USER_AGENT_BASIC allowFileAccess = true defaultFontSize + textZoom = Prefs.webTextScaling } setLayerType(View.LAYER_TYPE_HARDWARE, null) frostWebClient = baseEnum?.webClient?.invoke(this) ?: FrostWebViewClient(this) webViewClient = frostWebClient webChromeClient = FrostChromeClient(this) - addJavascriptInterface(FrostJSI(context, this, contextMenu), "Frost") + addJavascriptInterface(FrostJSI(context, this), "Frost") setBackgroundColor(Color.TRANSPARENT) } } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt index 4484dcdb..16a4a092 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt @@ -62,7 +62,7 @@ open class FrostWebViewClient(val webCore: FrostWebViewCore) : WebViewClient() { webCore.jsInject(CssHider.HEADER, Prefs.themeInjector, JsAssets.CLICK_A.maybe(webCore.baseEnum != null), -// JsAssets.CONTEXT_A, + JsAssets.CONTEXT_A, callback = { refreshObservable.onNext(false) }) } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt index 76b04f23..1e023dca 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt @@ -1,15 +1,12 @@ package com.pitchedapps.frost.web import android.animation.ValueAnimator -import android.annotation.SuppressLint import android.content.Context -import android.graphics.Color import android.support.v4.view.NestedScrollingChild import android.support.v4.view.NestedScrollingChildHelper import android.support.v4.view.ViewCompat import android.util.AttributeSet import android.view.MotionEvent -import android.view.View import android.view.animation.DecelerateInterpolator import android.webkit.WebView import ca.allanwang.kau.utils.circularReveal @@ -17,7 +14,6 @@ import ca.allanwang.kau.utils.fadeIn import ca.allanwang.kau.utils.fadeOut import ca.allanwang.kau.utils.isVisible import com.pitchedapps.frost.facebook.FbTab -import com.pitchedapps.frost.facebook.USER_AGENT_BASIC import com.pitchedapps.frost.utils.Prefs import io.reactivex.Scheduler import io.reactivex.android.schedulers.AndroidSchedulers @@ -45,7 +41,7 @@ class FrostWebViewCore @JvmOverloads constructor( var baseUrl: String? = null var baseEnum: FbTab? = null //only viewpager items should pass the base enum - internal var frostWebClient: FrostWebViewClient? = null + internal lateinit var frostWebClient: FrostWebViewClient init { isNestedScrollingEnabled = true diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewSearch.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewSearch.kt index fb2e1851..d4d08958 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewSearch.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewSearch.kt @@ -14,6 +14,7 @@ import com.pitchedapps.frost.injectors.JsAssets import com.pitchedapps.frost.injectors.JsBuilder import com.pitchedapps.frost.injectors.jsInject import com.pitchedapps.frost.utils.L +import com.pitchedapps.frost.utils.Prefs import io.reactivex.schedulers.Schedulers import io.reactivex.subjects.PublishSubject import org.jetbrains.anko.runOnUiThread @@ -62,10 +63,10 @@ class FrostWebViewSearch(context: Context, val contract: SearchContract) : WebVi Jsoup.parse(it).select("a:not([rel*='keywords(']):not([href=#])[rel]").map { element -> //split text into separate items - L.i("Search element ${element.attr("href")}") + L.v("Search element ${element.attr("href")}") val texts = element.select("div").map { (it.ownText()) }.filter { it.isNotBlank() } val pair = Pair(texts, element.attr("href")) - L.i("Search element potential $pair") + L.v("Search element potential $pair") pair }.filter { it.first.isNotEmpty() } } @@ -135,6 +136,7 @@ class FrostWebViewSearch(context: Context, val contract: SearchContract) : WebVi } 1 -> { //something is not found in the search view; this is effectively useless L.eThrow("Search subject error; reverting to full overlay") + Prefs.searchBar = false searchSubject.onComplete() contract.searchOverlayDispose() } -- cgit v1.2.3