From 6bca83c464337c37ebcbabe47f8a8e2e44dd4794 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 7 Oct 2017 01:51:47 -0400 Subject: Create email sender base --- .../com/pitchedapps/frost/activities/ImageActivity.kt | 3 +-- app/src/main/kotlin/com/pitchedapps/frost/enums/Support.kt | 8 ++------ .../main/kotlin/com/pitchedapps/frost/settings/Debug.kt | 8 +++----- app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt | 14 ++++++++++++++ .../kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt | 6 ++---- 5 files changed, 22 insertions(+), 17 deletions(-) (limited to 'app/src/main/kotlin/com/pitchedapps') 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 1a253fa8..e32a2ea9 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt @@ -13,7 +13,6 @@ import android.view.View import android.view.ViewGroup import android.widget.ProgressBar import android.widget.TextView -import ca.allanwang.kau.email.sendEmail import ca.allanwang.kau.internal.KauBaseActivity import ca.allanwang.kau.mediapicker.scanMedia import ca.allanwang.kau.permissions.PERMISSION_WRITE_EXTERNAL_STORAGE @@ -214,7 +213,7 @@ internal enum class FabStates(val iicon: IIcon, val iconColor: Int = Prefs.iconC onPositive { _, _ -> if (activity.errorRef != null) L.e(activity.errorRef, "ImageActivity error report") - activity.sendEmail(R.string.dev_email, R.string.debug_image_link_subject) { + activity.sendFrostEmail(R.string.debug_image_link_subject) { addItem("Url", activity.imageUrl) addItem("Message", activity.errorRef?.message ?: "Null") } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/enums/Support.kt b/app/src/main/kotlin/com/pitchedapps/frost/enums/Support.kt index a624e429..ef3c88b6 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/enums/Support.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/enums/Support.kt @@ -2,11 +2,9 @@ package com.pitchedapps.frost.enums import android.content.Context import android.support.annotation.StringRes -import ca.allanwang.kau.email.sendEmail import ca.allanwang.kau.utils.string import com.pitchedapps.frost.R -import com.pitchedapps.frost.utils.Prefs -import com.pitchedapps.frost.utils.iab.IS_FROST_PRO +import com.pitchedapps.frost.utils.sendFrostEmail /** * Created by Allan Wang on 2017-06-29. @@ -19,9 +17,7 @@ enum class Support(@StringRes val title: Int) { fun sendEmail(context: Context) { with(context) { - this.sendEmail(string(R.string.dev_email), "${string(R.string.frost_prefix)} ${string(title)}") { - val proTag = if (IS_FROST_PRO) "TY" else "FP" - addItem("Random Frost ID", "${Prefs.frostId}-$proTag") + this.sendFrostEmail("${string(R.string.frost_prefix)} ${string(title)}") { } } } 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 3375a444..5784e2a8 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt @@ -2,7 +2,6 @@ package com.pitchedapps.frost.settings import android.content.Context import android.support.annotation.UiThread -import ca.allanwang.kau.email.sendEmail import ca.allanwang.kau.kpref.activity.KPrefAdapterBuilder import ca.allanwang.kau.utils.string import com.afollestad.materialdialogs.MaterialDialog @@ -18,6 +17,7 @@ import com.pitchedapps.frost.injectors.JsAssets import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.cleanHtml import com.pitchedapps.frost.utils.materialDialogThemed +import com.pitchedapps.frost.utils.sendFrostEmail import com.pitchedapps.frost.web.launchHeadlessHtmlExtractor import com.pitchedapps.frost.web.query import io.reactivex.disposables.Disposable @@ -95,8 +95,7 @@ private enum class Debugger(val data: FbItem, val injector: InjectorContract?, v var disposable: Disposable? = null setOnCancelListener { disposable?.dispose() } context.launchHeadlessHtmlExtractor(data.url, injector) { - disposable = it.subscribe { - (html, errorRes) -> + disposable = it.subscribe { (html, errorRes) -> debugAsync { if (errorRes == -1) { L.i("Debug report successful", html) @@ -143,8 +142,7 @@ private enum class Debugger(val data: FbItem, val injector: InjectorContract?, v uiThread { val c = it.context it.dismiss() - c.sendEmail(c.string(R.string.dev_email), - "${c.string(R.string.debug_report_email_title)} $name") { + c.sendFrostEmail("${c.string(R.string.debug_report_email_title)} $name") { addItem("Query List", query.contentToString()) footer = cleanHtml } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt index aeddd20c..5726409c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt @@ -13,6 +13,8 @@ import android.support.v7.widget.Toolbar import android.view.View import android.widget.FrameLayout import android.widget.TextView +import ca.allanwang.kau.email.EmailBuilder +import ca.allanwang.kau.email.sendEmail import ca.allanwang.kau.mediapicker.createMediaFile import ca.allanwang.kau.mediapicker.createPrivateMediaFile import ca.allanwang.kau.utils.* @@ -31,6 +33,7 @@ import com.pitchedapps.frost.facebook.FACEBOOK_COM import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.FbItem import com.pitchedapps.frost.facebook.formattedFbUrl +import com.pitchedapps.frost.utils.iab.IS_FROST_PRO import java.io.IOException import java.util.* @@ -206,4 +209,15 @@ fun Context.frostChangelog() = showChangelog(R.xml.frost_changelog, Prefs.textCo } } +inline fun Context.sendFrostEmail(@StringRes subjectId: Int, crossinline builder: EmailBuilder.() -> Unit) + = sendFrostEmail(string(subjectId), builder) + +inline fun Context.sendFrostEmail(subjectId: String, crossinline builder: EmailBuilder.() -> Unit) + = sendEmail(string(R.string.dev_email), subjectId) { + builder() + val proTag = if (IS_FROST_PRO) "TY" else "FP" + addItem("Random Frost ID", "${Prefs.frostId}-$proTag") +} + + diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt index 3918a993..dc2d7549 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt @@ -1,7 +1,6 @@ package com.pitchedapps.frost.utils import android.content.Context -import ca.allanwang.kau.email.sendEmail import ca.allanwang.kau.utils.copyToClipboard import ca.allanwang.kau.utils.shareText import ca.allanwang.kau.utils.string @@ -25,8 +24,7 @@ fun Context.showWebContextMenu(wc: WebContext) { if (it == WebContextType.COPY_TEXT && wc.text == null) return@map null this@showWebContextMenu.string(it.textId) }.filterNotNull()) - itemsCallback { - _, _, position, _ -> + itemsCallback { _, _, position, _ -> WebContextType[position].onClick(this@showWebContextMenu, wc) } dismissListener { @@ -51,7 +49,7 @@ enum class WebContextType(val textId: Int, val onClick: (c: Context, wc: WebCont content(R.string.debug_link_desc) positiveText(R.string.kau_ok) onPositive { _, _ -> - c.sendEmail(R.string.dev_email, R.string.debug_link_subject) { + c.sendFrostEmail(R.string.debug_link_subject) { message = c.string(R.string.debug_link_content) addItem("Unformatted url", wc.unformattedUrl) addItem("Formatted url", wc.url) -- cgit v1.2.3