diff options
author | Allan Wang <me@allanwang.ca> | 2017-06-03 15:51:36 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2017-06-03 15:51:36 -0700 |
commit | 8ec65f55f85c730e97d5521c1443819435b98208 (patch) | |
tree | 6bd4350b3f6e5eda03c95c4a13fd7b7c7f50f2ac /app/src | |
parent | a5aa87bbaef7d2c937cc89295942882d050c3b5c (diff) | |
download | frost-8ec65f55f85c730e97d5521c1443819435b98208.tar.gz frost-8ec65f55f85c730e97d5521c1443819435b98208.tar.bz2 frost-8ec65f55f85c730e97d5521c1443819435b98208.zip |
Add toolbar title listeners
Diffstat (limited to 'app/src')
11 files changed, 70 insertions, 45 deletions
diff --git a/app/src/main/assets/core/login.compact.css b/app/src/main/assets/core/login.compact.css index 4a99bbf3..436b1875 100644 --- a/app/src/main/assets/core/login.compact.css +++ b/app/src/main/assets/core/login.compact.css @@ -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; } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt index 047cedac..f4ffd2b1 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt @@ -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) { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt index 9a071285..3ec47a10 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt @@ -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?) { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/BaseFragment.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/BaseFragment.kt index cb3bb713..06484500 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/BaseFragment.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/BaseFragment.kt @@ -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. diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/ContextUtils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/ContextUtils.kt index 31055c4e..b87eaa8f 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/ContextUtils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/ContextUtils.kt @@ -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) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Interfaces.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Interfaces.kt deleted file mode 100644 index 1e42f59f..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Interfaces.kt +++ /dev/null @@ -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>>
\ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClient.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClient.kt index fe3c92e8..ff8637b1 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClient.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClient.kt @@ -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) { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt index 087e9174..d5fd6391 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt @@ -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. diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt index b2260b6f..eaee60bc 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt @@ -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) diff --git a/app/src/main/res/layout/activity_web_overlay.xml b/app/src/main/res/layout/activity_web_overlay.xml index f962b396..ed6b8bb8 100644 --- a/app/src/main/res/layout/activity_web_overlay.xml +++ b/app/src/main/res/layout/activity_web_overlay.xml @@ -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> diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index ded59278..40224e12 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -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> |