diff options
author | Allan Wang <me@allanwang.ca> | 2017-05-29 15:05:26 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2017-05-29 15:05:26 -0700 |
commit | e33120d454aeb72acc2c1315bddea31dd2f15bb2 (patch) | |
tree | 6754e8c5c9e8303b0943d1716560b31a0953361a /app/src/main/kotlin/com/pitchedapps/frost/fragments | |
parent | f83fb56dca63a06e4706e6cb404bca9c49e5dbe0 (diff) | |
download | frost-e33120d454aeb72acc2c1315bddea31dd2f15bb2.tar.gz frost-e33120d454aeb72acc2c1315bddea31dd2f15bb2.tar.bz2 frost-e33120d454aeb72acc2c1315bddea31dd2f15bb2.zip |
initial port
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/fragments')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt | 75 |
1 files changed, 75 insertions, 0 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 new file mode 100644 index 00000000..140d8df1 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt @@ -0,0 +1,75 @@ +package com.pitchedapps.frost.fragments + +import android.os.Bundle +import android.support.v4.app.Fragment +import android.support.v4.widget.SwipeRefreshLayout +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import butterknife.ButterKnife +import butterknife.Unbinder +import com.pitchedapps.frost.R +import com.pitchedapps.frost.facebook.FBURL +import com.pitchedapps.frost.utils.L +import com.pitchedapps.frost.utils.bindView +import com.pitchedapps.frost.utils.withBundle +import com.pitchedapps.frost.views.FrostWebView +import com.pitchedapps.frost.views.SwipeRefreshBase +import com.pitchedapps.frost.views.WebStatus + +/** + * Created by Allan Wang on 2017-05-29. + */ + + +class WebFragment : Fragment(), SwipeRefreshLayout.OnRefreshListener { + + override fun onRefresh() { + web.reload() + } + + companion object { + private val ARG_URL = "arg_url" + fun newInstance(url: String) = WebFragment().withBundle { b -> b.putString(ARG_URL, url) } + fun newInstance(url: FBURL = FBURL.FEED) = newInstance(url.url) + } + + val refresh: SwipeRefreshBase by bindView(R.id.swipe_refresh) + val web: FrostWebView by bindView(R.id.frost_webview) + lateinit var url: String + private lateinit var unbinder: Unbinder + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + url = arguments.getString(ARG_URL) + } + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { + super.onCreateView(inflater, container, savedInstanceState) + val view = inflater.inflate(R.layout.swipe_webview, container, false) + unbinder = ButterKnife.bind(this, view) + return view + } + + override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + web.observable.subscribe { + t: WebStatus -> + when (t) { + WebStatus.LOADED, WebStatus.ERROR -> refresh.isRefreshing = false + WebStatus.LOADING -> refresh.isRefreshing = true + } + } + refresh.setOnRefreshListener(this) + refresh.shouldSwipe = { + L.e("Y ${web.scrollY}") + SwipeRefreshBase.shouldScroll(web) + } + web.loadUrl(url) + } + + override fun onDestroyView() { + super.onDestroyView() + unbinder.unbind() + } +}
\ No newline at end of file |