diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/activities/DebugActivity.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/activities/DebugActivity.kt | 75 |
1 files changed, 41 insertions, 34 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/DebugActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/DebugActivity.kt index 9b1d8e79..6257e6f1 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/DebugActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/DebugActivity.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2018 Allan Wang + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ package com.pitchedapps.frost.activities import android.app.Activity @@ -5,11 +21,7 @@ import android.content.Context import android.content.Intent import android.content.res.ColorStateList import android.os.Bundle -import android.support.design.widget.FloatingActionButton -import android.support.v4.widget.SwipeRefreshLayout -import android.support.v7.widget.Toolbar import ca.allanwang.kau.internal.KauBaseActivity -import ca.allanwang.kau.utils.bindView import ca.allanwang.kau.utils.setIcon import ca.allanwang.kau.utils.visible import com.mikepenz.google_material_typeface_library.GoogleMaterial @@ -20,10 +32,11 @@ import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.Prefs import com.pitchedapps.frost.utils.createFreshDir import com.pitchedapps.frost.utils.setFrostColors -import com.pitchedapps.frost.web.DebugWebView import io.reactivex.Single import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.schedulers.Schedulers +import kotlinx.android.synthetic.main.activity_debug.* +import kotlinx.android.synthetic.main.view_main_fab.* import java.io.File /** @@ -31,11 +44,6 @@ import java.io.File */ class DebugActivity : KauBaseActivity() { - private val toolbar: Toolbar by bindView(R.id.toolbar) - private val web: DebugWebView by bindView(R.id.debug_webview) - private val swipeRefresh: SwipeRefreshLayout by bindView(R.id.swipe_refresh) - private val fab: FloatingActionButton by bindView(R.id.fab) - companion object { const val RESULT_URL = "extra_result_url" const val RESULT_SCREENSHOT = "extra_result_screenshot" @@ -56,10 +64,10 @@ class DebugActivity : KauBaseActivity() { setFrostColors { toolbar(toolbar) } - web.loadUrl(FbItem.FEED.url) - web.onPageFinished = { swipeRefresh.isRefreshing = false } + debug_webview.loadUrl(FbItem.FEED.url) + debug_webview.onPageFinished = { swipe_refresh.isRefreshing = false } - swipeRefresh.setOnRefreshListener(web::reload) + swipe_refresh.setOnRefreshListener(debug_webview::reload) fab.visible().setIcon(GoogleMaterial.Icon.gmd_bug_report, Prefs.iconColor) fab.backgroundTintList = ColorStateList.valueOf(Prefs.accentColor) @@ -69,10 +77,10 @@ class DebugActivity : KauBaseActivity() { val parent = baseDir(this) parent.createFreshDir() val rxScreenshot = Single.fromCallable { - web.getScreenshot(File(parent, "screenshot.png")) + debug_webview.getScreenshot(File(parent, "screenshot.png")) }.subscribeOn(Schedulers.io()) val rxBody = Single.create<String> { emitter -> - web.evaluateJavascript(JsActions.RETURN_BODY.function) { + debug_webview.evaluateJavascript(JsActions.RETURN_BODY.function) { emitter.onSuccess(it) } }.subscribeOn(AndroidSchedulers.mainThread()) @@ -81,23 +89,22 @@ class DebugActivity : KauBaseActivity() { val body = it[1] as? String screenshot to body }.observeOn(AndroidSchedulers.mainThread()) - .subscribe { (screenshot, body), err -> - if (err != null) { - L.e { "DebugActivity error ${err.message}" } - setResult(Activity.RESULT_CANCELED) - finish() - return@subscribe - } - val intent = Intent() - intent.putExtra(RESULT_URL, web.url) - intent.putExtra(RESULT_SCREENSHOT, screenshot) - if (body != null) - intent.putExtra(RESULT_BODY, body) - setResult(Activity.RESULT_OK, intent) + .subscribe { (screenshot, body), err -> + if (err != null) { + L.e { "DebugActivity error ${err.message}" } + setResult(Activity.RESULT_CANCELED) finish() + return@subscribe } + val intent = Intent() + intent.putExtra(RESULT_URL, debug_webview.url) + intent.putExtra(RESULT_SCREENSHOT, screenshot) + if (body != null) + intent.putExtra(RESULT_BODY, body) + setResult(Activity.RESULT_OK, intent) + finish() + } } - } override fun onSupportNavigateUp(): Boolean { @@ -107,18 +114,18 @@ class DebugActivity : KauBaseActivity() { override fun onResume() { super.onResume() - web.resumeTimers() + debug_webview.resumeTimers() } override fun onPause() { - web.pauseTimers() + debug_webview.pauseTimers() super.onPause() } override fun onBackPressed() { - if (web.canGoBack()) - web.goBack() + if (debug_webview.canGoBack()) + debug_webview.goBack() else super.onBackPressed() } -}
\ No newline at end of file +} |