From 55bf3e4b5b4af5baa3c230ca82f74988608971a3 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 6 Aug 2019 00:49:58 -0700 Subject: Format kotlin --- .../com/pitchedapps/frost/facebook/FbCookie.kt | 9 +++---- .../com/pitchedapps/frost/facebook/FbItem.kt | 10 ++++++-- .../frost/facebook/parsers/FrostParser.kt | 3 ++- .../frost/facebook/parsers/MessageParser.kt | 8 +++++-- .../frost/facebook/parsers/NotifParser.kt | 6 +++-- .../pitchedapps/frost/facebook/requests/Images.kt | 28 ++++++++++++---------- 6 files changed, 41 insertions(+), 23 deletions(-) (limited to 'app/src/main/kotlin/com/pitchedapps/frost/facebook') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt index 0c1da3a3..b1bb3fb8 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt @@ -77,11 +77,12 @@ object FbCookie { } } - private suspend fun CookieManager.setSingleWebCookie(cookie: String): Boolean = suspendCoroutine { cont -> - setCookie(COOKIE_DOMAIN, cookie.trim()) { - cont.resume(it) + private suspend fun CookieManager.setSingleWebCookie(cookie: String): Boolean = + suspendCoroutine { cont -> + setCookie(COOKIE_DOMAIN, cookie.trim()) { + cont.resume(it) + } } - } suspend fun save(id: Long) { L.d { "New cookie found" } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt index 82e15111..a09b5d39 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt @@ -50,7 +50,12 @@ enum class FbItem( MENU(R.string.menu, GoogleMaterial.Icon.gmd_menu, "settings", ::MenuFragment), MESSAGES(R.string.messages, MaterialDesignIconic.Icon.gmi_comments, "messages"), NOTES(R.string.notes, CommunityMaterial.Icon2.cmd_note, "notes"), - NOTIFICATIONS(R.string.notifications, MaterialDesignIconic.Icon.gmi_globe, "notifications", ::NotificationFragment), + NOTIFICATIONS( + R.string.notifications, + MaterialDesignIconic.Icon.gmi_globe, + "notifications", + ::NotificationFragment + ), ON_THIS_DAY(R.string.on_this_day, GoogleMaterial.Icon.gmd_today, "onthisday"), PAGES(R.string.pages, GoogleMaterial.Icon.gmd_flag, "pages"), PHOTOS(R.string.photos, GoogleMaterial.Icon.gmd_photo, "me/photos"), @@ -77,4 +82,5 @@ enum class FbItem( companion object : EnumCompanion("frost_arg_fb_item", values()) } -fun defaultTabs(): List = listOf(FbItem.FEED, FbItem.MESSAGES, FbItem.NOTIFICATIONS, FbItem.MENU) +fun defaultTabs(): List = + listOf(FbItem.FEED, FbItem.MESSAGES, FbItem.NOTIFICATIONS, FbItem.MENU) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/FrostParser.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/FrostParser.kt index 6af21259..1240614b 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/FrostParser.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/FrostParser.kt @@ -99,7 +99,8 @@ internal fun List.toJsonString(tag: String, indent: Int) = StringBuilder( * T should have a readable toString() function * [redirectToText] dictates whether all data should be converted to text then back to document before parsing */ -internal abstract class FrostParserBase(private val redirectToText: Boolean) : FrostParser { +internal abstract class FrostParserBase(private val redirectToText: Boolean) : + FrostParser { final override fun parse(cookie: String?) = parseFromUrl(cookie, url) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/MessageParser.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/MessageParser.kt index 00a1432f..3705448a 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/MessageParser.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/MessageParser.kt @@ -38,7 +38,8 @@ import org.jsoup.nodes.Element */ object MessageParser : FrostParser by MessageParserImpl() { - fun queryUser(cookie: String?, name: String) = parseFromUrl(cookie, "${FbItem.MESSAGES.url}/?q=$name") + fun queryUser(cookie: String?, name: String) = + parseFromUrl(cookie, "${FbItem.MESSAGES.url}/?q=$name") } data class FrostMessages( @@ -120,7 +121,10 @@ private class MessageParserImpl : FrostParserBase(true) { override fun parseImpl(doc: Document): FrostMessages? { val threadList = doc.getElementById("threadlist_rows") ?: return null val threads: List = - threadList.getElementsByAttributeValueMatching("id", ".*${FB_MESSAGE_NOTIF_ID_MATCHER.pattern}.*") + threadList.getElementsByAttributeValueMatching( + "id", + ".*${FB_MESSAGE_NOTIF_ID_MATCHER.pattern}.*" + ) .mapNotNull(this::parseMessage) val seeMore = parseLink(doc.getElementById("see_older_threads")) val extraLinks = threadList.nextElementSibling().select("a") diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/NotifParser.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/NotifParser.kt index faeaa27c..f9db0a8f 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/NotifParser.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/NotifParser.kt @@ -96,7 +96,8 @@ private class NotifParserImpl : FrostParserBase(false) { val notifications = notificationList .getElementsByAttributeValueMatching("id", ".*${FB_NOTIF_ID_MATCHER.pattern}.*") .mapNotNull(this::parseNotif) - val seeMore = parseLink(doc.getElementsByAttributeValue("href", "/notifications.php?more").first()) + val seeMore = + parseLink(doc.getElementsByAttributeValue("href", "/notifications.php?more").first()) return FrostNotifs(notifications, seeMore) } @@ -109,7 +110,8 @@ private class NotifParserImpl : FrostParserBase(false) { ?: System.currentTimeMillis() % FALLBACK_TIME_MOD val img = element.getInnerImgStyle() val timeString = abbr.text() - val content = a.text().replace("\u00a0", " ").removeSuffix(timeString).trim() //remove   + val content = + a.text().replace("\u00a0", " ").removeSuffix(timeString).trim() //remove   val thumbnail = element.selectFirst("img.thumbnail")?.attr("src") return FrostNotif( id = id, 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 36dff6ff..1b5e8b99 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 @@ -52,18 +52,19 @@ fun RequestAuth.getFullSizedImage(fbid: Long) = frostRequest(::getJsonUrl) { /** * Attempts to get the fbcdn url of the supplied image redirect url */ -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 +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 } - } catch (e: Exception) { - L.e(e) { "Failed to load full size image url" } - null } -} /** * Request loader for a potentially hd version of a url @@ -135,7 +136,8 @@ class HdImageFetcher(private val model: HdImageMaybe) : DataFetcher withTimeout(20000L) { val auth = fbAuth.fetch(model.cookie).await() if (cancelled) throw RuntimeException("Cancelled") - val url = auth.getFullSizedImage(model.id).invoke() ?: throw RuntimeException("Null url") + val url = auth.getFullSizedImage(model.id).invoke() + ?: throw RuntimeException("Null url") if (cancelled) throw RuntimeException("Cancelled") if (!url.contains("png") && !url.contains("jpg")) throw RuntimeException("Invalid format") urlCall?.execute()?.body()?.byteStream() @@ -145,7 +147,9 @@ class HdImageFetcher(private val model: HdImageMaybe) : DataFetcher if (result.isSuccess) callback.onDataReady(result.getOrNull()) else - callback.onLoadFailed(result.exceptionOrNull() as? Exception ?: RuntimeException("Failed")) + callback.onLoadFailed( + result.exceptionOrNull() as? Exception ?: RuntimeException("Failed") + ) } override fun cleanup() { -- cgit v1.2.3