diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/activities')
5 files changed, 85 insertions, 52 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/AboutActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/AboutActivity.kt index a4d98d8a..691f050e 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/AboutActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/AboutActivity.kt @@ -59,7 +59,7 @@ class AboutActivity : AboutActivityBase(null, { "subsamplingscaleimageview" ) - val l = libs.prepareLibraries(this, include, null, false, true,true) + val l = libs.prepareLibraries(this, include, null, false, true, true) // l.forEach { KL.d{"Lib ${it.definedName}"} } return l } @@ -88,14 +88,18 @@ class AboutActivity : AboutActivityBase(null, { if (item is LibraryIItem) { val now = System.currentTimeMillis() if (now - lastClick > 500) - clickCount = 0 + clickCount = 1 else clickCount++ lastClick = now - if (clickCount == 7 && !Prefs.debugSettings) { - Prefs.debugSettings = true - L.d { "Debugging section enabled" } - toast(R.string.debug_toast_enabled) + if (clickCount == 8) { + if (!Prefs.debugSettings) { + Prefs.debugSettings = true + L.d { "Debugging section enabled" } + toast(R.string.debug_toast_enabled) + } else { + toast(R.string.debug_toast_already_enabled) + } } } false 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 685e6532..30f12c1d 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/DebugActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/DebugActivity.kt @@ -15,10 +15,15 @@ import ca.allanwang.kau.utils.visible import com.mikepenz.google_material_typeface_library.GoogleMaterial import com.pitchedapps.frost.R import com.pitchedapps.frost.facebook.FbItem +import com.pitchedapps.frost.injectors.JsActions +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 java.io.File /** @@ -33,6 +38,8 @@ class DebugActivity : KauBaseActivity() { companion object { const val RESULT_URL = "extra_result_url" + const val RESULT_SCREENSHOT = "extra_result_screenshot" + const val RESULT_BODY = "extra_result_body" fun baseDir(context: Context) = File(context.externalCacheDir, "offline_debug") } @@ -61,13 +68,34 @@ class DebugActivity : KauBaseActivity() { val parent = baseDir(this) parent.createFreshDir() - val file = File(parent, "screenshot.png") - web.getScreenshot(file) { - val intent = Intent() - intent.putExtra(RESULT_URL, web.url) - setResult(Activity.RESULT_OK, intent) - finish() - } + val rxScreenshot = Single.fromCallable { + web.getScreenshot(File(parent, "screenshot.png")) + }.subscribeOn(Schedulers.io()) + val rxBody = Single.create<String> { emitter -> + web.evaluateJavascript(JsActions.RETURN_BODY.function) { + emitter.onSuccess(it) + } + }.subscribeOn(AndroidSchedulers.mainThread()) + Single.zip(listOf(rxScreenshot, rxBody), { + val screenshot = it[0] == true + 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) + finish() + } } } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt index e563ff8a..9f191460 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt @@ -92,7 +92,8 @@ class ImageActivity : KauBaseActivity() { // a unique image identifier based on the id (if it exists), and its hash private val IMAGE_HASH: String by lazy { - "${Math.abs(FB_IMAGE_ID_MATCHER.find(IMAGE_URL)[1]?.hashCode() ?: 0)}_${Math.abs(IMAGE_URL.hashCode())}" + "${Math.abs(FB_IMAGE_ID_MATCHER.find(IMAGE_URL)[1]?.hashCode() + ?: 0)}_${Math.abs(IMAGE_URL.hashCode())}" } override fun onCreate(savedInstanceState: Bundle?) { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt index 3b320cce..aa2e5871 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt @@ -83,32 +83,32 @@ class LoginActivity : BaseActivity() { usernameSubject, BiFunction(::Pair)) .observeOn(AndroidSchedulers.mainThread()).subscribe { (foundImage, name) -> - refresh = false - if (!foundImage) { - L.e { "Could not get profile photo; Invalid userId?" } - L._i { cookie } - } - textview.text = String.format(getString(R.string.welcome), name) - textview.fadeIn() - frostAnswers { - logLogin(LoginEvent() - .putMethod("frost_browser") - .putSuccess(true)) - } - /* - * The user may have logged into an account that is already in the database - * We will let the db handle duplicates and load it now after the new account has been saved - */ - loadFbCookiesAsync { - val cookies = ArrayList(it) - Handler().postDelayed({ - if (Showcase.intro) - launchNewTask<IntroActivity>(cookies, true) - else - launchNewTask<MainActivity>(cookies, true) - }, 1000) - } - } + refresh = false + if (!foundImage) { + L.e { "Could not get profile photo; Invalid userId?" } + L._i { cookie } + } + textview.text = String.format(getString(R.string.welcome), name) + textview.fadeIn() + frostAnswers { + logLogin(LoginEvent() + .putMethod("frost_browser") + .putSuccess(true)) + } + /* + * The user may have logged into an account that is already in the database + * We will let the db handle duplicates and load it now after the new account has been saved + */ + loadFbCookiesAsync { + val cookies = ArrayList(it) + Handler().postDelayed({ + if (Showcase.intro) + launchNewTask<IntroActivity>(cookies, true) + else + launchNewTask<MainActivity>(cookies, true) + }, 1000) + } + } loadProfile(cookie.id) loadUsername(cookie) } @@ -117,17 +117,17 @@ class LoginActivity : BaseActivity() { private fun loadProfile(id: Long) { profileLoader.load(PROFILE_PICTURE_URL(id)) .transform(FrostGlide.roundCorner).listener(object : RequestListener<Drawable> { - override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean { - profileSubject.onSuccess(true) - return false - } - - override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean { - e.logFrostAnswers("Profile loading exception") - profileSubject.onSuccess(false) - return false - } - }).into(profile) + override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean { + profileSubject.onSuccess(true) + return false + } + + override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean { + e.logFrostAnswers("Profile loading exception") + profileSubject.onSuccess(false) + return false + } + }).into(profile) } private fun loadUsername(cookie: CookieModel) { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt index 2de7a843..8d4e521f 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt @@ -52,7 +52,7 @@ class SettingsActivity : KPrefActivity(), FrostBilling by IabSettings() { ACTIVITY_REQUEST_DEBUG -> { val url = data?.extras?.getString(DebugActivity.RESULT_URL) if (resultCode == Activity.RESULT_OK && url?.isNotBlank() == true) - sendDebug(url) + sendDebug(url, data.extras.getString(DebugActivity.RESULT_BODY)) return } } |