aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt7
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt54
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt3
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt2
5 files changed, 39 insertions, 29 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt
index a3ab6172..4aa0966c 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt
@@ -53,7 +53,6 @@ import com.pitchedapps.frost.intro.IntroTabTouchFragment
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.cookies
import com.pitchedapps.frost.utils.launchNewTask
-import org.jetbrains.anko.find
/**
* Created by Allan Wang on 2017-07-25.
@@ -137,13 +136,13 @@ class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer, ViewPager.On
val lastView: View? = fragments.last().view
arrayOf<View?>(
skip, indicator, next,
- lastView?.find(R.id.intro_title),
- lastView?.find(R.id.intro_desc)
+ lastView?.findViewById(R.id.intro_title),
+ lastView?.findViewById(R.id.intro_desc)
).forEach {
it?.animate()?.alpha(0f)?.setDuration(600)?.start()
}
if (Prefs.textColor != Color.WHITE) {
- val f = lastView?.find<ImageView>(R.id.intro_image)?.drawable
+ val f = lastView?.findViewById<ImageView>(R.id.intro_image)?.drawable
if (f != null)
ValueAnimator.ofFloat(0f, 1f).apply {
addUpdateListener {
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt
index 4b538e87..ece1f677 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt
@@ -21,6 +21,7 @@ import ca.allanwang.kau.kpref.activity.KPrefAdapterBuilder
import ca.allanwang.kau.utils.materialDialog
import ca.allanwang.kau.utils.startActivityForResult
import ca.allanwang.kau.utils.string
+import ca.allanwang.kau.utils.toast
import com.pitchedapps.frost.R
import com.pitchedapps.frost.activities.DebugActivity
import com.pitchedapps.frost.activities.SettingsActivity
@@ -35,11 +36,13 @@ import com.pitchedapps.frost.facebook.parsers.SearchParser
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.frostUriFromFile
import com.pitchedapps.frost.utils.sendFrostEmail
-import org.jetbrains.anko.doAsync
-import org.jetbrains.anko.toast
-import org.jetbrains.anko.uiThread
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.Job
+import kotlinx.coroutines.channels.Channel
+import kotlinx.coroutines.isActive
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
import java.io.File
-import java.util.concurrent.Future
/**
* Created by Allan Wang on 2017-06-30.
@@ -69,26 +72,29 @@ fun SettingsActivity.getDebugPrefs(): KPrefAdapterBuilder.() -> Unit = {
itemsCallback { dialog, _, position, _ ->
dialog.dismiss()
val parser = parsers[position]
- var attempt: Future<Unit>? = null
+ var attempt: Job? = null
val loading = materialDialog {
content(parser.nameRes)
progress(true, 100)
negativeText(R.string.kau_cancel)
onNegative { dialog, _ ->
- attempt?.cancel(true)
+ attempt?.cancel()
dialog.dismiss()
}
canceledOnTouchOutside(false)
}
- attempt = loading.doAsync({
- createEmail(parser, "Error: ${it.message}")
- }) {
- val data = parser.parse(FbCookie.webCookie)
- uiThread {
- if (it.isCancelled) return@uiThread
- it.dismiss()
- createEmail(parser, data?.data)
+ attempt = launch(Dispatchers.IO) {
+ try {
+ val data = parser.parse(FbCookie.webCookie)
+ withContext(Dispatchers.Main) {
+ if (!isActive)
+ return@withContext
+ loading.dismiss()
+ createEmail(parser, data?.data)
+ }
+ } catch (e: Exception) {
+ createEmail(parser, "Error: ${e.message}")
}
}
}
@@ -123,14 +129,20 @@ fun SettingsActivity.sendDebug(url: String, html: String?) {
dismissListener { downloader.cancel() }
}
- md.doAsync {
- downloader.loadAndZip(ZIP_NAME, { progress ->
- uiThread { it.setProgress(progress) }
- }) { success ->
- uiThread {
- it.dismiss()
+ val progressChannel = Channel<Int>(10)
+
+ launch(Dispatchers.Main) {
+ for (p in progressChannel) {
+ md.setProgress(p)
+ }
+ }
+ launch(Dispatchers.IO) {
+ downloader.loadAndZip(ZIP_NAME, { progressChannel.offer(it) }) { success ->
+ launch(Dispatchers.Main) {
+ if (!isActive) return@launch
+ md.dismiss()
if (success) {
- val zipUri = it.context.frostUriFromFile(
+ val zipUri = frostUriFromFile(
File(downloader.baseDir, "$ZIP_NAME.zip")
)
L.i { "Sending debug zip with uri $zipUri" }
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt
index bb196221..22668309 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt
@@ -24,6 +24,7 @@ import android.util.AttributeSet
import android.view.View
import android.webkit.WebView
import androidx.annotation.WorkerThread
+import ca.allanwang.kau.utils.withAlpha
import com.pitchedapps.frost.facebook.USER_AGENT_BASIC
import com.pitchedapps.frost.injectors.CssAssets
import com.pitchedapps.frost.injectors.CssHider
@@ -32,7 +33,6 @@ import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.createFreshFile
import com.pitchedapps.frost.utils.isFacebookUrl
-import org.jetbrains.anko.withAlpha
import java.io.File
/**
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt
index 490c02e5..24885fdf 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt
@@ -16,9 +16,9 @@
*/
package com.pitchedapps.frost.web
+import ca.allanwang.kau.utils.runOnUiThread
import com.pitchedapps.frost.activities.WebOverlayActivity
import com.pitchedapps.frost.activities.WebOverlayActivityBase
-import com.pitchedapps.frost.activities.WebOverlayBasicActivity
import com.pitchedapps.frost.contracts.VideoViewHolder
import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.facebook.FbItem
@@ -34,7 +34,6 @@ import com.pitchedapps.frost.utils.launchImageActivity
import com.pitchedapps.frost.utils.launchWebOverlay
import com.pitchedapps.frost.utils.launchWebOverlayBasic
import com.pitchedapps.frost.views.FrostWebView
-import org.jetbrains.anko.runOnUiThread
/**
* Created by Allan Wang on 2017-08-15.
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt
index ab97c0a8..2e8408ea 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt
@@ -22,6 +22,7 @@ import android.webkit.WebResourceRequest
import android.webkit.WebResourceResponse
import android.webkit.WebView
import android.webkit.WebViewClient
+import ca.allanwang.kau.utils.withAlpha
import com.pitchedapps.frost.facebook.FB_URL_BASE
import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.facebook.FbItem
@@ -41,7 +42,6 @@ import com.pitchedapps.frost.utils.launchImageActivity
import com.pitchedapps.frost.utils.resolveActivityForUri
import com.pitchedapps.frost.views.FrostWebView
import kotlinx.coroutines.channels.SendChannel
-import org.jetbrains.anko.withAlpha
/**
* Created by Allan Wang on 2017-05-31.