aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-03 15:51:36 -0700
committerAllan Wang <me@allanwang.ca>2017-06-03 15:51:36 -0700
commit8ec65f55f85c730e97d5521c1443819435b98208 (patch)
tree6bd4350b3f6e5eda03c95c4a13fd7b7c7f50f2ac /app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt
parenta5aa87bbaef7d2c937cc89295942882d050c3b5c (diff)
downloadfrost-8ec65f55f85c730e97d5521c1443819435b98208.tar.gz
frost-8ec65f55f85c730e97d5521c1443819435b98208.tar.bz2
frost-8ec65f55f85c730e97d5521c1443819435b98208.zip
Add toolbar title listeners
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt20
1 files changed, 15 insertions, 5 deletions
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 b2260b6f..eaee60bc 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt
@@ -11,7 +11,9 @@ import android.view.MotionEvent
import android.view.View
import android.webkit.WebView
import com.pitchedapps.frost.events.FbAccountEvent
-import com.pitchedapps.frost.utils.ObservableContainer
+import io.reactivex.Scheduler
+import io.reactivex.android.schedulers.AndroidSchedulers
+import io.reactivex.disposables.Disposable
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.subjects.Subject
import org.greenrobot.eventbus.EventBus
@@ -27,20 +29,25 @@ import org.greenrobot.eventbus.ThreadMode
*/
class FrostWebViewCore @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
-) : WebView(context, attrs, defStyleAttr), NestedScrollingChild, ObservableContainer<Int> {
+) : WebView(context, attrs, defStyleAttr), NestedScrollingChild {
private val childHelper = NestedScrollingChildHelper(this)
private var lastY: Int = 0
private val scrollOffset = IntArray(2)
private val scrollConsumed = IntArray(2)
private var nestedOffsetY: Int = 0
- override val progressObservable: Subject<Int> //TODO see if we need this
+ val progressObservable: Subject<Int>
+ val titleObservable: Subject<String>
+
+ private val chromeClient: FrostChromeClient
var baseUrl: String? = null
var position: Int = -1
init {
isNestedScrollingEnabled = true
progressObservable = BehaviorSubject.create<Int>()
+ titleObservable = BehaviorSubject.create<String>()
+ chromeClient = FrostChromeClient(progressObservable, titleObservable)
setupWebview()
}
@@ -49,8 +56,8 @@ class FrostWebViewCore @JvmOverloads constructor(
settings.javaScriptEnabled = true
settings.domStorageEnabled = true
setLayerType(View.LAYER_TYPE_HARDWARE, null)
- setWebViewClient(FrostWebViewClient({position}))
- setWebChromeClient(FrostChromeClient(progressObservable))
+ setWebViewClient(FrostWebViewClient({ position }))
+ setWebChromeClient(chromeClient)
}
override fun loadUrl(url: String?) {
@@ -60,6 +67,9 @@ class FrostWebViewCore @JvmOverloads constructor(
fun loadBaseUrl() = loadUrl(baseUrl)
+ fun addTitleListener(subscriber: (title: String) -> Unit, scheduler: Scheduler = AndroidSchedulers.mainThread()): Disposable
+ = titleObservable.observeOn(scheduler).subscribe(subscriber)
+
override fun onTouchEvent(ev: MotionEvent): Boolean {
val event = MotionEvent.obtain(ev)
val action = MotionEventCompat.getActionMasked(event)