diff options
author | Allan Wang <me@allanwang.ca> | 2017-06-04 10:45:23 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2017-06-04 10:45:23 -0700 |
commit | 4b78e433e1f55b278623c84d1223e42cab875be6 (patch) | |
tree | 5c443851d2bd181d63148474be0f7e8bf8f4ff6c /app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt | |
parent | 6fa685433e23ce56286c3fbcae9cf1ef7a1a6e68 (diff) | |
download | frost-4b78e433e1f55b278623c84d1223e42cab875be6.tar.gz frost-4b78e433e1f55b278623c84d1223e42cab875be6.tar.bz2 frost-4b78e433e1f55b278623c84d1223e42cab875be6.zip |
Create activity refresh observable
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt index 39c93b01..3c8094aa 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt @@ -1,14 +1,17 @@ package com.pitchedapps.frost.fragments +import android.content.Context import android.os.Bundle import android.support.v4.widget.SwipeRefreshLayout import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import com.pitchedapps.frost.MainActivity import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.putString import com.pitchedapps.frost.web.FrostWebView import com.pitchedapps.frost.web.FrostWebViewCore +import io.reactivex.disposables.Disposable /** * Created by Allan Wang on 2017-05-29. @@ -22,11 +25,12 @@ class WebFragment : BaseFragment() { fun newInstance(position: Int, url: String) = BaseFragment.newInstance(WebFragment(), position).putString(ARG_URL, url) } - val refresh: SwipeRefreshLayout by lazy { frostWebView.refresh } +// val refresh: SwipeRefreshLayout by lazy { frostWebView.refresh } val web: FrostWebViewCore by lazy { frostWebView.web } lateinit var url: String lateinit private var frostWebView: FrostWebView private var firstLoad = true + private var refreshDisposable: Disposable? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -58,5 +62,21 @@ class WebFragment : BaseFragment() { } } + override fun onAttach(context: Context) { + super.onAttach(context) + refreshDisposable?.dispose() + if (context is MainActivity) + refreshDisposable = context.refreshObservable.subscribe { + web.clearHistory() + web.loadBaseUrl() + } + } + + override fun onDetach() { + refreshDisposable?.dispose() + L.d("F Detatch") + super.onDetach() + } + override fun onBackPressed() = frostWebView.onBackPressed() }
\ No newline at end of file |