Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Commit

Permalink
Fix notifications and long press for albums (#69)
Browse files Browse the repository at this point in the history
* Allow for album images to be viewed

* Update listing info

* Web refractoring

* Test message notifications

* Fix notifications and context press
  • Loading branch information
AllanWang authored Jul 17, 2017
1 parent 7bf93ea commit e4679b1
Show file tree
Hide file tree
Showing 18 changed files with 250 additions and 131 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ It contains many features, including:
* Full theming across all activities
* Overlaying browser to read posts and get right back to your previous task
* Extensive notification support, with bundling, filtering, battery friendly scheduling, icons, and multi user support
* Context menu from any link through long press
* Context menu from any link via long press
* Native image viewer and downloader via long press
* Reactive based loading
* The transparency of open sourced development
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ android {
versionNameSuffix "-debug"
resValue "string", "app_name", "Frost Debug"
resValue "string", "frost_web", "Frost Web Debug"
ext.enableCrashlytics = false
}
releaseTest {
minifyEnabled true
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!--<uses-permission android:name="android.permission.VIBRATE" />-->
<uses-permission android:name="android.permission.VIBRATE" />
<!--<uses-permission android:name="android.permission.USE_FINGERPRINT" />-->
<uses-permission android:name="com.android.vending.BILLING" />

Expand Down
5 changes: 3 additions & 2 deletions app/src/main/assets/js/context_a.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ if (!window.hasOwnProperty('frost_context_a')) {
if (!url) return;
var text = element.parentNode.innerText;

//check if image item exists
var image = element.parentNode.querySelector('[style*="background-image: url("]');
//check if image item exists, first in children and then in parent
var image = element.querySelector('[style*="background-image: url("]');
if (!image) image = element.parentNode.querySelector('[style*="background-image: url("]');
if (image) {
var imageUrl = window.getComputedStyle(image, null).backgroundImage.slice(5, -2);
console.log('Context image', imageUrl);
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/assets/js/context_a.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ longClick=!0
"A"!==t.tagName&&(t=t.parentNode),"A"===t.tagName&&"#"!==t.getAttribute("href"))){
var o=t.getAttribute("href")
;if(!o)return
;var n=t.parentNode.innerText,r=t.parentNode.querySelector('[style*="background-image: url("]')
;if(r){
;var n=t.parentNode.innerText,r=t.querySelector('[style*="background-image: url("]')
;if(r||(r=t.parentNode.querySelector('[style*="background-image: url("]')),
r){
var a=window.getComputedStyle(r,null).backgroundImage.slice(5,-2)
;console.log("Context image",a),
"undefined"!=typeof Frost&&Frost.loadImage(a,n)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ import com.pitchedapps.frost.utils.*
import com.pitchedapps.frost.utils.iab.validatePro
import com.pitchedapps.frost.views.BadgedIcon
import com.pitchedapps.frost.views.FrostViewPager
import com.pitchedapps.frost.web.FrostWebViewSearch
import com.pitchedapps.frost.web.SearchWebView
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import io.reactivex.subjects.PublishSubject
import org.jsoup.Jsoup
import java.util.concurrent.TimeUnit

class MainActivity : BaseActivity(), FrostWebViewSearch.SearchContract,
class MainActivity : BaseActivity(), SearchWebView.SearchContract,
ActivityWebContract, FileChooserContract by FileChooserDelegate() {

lateinit var adapter: SectionsPagerAdapter
Expand All @@ -78,13 +78,13 @@ class MainActivity : BaseActivity(), FrostWebViewSearch.SearchContract,
var webFragmentObservable = PublishSubject.create<Int>()!!
var lastPosition = -1
val headerBadgeObservable = PublishSubject.create<String>()
var hiddenSearchView: FrostWebViewSearch? = null
var hiddenSearchView: SearchWebView? = null
var firstLoadFinished = false
set(value) {
L.d("First fragment load has finished")
field = value
if (value && hiddenSearchView == null) {
hiddenSearchView = FrostWebViewSearch(this, this)
hiddenSearchView = SearchWebView(this, this)
}
}
var searchView: SearchView? = null
Expand Down Expand Up @@ -354,7 +354,7 @@ class MainActivity : BaseActivity(), FrostWebViewSearch.SearchContract,
R.id.action_settings to GoogleMaterial.Icon.gmd_settings,
R.id.action_search to GoogleMaterial.Icon.gmd_search)
if (Prefs.searchBar) {
if (firstLoadFinished && hiddenSearchView == null) hiddenSearchView = FrostWebViewSearch(this, this)
if (firstLoadFinished && hiddenSearchView == null) hiddenSearchView = SearchWebView(this, this)
if (searchView == null) searchView = bindSearchView(menu, R.id.action_search, Prefs.iconColor) {
textObserver = {
observable, _ ->
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,14 @@ object FbCookie {
* When coming back to the main app, switch back to our original account before continuing
*/
fun switchBackUser(callback: () -> Unit) {
if (Prefs.prevId != -1L && Prefs.prevId != Prefs.userId) {
switchUser(Prefs.prevId) {
L.d("Switch back user", "${Prefs.userId} to ${Prefs.prevId}")
if (Prefs.prevId == -1L) return callback()
val prevId = Prefs.prevId
Prefs.prevId = -1L
if (prevId != Prefs.userId) {
switchUser(prevId) {
L.d("Switch back user", "${Prefs.userId} to ${prevId}")
callback()
}
} else callback()
if (Prefs.prevId != -1L) Prefs.prevId = -1L
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enum class JsActions(body: String) : InjectorContract {
*/
LOGIN_CHECK("document.getElementById('signup-button')&&Frost.loadLogin();"),
BASE_HREF("document.write(\"<base href='$FB_URL_BASE'/>\");"),
GET_MESSAGES("setTimeout(function(){Frost.handleHtml(document.getElementById('threadlist_rows').outerHtml)},1000)"),
EMPTY("");

val function = "!function(){$body}();"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import com.pitchedapps.frost.facebook.USER_AGENT_BASIC
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.frostAnswersCustom
import com.pitchedapps.frost.web.MessageWebView
import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread
import org.jsoup.Jsoup
import org.jsoup.nodes.Element
import java.util.concurrent.Future
Expand Down Expand Up @@ -45,17 +47,29 @@ class NotificationService : JobService() {
return false
}


override fun onStartJob(params: JobParameters?): Boolean {
future = doAsync {
if (Prefs.notificationAllAccounts) {
loadFbCookiesSync().forEach {
data ->
fetchNotifications(data)
}
val cookies = loadFbCookiesSync()
cookies.forEach { fetchGeneralNotifications(it) }
// if (Prefs.notificationsInstantMessages) {
// Prefs.prevId = Prefs.userId
// uiThread {
// val messageWebView = MessageWebView(this@NotificationService, params)
// cookies.forEach { messageWebView.request(it) }
// }
// return@doAsync
// }
} else {
val currentCookie = loadFbCookie(Prefs.userId)
if (currentCookie != null)
fetchNotifications(currentCookie)
if (currentCookie != null) {
fetchGeneralNotifications(currentCookie)
// if (Prefs.notificationsInstantMessages) {
// uiThread { MessageWebView(this@NotificationService, params).request(currentCookie) }
// return@doAsync
// }
}
}
L.d("Finished notifications")
jobFinished(params, false)
Expand All @@ -69,12 +83,6 @@ class NotificationService : JobService() {
return null
}

fun fetchNotifications(data: CookieModel) {
fetchGeneralNotifications(data)
// fetchMessageNotifications(data)
debugNotification("Hello")
}

fun fetchGeneralNotifications(data: CookieModel) {
L.i("Notif fetch for $data")
val doc = Jsoup.connect(FbTab.NOTIFICATIONS.url).cookie(FACEBOOK_COM, data.cookie).userAgent(USER_AGENT_BASIC).get()
Expand All @@ -96,7 +104,8 @@ class NotificationService : JobService() {
newLatestEpoch = notif.timestamp
notifCount++
}
if (newLatestEpoch != prevLatestEpoch) prevNotifTime.copy(epoch = newLatestEpoch).update()
if (newLatestEpoch != prevLatestEpoch) prevNotifTime.copy(epoch = newLatestEpoch).save()
L.d("Notif new latest epoch ${lastNotificationTime(data.id).epoch}")
frostAnswersCustom("Notifications") {
putCustomAttribute("Type", "General")
putCustomAttribute("Count", notifCount)
Expand All @@ -120,10 +129,9 @@ class NotificationService : JobService() {
return NotificationContent(data, notifId.toInt(), a.attr("href"), null, text, epoch, pUrl)
}

fun fetchMessageNotifications(data: CookieModel) {
if (!Prefs.notificationsInstantMessages) return
fun fetchMessageNotifications(data: CookieModel, content: String) {
L.i("Notif IM fetch for $data")
val doc = Jsoup.connect(FbTab.MESSAGES.url).cookie(FACEBOOK_COM, data.cookie).userAgent(USER_AGENT_BASIC).get()
val doc = Jsoup.parseBodyFragment(content)
val unreadNotifications = (doc.getElementById("threadlist_rows") ?: return L.eThrow("Notification messages not found")).getElementsByClass("aclb")
var notifCount = 0
L.d("IM notif count ${unreadNotifications.size}")
Expand All @@ -146,7 +154,8 @@ class NotificationService : JobService() {
newLatestEpoch = notif.timestamp
notifCount++
}
// if (newLatestEpoch != prevLatestEpoch) prevNotifTime.copy(epochIm = newLatestEpoch).update()
if (newLatestEpoch != prevLatestEpoch) prevNotifTime.copy(epochIm = newLatestEpoch).save()
L.d("Notif new latest im epoch ${lastNotificationTime(data.id).epochIm}")
frostAnswersCustom("Notifications") {
putCustomAttribute("Type", "Message")
putCustomAttribute("Count", notifCount)
Expand Down
16 changes: 0 additions & 16 deletions app/src/main/kotlin/com/pitchedapps/frost/web/BaseWebViewClient.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ import io.reactivex.subjects.Subject

/**
* Created by Allan Wang on 2017-05-31.
*
* Collection of chrome clients
*/

/**
* Nothing more than a client without logging
*/
class QuietChromeClient : WebChromeClient() {
override fun onConsoleMessage(consoleMessage: ConsoleMessage) = true
}

/**
* The default chrome client
*/
class FrostChromeClient(webCore: FrostWebViewCore) : WebChromeClient() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package com.pitchedapps.frost.web

import android.graphics.Bitmap.CompressFormat
import android.webkit.WebResourceRequest
import android.webkit.WebResourceResponse
import android.webkit.WebView
import ca.allanwang.kau.utils.use
import com.pitchedapps.frost.utils.GlideApp
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
import okhttp3.HttpUrl
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.InputStream


/**
Expand Down Expand Up @@ -62,6 +57,23 @@ fun shouldFrostInterceptRequest(view: WebView, request: WebResourceRequest): Web
return null
}

/**
* Wrapper to ensure that null exceptions are not reached
*/
fun WebResourceRequest.query(action: (url: String) -> Boolean): Boolean {
return action(url?.path ?: return false)
}

/**
* Generic filter passthrough
* If Resource is already nonnull, pass it, otherwise check if filter is met and override the response accordingly
*/
fun WebResourceResponse?.filter(request: WebResourceRequest, filter: (url: String) -> Boolean): WebResourceResponse?
= this ?: if (request.query { filter(it) }) blankResource else null

fun WebResourceResponse?.filterCss(request: WebResourceRequest): WebResourceResponse?
= this ?: if (request.url.path.endsWith(".css")) blankResource else null
= filter(request) { it.endsWith(".css") }

fun WebResourceResponse?.filterImage(request: WebResourceRequest): WebResourceResponse?
= filter(request) { it.contains(".jpg") || it.contains(".png") }

This file was deleted.

Loading

0 comments on commit e4679b1

Please sign in to comment.