aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt22
2 files changed, 16 insertions, 8 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt
index 7735c034..f7dcf845 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt
@@ -150,7 +150,7 @@ class ImageActivity : KauBaseActivity() {
L.i { "Displaying image" }
trueImageUrl = async(Dispatchers.IO) {
val result = if (!imageUrl.isIndirectImageUrl) imageUrl
- else cookie?.getFullSizedImageUrl(imageUrl)?.blockingGet() ?: imageUrl
+ else cookie?.getFullSizedImageUrl(imageUrl) ?: imageUrl
if (result != imageUrl)
L.v { "Launching with true url $result" }
result
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt
index 9e92c939..ee18e15e 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt
@@ -32,8 +32,10 @@ import com.pitchedapps.frost.facebook.FB_REDIRECT_URL_MATCHER
import com.pitchedapps.frost.facebook.FB_URL_BASE
import com.pitchedapps.frost.facebook.formattedFbUrl
import com.pitchedapps.frost.facebook.get
-import io.reactivex.Maybe
+import com.pitchedapps.frost.utils.L
+import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
+import kotlinx.coroutines.withContext
import kotlinx.coroutines.withTimeout
import okhttp3.Call
import java.io.IOException
@@ -50,12 +52,18 @@ fun RequestAuth.getFullSizedImage(fbid: Long) = frostRequest(::getJsonUrl) {
/**
* Attempts to get the fbcdn url of the supplied image redirect url
*/
-fun String.getFullSizedImageUrl(url: String): Maybe<String?> = Maybe.fromCallable {
- val redirect = requestBuilder().url(url).get().call()
- .execute().body()?.string() ?: return@fromCallable null
- return@fromCallable FB_REDIRECT_URL_MATCHER.find(redirect)[1]?.formattedFbUrl
- ?: return@fromCallable null
-}.onErrorComplete()
+suspend fun String.getFullSizedImageUrl(url: String, timeout: Long = 3000): String? = withContext(Dispatchers.IO) {
+ try {
+ withTimeout(timeout) {
+ val redirect = requestBuilder().url(url).get().call()
+ .execute().body()?.string() ?: return@withTimeout null
+ FB_REDIRECT_URL_MATCHER.find(redirect)[1]?.formattedFbUrl
+ }
+ } catch (e: Exception) {
+ L.e(e) { "Failed to load full size image url" }
+ null
+ }
+}
/**
* Request loader for a potentially hd version of a url