1
0
mirror of https://github.com/AllanWang/Frost-for-Facebook.git synced 2024-11-10 04:52:38 +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; } [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; } ._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; } .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.support.v7.widget.Toolbar
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.ViewTreeObserver
import butterknife.ButterKnife import butterknife.ButterKnife
import co.zsmb.materialdrawerkt.builders.Builder import co.zsmb.materialdrawerkt.builders.Builder
import co.zsmb.materialdrawerkt.builders.accountHeader 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.FbCookie.switchUser
import com.pitchedapps.frost.facebook.FbTab import com.pitchedapps.frost.facebook.FbTab
import com.pitchedapps.frost.facebook.PROFILE_PICTURE_URL import com.pitchedapps.frost.facebook.PROFILE_PICTURE_URL
import com.pitchedapps.frost.fragments.BaseFragment
import com.pitchedapps.frost.fragments.WebFragment import com.pitchedapps.frost.fragments.WebFragment
import com.pitchedapps.frost.utils.* import com.pitchedapps.frost.utils.*
import io.reactivex.disposables.Disposable
import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode import org.greenrobot.eventbus.ThreadMode
@ -43,6 +44,7 @@ class MainActivity : AppCompatActivity() {
lateinit var drawer: Drawer lateinit var drawer: Drawer
lateinit var drawerHeader: AccountHeader lateinit var drawerHeader: AccountHeader
val cookies: ArrayList<CookieModel> by lazy { cookies() } val cookies: ArrayList<CookieModel> by lazy { cookies() }
var titleDisposable: Disposable? = null
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -53,6 +55,11 @@ class MainActivity : AppCompatActivity() {
viewPager.adapter = adapter viewPager.adapter = adapter
viewPager.offscreenPageLimit = 5 viewPager.offscreenPageLimit = 5
viewPager.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() { viewPager.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() {
override fun onPageSelected(position: Int) {
super.onPageSelected(position)
updateTitleListener()
}
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) { override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
super.onPageScrolled(position, positionOffset, positionOffsetPixels) super.onPageScrolled(position, positionOffset, positionOffsetPixels)
val delta: Float by lazy { positionOffset * (255 - 128).toFloat() } 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) Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show() .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() { fun setupTabs() {
@ -144,8 +162,8 @@ class MainActivity : AppCompatActivity() {
super.onBackPressed() super.onBackPressed()
} }
val currentFragment: BaseFragment val currentFragment
get() = supportFragmentManager.findFragmentByTag("android:switcher:${R.id.container}:${viewPager.currentItem}") as BaseFragment get() = supportFragmentManager.findFragmentByTag("android:switcher:${R.id.container}:${viewPager.currentItem}") as WebFragment
inner class SectionsPagerAdapter(fm: FragmentManager, val pages: List<FbTab>) : FragmentPagerAdapter(fm) { 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() { class WebOverlayActivity : AppCompatActivity() {
val toolbar: Toolbar by bindView(R.id.toolbar) val toolbar: Toolbar by bindView(R.id.overlay_toolbar)
val frostWeb: FrostWebView by bindView(R.id.frost_webview) val frostWeb: FrostWebView by bindView(R.id.overlay_frost_webview)
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_web_overlay) setContentView(R.layout.activity_web_overlay)
ButterKnife.bind(this) ButterKnife.bind(this)
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
supportActionBar?.setDisplayShowHomeEnabled(true)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
toolbar.setNavigationOnClickListener { onBackPressed() }
frostWeb.baseUrl = url() frostWeb.baseUrl = url()
frostWeb.web.loadBaseUrl() frostWeb.web.loadBaseUrl()
SwipeBackHelper.onCreate(this) SwipeBackHelper.onCreate(this)
@ -31,6 +34,7 @@ class WebOverlayActivity : AppCompatActivity() {
.setSwipeSensitivity(0.5f) .setSwipeSensitivity(0.5f)
.setSwipeRelateEnable(true) .setSwipeRelateEnable(true)
.setSwipeRelateOffset(300) .setSwipeRelateOffset(300)
frostWeb.web.addTitleListener({ toolbar.title = it })
} }
override fun onPostCreate(savedInstanceState: Bundle?) { override fun onPostCreate(savedInstanceState: Bundle?) {

View File

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

View File

@ -30,6 +30,7 @@ fun Activity.cookies(): ArrayList<CookieModel> {
fun Context.launchWebOverlay(url: String) { fun Context.launchWebOverlay(url: String) {
val intent = Intent(this, WebOverlayActivity::class.java) 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) intent.putExtra(ARG_URL, url)
val bundle = ActivityOptionsCompat.makeCustomAnimation(this, R.anim.slide_in_right, R.anim.slide_out_right).toBundle() val bundle = ActivityOptionsCompat.makeCustomAnimation(this, R.anim.slide_in_right, R.anim.slide_out_right).toBundle()
ContextCompat.startActivity(this, intent, bundle) 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.WebChromeClient
import android.webkit.WebView import android.webkit.WebView
import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.L
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.subjects.Subject import io.reactivex.subjects.Subject
/** /**
* Created by Allan Wang on 2017-05-31. * 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 { 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) return super.onConsoleMessage(consoleMessage)
} }
override fun onReceivedTitle(view: WebView?, title: String?) { override fun onReceivedTitle(view: WebView, title: String) {
super.onReceivedTitle(view, title) 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) { override fun onProgressChanged(view: WebView, newProgress: Int) {

View File

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

View File

@ -11,7 +11,9 @@ import android.view.MotionEvent
import android.view.View import android.view.View
import android.webkit.WebView import android.webkit.WebView
import com.pitchedapps.frost.events.FbAccountEvent 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.BehaviorSubject
import io.reactivex.subjects.Subject import io.reactivex.subjects.Subject
import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.EventBus
@ -27,20 +29,25 @@ import org.greenrobot.eventbus.ThreadMode
*/ */
class FrostWebViewCore @JvmOverloads constructor( class FrostWebViewCore @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 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 val childHelper = NestedScrollingChildHelper(this)
private var lastY: Int = 0 private var lastY: Int = 0
private val scrollOffset = IntArray(2) private val scrollOffset = IntArray(2)
private val scrollConsumed = IntArray(2) private val scrollConsumed = IntArray(2)
private var nestedOffsetY: Int = 0 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 baseUrl: String? = null
var position: Int = -1 var position: Int = -1
init { init {
isNestedScrollingEnabled = true isNestedScrollingEnabled = true
progressObservable = BehaviorSubject.create<Int>() progressObservable = BehaviorSubject.create<Int>()
titleObservable = BehaviorSubject.create<String>()
chromeClient = FrostChromeClient(progressObservable, titleObservable)
setupWebview() setupWebview()
} }
@ -49,8 +56,8 @@ class FrostWebViewCore @JvmOverloads constructor(
settings.javaScriptEnabled = true settings.javaScriptEnabled = true
settings.domStorageEnabled = true settings.domStorageEnabled = true
setLayerType(View.LAYER_TYPE_HARDWARE, null) setLayerType(View.LAYER_TYPE_HARDWARE, null)
setWebViewClient(FrostWebViewClient({position})) setWebViewClient(FrostWebViewClient({ position }))
setWebChromeClient(FrostChromeClient(progressObservable)) setWebChromeClient(chromeClient)
} }
override fun loadUrl(url: String?) { override fun loadUrl(url: String?) {
@ -60,6 +67,9 @@ class FrostWebViewCore @JvmOverloads constructor(
fun loadBaseUrl() = loadUrl(baseUrl) 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 { override fun onTouchEvent(ev: MotionEvent): Boolean {
val event = MotionEvent.obtain(ev) val event = MotionEvent.obtain(ev)
val action = MotionEventCompat.getActionMasked(event) 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" <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" 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_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@android:color/white" android:background="@android:color/white"
@ -10,16 +10,18 @@
tools:context=".WebOverlayActivity"> tools:context=".WebOverlayActivity">
<android.support.v7.widget.Toolbar <android.support.v7.widget.Toolbar
android:id="@+id/toolbar" android:id="@+id/overlay_toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" android:background="?attr/colorPrimary"
android:theme="@style/AppTheme.AppBarOverlay"
app:layout_scrollFlags="scroll|enterAlways" app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay" /> app:popupTheme="@style/AppTheme.PopupOverlay" />
<com.pitchedapps.frost.web.FrostWebView <com.pitchedapps.frost.web.FrostWebView
android:id="@+id/frost_webview" android:id="@+id/overlay_frost_webview"
android:layout_width="match_parent" 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> </android.support.design.widget.CoordinatorLayout>

View File

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