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 75dabec25..30fa59ed8 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 @@ -47,18 +47,26 @@ fun String?.getFullSizedImageUrl(url: String): String { } @Parcelize -data class FbImageData(val current: String, val prev: String? = null, val next: String? = null) : +data class FbImageData( + val current: String, + val url: String, + val prev: String? = null, + val next: String? = null +) : Parcelable { companion object { fun imageContextUrl(id: String) = "https://mbasic.facebook.com/photo.php?fbid=$id" fun fullSizeImageUrl(id: String) = "https://mbasic.facebook.com/photo/view_full_size/?fbid=$id" - fun urlImageId(url: String): String? = FB_FBCDN_ID_MATCHER.find(url)[1] ?: FB_PHOTO_ID_MATCHER.find(url)[1] + + fun urlImageId(url: String): String? = + FB_FBCDN_ID_MATCHER.find(url)[1] ?: FB_PHOTO_ID_MATCHER.find(url)[1] } } fun String?.getImageData(id: String): FbImageData { - fun fallback() = FbImageData(current = id) + val url = getFullSizedImageUrl(FbImageData.fullSizeImageUrl(id)) + fun fallback() = FbImageData(current = id, url = url) if (this == null) return fallback() val doc = try { frostJsoup(url = FbImageData.imageContextUrl(id), cookie = this) @@ -72,7 +80,6 @@ fun String?.getImageData(id: String): FbImageData { */ fun Element.adjacentId(): String? { val adjacentUrl = selectFirst("a")?.attr("href") ?: return null - println(adjacentUrl) return FbImageData.urlImageId(adjacentUrl) } @@ -84,5 +91,5 @@ fun String?.getImageData(id: String): FbImageData { ?.takeIf { it.size == 2 } ?: return fallback() - return FbImageData(current = id, prev = adjacent[0], next = adjacent[1]) + return FbImageData(current = id, url = url, prev = adjacent[0], next = adjacent[1]) } \ No newline at end of file diff --git a/app/src/test/kotlin/com/pitchedapps/frost/facebook/requests/FbFullImageTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/facebook/requests/FbFullImageTest.kt index 8769fdf3d..04ff0887c 100644 --- a/app/src/test/kotlin/com/pitchedapps/frost/facebook/requests/FbFullImageTest.kt +++ b/app/src/test/kotlin/com/pitchedapps/frost/facebook/requests/FbFullImageTest.kt @@ -23,6 +23,7 @@ import org.junit.BeforeClass import org.junit.Test import kotlin.test.assertEquals import kotlin.test.assertNotNull +import kotlin.test.assertTrue /** * Created by Allan Wang on 12/04/18. @@ -48,7 +49,10 @@ class FbFullImageTest { @Test fun getImageData() { val result = COOKIE.getImageData("895534407495141") - assertEquals(FbImageData(current = "895534407495141", prev = "508130796235506", next = "895534404161808"), result) + assertEquals("895534407495141", result.current) + assertEquals("508130796235506", result.prev) + assertEquals("895534404161808", result.next) + assertTrue(result.url.contains("fbcdn")) println(result) } }