aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt31
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbSearch.kt9
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewSearch.kt10
-rw-r--r--app/src/main/res/menu/menu_main.xml7
4 files changed, 35 insertions, 22 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt
index cccb3e0c..2103a8ee 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt
@@ -4,10 +4,7 @@ import android.content.Intent
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.support.annotation.StringRes
-import android.support.design.widget.AppBarLayout
-import android.support.design.widget.FloatingActionButton
-import android.support.design.widget.Snackbar
-import android.support.design.widget.TabLayout
+import android.support.design.widget.*
import android.support.v4.app.ActivityOptionsCompat
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
@@ -17,6 +14,9 @@ import android.support.v7.widget.Toolbar
import android.view.Menu
import android.view.MenuItem
import ca.allanwang.kau.changelog.showChangelog
+import ca.allanwang.kau.searchview.SearchItem
+import ca.allanwang.kau.searchview.SearchView
+import ca.allanwang.kau.searchview.bindSearchView
import ca.allanwang.kau.utils.*
import co.zsmb.materialdrawerkt.builders.Builder
import co.zsmb.materialdrawerkt.builders.accountHeader
@@ -56,6 +56,7 @@ class MainActivity : BaseActivity(), FrostWebViewSearch.SearchContract {
val fab: FloatingActionButton by bindView(R.id.fab)
val tabs: TabLayout by bindView(R.id.tabs)
val appBar: AppBarLayout by bindView(R.id.appbar)
+ val coordinator: CoordinatorLayout by bindView(R.id.main_content)
lateinit var drawer: Drawer
lateinit var drawerHeader: AccountHeader
var webFragmentObservable = PublishSubject.create<Int>()!!
@@ -71,6 +72,7 @@ class MainActivity : BaseActivity(), FrostWebViewSearch.SearchContract {
currentFragment.frostWebView.addView(hiddenSearchView)
}
}
+ var searchView: SearchView? = null
companion object {
const val FRAGMENT_REFRESH = 99
@@ -306,9 +308,8 @@ class MainActivity : BaseActivity(), FrostWebViewSearch.SearchContract {
//todo remove true searchview and add contract
}
- //todo add args
- override fun emitSearchResponse() {
-
+ override fun emitSearchResponse(items: List<SearchItem>) {
+ searchView?.results = items
}
fun refreshAll() {
@@ -320,6 +321,22 @@ class MainActivity : BaseActivity(), FrostWebViewSearch.SearchContract {
toolbar.tint(Prefs.iconColor)
setMenuIcons(menu, Prefs.iconColor,
R.id.action_settings to GoogleMaterial.Icon.gmd_settings)
+ searchView = coordinator.bindSearchView(menu, R.id.action_search) {
+ textObserver = {
+ observable, _ ->
+ observable.subscribe {
+ hiddenSearchView?.query(it)
+ }
+ }
+ foregroundColor = Prefs.textColor
+ backgroundColor = Prefs.bgColor
+ openListener = {
+ hiddenSearchView?.pauseLoad = false
+ }
+ closeListener = {
+ hiddenSearchView?.pauseLoad = true
+ }
+ }
return true
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbSearch.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbSearch.kt
deleted file mode 100644
index 151957d3..00000000
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbSearch.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.pitchedapps.frost.facebook
-
-/**
- * Created by Allan Wang on 2017-06-26.
- *
- * Handles asynchronous user graph searches
- */
-class FbSearch {
-} \ No newline at end of file
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewSearch.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewSearch.kt
index 6c9ee9d5..d42ea33e 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewSearch.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewSearch.kt
@@ -6,6 +6,7 @@ import android.view.View
import android.webkit.JavascriptInterface
import android.webkit.WebView
import android.webkit.WebViewClient
+import ca.allanwang.kau.searchview.SearchItem
import ca.allanwang.kau.utils.gone
import com.pitchedapps.frost.facebook.FbTab
import com.pitchedapps.frost.facebook.USER_AGENT_BASIC
@@ -68,11 +69,11 @@ class FrostWebViewSearch(context: Context, val contract: SearchContract) : WebVi
.subscribe {
content: List<Pair<List<String>, String>> ->
saveResultFrame(content)
- content.forEach {
+ contract.emitSearchResponse(content.map {
(texts, href) ->
L.d("Search element $texts $href")
- }
- contract.emitSearchResponse()
+ SearchItem(href, texts[0], texts.getOrNull(1))
+ })
}
reload()
}
@@ -138,8 +139,7 @@ class FrostWebViewSearch(context: Context, val contract: SearchContract) : WebVi
interface SearchContract {
fun searchOverlayError()
- //todo add args
- fun emitSearchResponse()
+ fun emitSearchResponse(items: List<SearchItem>)
}
}
diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml
index e82d1f44..d4cdddb9 100644
--- a/app/src/main/res/menu/menu_main.xml
+++ b/app/src/main/res/menu/menu_main.xml
@@ -4,9 +4,14 @@
tools:context="com.pitchedapps.myapplication.MainActivity">
<item
+ android:id="@+id/action_search"
+ android:orderInCategory="200"
+ android:title="@string/kau_search"
+ app:showAsAction="always" />
+ <item
android:id="@+id/action_settings"
android:orderInCategory="200"
android:title="@string/kau_settings"
- app:showAsAction="always" />
+ app:showAsAction="ifRoom" />
</menu>