From d683cae6ffe644a9f63eea6cf3b7e59d2bde617b Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Thu, 21 Dec 2017 02:16:34 -0500 Subject: Enhancement/fragment interface (#564) * Begin fragment interfaces and themable contracts * Prepare swiperefresh interface * Snapshot * Add compilable version * Revamp once more * Finalize layouts * Cleanup --- .../com/pitchedapps/frost/fragments/WebFragment.kt | 133 --------------------- 1 file changed, 133 deletions(-) delete mode 100644 app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt (limited to 'app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt deleted file mode 100644 index f1b76e57..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt +++ /dev/null @@ -1,133 +0,0 @@ -package com.pitchedapps.frost.fragments - -import android.content.Context -import android.os.Bundle -import android.support.v4.app.Fragment -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import ca.allanwang.kau.utils.withArguments -import com.pitchedapps.frost.activities.MainActivity -import com.pitchedapps.frost.enums.FeedSort -import com.pitchedapps.frost.facebook.FbItem -import com.pitchedapps.frost.utils.Prefs -import com.pitchedapps.frost.web.FrostWebView -import com.pitchedapps.frost.web.FrostWebViewCore -import io.reactivex.android.schedulers.AndroidSchedulers -import io.reactivex.disposables.Disposable - -/** - * Created by Allan Wang on 2017-05-29. - */ - - -class WebFragment : Fragment() { - - companion object { - private const val ARG_URL = "arg_url" - private const val ARG_URL_ENUM = "arg_url_enum" - private const val ARG_POSITION = "arg_position" - const val REQUEST_TEXT_ZOOM = 17 - const val REQUEST_REFRESH = 99 - - operator fun invoke(data: FbItem, position: Int) = WebFragment().apply { - val d = if (data == FbItem.FEED) FeedSort(Prefs.feedSort).item else data - withArguments( - ARG_URL to d.url, - ARG_POSITION to position, - ARG_URL_ENUM to d - ) - } - } - - // val refresh: SwipeRefreshLayout by lazy { frostWebView.refresh } - val web: FrostWebViewCore by lazy { frostWebView.web } - val url: String by lazy { arguments!!.getString(ARG_URL) } - val urlEnum: FbItem by lazy { arguments!!.getSerializable(ARG_URL_ENUM) as FbItem } - val position: Int by lazy { arguments!!.getInt(ARG_POSITION) } - lateinit var frostWebView: FrostWebView - private var firstLoad = true - private var activityDisposable: Disposable? = null - private var onCreateRunnable: ((fragment: WebFragment) -> Unit)? = null - - /** - * Hook to run action once fragment is properly created - * This is not saved elsewhere and may not always execute - */ - fun post(action: (fragment: WebFragment) -> Unit) { - onCreateRunnable = action - } - - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { - super.onCreateView(inflater, container, savedInstanceState) - frostWebView = FrostWebView(context!!) - frostWebView.setupWebview(url, urlEnum) - return frostWebView - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - onCreateRunnable?.invoke(this) - onCreateRunnable = null - firstLoad() - } - - override fun setUserVisibleHint(isVisibleToUser: Boolean) { - super.setUserVisibleHint(isVisibleToUser) - firstLoad() - } - - fun firstLoad() { - if (userVisibleHint && isVisible && firstLoad) { - web.loadBaseUrl() - firstLoad = false - } - } - - override fun onAttach(context: Context) { - super.onAttach(context) - activityDisposable?.dispose() - if (context is MainActivity) { - activityDisposable = context.webFragmentObservable.observeOn(AndroidSchedulers.mainThread()).subscribe { - /** - * Execute actions based on flags - * Flags between -10 and 10 are reserved for viewpager events - */ - when (it) { - REQUEST_REFRESH -> { - web.clearHistory() - web.loadBaseUrl(true) - } - position -> { - context.toolbar.setTitle(urlEnum.titleId) - pauseLoad = false - } - -(position + 1) -> { //we are moving away from this fragment - if (!frostWebView.refresh.isRefreshing) pauseLoad = true - } - REQUEST_TEXT_ZOOM -> frostWebView.web.settings.textZoom = Prefs.webTextScaling - } - } - } - } - - override fun onDetach() { - activityDisposable?.dispose() - super.onDetach() - } - - override fun onResume() { - super.onResume() - pauseLoad = false - firstLoad() - } - - var pauseLoad: Boolean - get() = web.settings.blockNetworkLoads - set(value) { - web.settings.blockNetworkLoads = value - } - - - fun onBackPressed() = frostWebView.onBackPressed() -} \ No newline at end of file -- cgit v1.2.3