aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/facebook
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-08-06 00:49:58 -0700
committerAllan Wang <me@allanwang.ca>2019-08-06 00:49:58 -0700
commit55bf3e4b5b4af5baa3c230ca82f74988608971a3 (patch)
tree3db856e037b70257aaef19e34db6b0856bda6412 /app/src/main/kotlin/com/pitchedapps/frost/facebook
parent99953f087f2c363dad05ae3f86b5bcba22484e43 (diff)
downloadfrost-55bf3e4b5b4af5baa3c230ca82f74988608971a3.tar.gz
frost-55bf3e4b5b4af5baa3c230ca82f74988608971a3.tar.bz2
frost-55bf3e4b5b4af5baa3c230ca82f74988608971a3.zip
Format kotlin
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/facebook')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt9
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt10
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/FrostParser.kt3
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/MessageParser.kt8
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/NotifParser.kt6
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt28
6 files changed, 41 insertions, 23 deletions
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<FbItem>("frost_arg_fb_item", values())
}
-fun defaultTabs(): List<FbItem> = listOf(FbItem.FEED, FbItem.MESSAGES, FbItem.NOTIFICATIONS, FbItem.MENU)
+fun defaultTabs(): List<FbItem> =
+ 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 <T> List<T>.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<out T : ParseData>(private val redirectToText: Boolean) : FrostParser<T> {
+internal abstract class FrostParserBase<out T : ParseData>(private val redirectToText: Boolean) :
+ FrostParser<T> {
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<FrostMessages> 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<FrostMessages>(true) {
override fun parseImpl(doc: Document): FrostMessages? {
val threadList = doc.getElementById("threadlist_rows") ?: return null
val threads: List<FrostThread> =
- 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<FrostNotifs>(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<FrostNotifs>(false) {
?: System.currentTimeMillis() % FALLBACK_TIME_MOD
val img = element.getInnerImgStyle()
val timeString = abbr.text()
- val content = a.text().replace("\u00a0", " ").removeSuffix(timeString).trim() //remove &nbsp;
+ val content =
+ a.text().replace("\u00a0", " ").removeSuffix(timeString).trim() //remove &nbsp;
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<InputStream>
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<InputStream>
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() {