aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-12-31 02:44:46 -0500
committerGitHub <noreply@github.com>2017-12-31 02:44:46 -0500
commit725d6a99a07f91f940a07e6b49dd6224a6aa32d1 (patch)
tree4e0b1b3b9ffe9b5aef3c8d0f154ea9ab1058fd5e /app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt
parent3076d9a97c203497aec1415d8ac6037d10eebb46 (diff)
downloadfrost-725d6a99a07f91f940a07e6b49dd6224a6aa32d1.tar.gz
frost-725d6a99a07f91f940a07e6b49dd6224a6aa32d1.tar.bz2
frost-725d6a99a07f91f940a07e6b49dd6224a6aa32d1.zip
Enhancement/proguard (#589)
* Add error log * Rewrite logger
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt223
1 files changed, 103 insertions, 120 deletions
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 60512f17..269b5a95 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt
@@ -1,25 +1,8 @@
package com.pitchedapps.frost.settings
-import android.content.Context
-import android.support.annotation.UiThread
import ca.allanwang.kau.kpref.activity.KPrefAdapterBuilder
-import ca.allanwang.kau.utils.string
-import com.afollestad.materialdialogs.MaterialDialog
import com.pitchedapps.frost.R
import com.pitchedapps.frost.activities.SettingsActivity
-import com.pitchedapps.frost.facebook.FbItem
-import com.pitchedapps.frost.injectors.InjectorContract
-import com.pitchedapps.frost.injectors.JsAssets
-import com.pitchedapps.frost.utils.*
-import com.pitchedapps.frost.web.launchHeadlessHtmlExtractor
-import com.pitchedapps.frost.web.query
-import io.reactivex.disposables.Disposable
-import org.jetbrains.anko.AnkoAsyncContext
-import org.jetbrains.anko.doAsync
-import org.jetbrains.anko.runOnUiThread
-import org.jetbrains.anko.uiThread
-import org.jsoup.Jsoup
-import org.jsoup.nodes.Document
/**
* Created by Allan Wang on 2017-06-30.
@@ -33,108 +16,108 @@ fun SettingsActivity.getDebugPrefs(): KPrefAdapterBuilder.() -> Unit = {
descRes = R.string.debug_disclaimer_info
}
- Debugger.values().forEach {
- plainText(it.data.titleId) {
- iicon = it.data.icon
- onClick = { it.debug(itemView.context) }
- }
- }
+// Debugger.values().forEach {
+// plainText(it.data.titleId) {
+// iicon = it.data.icon
+// onClick = { it.debug(itemView.context) }
+// }
+// }
}
-
-private enum class Debugger(val data: FbItem, val injector: InjectorContract?, vararg query: String) {
- MENU(FbItem.MENU, JsAssets.MENU_DEBUG, "#viewport"), //todo modify menu js for debugging
- NOTIFICATIONS(FbItem.NOTIFICATIONS, null, "#notifications_list");
-// SEARCH(FbItem.SEARCH, JsActions.FETCH_BODY);
-
- val query = if (query.isNotEmpty()) arrayOf(*query, "#root", "main", "body") else emptyArray()
-
- fun debug(context: Context) {
- val dialog = context.materialDialogThemed {
- title("Debugging")
- progress(true, 0)
- canceledOnTouchOutside(false)
- positiveText(R.string.kau_cancel)
- onPositive { dialog, _ -> dialog.cancel() }
- }
- if (injector != null) dialog.extractHtml(injector)
- else dialog.debugAsync {
- loadJsoup()
- }
- }
-
- fun MaterialDialog.debugAsync(task: AnkoAsyncContext<MaterialDialog>.() -> Unit) {
- doAsync({ t: Throwable ->
- val msg = t.message
- L.e("Debugger failed: $msg")
- context.runOnUiThread {
- cancel()
- context.materialDialogThemed {
- title(R.string.debug_incomplete)
- if (msg != null) content(msg)
- }
- }
- }, task)
- }
-
- /**
- * Wait for html to be returned from headless webview
- *
- * from [debug] to [simplifyJsoup] if [query] is not empty, or [createReport] otherwise
- */
- @UiThread
- private fun MaterialDialog.extractHtml(injector: InjectorContract) {
- setContent("Fetching webpage")
- var disposable: Disposable? = null
- setOnCancelListener { disposable?.dispose() }
- context.launchHeadlessHtmlExtractor(data.url, injector) {
- disposable = it.subscribe { (html, errorRes) ->
- debugAsync {
- if (errorRes == -1) {
- L.i("Debug report successful", html)
- if (query.isNotEmpty()) simplifyJsoup(Jsoup.parseBodyFragment(html))
- else createReport(html)
- } else {
- throw Throwable(context.string(errorRes))
- }
- }
- }
- }
- }
-
- /**
- * Get data directly from the link and search for our queries, returning the outerHTML
- * of the first query found
- *
- * from [debug] to [simplifyJsoup]
- */
- private fun AnkoAsyncContext<MaterialDialog>.loadJsoup() {
- uiThread {
- it.setContent("Load Jsoup")
- it.setOnCancelListener(null)
- it.debugAsync { simplifyJsoup(frostJsoup(data.url)) }
- }
- }
-
- /**
- * Takes snippet of given document that matches the first query in the [query] items
- * before sending it to [createReport]
- */
- private fun AnkoAsyncContext<MaterialDialog>.simplifyJsoup(doc: Document) {
- weakRef.get() ?: return
- val q = query.first { doc.select(it).isNotEmpty() }
- createReport(doc.select(q).outerHtml())
- }
-
- private fun AnkoAsyncContext<MaterialDialog>.createReport(html: String) {
- val cleanHtml = html.cleanHtml()
- uiThread {
- val c = it.context
- it.dismiss()
- c.sendFrostEmail("${c.string(R.string.debug_report_email_title)} $name") {
- addItem("Query List", query.contentToString())
- footer = cleanHtml
- }
- }
- }
-} \ No newline at end of file
+//
+//private enum class Debugger(val data: FbItem, val injector: InjectorContract?, vararg query: String) {
+// MENU(FbItem.MENU, JsAssets.MENU_DEBUG, "#viewport"), //todo modify menu js for debugging
+// NOTIFICATIONS(FbItem.NOTIFICATIONS, null, "#notifications_list");
+//// SEARCH(FbItem.SEARCH, JsActions.FETCH_BODY);
+//
+// val query = if (query.isNotEmpty()) arrayOf(*query, "#root", "main", "body") else emptyArray()
+//
+// fun debug(context: Context) {
+// val dialog = context.materialDialogThemed {
+// title("Debugging")
+// progress(true, 0)
+// canceledOnTouchOutside(false)
+// positiveText(R.string.kau_cancel)
+// onPositive { dialog, _ -> dialog.cancel() }
+// }
+// if (injector != null) dialog.extractHtml(injector)
+// else dialog.debugAsync {
+// loadJsoup()
+// }
+// }
+//
+// fun MaterialDialog.debugAsync(task: AnkoAsyncContext<MaterialDialog>.() -> Unit) {
+// doAsync({ t: Throwable ->
+// val msg = t.message
+// L.e{"Debugger failed: $msg"}
+// context.runOnUiThread {
+// cancel()
+// context.materialDialogThemed {
+// title(R.string.debug_incomplete)
+// if (msg != null) content(msg)
+// }
+// }
+// }, task)
+// }
+//
+// /**
+// * Wait for html to be returned from headless webview
+// *
+// * from [debug] to [simplifyJsoup] if [query] is not empty, or [createReport] otherwise
+// */
+// @UiThread
+// private fun MaterialDialog.extractHtml(injector: InjectorContract) {
+// setContent("Fetching webpage")
+// var disposable: Disposable? = null
+// setOnCancelListener { disposable?.dispose() }
+// context.launchHeadlessHtmlExtractor(data.url, injector) {
+// disposable = it.subscribe { (html, errorRes) ->
+// debugAsync {
+// if (errorRes == -1) {
+// L.i("Debug report successful", html)
+// if (query.isNotEmpty()) simplifyJsoup(Jsoup.parseBodyFragment(html))
+// else createReport(html)
+// } else {
+// throw Throwable(context.string(errorRes))
+// }
+// }
+// }
+// }
+// }
+//
+// /**
+// * Get data directly from the link and search for our queries, returning the outerHTML
+// * of the first query found
+// *
+// * from [debug] to [simplifyJsoup]
+// */
+// private fun AnkoAsyncContext<MaterialDialog>.loadJsoup() {
+// uiThread {
+// it.setContent("Load Jsoup")
+// it.setOnCancelListener(null)
+// it.debugAsync { simplifyJsoup(frostJsoup(data.url)) }
+// }
+// }
+//
+// /**
+// * Takes snippet of given document that matches the first query in the [query] items
+// * before sending it to [createReport]
+// */
+// private fun AnkoAsyncContext<MaterialDialog>.simplifyJsoup(doc: Document) {
+// weakRef.get() ?: return
+// val q = query.first { doc.select(it).isNotEmpty() }
+// createReport(doc.select(q).outerHtml())
+// }
+//
+// private fun AnkoAsyncContext<MaterialDialog>.createReport(html: String) {
+// val cleanHtml = html.cleanHtml()
+// uiThread {
+// val c = it.context
+// it.dismiss()
+// c.sendFrostEmail("${c.string(R.string.debug_report_email_title)} $name") {
+// addItem("Query List", query.contentToString())
+// footer = cleanHtml
+// }
+// }
+// }
+//} \ No newline at end of file