aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/activities
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/activities')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt10
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt55
2 files changed, 41 insertions, 24 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
index 80d248bc..8f932a94 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
@@ -58,6 +58,7 @@ import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.facebook.FbItem
import com.pitchedapps.frost.facebook.PROFILE_PICTURE_URL
import com.pitchedapps.frost.fragments.BaseFragment
+import com.pitchedapps.frost.parsers.FrostSearch
import com.pitchedapps.frost.parsers.SearchParser
import com.pitchedapps.frost.utils.*
import com.pitchedapps.frost.utils.iab.FrostBilling
@@ -127,6 +128,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
onCreateBilling()
}
+
fun tabsForEachView(action: (position: Int, view: BadgedIcon) -> Unit) {
(0 until tabs.tabCount).asSequence().forEach { i ->
action(i, tabs.getTabAt(i)!!.customView as BadgedIcon)
@@ -193,7 +195,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
-3L -> launchNewTask(LoginActivity::class.java, clearStack = false)
-4L -> launchNewTask(SelectorActivity::class.java, cookies(), false)
else -> {
- FbCookie.switchUser(profile.identifier, { refreshAll() })
+ FbCookie.switchUser(profile.identifier, this@BaseMainActivity::refreshAll)
tabsForEachView { _, view -> view.badgeText = null }
}
}
@@ -248,7 +250,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
onClick { _ -> onClick(); false }
}
- fun refreshAll() {
+ private fun refreshAll() {
fragmentSubject.onNext(REQUEST_REFRESH)
}
@@ -266,8 +268,8 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
runOnUiThread { searchView?.results = results }
else
doAsync {
- val data = SearchParser.query(query) ?: return@doAsync
- val items = data.map { SearchItem(it.href, it.title, it.description) }.toMutableList()
+ val data = SearchParser.query(FbCookie.webCookie, query)?.data?.results ?: return@doAsync
+ val items = data.map(FrostSearch::toSearchItem).toMutableList()
if (items.isNotEmpty())
items.add(SearchItem("${FbItem._SEARCH.url}?q=$query", string(R.string.show_all_results), iicon = null))
searchViewCache.put(query, items)
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt
index 0d6cce07..e2f7a3d2 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt
@@ -25,10 +25,9 @@ import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.facebook.PROFILE_PICTURE_URL
import com.pitchedapps.frost.utils.*
import com.pitchedapps.frost.web.LoginWebView
-import io.reactivex.Observable
+import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.functions.BiFunction
-import io.reactivex.internal.operators.single.SingleToObservable
import io.reactivex.subjects.SingleSubject
@@ -37,18 +36,18 @@ import io.reactivex.subjects.SingleSubject
*/
class LoginActivity : BaseActivity() {
- val toolbar: Toolbar by bindView(R.id.toolbar)
- val web: LoginWebView by bindView(R.id.login_webview)
- val swipeRefresh: SwipeRefreshLayout by bindView(R.id.swipe_refresh)
- val textview: AppCompatTextView by bindView(R.id.textview)
- val profile: ImageView by bindView(R.id.profile)
+ private val toolbar: Toolbar by bindView(R.id.toolbar)
+ private val web: LoginWebView by bindView(R.id.login_webview)
+ private val swipeRefresh: SwipeRefreshLayout by bindView(R.id.swipe_refresh)
+ private val textview: AppCompatTextView by bindView(R.id.textview)
+ private val profile: ImageView by bindView(R.id.profile)
- val profileObservable = SingleSubject.create<Boolean>()
- val usernameObservable = SingleSubject.create<String>()
- lateinit var profileLoader: RequestManager
+ private val profileSubject = SingleSubject.create<Boolean>()
+ private val usernameSubject = SingleSubject.create<String>()
+ private lateinit var profileLoader: RequestManager
// Helper to set and enable swipeRefresh
- var refresh: Boolean
+ private var refresh: Boolean
get() = swipeRefresh.isRefreshing
set(value) {
if (value) swipeRefresh.isEnabled = true
@@ -73,10 +72,12 @@ class LoginActivity : BaseActivity() {
profileLoader = Glide.with(profile)
}
- fun loadInfo(cookie: CookieModel) {
+ private fun loadInfo(cookie: CookieModel) {
refresh = true
- Observable.zip(SingleToObservable(profileObservable), SingleToObservable(usernameObservable),
- BiFunction<Boolean, String, Pair<Boolean, String>> { foundImage, name -> Pair(foundImage, name) })
+ Single.zip<Boolean, String, Pair<Boolean, String>>(
+ profileSubject,
+ usernameSubject,
+ BiFunction(::Pair))
.observeOn(AndroidSchedulers.mainThread()).subscribe { (foundImage, name) ->
refresh = false
if (!foundImage) {
@@ -85,7 +86,11 @@ class LoginActivity : BaseActivity() {
}
textview.text = String.format(getString(R.string.welcome), name)
textview.fadeIn()
- frostAnswers { logLogin(LoginEvent().putMethod("frost_browser").putSuccess(true)) }
+ frostAnswers {
+ logLogin(LoginEvent()
+ .putMethod("frost_browser")
+ .putSuccess(true))
+ }
/*
* The user may have logged into an account that is already in the database
* We will let the db handle duplicates and load it now after the new account has been saved
@@ -102,23 +107,23 @@ class LoginActivity : BaseActivity() {
}
- fun loadProfile(id: Long) {
+ private fun loadProfile(id: Long) {
profileLoader.load(PROFILE_PICTURE_URL(id)).withRoundIcon().listener(object : RequestListener<Drawable> {
override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
- profileObservable.onSuccess(true)
+ profileSubject.onSuccess(true)
return false
}
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
e.logFrostAnswers("Profile loading exception")
- profileObservable.onSuccess(false)
+ profileSubject.onSuccess(false)
return false
}
}).into(profile)
}
- fun loadUsername(cookie: CookieModel) {
- cookie.fetchUsername { usernameObservable.onSuccess(it) }
+ private fun loadUsername(cookie: CookieModel) {
+ cookie.fetchUsername(usernameSubject::onSuccess)
}
override fun backConsumer(): Boolean {
@@ -129,4 +134,14 @@ class LoginActivity : BaseActivity() {
return false
}
+ override fun onResume() {
+ super.onResume()
+ web.resumeTimers()
+ }
+
+ override fun onPause() {
+ web.pauseTimers()
+ super.onPause()
+ }
+
} \ No newline at end of file