aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2018-12-27 16:54:11 -0500
committerAllan Wang <me@allanwang.ca>2018-12-27 16:54:11 -0500
commitc970d707105bbb614a630a1ac7340d6044e8fee1 (patch)
tree141f2e70c0fd34ea651fa9d00da23bd3eca9a0d7
parent0c3eb798345874b608776e9aab15278b33f996b5 (diff)
downloadfrost-c970d707105bbb614a630a1ac7340d6044e8fee1.tar.gz
frost-c970d707105bbb614a630a1ac7340d6044e8fee1.tar.bz2
frost-c970d707105bbb614a630a1ac7340d6044e8fee1.zip
Fix initial crash
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentContract.kt8
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragmentBase.kt16
2 files changed, 13 insertions, 11 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentContract.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentContract.kt
index 95322c1c..eaef17e5 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentContract.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentContract.kt
@@ -23,8 +23,6 @@ import com.pitchedapps.frost.contracts.MainActivityContract
import com.pitchedapps.frost.contracts.MainFabContract
import com.pitchedapps.frost.views.FrostRecyclerView
import io.reactivex.disposables.Disposable
-import kotlinx.coroutines.channels.ReceiveChannel
-import kotlinx.coroutines.channels.SendChannel
/**
* Created by Allan Wang on 2017-11-07.
@@ -103,9 +101,9 @@ interface RecyclerContentContract {
fun bind(recyclerView: FrostRecyclerView)
/**
- * Completely handle data reloading
- * The progress function allows optional emission of progress values (between 0 and 100).
- * This can be called from any thread.
+ * Completely handle data reloading, within a non-ui thread
+ * The progress function allows optional emission of progress values (between 0 and 100)
+ * and can be called from any thread.
* Returns [true] for success, [false] otherwise
*/
suspend fun reload(progress: (Int) -> Unit): Boolean
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 98c8f750..ddb9fde6 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragmentBase.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragmentBase.kt
@@ -30,6 +30,7 @@ import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.frostJsoup
import com.pitchedapps.frost.views.FrostRecyclerView
import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.isActive
import kotlinx.coroutines.withContext
/**
@@ -55,14 +56,17 @@ abstract class RecyclerFragment<T, Item : IItem<*, *>> : BaseFragment(), Recycle
} catch (e: Exception) {
null
}
- if (data == null) {
- valid = false
+ if (!isActive)
return false
+ return withContext(Dispatchers.Main) {
+ if (data == null) {
+ valid = false
+ return@withContext false
+ } else {
+ adapter.setNewList(data)
+ return@withContext true
+ }
}
- withContext(Dispatchers.Main) {
- adapter.setNewList(data)
- }
- return true
}
protected abstract suspend fun reloadImpl(progress: (Int) -> Unit): List<T>?