From e4377fed20ce1e3f4a0b236271eecdb1fe573b7a Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 13 Jun 2017 00:42:31 -0700 Subject: Created js base for facebook menu --- app/build.gradle | 2 - app/src/main/assets/core/_base.scss | 17 -------- app/src/main/assets/core/_colors.scss | 11 ----- app/src/main/assets/core/header.compact.css | 1 - app/src/main/assets/core/header.scss | 6 --- app/src/main/assets/core/login.compact.css | 25 ----------- app/src/main/assets/core/login.scss | 48 ---------------------- app/src/main/assets/css/core/_base.scss | 17 ++++++++ app/src/main/assets/css/core/_colors.scss | 11 +++++ app/src/main/assets/css/core/header.compact.css | 1 + app/src/main/assets/css/core/header.scss | 6 +++ app/src/main/assets/css/core/login.compact.css | 25 +++++++++++ app/src/main/assets/css/core/login.scss | 48 ++++++++++++++++++++++ app/src/main/assets/js/menu.js | 37 +++++++++++++++++ app/src/main/assets/js/menu.min.js | 1 + .../kotlin/com/pitchedapps/frost/BaseActivity.kt | 24 +++++++++++ .../main/kotlin/com/pitchedapps/frost/FrostApp.kt | 2 - .../kotlin/com/pitchedapps/frost/LoginActivity.kt | 6 +-- .../kotlin/com/pitchedapps/frost/MainActivity.kt | 28 +++++++++---- .../com/pitchedapps/frost/SelectorActivity.kt | 5 +-- .../com/pitchedapps/frost/WebOverlayActivity.kt | 4 +- .../kotlin/com/pitchedapps/frost/facebook/FbTab.kt | 7 +++- .../com/pitchedapps/frost/fragments/WebFragment.kt | 13 +++++- .../com/pitchedapps/frost/injectors/CssAssets.kt | 2 +- .../com/pitchedapps/frost/injectors/JsAssets.kt | 32 +++++++++++++++ .../com/pitchedapps/frost/injectors/JsInjector.kt | 10 ++++- .../com/pitchedapps/frost/utils/ContextUtils.kt | 16 ++++++++ .../kotlin/com/pitchedapps/frost/utils/Prefs.kt | 1 + .../com/pitchedapps/frost/web/FrostChromeClient.kt | 2 +- .../com/pitchedapps/frost/web/FrostWebView.kt | 15 ++++--- .../pitchedapps/frost/web/FrostWebViewClient.kt | 18 ++++---- .../com/pitchedapps/frost/web/FrostWebViewCore.kt | 10 +++-- app/src/main/res/values/strings.xml | 7 +++- app/src/main/res/values/strings_preferences | 1 - gradle.properties | 2 +- 35 files changed, 301 insertions(+), 160 deletions(-) delete mode 100644 app/src/main/assets/core/_base.scss delete mode 100644 app/src/main/assets/core/_colors.scss delete mode 100644 app/src/main/assets/core/header.compact.css delete mode 100644 app/src/main/assets/core/header.scss delete mode 100644 app/src/main/assets/core/login.compact.css delete mode 100644 app/src/main/assets/core/login.scss create mode 100644 app/src/main/assets/css/core/_base.scss create mode 100644 app/src/main/assets/css/core/_colors.scss create mode 100644 app/src/main/assets/css/core/header.compact.css create mode 100644 app/src/main/assets/css/core/header.scss create mode 100644 app/src/main/assets/css/core/login.compact.css create mode 100644 app/src/main/assets/css/core/login.scss create mode 100644 app/src/main/assets/js/menu.js create mode 100644 app/src/main/assets/js/menu.min.js create mode 100644 app/src/main/kotlin/com/pitchedapps/frost/BaseActivity.kt create mode 100644 app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt diff --git a/app/build.gradle b/app/build.gradle index dc682577..67360af3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -106,8 +106,6 @@ dependencies { compile "com.jakewharton.rxbinding2:rxbinding:${RX_BINDING}" compile "com.jakewharton.rxbinding2:rxbinding-appcompat-v7:${RX_BINDING}" -// compile "com.facebook.stetho:stetho-okhttp3:${STETHO}" - compile "com.lapism:searchview:${SEARCH_VIEW}" compile "org.jsoup:jsoup:${JSOUP}" diff --git a/app/src/main/assets/core/_base.scss b/app/src/main/assets/core/_base.scss deleted file mode 100644 index 344b6696..00000000 --- a/app/src/main/assets/core/_base.scss +++ /dev/null @@ -1,17 +0,0 @@ -@mixin placeholder { - ::-webkit-input-placeholder { - @content - } - - :-moz-placeholder { - @content - } - - ::-moz-placeholder { - @content - } - - :-ms-input-placeholder { - @content - } -} diff --git a/app/src/main/assets/core/_colors.scss b/app/src/main/assets/core/_colors.scss deleted file mode 100644 index 718c1e62..00000000 --- a/app/src/main/assets/core/_colors.scss +++ /dev/null @@ -1,11 +0,0 @@ -$transparent: transparent !default; - -//Keep above as first line so partials aren't compiled - -//$text: #f0f; -//$background: #f00; -//$background2: rgba(#ff0, 0.1); - -$text: #fff !default; -$background: #000 !default; -$background2: rgba(lighten($background, 10%), 0.1) !default; diff --git a/app/src/main/assets/core/header.compact.css b/app/src/main/assets/core/header.compact.css deleted file mode 100644 index 560a8465..00000000 --- a/app/src/main/assets/core/header.compact.css +++ /dev/null @@ -1 +0,0 @@ -#header[data-sigil="MTopBlueBarHeader"], #header-notices, [data-sigil*=m-promo-jewel-header] { display: None !important; } diff --git a/app/src/main/assets/core/header.scss b/app/src/main/assets/core/header.scss deleted file mode 100644 index 4e4a2148..00000000 --- a/app/src/main/assets/core/header.scss +++ /dev/null @@ -1,6 +0,0 @@ -// remove blue header - -#header[data-sigil="MTopBlueBarHeader"], #header-notices, -[data-sigil*=m-promo-jewel-header] { - display: None !important; -} diff --git a/app/src/main/assets/core/login.compact.css b/app/src/main/assets/core/login.compact.css deleted file mode 100644 index 436b1875..00000000 --- a/app/src/main/assets/core/login.compact.css +++ /dev/null @@ -1,25 +0,0 @@ -[data-sigil="m_login_upsell"] { display: none !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(26, 26, 26, 0.1) !important; } - -._56bf, .touch .btn { border-radius: 0 !important; border: 0 !important; } - -.touch ._56bt { text-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: #fff !important; } - -::-webkit-input-placeholder { color: #fff !important; } - -:-moz-placeholder { color: #fff !important; } - -::-moz-placeholder { color: #fff !important; } - -:-ms-input-placeholder { color: #fff !important; } - -._43mh::before, ._43mh::after { background: #fff !important; } - -._1rrd { border: 1px solid #fff !important; color: #fff !important; } diff --git a/app/src/main/assets/core/login.scss b/app/src/main/assets/core/login.scss deleted file mode 100644 index 00627838..00000000 --- a/app/src/main/assets/core/login.scss +++ /dev/null @@ -1,48 +0,0 @@ -@import "colors"; -@import "base"; - -//Get Android banner -[data-sigil="m_login_upsell"] { - display: none !important; -} - -body, #root, #header, .aclb, ._55wo, ._1upc, input, ._2f9r { - background: $background !important; -} - -button::before, .touch ._56bt, ._56be::before, .btnS, .touch::before, -._5xo2, ._5u5a::before { - background: $background2 !important; -} - -._56bf, .touch .btn { - border-radius: 0 !important; - border: 0 !important; -} - -.touch ._56bt { - text-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: $text !important; -} - -@include placeholder { - color: $text !important; -} - - -// divider lines -._43mh::before, ._43mh::after { - background: $text !important; -} - -._1rrd { - border: 1px solid $text !important; - color: $text !important; -} diff --git a/app/src/main/assets/css/core/_base.scss b/app/src/main/assets/css/core/_base.scss new file mode 100644 index 00000000..344b6696 --- /dev/null +++ b/app/src/main/assets/css/core/_base.scss @@ -0,0 +1,17 @@ +@mixin placeholder { + ::-webkit-input-placeholder { + @content + } + + :-moz-placeholder { + @content + } + + ::-moz-placeholder { + @content + } + + :-ms-input-placeholder { + @content + } +} diff --git a/app/src/main/assets/css/core/_colors.scss b/app/src/main/assets/css/core/_colors.scss new file mode 100644 index 00000000..718c1e62 --- /dev/null +++ b/app/src/main/assets/css/core/_colors.scss @@ -0,0 +1,11 @@ +$transparent: transparent !default; + +//Keep above as first line so partials aren't compiled + +//$text: #f0f; +//$background: #f00; +//$background2: rgba(#ff0, 0.1); + +$text: #fff !default; +$background: #000 !default; +$background2: rgba(lighten($background, 10%), 0.1) !default; diff --git a/app/src/main/assets/css/core/header.compact.css b/app/src/main/assets/css/core/header.compact.css new file mode 100644 index 00000000..560a8465 --- /dev/null +++ b/app/src/main/assets/css/core/header.compact.css @@ -0,0 +1 @@ +#header[data-sigil="MTopBlueBarHeader"], #header-notices, [data-sigil*=m-promo-jewel-header] { display: None !important; } diff --git a/app/src/main/assets/css/core/header.scss b/app/src/main/assets/css/core/header.scss new file mode 100644 index 00000000..4e4a2148 --- /dev/null +++ b/app/src/main/assets/css/core/header.scss @@ -0,0 +1,6 @@ +// remove blue header + +#header[data-sigil="MTopBlueBarHeader"], #header-notices, +[data-sigil*=m-promo-jewel-header] { + display: None !important; +} diff --git a/app/src/main/assets/css/core/login.compact.css b/app/src/main/assets/css/core/login.compact.css new file mode 100644 index 00000000..436b1875 --- /dev/null +++ b/app/src/main/assets/css/core/login.compact.css @@ -0,0 +1,25 @@ +[data-sigil="m_login_upsell"] { display: none !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(26, 26, 26, 0.1) !important; } + +._56bf, .touch .btn { border-radius: 0 !important; border: 0 !important; } + +.touch ._56bt { text-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: #fff !important; } + +::-webkit-input-placeholder { color: #fff !important; } + +:-moz-placeholder { color: #fff !important; } + +::-moz-placeholder { color: #fff !important; } + +:-ms-input-placeholder { color: #fff !important; } + +._43mh::before, ._43mh::after { background: #fff !important; } + +._1rrd { border: 1px solid #fff !important; color: #fff !important; } diff --git a/app/src/main/assets/css/core/login.scss b/app/src/main/assets/css/core/login.scss new file mode 100644 index 00000000..00627838 --- /dev/null +++ b/app/src/main/assets/css/core/login.scss @@ -0,0 +1,48 @@ +@import "colors"; +@import "base"; + +//Get Android banner +[data-sigil="m_login_upsell"] { + display: none !important; +} + +body, #root, #header, .aclb, ._55wo, ._1upc, input, ._2f9r { + background: $background !important; +} + +button::before, .touch ._56bt, ._56be::before, .btnS, .touch::before, +._5xo2, ._5u5a::before { + background: $background2 !important; +} + +._56bf, .touch .btn { + border-radius: 0 !important; + border: 0 !important; +} + +.touch ._56bt { + text-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: $text !important; +} + +@include placeholder { + color: $text !important; +} + + +// divider lines +._43mh::before, ._43mh::after { + background: $text !important; +} + +._1rrd { + border: 1px solid $text !important; + color: $text !important; +} diff --git a/app/src/main/assets/js/menu.js b/app/src/main/assets/js/menu.js new file mode 100644 index 00000000..94261146 --- /dev/null +++ b/app/src/main/assets/js/menu.js @@ -0,0 +1,37 @@ +var viewport = document.getElementById('viewport'); +var root = document.getElementById('root'); + +var y = new MutationObserver(function(mutations) { + viewport.removeAttribute('style'); + root.removeAttribute('style'); +}) + +y.observe(viewport, { + attributes: true +}); + +y.observe(root, { + attributes: true +}); + +var x = new MutationObserver(function(mutations) { + if (document.getElementsByClassName('mSideMenu').length) { + x.disconnect(); + console.log('Found side menu'); + var menu = document.getElementsByClassName('mSideMenu')[0]; + while (root.firstChild) + root.removeChild(root.firstChild); + while (menu.childNodes.length) + root.appendChild(menu.childNodes[0]); + setTimeout(function() { + y.disconnect(); + console.log('Unhook styler'); + }, 500) + } +}); + +x.observe(document.getElementById('mJewelNav'), { + childList: true, + subtree: true +}); +document.getElementById('bookmarks_jewel').getElementsByTagName('a')[0].click(); diff --git a/app/src/main/assets/js/menu.min.js b/app/src/main/assets/js/menu.min.js new file mode 100644 index 00000000..6943e2a5 --- /dev/null +++ b/app/src/main/assets/js/menu.min.js @@ -0,0 +1 @@ +var viewport=document.getElementById("viewport");var root=document.getElementById("root");var y=new MutationObserver(function(a){viewport.removeAttribute("style");root.removeAttribute("style")});y.observe(viewport,{attributes:true});y.observe(root,{attributes:true});var x=new MutationObserver(function(a){if(document.getElementsByClassName("mSideMenu").length){x.disconnect();console.log("Found side menu");var b=document.getElementsByClassName("mSideMenu")[0];while(root.firstChild){root.removeChild(root.firstChild)}while(b.childNodes.length){root.appendChild(b.childNodes[0])}setTimeout(function(){y.disconnect();console.log("Unhook styler")},500)}});x.observe(document.getElementById("mJewelNav"),{childList:true,subtree:true});document.getElementById("bookmarks_jewel").getElementsByTagName("a")[0].click(); \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/BaseActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/BaseActivity.kt new file mode 100644 index 00000000..6c638618 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/BaseActivity.kt @@ -0,0 +1,24 @@ +package com.pitchedapps.frost + +import android.support.v7.app.AppCompatActivity +import com.pitchedapps.frost.utils.Prefs +import com.pitchedapps.frost.utils.materialDialog + +/** + * Created by Allan Wang on 2017-06-12. + */ +open class BaseActivity : AppCompatActivity() { + override fun onBackPressed() { + if (isTaskRoot && Prefs.exitConfirmation) { + materialDialog { + title(R.string.exit) + content(R.string.exit_confirmation) + positiveText(android.R.string.yes) + negativeText(android.R.string.no) + onPositive { _, _ -> super.onBackPressed() } + checkBoxPromptRes(R.string.do_not_show_again, false, { _, b -> Prefs.exitConfirmation = !b }) + show() + } + } else super.onBackPressed() + } +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt index b5f8c9cb..85d1c8b5 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt @@ -17,8 +17,6 @@ import com.pitchedapps.frost.utils.CrashReportingTree import com.pitchedapps.frost.utils.Prefs import com.raizlabs.android.dbflow.config.FlowConfig import com.raizlabs.android.dbflow.config.FlowManager -import com.squareup.leakcanary.LeakCanary -import com.squareup.leakcanary.RefWatcher import io.fabric.sdk.android.Fabric import timber.log.Timber import timber.log.Timber.DebugTree diff --git a/app/src/main/kotlin/com/pitchedapps/frost/LoginActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/LoginActivity.kt index a9746d6f..9ba83879 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/LoginActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/LoginActivity.kt @@ -4,11 +4,10 @@ import android.graphics.drawable.Drawable import android.os.Bundle import android.os.Handler import android.support.v4.widget.SwipeRefreshLayout -import android.support.v7.app.AppCompatActivity import android.support.v7.widget.AppCompatTextView import android.support.v7.widget.Toolbar import android.widget.ImageView -import butterknife.ButterKnife +import ca.allanwang.kau.utils.bindView import com.bumptech.glide.Glide import com.bumptech.glide.load.DataSource import com.bumptech.glide.load.engine.GlideException @@ -21,7 +20,6 @@ import com.pitchedapps.frost.facebook.FACEBOOK_COM import com.pitchedapps.frost.facebook.FbTab import com.pitchedapps.frost.facebook.PROFILE_PICTURE_URL import com.pitchedapps.frost.utils.L -import ca.allanwang.kau.utils.bindView import com.pitchedapps.frost.utils.launchNewTask import com.pitchedapps.frost.views.fadeIn import com.pitchedapps.frost.views.fadeOut @@ -40,7 +38,7 @@ import kotlin.concurrent.thread /** * Created by Allan Wang on 2017-06-01. */ -class LoginActivity : AppCompatActivity() { +class LoginActivity : BaseActivity() { val toolbar: Toolbar by bindView(R.id.toolbar) val web: LoginWebView by bindView(R.id.login_webview) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt index 05ee2e50..12b308d0 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt @@ -1,6 +1,7 @@ package com.pitchedapps.frost import android.content.Intent +import android.graphics.drawable.ColorDrawable import android.os.Bundle import android.support.design.widget.FloatingActionButton import android.support.design.widget.Snackbar @@ -8,15 +9,11 @@ import android.support.design.widget.TabLayout import android.support.v4.app.FragmentManager import android.support.v4.app.FragmentPagerAdapter import android.support.v4.view.ViewPager -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 ca.allanwang.kau.utils.bindView -import ca.allanwang.kau.utils.restart -import ca.allanwang.kau.utils.showChangelog -import ca.allanwang.kau.utils.toDrawable +import ca.allanwang.kau.utils.* import co.zsmb.materialdrawerkt.builders.Builder import co.zsmb.materialdrawerkt.builders.accountHeader import co.zsmb.materialdrawerkt.builders.drawer @@ -40,7 +37,7 @@ import com.pitchedapps.frost.utils.launchWebOverlay import io.reactivex.disposables.Disposable import io.reactivex.subjects.PublishSubject -class MainActivity : AppCompatActivity() { +class MainActivity : BaseActivity() { lateinit var adapter: SectionsPagerAdapter val toolbar: Toolbar by bindView(R.id.toolbar) @@ -113,19 +110,27 @@ class MainActivity : AppCompatActivity() { toolbar = this@MainActivity.toolbar savedInstance = savedInstanceState translucentStatusBar = false + sliderBackgroundColor = Prefs.bgColor.withMinAlpha(200).toLong() drawerHeader = accountHeader { + textColor = Prefs.textColor.toLong() + backgroundDrawable = ColorDrawable(Prefs.headerColor) cookies().forEach { (id, name) -> profile(name = name ?: "") { iconUrl = PROFILE_PICTURE_URL(id) + textColor = Prefs.textColor.toLong() + selectedTextColor = Prefs.textColor.toLong() identifier = id } } - profileSetting(nameRes = R.string.add_account, descriptionRes = R.string.add_account_desc) { - iconDrawable = IconicsDrawable(this@MainActivity, GoogleMaterial.Icon.gmd_add).actionBar().paddingDp(5).colorRes(R.color.material_drawer_primary_text) + profileSetting(nameRes = R.string.add_account) { + iconDrawable = IconicsDrawable(this@MainActivity, GoogleMaterial.Icon.gmd_add).actionBar().paddingDp(5).color(Prefs.textColor) + textColor = Prefs.textColor.toLong() identifier = -2L } profileSetting(nameRes = R.string.manage_account) { iicon = GoogleMaterial.Icon.gmd_settings + iconColor = Prefs.textColor.toLong() + textColor = Prefs.textColor.toLong() identifier = -3L } onProfileChanged { _, profile, current -> @@ -147,6 +152,11 @@ class MainActivity : AppCompatActivity() { fun Builder.primaryItem(item: FbTab) = this.primaryItem(item.titleId) { iicon = item.icon + iconColor = Prefs.textColor.toLong() + textColor = Prefs.textColor.toLong() + selectedIconColor = Prefs.textColor.toLong() + selectedTextColor = Prefs.textColor.toLong() + selectedColor = 0x00000001.toLong() identifier = item.titleId.toLong() onClick { _ -> launchWebOverlay(item.url) @@ -187,7 +197,7 @@ class MainActivity : AppCompatActivity() { inner class SectionsPagerAdapter(fm: FragmentManager, val pages: List) : FragmentPagerAdapter(fm) { - override fun getItem(position: Int) = WebFragment(pages[position].url) + override fun getItem(position: Int) = WebFragment(pages[position]) override fun getCount() = pages.size diff --git a/app/src/main/kotlin/com/pitchedapps/frost/SelectorActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/SelectorActivity.kt index 57d0ff4d..082d7887 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/SelectorActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/SelectorActivity.kt @@ -1,15 +1,14 @@ package com.pitchedapps.frost import android.os.Bundle -import android.support.v7.app.AppCompatActivity import android.support.v7.widget.GridLayoutManager import android.support.v7.widget.RecyclerView import android.view.View +import ca.allanwang.kau.utils.bindView import com.mikepenz.fastadapter.FastAdapter import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter import com.mikepenz.fastadapter.listeners.ClickEventHook import com.pitchedapps.frost.facebook.FbCookie -import ca.allanwang.kau.utils.bindView import com.pitchedapps.frost.utils.cookies import com.pitchedapps.frost.utils.launchNewTask import com.pitchedapps.frost.views.AccountItem @@ -17,7 +16,7 @@ import com.pitchedapps.frost.views.AccountItem /** * Created by Allan Wang on 2017-06-04. */ -class SelectorActivity : AppCompatActivity() { +class SelectorActivity : BaseActivity() { val recycler: RecyclerView by bindView(R.id.selector_recycler) val adapter = FastItemAdapter() diff --git a/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt index 1968d07e..70e86239 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt @@ -3,10 +3,8 @@ package com.pitchedapps.frost import android.os.Bundle import android.support.v7.app.AppCompatActivity import android.support.v7.widget.Toolbar -import butterknife.ButterKnife import ca.allanwang.kau.utils.bindView import com.jude.swipbackhelper.SwipeBackHelper -import ca.allanwang.kau.utils.bindView import com.pitchedapps.frost.utils.url import com.pitchedapps.frost.web.FrostWebView @@ -26,7 +24,7 @@ class WebOverlayActivity : AppCompatActivity() { supportActionBar?.setDisplayShowHomeEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true) toolbar.setNavigationOnClickListener { onBackPressed() } - frostWeb.baseUrl = url() + frostWeb.web.baseUrl = url() frostWeb.web.loadBaseUrl() SwipeBackHelper.onCreate(this) SwipeBackHelper.getCurrentPage(this) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbTab.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbTab.kt index 17dd4862..c3bad56c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbTab.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbTab.kt @@ -6,8 +6,9 @@ import com.mikepenz.google_material_typeface_library.GoogleMaterial import com.mikepenz.iconics.typeface.IIcon import com.mikepenz.material_design_iconic_typeface_library.MaterialDesignIconic import com.pitchedapps.frost.R +import com.pitchedapps.frost.injectors.JsAssets -enum class FbTab(@StringRes val titleId: Int, val icon: IIcon, relativeUrl: String) { +enum class FbTab(@StringRes val titleId: Int, val icon: IIcon, relativeUrl: String, val javascript: JsAssets? = null) { FEED(R.string.feed, CommunityMaterial.Icon.cmd_newspaper, ""), FEED_MOST_RECENT(R.string.most_recent, GoogleMaterial.Icon.gmd_grade, "/?sk=h_chr"), FEED_TOP_STORIES(R.string.top_stories, GoogleMaterial.Icon.gmd_star, "/?sk=h_nor"), @@ -23,10 +24,12 @@ enum class FbTab(@StringRes val titleId: Int, val icon: IIcon, relativeUrl: Stri BIRTHDAYS(R.string.birthdays, GoogleMaterial.Icon.gmd_cake, "events/birthdays"), CHAT(R.string.chat, GoogleMaterial.Icon.gmd_chat, "buddylist"), PHOTOS(R.string.photos, GoogleMaterial.Icon.gmd_photo, "me/photos"), + SETTINGS(R.string.settings, GoogleMaterial.Icon.gmd_settings, "settings"), + MENU(R.string.menu, GoogleMaterial.Icon.gmd_menu, "settings", JsAssets.MENU) ; val url = "$FB_URL_BASE$relativeUrl" } -fun defaultTabs(): List = listOf(FbTab.FEED, FbTab.MESSAGES, FbTab.FRIENDS, FbTab.NOTIFICATIONS) +fun defaultTabs(): List = listOf(FbTab.FEED, FbTab.MESSAGES, FbTab.NOTIFICATIONS, FbTab.MENU) fun defaultDrawers(): List = listOf(FbTab.ACTIVITY_LOG, FbTab.PAGES, FbTab.GROUPS, FbTab.SAVED) \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt index 40f37189..0f56592c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt @@ -9,6 +9,8 @@ import android.view.View import android.view.ViewGroup import ca.allanwang.kau.utils.withBundle import com.pitchedapps.frost.MainActivity +import com.pitchedapps.frost.facebook.FbTab +import com.pitchedapps.frost.injectors.JsAssets import com.pitchedapps.frost.web.FrostWebView import com.pitchedapps.frost.web.FrostWebViewCore import io.reactivex.android.schedulers.AndroidSchedulers @@ -23,14 +25,21 @@ class WebFragment : Fragment() { companion object { private const val ARG_URL = "arg_url" + private const val ARG_ID = "arg_id" operator fun invoke(url: String) = WebFragment().withBundle { putString(ARG_URL, url) } + + operator fun invoke(data: FbTab) = WebFragment().withBundle { + putString(ARG_URL, data.url) + if (data.javascript != null) putSerializable(ARG_ID, data.javascript) + } } // val refresh: SwipeRefreshLayout by lazy { frostWebView.refresh } val web: FrostWebViewCore by lazy { frostWebView.web } lateinit var url: String + var baseJavascript: JsAssets? = null lateinit private var frostWebView: FrostWebView private var firstLoad = true private var refreshDisposable: Disposable? = null @@ -38,12 +47,14 @@ class WebFragment : Fragment() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) url = arguments.getString(ARG_URL) + baseJavascript = arguments.getSerializable(ARG_ID) as? JsAssets } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { super.onCreateView(inflater, container, savedInstanceState) frostWebView = FrostWebView(context) - frostWebView.baseUrl = url + frostWebView.web.baseUrl = url + frostWebView.web.baseJavascript = baseJavascript return frostWebView } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAssets.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAssets.kt index 336ffc71..ad257276 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAssets.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAssets.kt @@ -18,7 +18,7 @@ enum class CssAssets { fun inject(webView: WebView, callback: ((String) -> Unit)?) { if (injector == null) { - val content = webView.context.assets.open("core/$file").bufferedReader().use { it.readText() } + val content = webView.context.assets.open("css/core/$file").bufferedReader().use { it.readText() } injector = JsBuilder().css(content).build() } injector!!.inject(webView, callback) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt new file mode 100644 index 00000000..2bf53d2e --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt @@ -0,0 +1,32 @@ +package com.pitchedapps.frost.injectors + +import android.webkit.WebView +import com.pitchedapps.frost.utils.L + +/** + * Created by Allan Wang on 2017-05-31. + * Mapping of the available assets + * The enum name must match the css file name + * //TODO add folder mapping using Prefs + */ +enum class JsAssets { + MENU + ; + + var file = "${name.toLowerCase()}.min.js" + var injector: JsInjector? = null + + fun inject(webView: WebView, callback: ((String) -> Unit)?) { + if (injector == null) { + val content = webView.context.assets.open("js/$file").bufferedReader().use { it.readText() } + injector = JsBuilder().js(content).build() + } + injector!!.inject(webView, callback) + L.v("JS ${injector!!.function}") + } + + fun reset() { + injector = null + } + +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt index bda9ae16..14e0606b 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt @@ -3,13 +3,19 @@ package com.pitchedapps.frost.injectors import android.webkit.WebView class JsBuilder { - private val css: StringBuilder by lazy { StringBuilder() } + private val css = StringBuilder() + private val js = StringBuilder() fun css(css: String): JsBuilder { this.css.append(css) return this } + fun js(content: String): JsBuilder { + this.js.append(content) + return this + } + fun build() = JsInjector(toString()) override fun toString(): String { @@ -18,6 +24,8 @@ class JsBuilder { val cssMin = css.replace(Regex("\\s+"), "") builder.append("var a=document.createElement('style');a.innerHTML='$cssMin';document.head.appendChild(a);") } + if (js.isNotBlank()) + builder.append(js) return builder.append("}()").toString() } } 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 e601283c..1569532c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/ContextUtils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/ContextUtils.kt @@ -5,7 +5,10 @@ import android.content.Context import android.content.Intent import android.support.v4.app.ActivityOptionsCompat import android.support.v4.content.ContextCompat +import ca.allanwang.kau.utils.adjustAlpha +import ca.allanwang.kau.utils.lighten import ca.allanwang.kau.utils.startActivity +import com.afollestad.materialdialogs.MaterialDialog import com.pitchedapps.frost.LoginActivity import com.pitchedapps.frost.R import com.pitchedapps.frost.WebOverlayActivity @@ -38,4 +41,17 @@ fun Context.launchWebOverlay(url: String) { fun WebOverlayActivity.url(): String { return intent.extras?.getString(ARG_URL) ?: FbTab.FEED.url +} + +fun Activity.materialDialog(action: MaterialDialog.Builder.() -> Unit) { + val builder = MaterialDialog.Builder(this) + val dimmerTextColor = Prefs.textColor.adjustAlpha(0.8f) + builder.titleColor(Prefs.textColor) + .contentColor(dimmerTextColor) + .widgetColor(dimmerTextColor) + .backgroundColor(Prefs.bgColor.lighten(0.1f)) + .positiveColor(Prefs.textColor) + .negativeColor(Prefs.textColor) + .neutralColor(Prefs.textColor) + builder.action() } \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt index 89cccd40..6284a2f8 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt @@ -23,4 +23,5 @@ object Prefs : KPref() { var iconColor: Int by kpref("color_icons", Color.WHITE) + var exitConfirmation: Boolean by kpref("exit_confirmation", true) } 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 7ad12c3a..720026e6 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClient.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClient.kt @@ -13,7 +13,7 @@ import io.reactivex.subjects.Subject class FrostChromeClient(val progressObservable: Subject, val titleObservable: BehaviorSubject) : WebChromeClient() { override fun onConsoleMessage(consoleMessage: ConsoleMessage): Boolean { - L.v("Chrome Console ${consoleMessage.lineNumber()}: ${consoleMessage.message()}") + L.i("Chrome Console ${consoleMessage.lineNumber()}: ${consoleMessage.message()}") return super.onConsoleMessage(consoleMessage) } 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 d4bf8e07..4554e0a4 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt @@ -7,9 +7,9 @@ import android.util.AttributeSet import android.view.View import android.widget.FrameLayout import android.widget.ProgressBar -import butterknife.ButterKnife -import com.pitchedapps.frost.R import ca.allanwang.kau.utils.bindView +import com.pitchedapps.frost.R +import com.pitchedapps.frost.facebook.FbTab import io.reactivex.android.schedulers.AndroidSchedulers /** @@ -17,11 +17,6 @@ import io.reactivex.android.schedulers.AndroidSchedulers */ class FrostWebView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0) : FrameLayout(context, attrs, defStyleAttr, defStyleRes), SwipeRefreshLayout.OnRefreshListener { - var baseUrl: String? - get() = web.baseUrl - set(value) { - web.baseUrl = value - } val refresh: SwipeRefreshLayout by bindView(R.id.swipe_refresh) val web: FrostWebViewCore by bindView(R.id.frost_webview_core) val progress: ProgressBar by bindView(R.id.progressBar) @@ -46,8 +41,12 @@ class FrostWebView @JvmOverloads constructor(context: Context, attrs: AttributeS }) } + //Some urls have javascript injections so make sure we load the base url override fun onRefresh() { - web.reload() + when (web.baseUrl) { + FbTab.MENU.url -> web.loadBaseUrl() + else -> web.reload() + } } fun onBackPressed(): Boolean { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt index 922d527b..28048a1d 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt @@ -24,15 +24,6 @@ import io.reactivex.subjects.Subject */ class FrostWebViewClient(val refreshObservable: Subject) : WebViewClient() { - companion object { - //Collections of jewels mapped with url match -> id - val jewelMap: Map = mapOf("a" to "b") - - fun test() { - - } - } - override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) { super.onPageStarted(view, url, favicon) L.i("FWV Loading $url") @@ -55,6 +46,15 @@ class FrostWebViewClient(val refreshObservable: Subject) : WebViewClien super.onPageFinished(view, url) refreshObservable.onNext(false) if (!url.contains(FACEBOOK_COM)) return + L.i("Page finished $url") + with(view as FrostWebViewCore) { + if (url == view.baseUrl && view.baseJavascript != null) { + L.i("Base inject ${view.baseJavascript!!.name}") + view.baseJavascript!!.inject(view, { + L.i("Base injection done") + }) + } + } JsActions.LOGIN_CHECK.inject(view) CssAssets.HEADER.inject(view, { view.circularReveal(offset = 150L) 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 1d3f348a..f0596f7c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt @@ -12,6 +12,7 @@ import android.view.View import android.view.animation.DecelerateInterpolator import android.webkit.WebView import com.pitchedapps.frost.facebook.USER_AGENT_BASIC +import com.pitchedapps.frost.injectors.JsAssets import io.reactivex.Scheduler import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable @@ -38,6 +39,7 @@ class FrostWebViewCore @JvmOverloads constructor( val titleObservable: BehaviorSubject // Only emits on different non http titles var baseUrl: String? = null + var baseJavascript: JsAssets? = null init { isNestedScrollingEnabled = true @@ -53,8 +55,8 @@ class FrostWebViewCore @JvmOverloads constructor( settings.userAgentString = USER_AGENT_BASIC // settings.domStorageEnabled = true setLayerType(View.LAYER_TYPE_HARDWARE, null) - setWebViewClient(FrostWebViewClient(refreshObservable)) - setWebChromeClient(FrostChromeClient(progressObservable, titleObservable)) + webViewClient = FrostWebViewClient(refreshObservable) + webChromeClient = FrostChromeClient(progressObservable, titleObservable) addJavascriptInterface(FrostJSI(context), "Frost") } @@ -63,7 +65,9 @@ class FrostWebViewCore @JvmOverloads constructor( super.loadUrl(url) } - fun loadBaseUrl() = loadUrl(baseUrl) + fun loadBaseUrl() { + loadUrl(baseUrl) + } fun addTitleListener(subscriber: (title: String) -> Unit, scheduler: Scheduler = AndroidSchedulers.mainThread()): Disposable = titleObservable.observeOn(scheduler).subscribe(subscriber) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ee5d1294..c7fc6e72 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -20,11 +20,16 @@ Birthdays Chat Photos + Settings + Menu + Getting everything ready… Welcome %s Login Select Facebook Account Add Account - Add Facebook Account Manage Account + Exit + Are you sure you want to exit Frost? + Don\'t show again diff --git a/app/src/main/res/values/strings_preferences b/app/src/main/res/values/strings_preferences index 9cb29553..9f9ca131 100644 --- a/app/src/main/res/values/strings_preferences +++ b/app/src/main/res/values/strings_preferences @@ -1,5 +1,4 @@ - Settings Text Color Background Color Header Color diff --git a/gradle.properties b/gradle.properties index cf41d83e..befbfcb9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,7 +20,7 @@ VERSION_CODE=1 VERSION_NAME=0.1 ANDROID_SUPPORT_LIBS=26.0.0-alpha1 -KAU=-SNAPSHOT +KAU=1805793c7c MATERIAL_DRAWER=5.9.2 MATERIAL_DRAWER_KT=1.0.2 IICON_GOOGLE=3.0.1.0 -- cgit v1.2.3