aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/fragments
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-08-06 00:49:58 -0700
committerAllan Wang <me@allanwang.ca>2019-08-06 00:49:58 -0700
commit55bf3e4b5b4af5baa3c230ca82f74988608971a3 (patch)
tree3db856e037b70257aaef19e34db6b0856bda6412 /app/src/main/kotlin/com/pitchedapps/frost/fragments
parent99953f087f2c363dad05ae3f86b5bcba22484e43 (diff)
downloadfrost-55bf3e4b5b4af5baa3c230ca82f74988608971a3.tar.gz
frost-55bf3e4b5b4af5baa3c230ca82f74988608971a3.tar.bz2
frost-55bf3e4b5b4af5baa3c230ca82f74988608971a3.zip
Format kotlin
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/fragments')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragmentBase.kt73
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragments.kt25
2 files changed, 51 insertions, 47 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragmentBase.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragmentBase.kt
index 9f2d704c..71c27dd2 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragmentBase.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragmentBase.kt
@@ -50,23 +50,24 @@ abstract class RecyclerFragment<T, Item : IItem<*, *>> : BaseFragment(), Recycle
}
}
- final override suspend fun reload(progress: (Int) -> Unit): Boolean = withContext(Dispatchers.IO) {
- val data = try {
- reloadImpl(progress)
- } catch (e: Exception) {
- L.e(e) { "Recycler reload fail $baseUrl" }
- null
- }
- withMainContext {
- if (data == null) {
- valid = false
- false
- } else {
- adapter.setNewList(data)
- true
+ final override suspend fun reload(progress: (Int) -> Unit): Boolean =
+ withContext(Dispatchers.IO) {
+ val data = try {
+ reloadImpl(progress)
+ } catch (e: Exception) {
+ L.e(e) { "Recycler reload fail $baseUrl" }
+ null
+ }
+ withMainContext {
+ if (data == null) {
+ valid = false
+ false
+ } else {
+ adapter.setNewList(data)
+ true
+ }
}
}
- }
protected abstract suspend fun reloadImpl(progress: (Int) -> Unit): List<T>?
}
@@ -95,7 +96,8 @@ abstract class GenericRecyclerFragment<T, Item : IItem<*, *>> : RecyclerFragment
open fun getAdapter(): FastAdapter<IItem<*, *>> = fastAdapter(this.adapter)
}
-abstract class FrostParserFragment<T : ParseData, Item : IItem<*, *>> : RecyclerFragment<Item, Item>() {
+abstract class FrostParserFragment<T : ParseData, Item : IItem<*, *>> :
+ RecyclerFragment<Item, Item>() {
/**
* The parser to make this all happen
@@ -125,24 +127,25 @@ abstract class FrostParserFragment<T : ParseData, Item : IItem<*, *>> : Recycler
*/
open fun getAdapter(): FastAdapter<IItem<*, *>> = fastAdapter(this.adapter)
- override suspend fun reloadImpl(progress: (Int) -> Unit): List<Item>? = withContext(Dispatchers.IO) {
- progress(10)
- val cookie = FbCookie.webCookie
- val doc = getDoc(cookie)
- progress(60)
- val response = try {
- parser.parse(cookie, doc)
- } catch (ignored: Exception) {
- null
- }
- if (response == null) {
- L.i { "RecyclerFragment failed for ${baseEnum.name}" }
- L._d { "Cookie used: $cookie" }
- return@withContext null
+ override suspend fun reloadImpl(progress: (Int) -> Unit): List<Item>? =
+ withContext(Dispatchers.IO) {
+ progress(10)
+ val cookie = FbCookie.webCookie
+ val doc = getDoc(cookie)
+ progress(60)
+ val response = try {
+ parser.parse(cookie, doc)
+ } catch (ignored: Exception) {
+ null
+ }
+ if (response == null) {
+ L.i { "RecyclerFragment failed for ${baseEnum.name}" }
+ L._d { "Cookie used: $cookie" }
+ return@withContext null
+ }
+ progress(80)
+ val items = toItems(response)
+ progress(97)
+ return@withContext items
}
- progress(80)
- val items = toItems(response)
- progress(97)
- return@withContext items
- }
}
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 d9d518b1..54ea388d 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragments.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragments.kt
@@ -71,16 +71,17 @@ class MenuFragment : GenericRecyclerFragment<MenuItemData, IItem<*, *>>() {
ClickableIItemContract.bindEvents(adapter)
}
- override suspend fun reloadImpl(progress: (Int) -> Unit): List<MenuItemData>? = withContext(Dispatchers.IO) {
- val cookie = FbCookie.webCookie ?: return@withContext null
- progress(10)
- val auth = fbAuth.fetch(cookie).await()
- progress(30)
- val data = auth.getMenuData().invoke() ?: return@withContext null
- if (data.data.isEmpty()) return@withContext null
- progress(70)
- val items = data.flatMapValid()
- progress(90)
- return@withContext items
- }
+ override suspend fun reloadImpl(progress: (Int) -> Unit): List<MenuItemData>? =
+ withContext(Dispatchers.IO) {
+ val cookie = FbCookie.webCookie ?: return@withContext null
+ progress(10)
+ val auth = fbAuth.fetch(cookie).await()
+ progress(30)
+ val data = auth.getMenuData().invoke() ?: return@withContext null
+ if (data.data.isEmpty()) return@withContext null
+ progress(70)
+ val items = data.flatMapValid()
+ progress(90)
+ return@withContext items
+ }
}