1
0
mirror of https://github.com/AllanWang/Frost-for-Facebook.git synced 2024-11-08 12:02:33 +01:00

Add toolbar title listeners

This commit is contained in:
Allan Wang 2017-06-03 15:51:36 -07:00
parent a5aa87bbae
commit 8ec65f55f8
11 changed files with 70 additions and 45 deletions

View File

@ -1,8 +1,8 @@
[data-sigil="m_login_upsell"] { display: none !important; }
body, #root, #header, .aclb, ._55wo, ._1upc, input, ._2f9r { background: #f00 !important; }
body, #root, #header, .aclb, ._55wo, ._1upc, input, ._2f9r { background: #000 !important; }
button::before, .touch ._56bt, ._56be::before, .btnS, .touch::before, ._5xo2, ._5u5a::before { background: rgba(255, 51, 51, 0.1) !important; }
button::before, .touch ._56bt, ._56be::before, .btnS, .touch::before, ._5xo2, ._5u5a::before { background: rgba(26, 26, 26, 0.1) !important; }
._56bf, .touch .btn { border-radius: 0 !important; border: 0 !important; }
@ -10,16 +10,16 @@ button::before, .touch ._56bt, ._56be::before, .btnS, .touch::before, ._5xo2, ._
.touch .btnS { box-shadow: none !important; }
input, ._43mh, .touch .btn, a, .fcg, button, ._52j9, ._52jb, h1, h2, h3, h4, h5, h6 { color: #f0f !important; }
input, ._43mh, .touch .btn, a, .fcg, button, ._52j9, ._52jb, h1, h2, h3, h4, h5, h6 { color: #fff !important; }
::-webkit-input-placeholder { color: #f0f !important; }
::-webkit-input-placeholder { color: #fff !important; }
:-moz-placeholder { color: #f0f !important; }
:-moz-placeholder { color: #fff !important; }
::-moz-placeholder { color: #f0f !important; }
::-moz-placeholder { color: #fff !important; }
:-ms-input-placeholder { color: #f0f !important; }
:-ms-input-placeholder { color: #fff !important; }
._43mh::before, ._43mh::after { background: #f0f !important; }
._43mh::before, ._43mh::after { background: #fff !important; }
._1rrd { border: 1px solid #f0f !important; color: #f0f !important; }
._1rrd { border: 1px solid #fff !important; color: #fff !important; }

View File

@ -11,6 +11,7 @@ import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import android.view.Menu
import android.view.MenuItem
import android.view.ViewTreeObserver
import butterknife.ButterKnife
import co.zsmb.materialdrawerkt.builders.Builder
import co.zsmb.materialdrawerkt.builders.accountHeader
@ -26,9 +27,9 @@ import com.pitchedapps.frost.events.FbAccountEvent
import com.pitchedapps.frost.facebook.FbCookie.switchUser
import com.pitchedapps.frost.facebook.FbTab
import com.pitchedapps.frost.facebook.PROFILE_PICTURE_URL
import com.pitchedapps.frost.fragments.BaseFragment
import com.pitchedapps.frost.fragments.WebFragment
import com.pitchedapps.frost.utils.*
import io.reactivex.disposables.Disposable
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
@ -43,6 +44,7 @@ class MainActivity : AppCompatActivity() {
lateinit var drawer: Drawer
lateinit var drawerHeader: AccountHeader
val cookies: ArrayList<CookieModel> by lazy { cookies() }
var titleDisposable: Disposable? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -53,6 +55,11 @@ class MainActivity : AppCompatActivity() {
viewPager.adapter = adapter
viewPager.offscreenPageLimit = 5
viewPager.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() {
override fun onPageSelected(position: Int) {
super.onPageSelected(position)
updateTitleListener()
}
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
super.onPageScrolled(position, positionOffset, positionOffsetPixels)
val delta: Float by lazy { positionOffset * (255 - 128).toFloat() }
@ -72,6 +79,17 @@ class MainActivity : AppCompatActivity() {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show()
}
viewPager.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener{
override fun onGlobalLayout() {
viewPager.viewTreeObserver.removeOnGlobalLayoutListener(this)
updateTitleListener()
}
})
}
fun updateTitleListener() {
titleDisposable?.dispose()
titleDisposable = currentFragment.web.addTitleListener({ toolbar.title = it })
}
fun setupTabs() {
@ -144,8 +162,8 @@ class MainActivity : AppCompatActivity() {
super.onBackPressed()
}
val currentFragment: BaseFragment
get() = supportFragmentManager.findFragmentByTag("android:switcher:${R.id.container}:${viewPager.currentItem}") as BaseFragment
val currentFragment
get() = supportFragmentManager.findFragmentByTag("android:switcher:${R.id.container}:${viewPager.currentItem}") as WebFragment
inner class SectionsPagerAdapter(fm: FragmentManager, val pages: List<FbTab>) : FragmentPagerAdapter(fm) {

View File

@ -15,14 +15,17 @@ import com.pitchedapps.frost.web.FrostWebView
*/
class WebOverlayActivity : AppCompatActivity() {
val toolbar: Toolbar by bindView(R.id.toolbar)
val frostWeb: FrostWebView by bindView(R.id.frost_webview)
val toolbar: Toolbar by bindView(R.id.overlay_toolbar)
val frostWeb: FrostWebView by bindView(R.id.overlay_frost_webview)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_web_overlay)
ButterKnife.bind(this)
setSupportActionBar(toolbar)
supportActionBar?.setDisplayShowHomeEnabled(true)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
toolbar.setNavigationOnClickListener { onBackPressed() }
frostWeb.baseUrl = url()
frostWeb.web.loadBaseUrl()
SwipeBackHelper.onCreate(this)
@ -31,6 +34,7 @@ class WebOverlayActivity : AppCompatActivity() {
.setSwipeSensitivity(0.5f)
.setSwipeRelateEnable(true)
.setSwipeRelateOffset(300)
frostWeb.web.addTitleListener({ toolbar.title = it })
}
override fun onPostCreate(savedInstanceState: Bundle?) {

View File

@ -1,12 +1,7 @@
package com.pitchedapps.frost.fragments
import android.content.Context
import android.support.v4.app.Fragment
import com.pitchedapps.frost.utils.KeyPairObservable
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.putInt
import io.reactivex.disposables.Disposable
import io.reactivex.functions.Consumer
/**
* Created by Allan Wang on 2017-05-29.

View File

@ -30,6 +30,7 @@ fun Activity.cookies(): ArrayList<CookieModel> {
fun Context.launchWebOverlay(url: String) {
val intent = Intent(this, WebOverlayActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
intent.putExtra(ARG_URL, url)
val bundle = ActivityOptionsCompat.makeCustomAnimation(this, R.anim.slide_in_right, R.anim.slide_out_right).toBundle()
ContextCompat.startActivity(this, intent, bundle)

View File

@ -1,12 +0,0 @@
package com.pitchedapps.frost.utils
import io.reactivex.subjects.Subject
/**
* Created by Allan Wang on 2017-05-29.
*/
interface ObservableContainer<T> {
val progressObservable: Subject<T>
}
interface KeyPairObservable : ObservableContainer<Pair<Int, Int>>

View File

@ -4,20 +4,25 @@ import android.webkit.ConsoleMessage
import android.webkit.WebChromeClient
import android.webkit.WebView
import com.pitchedapps.frost.utils.L
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.subjects.Subject
/**
* Created by Allan Wang on 2017-05-31.
*/
class FrostChromeClient(val progressObservable: Subject<Int>) : WebChromeClient() {
class FrostChromeClient(val progressObservable: Subject<Int>, val titleObservable: BehaviorSubject<String>) : WebChromeClient() {
override fun onConsoleMessage(consoleMessage: ConsoleMessage): Boolean {
L.d("Console ${consoleMessage.lineNumber()}: ${consoleMessage.message()}")
L.d("Chrome Console ${consoleMessage.lineNumber()}: ${consoleMessage.message()}")
return super.onConsoleMessage(consoleMessage)
}
override fun onReceivedTitle(view: WebView?, title: String?) {
override fun onReceivedTitle(view: WebView, title: String) {
super.onReceivedTitle(view, title)
L.v("Title $title")
if (title.contains("http") || titleObservable.value == title) return
// L.v("Title $title")
titleObservable.onNext(title)
}
override fun onProgressChanged(view: WebView, newProgress: Int) {

View File

@ -10,7 +10,9 @@ import android.widget.ProgressBar
import butterknife.ButterKnife
import com.pitchedapps.frost.R
import com.pitchedapps.frost.utils.bindView
import io.reactivex.Scheduler
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
/**
* Created by Allan Wang on 2017-06-01.

View File

@ -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)

View File

@ -2,7 +2,7 @@
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:id="@+id/overlay_main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
@ -10,16 +10,18 @@
tools:context=".WebOverlayActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:id="@+id/overlay_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/AppTheme.AppBarOverlay"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<com.pitchedapps.frost.web.FrostWebView
android:id="@+id/frost_webview"
android:id="@+id/overlay_frost_webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize" />
</android.support.design.widget.CoordinatorLayout>

View File

@ -23,7 +23,7 @@
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Dark" />
<style name="Theme.Splash" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/splash_screen</item>