diff options
Diffstat (limited to 'app/src/main/kotlin')
18 files changed, 102 insertions, 61 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/AboutActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/AboutActivity.kt index 552339ba..67ce8f7c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/AboutActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/AboutActivity.kt @@ -24,6 +24,12 @@ class AboutActivity : AboutActivityBase(R.string::class.java, configBuilder = { }) { override fun getLibraries(libs: Libs): List<Library> { + val include = arrayOf( + "materialdialogs", + "kotterknife", + "glide", + "jsoup" + ) /* * These are great libraries, but either aren't used directly or are too common to be listed * Give more emphasis on the unique libs! @@ -39,7 +45,7 @@ class AboutActivity : AboutActivityBase(R.string::class.java, configBuilder = { "recyclerview_v7", "support_v4" ) - val l = libs.prepareLibraries(this, null, exclude, true, true) + val l = libs.prepareLibraries(this, include, exclude, true, true) // l.forEach { KL.d("Lib ${it.definedName}") } return l } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt index d8230159..dcb68696 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt @@ -14,7 +14,6 @@ import android.support.v7.widget.Toolbar import android.view.Menu import android.view.MenuItem import ca.allanwang.kau.changelog.showChangelog -import ca.allanwang.kau.logging.KL import ca.allanwang.kau.searchview.SearchItem import ca.allanwang.kau.searchview.SearchView import ca.allanwang.kau.searchview.bindSearchView @@ -331,10 +330,7 @@ class MainActivity : BaseActivity(), FrostWebViewSearch.SearchContract { if (searchView == null) searchView = bindSearchView(menu, R.id.action_search, Prefs.iconColor) { textObserver = { observable, _ -> - observable.observeOn(AndroidSchedulers.mainThread()).subscribe { - L.d("Input $it") - hiddenSearchView?.query(it) - } + observable.observeOn(AndroidSchedulers.mainThread()).subscribe { hiddenSearchView?.query(it) } } foregroundColor = Prefs.textColor backgroundColor = Prefs.bgColor diff --git a/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt index 7facc931..580c7dbc 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt @@ -12,10 +12,7 @@ import ca.allanwang.kau.utils.* import ca.allanwang.kau.views.RippleCanvas import com.mikepenz.community_material_typeface_library.CommunityMaterial import com.mikepenz.google_material_typeface_library.GoogleMaterial -import com.pitchedapps.frost.settings.getAppearancePrefs -import com.pitchedapps.frost.settings.getExperimentalPrefs -import com.pitchedapps.frost.settings.getFeedPrefs -import com.pitchedapps.frost.settings.getNotificationPrefs +import com.pitchedapps.frost.settings.* import com.pitchedapps.frost.utils.* import com.pitchedapps.frost.utils.iab.IS_FROST_PRO import com.pitchedapps.frost.utils.iab.openPlayProPurchase @@ -37,6 +34,11 @@ class SettingsActivity : KPrefActivity() { iicon = GoogleMaterial.Icon.gmd_palette } + subItems(R.string.behaviour, getBehaviourPrefs()) { + descRes = R.string.behaviour_desc + iicon = GoogleMaterial.Icon.gmd_trending_up + } + subItems(R.string.newsfeed, getFeedPrefs()) { descRes = R.string.newsfeed_desc iicon = CommunityMaterial.Icon.cmd_newspaper diff --git a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt index 9e15073c..122c571e 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt @@ -15,11 +15,10 @@ class StartActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - L.d("Load cookies ${System.currentTimeMillis()}") FbCookie.switchBackUser { loadFbCookiesAsync { cookies -> - L.d("Cookies loaded ${System.currentTimeMillis()} $cookies") + L.d("Cookies loaded ${System.currentTimeMillis()}", cookies.toString()) if (cookies.isNotEmpty()) launchNewTask(if (Prefs.userId != -1L) MainActivity::class.java else SelectorActivity::class.java, ArrayList(cookies)) else diff --git a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt index 0f8eee09..932324f2 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt @@ -51,14 +51,14 @@ fun loadFbCookiesSync(): List<CookieModel> = (select from CookieModel::class).or fun saveFbCookie(cookie: CookieModel, callback: (() -> Unit)? = null) { cookie.async save { - L.d("Fb cookie $cookie saved") + L.d("Fb cookie saved", cookie.toString()) callback?.invoke() } } fun removeCookie(id: Long) { loadFbCookie(id)?.async?.delete({ - L.d("Fb cookie $id deleted") + L.d("Fb cookie deleted", id.toString()) }) } @@ -69,9 +69,9 @@ fun CookieModel.fetchUsername(callback: (String) -> Unit) { result = Jsoup.connect(FbTab.PROFILE.url) .cookie(FACEBOOK_COM, cookie) .get().title() - L.d("User name found: $result") + L.d("Fetch username found", result) } catch (e: Exception) { - L.e("User name fetching failed: ${e.message}") + L.e(e, "Fetch username failed") } finally { if (result.isBlank() && (name?.isNotBlank() ?: false)) { callback(name!!) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/NotificationDb.kt b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/NotificationDb.kt index e71500fc..1585e425 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/NotificationDb.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/NotificationDb.kt @@ -25,7 +25,7 @@ fun lastNotificationTime(id: Long): Long = (select from NotificationModel::class fun saveNotificationTime(notificationModel: NotificationModel, callback: (() -> Unit)? = null) { notificationModel.async save { - L.d("Fb notification $notificationModel saved") + L.d("Fb notification model saved", notificationModel.toString()) callback?.invoke() } }
\ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt index f5f8a8f7..875f1c49 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt @@ -26,12 +26,12 @@ object FbCookie { callback?.invoke() return@removeAllCookies } - L.d("Setting cookie to $cookie") + L.d("Setting cookie", cookie) val cookies = cookie.split(";").map { Pair(it, SingleSubject.create<Boolean>()) } cookies.forEach { (cookie, callback) -> setCookie(FB_URL_BASE, cookie, { callback.onSuccess(it) }) } Observable.zip<Boolean, Unit>(cookies.map { (_, callback) -> callback.toObservable() }, {}).subscribeOn(AndroidSchedulers.mainThread()).subscribe({ callback?.invoke() - L.d("Cookies set: $webCookie") + L.d("Cookies set", webCookie) flush() }) }) @@ -39,7 +39,7 @@ object FbCookie { } operator fun invoke() { - L.d("User ${Prefs.userId}") + L.d("FbCookie Invoke User", Prefs.userId.toString()) with(CookieManager.getInstance()) { setAcceptCookie(true) } @@ -51,7 +51,7 @@ object FbCookie { } fun save(id: Long) { - L.d("New cookie found for $id") + L.d("New cookie found", id.toString()) Prefs.userId = id CookieManager.getInstance().flush() val cookie = CookieModel(Prefs.userId, "", webCookie) @@ -74,10 +74,11 @@ object FbCookie { fun switchUser(cookie: CookieModel?, callback: () -> Unit) { if (cookie == null) { + L.d("Switching User; null cookie") callback() return } - L.d("Switching user to $cookie") + L.d("Switching User", cookie.toString()) Prefs.userId = cookie.id setWebCookie(cookie.cookie, callback) } @@ -95,7 +96,7 @@ object FbCookie { fun switchBackUser(callback: () -> Unit) { if (Prefs.prevId != -1L && Prefs.prevId != Prefs.userId) { switchUser(Prefs.prevId) { - L.d("Switched from ${Prefs.userId} to ${Prefs.prevId}") + L.d("Switch back user", "${Prefs.userId} to ${Prefs.prevId}") callback() } } else callback() diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/UsernameFetcher.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/UsernameFetcher.kt index cbb6222a..dfdfa027 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/UsernameFetcher.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/UsernameFetcher.kt @@ -19,7 +19,7 @@ object UsernameFetcher { name = Jsoup.connect(FbTab.PROFILE.url) .cookie(FACEBOOK_COM, data.cookie) .get().title() - L.d("User name found: $name") + L.d("User name found", name) } catch (e: Exception) { L.e(e, "User name fetching failed") } finally { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt index 267e5e75..d25e0939 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt @@ -112,10 +112,6 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { descRes = R.string.rounded_icons_desc } - checkbox(R.string.fancy_animations, { Prefs.animate }, { Prefs.animate = it; animate = it }) { - descRes = R.string.fancy_animations_desc - } - checkbox(R.string.tint_nav, { Prefs.tintNavBar }, { Prefs.tintNavBar = it frostNavigationBar() diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt new file mode 100644 index 00000000..28554092 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt @@ -0,0 +1,25 @@ +package com.pitchedapps.frost.settings + +import ca.allanwang.kau.kpref.KPrefAdapterBuilder +import com.pitchedapps.frost.R +import com.pitchedapps.frost.SettingsActivity +import com.pitchedapps.frost.utils.Prefs + +/** + * Created by Allan Wang on 2017-06-30. + */ +fun SettingsActivity.getBehaviourPrefs(): KPrefAdapterBuilder.() -> Unit = { + + checkbox(R.string.fancy_animations, { Prefs.animate }, { Prefs.animate = it; animate = it }) { + descRes = R.string.fancy_animations_desc + } + + checkbox(R.string.exit_confirmation, { Prefs.exitConfirmation }, { Prefs.exitConfirmation = it }) { + descRes = R.string.exit_confirmation_desc + } + + checkbox(R.string.analytics, { Prefs.analytics }, { Prefs.analytics = it }) { + descRes = R.string.analytics_desc + } + +} diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt index 679eef36..054b3669 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt @@ -18,4 +18,8 @@ fun SettingsActivity.getExperimentalPrefs(): KPrefAdapterBuilder.() -> Unit = { checkbox(R.string.search, { Prefs.searchBar }, { Prefs.searchBar = it; setResult(MainActivity.REQUEST_SEARCH) }) { descRes = R.string.search_desc } + + checkbox(R.string.verbose_logging, { Prefs.verboseLogging }, { Prefs.verboseLogging = it }) { + descRes = R.string.verbose_logging_desc + } }
\ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt index d9ce828e..dcf97265 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt @@ -8,14 +8,36 @@ import timber.log.Timber /** * Created by Allan Wang on 2017-05-28. + * + * Logging for frost + * + * To ensure privacy, the following rules are set: + * + * Debug and Error logs must not reveal person info + * Person info logs can be marked as info or verbose */ -object L : TimberLogger("Frost") +object L : TimberLogger("Frost") { + + /** + * Helper function to separate private info + */ + fun d(tag: String, personal: String?) { + L.d(tag) + if (personal != null) L.i(personal) + } +} internal class CrashReportingTree : Timber.Tree() { override fun log(priority: Int, tag: String?, message: String?, t: Throwable?) { - if (priority == Log.VERBOSE || priority == Log.DEBUG) - return - if (message != null) Crashlytics.log(priority, tag ?: "Frost", message) + when (priority) { + Log.VERBOSE, Log.INFO -> return + Log.DEBUG -> if (!Prefs.verboseLogging) return + } + if (message != null) + if (priority == Log.ERROR) + Crashlytics.log(Log.ERROR, "Frost", message) + else + Crashlytics.log(message) if (t != null) Crashlytics.logException(t) } }
\ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt index f73350f2..287e0d7d 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt @@ -91,5 +91,9 @@ object Prefs : KPref() { var debugPro: Boolean by kpref("debug_pro", false) - var searchBar :Boolean by kpref("search_bar", false) + var searchBar: Boolean by kpref("search_bar", false) + + var verboseLogging: Boolean by kpref("verbose_logging", false) + + var analytics: Boolean by kpref("analytics", true) } 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 eb346140..6a99021d 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt @@ -140,8 +140,7 @@ fun Context.scheduleNotifications(minutes: Long): Boolean { } fun frostAnswers(action: Answers.() -> Unit) { - if (BuildConfig.DEBUG) return - //TODO add opt out toggle + if (BuildConfig.DEBUG || !Prefs.analytics) return Answers.getInstance().action() } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IAB.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IAB.kt index 5d0cdfa2..19b9b6f7 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IAB.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IAB.kt @@ -38,7 +38,7 @@ val IS_FROST_PRO: Boolean get() = (BuildConfig.DEBUG && Prefs.debugPro) || (IAB.helper?.queryInventory()?.getSkuDetails(FROST_PRO) != null) private fun Context.checkFromPlay(): Boolean { - val isPlay = isFromGooglePlay + val isPlay = isFromGooglePlay || BuildConfig.DEBUG if (!isPlay) materialDialogThemed { title(R.string.uh_oh) content(R.string.play_store_not_found) @@ -63,7 +63,7 @@ fun Activity.openPlayPurchase(key: String, code: Int) { L.e("IAB error: ${res.message}") playStoreErrorDialog() } else if (inv == null) { - playStoreErrorDialog() + playStoreErrorDialog("Empty inventory") } else { val donation = inv.getSkuDetails(key) if (donation != null) { @@ -73,23 +73,23 @@ fun Activity.openPlayPurchase(key: String, code: Int) { title(R.string.play_thank_you) content(R.string.play_purchased_pro) positiveText(R.string.kau_ok) - } else playStoreErrorDialog() + } else playStoreErrorDialog("Result: ${result.message}") frostAnswers { logPurchase(PurchaseEvent() .putItemId(key) .putSuccess(result.isSuccess)) } - } ?: playStoreErrorDialog() + } ?: playStoreErrorDialog("Launch Purchase Flow") } } } } -private fun Context.playStoreErrorDialog() { +private fun Context.playStoreErrorDialog(s: String = "Play Store Error") { materialDialogThemed { title(R.string.uh_oh) content(R.string.play_store_billing_error) positiveText(R.string.kau_ok) } - L.eThrow("Play Store Error") + L.e(Throwable(s), "Play Store Error") }
\ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt index 065c9c08..f12212ed 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt @@ -80,20 +80,9 @@ open class FrostWebViewClient(val webCore: FrostWebViewCore) : WebViewClient() { L.d("Emit $flag") } - override fun shouldOverrideKeyEvent(view: WebView, event: KeyEvent): Boolean { - L.d("Key event ${event.keyCode}") - return super.shouldOverrideKeyEvent(view, event) - } - override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest?): Boolean { - L.d("Url Loading ${request?.url?.path}") + L.i("Url Loading ${request?.url?.path}") return super.shouldOverrideUrlLoading(view, request) } - override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest?): WebResourceResponse? { - if (request == null || !(request.url.host?.contains(FACEBOOK_COM) ?: false)) return super.shouldInterceptRequest(view, request) - L.v("Url intercept ${request.url.path}") - return super.shouldInterceptRequest(view, request) - } - }
\ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewSearch.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewSearch.kt index f83fd63b..837df260 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewSearch.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewSearch.kt @@ -69,9 +69,10 @@ class FrostWebViewSearch(context: Context, val contract: SearchContract) : WebVi .subscribe { content: List<Pair<List<String>, String>> -> saveResultFrame(content) + L.d("Search element count ${content.size}") contract.emitSearchResponse(content.map { (texts, href) -> - L.d("Search element $texts $href") + L.i("Search element $texts $href") SearchItem(href, texts[0], texts.getOrNull(1)) }) } @@ -96,10 +97,8 @@ class FrostWebViewSearch(context: Context, val contract: SearchContract) : WebVi * Sets the input to have our given text, then dispatches the input event so the webpage recognizes it */ fun query(input: String) { - L.d("Searching attempt for $input") - JsBuilder().js("var e=document.getElementById('main-search-input');if(e){e.value='$input';var n=new Event('input',{bubbles:!0,cancelable:!0});e.dispatchEvent(n)}else console.log('Input field not found')").build().inject(this) { - L.d("Searching for $input") - } + L.d("Searching attempt", input) + JsBuilder().js("var e=document.getElementById('main-search-input');if(e){e.value='$input';var n=new Event('input',{bubbles:!0,cancelable:!0});e.dispatchEvent(n)}else console.log('Input field not found')").build().inject(this) } /** @@ -130,7 +129,7 @@ class FrostWebViewSearch(context: Context, val contract: SearchContract) : WebVi L.d("Search loaded successfully") } 1 -> { //something is not found in the search view; this is effectively useless - L.d("Search subject error; reverting to full overlay") + L.eThrow("Search subject error; reverting to full overlay") searchSubject.onComplete() contract.searchOverlayDispose() } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt index fe024ea3..a42ee4fb 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt @@ -6,7 +6,6 @@ import android.util.AttributeSet import android.view.View import android.webkit.* import ca.allanwang.kau.utils.fadeIn -import ca.allanwang.kau.utils.snackbar import com.pitchedapps.frost.R import com.pitchedapps.frost.dbflow.CookieModel import com.pitchedapps.frost.facebook.FACEBOOK_COM @@ -44,7 +43,7 @@ class LoginWebView @JvmOverloads constructor( cookieObservable.filter { (_, cookie) -> cookie?.contains(userMatcher) ?: false } .subscribe { (url, cookie) -> - L.d("Checking cookie for $url\n\t$cookie") + L.d("Checking cookie for login", "$url\n\t$cookie") val id = userMatcher.find(cookie!!)?.groups?.get(1)?.value if (id != null) { try { |