From 149c6be1bfd4bd84381757940fece1be7b9801aa Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 31 Dec 2018 18:57:28 -0500 Subject: Enhancement/coroutines (#1273) * Convert rest of fbcookie to suspended methods * Replace active checks with yield * Apply spotless * Switch cookie domain to exact url * Optimize imports and enable travis tests again * Update proguard rules * Remove unnecessary yield * Remove unused flyweight * Remove unused disposable and method * Use contexthelper instead of dispatcher main * Convert login activity to coroutines * Use kau helper methods for coroutines * Enhancement/offline site (#1288) * Begin conversion of offline site logic * Fix offline tests and add validation tests * Ignore cookie in jsoup if it is blank * Force load and zip to be in io * Use different zip files to fix tests * Log all test output * Do not log stdout * Allow test skip for fb offline --- .../com/pitchedapps/frost/fragments/RecyclerFragmentBase.kt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragmentBase.kt') 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 7a8309ff..00d04a3e 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragmentBase.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragmentBase.kt @@ -17,6 +17,7 @@ package com.pitchedapps.frost.fragments import ca.allanwang.kau.adapters.fastAdapter +import ca.allanwang.kau.utils.withMainContext import com.mikepenz.fastadapter.FastAdapter import com.mikepenz.fastadapter.IItem import com.mikepenz.fastadapter.adapters.ItemAdapter @@ -29,7 +30,6 @@ 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 /** @@ -49,22 +49,20 @@ abstract class RecyclerFragment> : BaseFragment(), Recycle } } - final override suspend fun reload(progress: (Int) -> Unit): Boolean { + 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" } null } - if (!isActive) - return false - return withContext(Dispatchers.Main) { + withMainContext { if (data == null) { valid = false - return@withContext false + false } else { adapter.setNewList(data) - return@withContext true + true } } } @@ -134,6 +132,7 @@ abstract class FrostParserFragment> : RecyclerFragme val response = parser.parse(cookie, doc) if (response == null) { L.i { "RecyclerFragment failed for ${baseEnum.name}" } + L._d { "Cookie used: $cookie" } return@withContext null } progress(80) -- cgit v1.2.3