aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-12-26 03:37:32 -0500
committerAllan Wang <me@allanwang.ca>2017-12-26 03:39:28 -0500
commit1769dbcef9786b847ffeaebdf6ecced45da9222c (patch)
tree50f543469607b608c0b62ca8a63c6a65325802b9 /app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt
parent8080d43dbd9a6863fadb86594b179d0919d6215b (diff)
downloadfrost-1769dbcef9786b847ffeaebdf6ecced45da9222c.tar.gz
frost-1769dbcef9786b847ffeaebdf6ecced45da9222c.tar.bz2
frost-1769dbcef9786b847ffeaebdf6ecced45da9222c.zip
Enhancement/fb requests (#575)v1.7.2
* Update lambdas to references * Simplify regex and parsers * Fix some parsing and add more tests * Improve message parser and tests * Simplify parser * Shorten interfaces * Push rem * Create notification parser * Clean up notification service * Clean up notification service * Add safe cookie fallback * Fix cookie reference * Make parsers only hold cookie string * Clean up cookie references * Fix up login and event theme * Update changelog Remove workspace backup
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt17
1 files changed, 14 insertions, 3 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt
index 498164c0..58d9ebd4 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt
@@ -13,7 +13,9 @@ import com.pitchedapps.frost.R
import com.pitchedapps.frost.contracts.DynamicUiContract
import com.pitchedapps.frost.contracts.FrostContentParent
import com.pitchedapps.frost.contracts.MainActivityContract
+import com.pitchedapps.frost.dbflow.CookieModel
import com.pitchedapps.frost.enums.FeedSort
+import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.facebook.FbItem
import com.pitchedapps.frost.parsers.FrostParser
import com.pitchedapps.frost.utils.*
@@ -28,6 +30,9 @@ import org.jetbrains.anko.toast
/**
* Created by Allan Wang on 2017-11-07.
+ *
+ * All fragments pertaining to the main view
+ * Must be attached to activities implementing [MainActivityContract]
*/
abstract class BaseFragment : Fragment(), FragmentContract, DynamicUiContract {
@@ -59,6 +64,12 @@ abstract class BaseFragment : Fragment(), FragmentContract, DynamicUiContract {
protected abstract val layoutRes: Int
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ if (context !is MainActivityContract)
+ throw IllegalArgumentException("${this::class.java.simpleName} is not attached to a context implementing MainActivityContract")
+ }
+
override final fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(layoutRes, container, false)
val content = view as? FrostContentParent
@@ -162,7 +173,7 @@ abstract class BaseFragment : Fragment(), FragmentContract, DynamicUiContract {
override fun onTabClick(): Unit = content?.core?.onTabClicked() ?: Unit
}
-abstract class RecyclerFragment<T, Item : IItem<*, *>> : BaseFragment(), RecyclerContentContract {
+abstract class RecyclerFragment<T : Any, Item : IItem<*, *>> : BaseFragment(), RecyclerContentContract {
override val layoutRes: Int = R.layout.view_content_recycler
@@ -199,7 +210,7 @@ abstract class RecyclerFragment<T, Item : IItem<*, *>> : BaseFragment(), Recycle
progress(10)
val doc = frostJsoup(baseUrl)
progress(60)
- val data = parser.parse(doc)
+ val data = parser.parse(FbCookie.webCookie, doc)
if (data == null) {
context?.toast(R.string.error_generic)
L.eThrow("RecyclerFragment failed for ${baseEnum.name}")
@@ -207,7 +218,7 @@ abstract class RecyclerFragment<T, Item : IItem<*, *>> : BaseFragment(), Recycle
return@doAsync callback(false)
}
progress(80)
- val items = toItems(data)
+ val items = toItems(data.data)
progress(97)
adapter.setNewList(items)
}