aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/utils
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Animator.kt70
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt19
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt2
3 files changed, 19 insertions, 72 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Animator.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Animator.kt
deleted file mode 100644
index da852e6e..00000000
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Animator.kt
+++ /dev/null
@@ -1,70 +0,0 @@
-package com.pitchedapps.frost.utils
-
-import android.animation.Animator
-import android.animation.AnimatorListenerAdapter
-import android.animation.ValueAnimator
-import android.view.animation.Interpolator
-
-/**
- * Created by Allan Wang on 2017-11-10.
- */
-class ProgressAnimator private constructor(private vararg val values: Float) {
-
- companion object {
- inline fun ofFloat(crossinline builder: ProgressAnimator.() -> Unit) = ofFloat(0f, 1f) { builder() }
-
- fun ofFloat(vararg values: Float, builder: ProgressAnimator.() -> Unit) = ProgressAnimator(*values).apply {
- builder()
- build()
- }
- }
-
- private val animators: MutableList<(Float) -> Unit> = mutableListOf()
- private val startActions: MutableList<() -> Unit> = mutableListOf()
- private val endActions: MutableList<() -> Unit> = mutableListOf()
-
- var duration: Long = -1L
- var interpolator: Interpolator? = null
-
- /**
- * Add more changes to the [ValueAnimator] before running
- */
- var extraConfigs: ValueAnimator.() -> Unit = {}
-
- fun withAnimator(from: Float, to: Float, animator: (Float) -> Unit) = animators.add {
- val range = to - from
- animator(range * it + from)
- }
-
- fun withAnimator(animator: (Float) -> Unit) = animators.add(animator)
-
- fun withAnimatorInv(animator: (Float) -> Unit) = animators.add { animator(1f - it) }
-
- fun withStartAction(action: () -> Unit) = startActions.add(action)
-
- fun withEndAction(action: () -> Unit) = endActions.add(action)
-
- fun build() {
- ValueAnimator.ofFloat(*values).apply {
- if (this@ProgressAnimator.duration > 0L)
- duration = this@ProgressAnimator.duration
- if (this@ProgressAnimator.interpolator != null)
- interpolator = this@ProgressAnimator.interpolator
- addUpdateListener {
- val progress = it.animatedValue as Float
- animators.forEach { it(progress) }
- }
- addListener(object : AnimatorListenerAdapter() {
- override fun onAnimationStart(animation: Animator?) {
- startActions.forEach { it() }
- }
-
- override fun onAnimationEnd(animation: Animator?) {
- endActions.forEach { it() }
- }
- })
- extraConfigs()
- start()
- }
- }
-} \ No newline at end of file
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 3e1e1dde..e6db8eee 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt
@@ -8,10 +8,15 @@ import android.os.Environment
import android.webkit.URLUtil
import ca.allanwang.kau.permissions.PERMISSION_WRITE_EXTERNAL_STORAGE
import ca.allanwang.kau.permissions.kauRequestPermissions
+import ca.allanwang.kau.utils.isAppEnabled
import ca.allanwang.kau.utils.string
import com.pitchedapps.frost.R
import com.pitchedapps.frost.dbflow.loadFbCookie
import com.pitchedapps.frost.facebook.USER_AGENT_BASIC
+import android.support.v4.content.ContextCompat.startActivity
+import android.content.Intent
+import android.content.ActivityNotFoundException
+import ca.allanwang.kau.utils.showAppInfo
/**
@@ -37,6 +42,16 @@ fun Context.frostDownload(uri: Uri?,
L.d("Received download request", "Download $uri")
if (uri.scheme != "http" && uri.scheme != "https")
return L.e("Invalid download attempt", uri.toString())
+ if (!isAppEnabled(DOWNLOAD_MANAGER_PACKAGE)) {
+ materialDialogThemed {
+ title(R.string.no_download_manager)
+ content(R.string.no_download_manager_desc)
+ positiveText(R.string.kau_yes)
+ onPositive { _, _ -> showAppInfo(DOWNLOAD_MANAGER_PACKAGE) }
+ negativeText(R.string.kau_no)
+ }
+ return
+ }
kauRequestPermissions(PERMISSION_WRITE_EXTERNAL_STORAGE) { granted, _ ->
if (!granted) return@kauRequestPermissions
val request = DownloadManager.Request(uri)
@@ -53,4 +68,6 @@ fun Context.frostDownload(uri: Uri?,
val dm = getSystemService(DOWNLOAD_SERVICE) as DownloadManager
dm.enqueue(request)
}
-} \ No newline at end of file
+}
+
+private const val DOWNLOAD_MANAGER_PACKAGE = "com.android.providers.downloads" \ No newline at end of file
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
index 22c77f5f..c644499e 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
@@ -202,7 +202,7 @@ inline val String?.isFacebookUrl
get() = this != null && this.contains(FACEBOOK_COM)
inline val String?.isVideoUrl
- get() = this != null && this.startsWith(VIDEO_REDIRECT)
+ get() = this != null && (this.startsWith(VIDEO_REDIRECT) || this.startsWith("https://video-"))
fun Context.frostChangelog() = showChangelog(R.xml.frost_changelog, Prefs.textColor) {
theme()