aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragments.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-12-31 00:42:49 -0500
committerGitHub <noreply@github.com>2017-12-31 00:42:49 -0500
commit3076d9a97c203497aec1415d8ac6037d10eebb46 (patch)
treecdeb914fa95f2b230f6327be3e1527d15b41dc94 /app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragments.kt
parent041bafcceadbd5203e95f2692899ac903dd2e883 (diff)
downloadfrost-3076d9a97c203497aec1415d8ac6037d10eebb46.tar.gz
frost-3076d9a97c203497aec1415d8ac6037d10eebb46.tar.bz2
frost-3076d9a97c203497aec1415d8ac6037d10eebb46.zip
feature/menu-parser (#582)
* Test menu parser * Add menu fragment implementation * Test proguard * Clean up * Use async * Use invoke * Try without proguard * Try 2 * Add fallback logic * Use normal notification event * Add custom event flag * Add rest of menu fragment data * Ensure fallback works * Update docs
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragments.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragments.kt41
1 files changed, 39 insertions, 2 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragments.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragments.kt
index 4d4a6f8b..ca2912e8 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragments.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragments.kt
@@ -1,17 +1,22 @@
package com.pitchedapps.frost.fragments
+import com.mikepenz.fastadapter.IItem
+import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.facebook.FbItem
-import com.pitchedapps.frost.iitems.NotificationIItem
+import com.pitchedapps.frost.facebook.requests.*
+import com.pitchedapps.frost.iitems.*
import com.pitchedapps.frost.parsers.FrostNotifs
import com.pitchedapps.frost.parsers.NotifParser
import com.pitchedapps.frost.parsers.ParseResponse
import com.pitchedapps.frost.utils.frostJsoup
import com.pitchedapps.frost.views.FrostRecyclerView
+import org.jetbrains.anko.doAsync
+import org.jetbrains.anko.uiThread
/**
* Created by Allan Wang on 27/12/17.
*/
-class NotificationFragment : RecyclerFragment<FrostNotifs, NotificationIItem>() {
+class NotificationFragment : FrostParserFragment<FrostNotifs, NotificationIItem>() {
override val parser = NotifParser
@@ -23,5 +28,37 @@ class NotificationFragment : RecyclerFragment<FrostNotifs, NotificationIItem>()
override fun bindImpl(recyclerView: FrostRecyclerView) {
NotificationIItem.bindEvents(adapter)
}
+}
+class MenuFragment : GenericRecyclerFragment<MenuItemData, IItem<*, *>>() {
+
+ override fun mapper(data: MenuItemData): IItem<*, *> = when (data) {
+ is MenuHeader -> MenuHeaderIItem(data)
+ is MenuItem -> MenuContentIItem(data)
+ is MenuFooterItem ->
+ if (data.isSmall) MenuFooterSmallIItem(data)
+ else MenuFooterIItem(data)
+ else -> throw IllegalArgumentException("Menu item in fragment has invalid type ${data::class.java.simpleName}")
+ }
+
+ override fun bindImpl(recyclerView: FrostRecyclerView) {
+ ClickableIItemContract.bindEvents(adapter)
+ }
+
+ override fun reloadImpl(progress: (Int) -> Unit, callback: (Boolean) -> Unit) {
+ doAsync {
+ val cookie = FbCookie.webCookie
+ progress(10)
+ cookie.fbRequest({ callback(false) }) {
+ progress(30)
+ val data = getMenuData().invoke() ?: return@fbRequest callback(false)
+ if (data.data.isEmpty()) return@fbRequest callback(false)
+ progress(70)
+ val items = data.flatMapValid()
+ progress(90)
+ uiThread { adapter.add(items) }
+ callback(true)
+ }
+ }
+ }
} \ No newline at end of file