diff options
author | Allan Wang <me@allanwang.ca> | 2017-12-21 02:16:34 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-21 02:16:34 -0500 |
commit | d683cae6ffe644a9f63eea6cf3b7e59d2bde617b (patch) | |
tree | 517fe1d44c27084ccd87507d9804ba28f15c1647 /app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt | |
parent | 82f9aca96493316bc62008f2b3167d34a6029b38 (diff) | |
download | frost-d683cae6ffe644a9f63eea6cf3b7e59d2bde617b.tar.gz frost-d683cae6ffe644a9f63eea6cf3b7e59d2bde617b.tar.bz2 frost-d683cae6ffe644a9f63eea6cf3b7e59d2bde617b.zip |
Enhancement/fragment interface (#564)
* Begin fragment interfaces and themable contracts
* Prepare swiperefresh interface
* Snapshot
* Add compilable version
* Revamp once more
* Finalize layouts
* Cleanup
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt | 77 |
1 files changed, 47 insertions, 30 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt index c41964cd..0dbbacbc 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt @@ -1,5 +1,6 @@ package com.pitchedapps.frost.activities +import android.annotation.SuppressLint import android.content.Intent import android.graphics.PointF import android.net.Uri @@ -18,15 +19,14 @@ import ca.allanwang.kau.utils.* import com.mikepenz.community_material_typeface_library.CommunityMaterial import com.mikepenz.google_material_typeface_library.GoogleMaterial import com.pitchedapps.frost.R -import com.pitchedapps.frost.contracts.ActivityWebContract -import com.pitchedapps.frost.contracts.FileChooserContract -import com.pitchedapps.frost.contracts.FileChooserDelegate -import com.pitchedapps.frost.contracts.VideoViewHolder +import com.pitchedapps.frost.contracts.* import com.pitchedapps.frost.enums.OverlayContext import com.pitchedapps.frost.facebook.* import com.pitchedapps.frost.utils.* +import com.pitchedapps.frost.views.FrostContentWeb import com.pitchedapps.frost.views.FrostVideoViewer -import com.pitchedapps.frost.web.FrostWebView +import com.pitchedapps.frost.views.FrostWebView +import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable import okhttp3.HttpUrl @@ -56,7 +56,7 @@ class FrostWebActivity : WebOverlayActivityBase(false) { * and pop a dialog giving the user the option to copy the shared text */ var disposable: Disposable? = null - disposable = frostWeb.web.refreshObservable.subscribe { + disposable = content.refreshObservable.subscribe { disposable?.dispose() materialDialogThemed { title(R.string.invalid_share_url) @@ -98,26 +98,36 @@ class WebOverlayBasicActivity : WebOverlayActivityBase(true) */ class WebOverlayActivity : WebOverlayActivityBase(false) +@SuppressLint("Registered") open class WebOverlayActivityBase(private val forceBasicAgent: Boolean) : BaseActivity(), - ActivityWebContract, VideoViewHolder, FileChooserContract by FileChooserDelegate() { + ActivityContract, FrostContentContainer, + VideoViewHolder, FileChooserContract by FileChooserDelegate() { override val frameWrapper: FrameLayout by bindView(R.id.frame_wrapper) val toolbar: Toolbar by bindView(R.id.overlay_toolbar) - val frostWeb: FrostWebView by bindView(R.id.overlay_frost_webview) + val content: FrostContentWeb by bindView(R.id.frost_content_web) + val web: FrostWebView + get() = content.coreView val coordinator: CoordinatorLayout by bindView(R.id.overlay_main_content) - inline val urlTest: String? + private inline val urlTest: String? get() = intent.extras?.getString(ARG_URL) ?: intent.dataString - open val url: String + override val baseUrl: String get() = (intent.extras?.getString(ARG_URL) ?: intent.dataString).formattedFbUrl - inline val userId: Long + override val baseEnum: FbItem? = null + + private inline val userId: Long get() = intent.extras?.getLong(ARG_USER_ID, Prefs.userId) ?: Prefs.userId - inline val overlayContext: OverlayContext? + private inline val overlayContext: OverlayContext? get() = intent.extras?.getSerializable(ARG_OVERLAY_CONTEXT) as OverlayContext? + override fun setTitle(title: String) { + toolbar.title = title + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) if (urlTest == null) { @@ -136,17 +146,24 @@ open class WebOverlayActivityBase(private val forceBasicAgent: Boolean) : BaseAc setFrostColors(toolbar, themeWindow = false) coordinator.setBackgroundColor(Prefs.bgColor.withAlpha(255)) - frostWeb.setupWebview(url) - if (forceBasicAgent) - frostWeb.web.userAgentString = USER_AGENT_BASIC - frostWeb.web.addTitleListener({ toolbar.title = it }) - Prefs.prevId = Prefs.userId - if (userId != Prefs.userId) FbCookie.switchUser(userId) { frostWeb.web.loadBaseUrl() } - else frostWeb.web.loadBaseUrl() - if (Showcase.firstWebOverlay) { - coordinator.frostSnackbar(R.string.web_overlay_swipe_hint) { - duration = Snackbar.LENGTH_INDEFINITE - setAction(R.string.kau_got_it) { _ -> this.dismiss() } + content.bind(this) + web.reloadBase(true) + + content.titleObservable + .observeOn(AndroidSchedulers.mainThread()) + .subscribe { toolbar.title = it } + + with(web) { + if (forceBasicAgent) + userAgentString = USER_AGENT_BASIC + Prefs.prevId = Prefs.userId + if (userId != Prefs.userId) FbCookie.switchUser(userId) { reloadBase(true) } + else reloadBase(true) + if (Showcase.firstWebOverlay) { + coordinator.frostSnackbar(R.string.web_overlay_swipe_hint) { + duration = Snackbar.LENGTH_INDEFINITE + setAction(R.string.kau_got_it) { _ -> this.dismiss() } + } } } @@ -165,15 +182,15 @@ open class WebOverlayActivityBase(private val forceBasicAgent: Boolean) : BaseAc super.onNewIntent(intent) val newUrl = (intent.extras?.getString(ARG_URL) ?: intent.dataString ?: return).formattedFbUrl L.d("New intent") - if (url != newUrl) { + if (baseUrl != newUrl) { this.intent = intent - frostWeb.web.baseUrl = newUrl - frostWeb.web.loadBaseUrl() + content.baseUrl = newUrl + web.reloadBase(true) } } override fun backConsumer(): Boolean { - if (!frostWeb.onBackPressed()) + if (!web.onBackPressed()) finishSlideOut() return true } @@ -216,9 +233,9 @@ open class WebOverlayActivityBase(private val forceBasicAgent: Boolean) : BaseAc override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - R.id.action_copy_link -> copyToClipboard(frostWeb.web.url) - R.id.action_share -> shareText(frostWeb.web.url) - else -> if (!OverlayContext.onOptionsItemSelected(frostWeb.web, item.itemId)) + R.id.action_copy_link -> copyToClipboard(web.currentUrl) + R.id.action_share -> shareText(web.currentUrl) + else -> if (!OverlayContext.onOptionsItemSelected(web, item.itemId)) return super.onOptionsItemSelected(item) } return true |