aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-03-05 21:06:24 -0500
committerAllan Wang <me@allanwang.ca>2019-03-05 21:06:24 -0500
commit65bb9233b2a0d8734c1d13e8f3a01bee0f6c3b17 (patch)
treeabe5c5db1b05757375d63c32ec8afae9893a9dee /app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt
parent5c4400975450c9739f0986561075983e08afae89 (diff)
downloadfrost-65bb9233b2a0d8734c1d13e8f3a01bee0f6c3b17.tar.gz
frost-65bb9233b2a0d8734c1d13e8f3a01bee0f6c3b17.tar.bz2
frost-65bb9233b2a0d8734c1d13e8f3a01bee0f6c3b17.zip
Convert fbcookies to room entities
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt7
1 files changed, 4 insertions, 3 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt
index 254297a6..64094d1e 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt
@@ -29,7 +29,7 @@ import ca.allanwang.kau.utils.showAppInfo
import ca.allanwang.kau.utils.string
import ca.allanwang.kau.utils.toast
import com.pitchedapps.frost.R
-import com.pitchedapps.frost.db.loadFbCookie
+import com.pitchedapps.frost.db.CookieEntity
import com.pitchedapps.frost.facebook.USER_AGENT_BASIC
/**
@@ -38,6 +38,7 @@ import com.pitchedapps.frost.facebook.USER_AGENT_BASIC
* With reference to <a href="https://stackoverflow.com/questions/33434532/android-webview-download-files-like-browsers-do">Stack Overflow</a>
*/
fun Context.frostDownload(
+ cookie: CookieEntity,
url: String?,
userAgent: String = USER_AGENT_BASIC,
contentDisposition: String? = null,
@@ -45,10 +46,11 @@ fun Context.frostDownload(
contentLength: Long = 0L
) {
url ?: return
- frostDownload(Uri.parse(url), userAgent, contentDisposition, mimeType, contentLength)
+ frostDownload(cookie, Uri.parse(url), userAgent, contentDisposition, mimeType, contentLength)
}
fun Context.frostDownload(
+ cookie: CookieEntity,
uri: Uri?,
userAgent: String = USER_AGENT_BASIC,
contentDisposition: String? = null,
@@ -75,7 +77,6 @@ fun Context.frostDownload(
if (!granted) return@kauRequestPermissions
val request = DownloadManager.Request(uri)
request.setMimeType(mimeType)
- val cookie = loadFbCookie(Prefs.userId) ?: return@kauRequestPermissions
val title = URLUtil.guessFileName(uri.toString(), contentDisposition, mimeType)
request.addRequestHeader("Cookie", cookie.cookie)
request.addRequestHeader("User-Agent", userAgent)