aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-08-30 12:55:56 -0400
committerGitHub <noreply@github.com>2017-08-30 12:55:56 -0400
commit270ff7705be5ec0c78f5eae4934779ff4b4c00ee (patch)
treefb0ba3e117e138391ac268bc8116e97140e6f436 /app/src/main/kotlin
parenta854dcc471078f4e21916730abb5d5d75dd7b03c (diff)
downloadfrost-270ff7705be5ec0c78f5eae4934779ff4b4c00ee.tar.gz
frost-270ff7705be5ec0c78f5eae4934779ff4b4c00ee.tar.bz2
frost-270ff7705be5ec0c78f5eae4934779ff4b4c00ee.zip
fix/searchview (#239)
* Keep searchview even if headless response fails * Keep searchview even if headless response fails * Update changelog and add search tests * Update kau and remove tests * Remove duplicate dispose calls
Diffstat (limited to 'app/src/main/kotlin')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt23
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostRequestInterceptor.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/SearchWebView.kt12
3 files changed, 14 insertions, 23 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
index 29bc350b..dd8ed558 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
@@ -143,8 +143,7 @@ class MainActivity : BaseActivity(), SearchWebView.SearchContract,
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
super.onPageScrolled(position, positionOffset, positionOffsetPixels)
val delta: Float by lazy { positionOffset * (255 - 128).toFloat() }
- tabsForEachView {
- tabPosition, view ->
+ tabsForEachView { tabPosition, view ->
view.setAllAlpha(when (tabPosition) {
position -> 255.0f - delta
position + 1 -> 128.0f + delta
@@ -163,15 +162,13 @@ class MainActivity : BaseActivity(), SearchWebView.SearchContract,
setFrostColors(toolbar, themeWindow = false, headers = arrayOf(appBar), backgrounds = arrayOf(viewPager))
tabs.setBackgroundColor(Prefs.mainActivityLayout.backgroundColor())
onCreateBilling()
- setNetworkObserver {
- connectivity ->
+ setNetworkObserver { connectivity ->
shouldLoadImages = !connectivity.isRoaming
}
}
fun tabsForEachView(action: (position: Int, view: BadgedIcon) -> Unit) {
- (0 until tabs.tabCount).asSequence().forEach {
- i ->
+ (0 until tabs.tabCount).asSequence().forEach { i ->
action(i, tabs.getTabAt(i)!!.customView as BadgedIcon)
}
}
@@ -200,10 +197,8 @@ class MainActivity : BaseActivity(), SearchWebView.SearchContract,
return@map arrayOf(feed, requests, messages, notifications).map { it?.getOrNull(0)?.ownText() }
}
.observeOn(AndroidSchedulers.mainThread())
- .subscribe {
- (feed, requests, messages, notifications) ->
- tabsForEachView {
- _, view ->
+ .subscribe { (feed, requests, messages, notifications) ->
+ tabsForEachView { _, view ->
when (view.iicon) {
FbItem.FEED.icon -> view.badgeText = feed
FbItem.FRIENDS.icon -> view.badgeText = requests
@@ -340,11 +335,9 @@ class MainActivity : BaseActivity(), SearchWebView.SearchContract,
* Something happened where the normal search function won't work
* Fallback to overlay style
*/
- override fun searchOverlayDispose() {
- hiddenSearchView?.dispose()
+ override fun disposeHeadlessSearch() {
hiddenSearchView = null
- searchView?.unBind { launchWebOverlay(FbItem.SEARCH.url); true }
- searchView = null
+ searchView?.config { textCallback = { _, _ -> } }
}
override fun emitSearchResponse(items: List<SearchItem>) {
@@ -373,7 +366,7 @@ class MainActivity : BaseActivity(), SearchWebView.SearchContract,
onItemClick = { _, key, _, _ -> launchWebOverlay(key) }
}
} else {
- if (searchView != null) searchOverlayDispose()
+ if (searchView != null) disposeHeadlessSearch()
else menu.findItem(R.id.action_search).setOnMenuItemClickListener { _ -> launchWebOverlay(FbItem.SEARCH.url); true }
}
return true
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostRequestInterceptor.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostRequestInterceptor.kt
index 34022c25..4936eaf4 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostRequestInterceptor.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostRequestInterceptor.kt
@@ -23,7 +23,7 @@ private val blankResource: WebResourceResponse by lazy { WebResourceResponse("te
//these hosts will redirect to a blank resource
private val blacklistHost: Set<String> =
setOf(
-// "edge-chat.facebook.com"
+// "edge-chat.facebook.com" //todo make more specific? This is required for message responses
)
//these hosts will return null and skip logging
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/SearchWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/SearchWebView.kt
index dc2bd8af..16d9f4bf 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/SearchWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/SearchWebView.kt
@@ -11,7 +11,6 @@ import com.pitchedapps.frost.facebook.USER_AGENT_BASIC
import com.pitchedapps.frost.injectors.JsAssets
import com.pitchedapps.frost.injectors.JsBuilder
import com.pitchedapps.frost.utils.L
-import com.pitchedapps.frost.utils.Prefs
import io.reactivex.schedulers.Schedulers
import io.reactivex.subjects.PublishSubject
import org.jetbrains.anko.runOnUiThread
@@ -118,13 +117,12 @@ class SearchWebView(context: Context, val contract: SearchContract) : WebView(co
fun emit(flag: Int) {
when (flag) {
0 -> {
- L.d("Search loaded successfully")
+ L.i("Search loaded successfully")
}
1 -> { //something is not found in the search view; this is effectively useless
- L.e("Search subject error; reverting to full overlay")
- Prefs.searchBar = false
- searchSubject.onComplete()
- contract.searchOverlayDispose()
+ L.e("Search subject error")
+ dispose()
+ contract.disposeHeadlessSearch()
}
2 -> {
L.v("Search emission received")
@@ -141,7 +139,7 @@ class SearchWebView(context: Context, val contract: SearchContract) : WebView(co
}
interface SearchContract {
- fun searchOverlayDispose()
+ fun disposeHeadlessSearch()
fun emitSearchResponse(items: List<SearchItem>)
val isSearchOpened: Boolean
}