diff options
author | Allan Wang <me@allanwang.ca> | 2018-01-07 02:43:57 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-07 02:43:57 -0500 |
commit | 8aece5e3f9209d7c161410c304655f0aec2d6054 (patch) | |
tree | 1a68d7289a7e67dfaba37a9152fc3942f944bc5e /app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt | |
parent | 726d2a4dc3d3158490ca94b660b195898becb30a (diff) | |
download | frost-8aece5e3f9209d7c161410c304655f0aec2d6054.tar.gz frost-8aece5e3f9209d7c161410c304655f0aec2d6054.tar.bz2 frost-8aece5e3f9209d7c161410c304655f0aec2d6054.zip |
Feature/website debug (#603)
* Create beginning of web downloader
* Clean up
* Update KAU for reified activity launching
* Update web attachments and setFrostColor
* Test other zipper
* Test simpler image saving model
* Finish up image activity
* Restore aggressive overlays
* Try new zipper
* Test again
* Fix tests
* Add working build
* Rename
* Support cancellation
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.kt | 171 |
1 files changed, 68 insertions, 103 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 269b5a95..76c6e5a4 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt @@ -1,8 +1,22 @@ package com.pitchedapps.frost.settings import ca.allanwang.kau.kpref.activity.KPrefAdapterBuilder +import ca.allanwang.kau.utils.materialDialog +import ca.allanwang.kau.utils.startActivityForResult import com.pitchedapps.frost.R +import com.pitchedapps.frost.activities.DebugActivity import com.pitchedapps.frost.activities.SettingsActivity +import com.pitchedapps.frost.activities.SettingsActivity.Companion.ACTIVITY_REQUEST_DEBUG +import com.pitchedapps.frost.debugger.OfflineWebsite +import com.pitchedapps.frost.facebook.FbCookie +import com.pitchedapps.frost.facebook.FbItem +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 java.io.File /** * Created by Allan Wang on 2017-06-30. @@ -16,108 +30,59 @@ 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) } -// } -// } + plainText(R.string.debug_web) { + descRes = R.string.debug_web_desc + onClick = { this@getDebugPrefs.startActivityForResult<DebugActivity>(ACTIVITY_REQUEST_DEBUG) } + } +} + +private const val ZIP_NAME = "debug" + +fun SettingsActivity.sendDebug(urlOrig: String) { + + val url = when { + urlOrig.endsWith("soft=requests") -> FbItem.FRIENDS.url + urlOrig.endsWith("soft=messages") -> FbItem.MESSAGES.url + urlOrig.endsWith("soft=notifications") -> FbItem.NOTIFICATIONS.url + urlOrig.endsWith("soft=search") -> "${FbItem._SEARCH.url}?q=a" + else -> urlOrig + } + + val downloader = OfflineWebsite(url, FbCookie.webCookie ?: "", + File(externalCacheDir, "offline_debug")) + + val md = materialDialog { + title(R.string.parsing_data) + progress(false, 100) + negativeText(R.string.kau_cancel) + onNegative { dialog, _ -> dialog.dismiss() } + canceledOnTouchOutside(false) + dismissListener { downloader.cancel() } + } + + md.doAsync { + downloader.loadAndZip(ZIP_NAME, { progress -> + uiThread { it.setProgress(progress) } + }) { success -> + uiThread { + it.dismiss() + if (success) { + val zipUri = it.context.frostUriFromFile( + File(downloader.baseDir, "$ZIP_NAME.zip")) + L.i { "Sending debug zip with uri $zipUri" } + sendFrostEmail(R.string.debug_report_email_title) { + addItem("Url", url) + addAttachment(zipUri) + extras = { + type = "application/zip" + } + } + } else { + toast(R.string.error_generic) + } + } + } + + } } -// -//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 |