Added loging url validation.

This commit is contained in:
Amine 2018-11-20 19:44:10 +01:00
parent 600adc81b5
commit d8478ebb01
5 changed files with 14 additions and 13 deletions

View File

@ -1,16 +1,8 @@
buildscript { buildscript {
} }
ext {
configuration = [
buildDate: new Date()
]
// This will make me able to build multiple times a day. May break thinks. I may forget it.
todaysBuilds = "1"
}
def gitVersion() { def gitVersion() {
def process = "git for-each-ref refs/tags --sort=-authordate --format='%(refname:short)' --count=1".execute() def process = "git for-each-ref refs/tags --sort=-taggerdate --format='%(refname:short)' --count=1".execute()
return process.text.replaceAll("'", "").substring(1).replaceAll("\\.", "").trim() return process.text.replaceAll("'", "").substring(1).replaceAll("\\.", "").trim()
} }

View File

@ -109,7 +109,7 @@ class AddSourceActivity : AppCompatActivity() {
super.onResume() super.onResume()
val config = Config(this) val config = Config(this)
if (config.baseUrl.isEmpty() || !config.baseUrl.isBaseUrlValid()) { if (config.baseUrl.isEmpty() || !config.baseUrl.isBaseUrlValid(false)) {
mustLoginToAddSource() mustLoginToAddSource()
} else { } else {
handleSpoutsSpinner(spoutsSpinner, api, progress, formContainer) handleSpoutsSpinner(spoutsSpinner, api, progress, formContainer)

View File

@ -145,7 +145,7 @@ class LoginActivity : AppCompatActivity() {
var cancel = false var cancel = false
var focusView: View? = null var focusView: View? = null
if (!url.isBaseUrlValid()) { if (!url.isBaseUrlValid(logErrors)) {
urlView.error = getString(R.string.login_url_problem) urlView.error = getString(R.string.login_url_problem)
focusView = urlView focusView = urlView
cancel = true cancel = true

View File

@ -9,4 +9,8 @@ fun ErrorReporter.maybeHandleSilentException(throwable: Throwable, ctx: Context)
if (sharedPref.getBoolean("acra_should_log", false)) { if (sharedPref.getBoolean("acra_should_log", false)) {
this.handleSilentException(throwable) this.handleSilentException(throwable)
} }
}
fun ErrorReporter.doHandleSilentException(throwable: Throwable) {
this.handleSilentException(throwable)
} }

View File

@ -19,6 +19,7 @@ import apps.amine.bou.readerforselfoss.ReaderActivity
import apps.amine.bou.readerforselfoss.api.selfoss.Item import apps.amine.bou.readerforselfoss.api.selfoss.Item
import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper
import okhttp3.HttpUrl import okhttp3.HttpUrl
import org.acra.ACRA
fun Context.buildCustomTabsIntent(): CustomTabsIntent { fun Context.buildCustomTabsIntent(): CustomTabsIntent {
@ -134,7 +135,7 @@ private fun openInBrowser(linkDecoded: String, app: Activity) {
fun String.isUrlValid(): Boolean = fun String.isUrlValid(): Boolean =
HttpUrl.parse(this) != null && Patterns.WEB_URL.matcher(this).matches() HttpUrl.parse(this) != null && Patterns.WEB_URL.matcher(this).matches()
fun String.isBaseUrlValid(): Boolean { fun String.isBaseUrlValid(logErrors: Boolean): Boolean {
val baseUrl = HttpUrl.parse(this) val baseUrl = HttpUrl.parse(this)
var existsAndEndsWithSlash = false var existsAndEndsWithSlash = false
if (baseUrl != null) { if (baseUrl != null) {
@ -142,7 +143,11 @@ fun String.isBaseUrlValid(): Boolean {
existsAndEndsWithSlash = "" == pathSegments[pathSegments.size - 1] existsAndEndsWithSlash = "" == pathSegments[pathSegments.size - 1]
} }
return Patterns.WEB_URL.matcher(this).matches() && existsAndEndsWithSlash val isValid = Patterns.WEB_URL.matcher(this).matches() && existsAndEndsWithSlash
if (!isValid && logErrors) {
ACRA.getErrorReporter().doHandleSilentException(java.lang.Exception("Patterns.WEB_URL.matcher(this).matches() == ${Patterns.WEB_URL.matcher(this).matches()} && existsAndEndsWithSlash == $existsAndEndsWithSlash && baseUrl.pathSegments() == ${baseUrl?.pathSegments()}"))
}
return isValid
} }
fun Context.openInBrowserAsNewTask(i: Item) { fun Context.openInBrowserAsNewTask(i: Item) {