Implemented null check for cookies to prevent app crash, tweaked HelperFunctions#assignRanking to prepare for future years

This commit is contained in:
Deniz Düzgören
2019-09-27 21:49:39 +02:00
parent 2e4f423586
commit 54acd982dc
7 changed files with 38 additions and 14 deletions
@@ -323,15 +323,15 @@ internal object HelperFunctions {
* @return the ranking as an integer
*/
fun assignRanking(group: String, isPSA: Boolean): Int {
if (isPSA) return -31
if (isPSA) return -102
return try {
when {
checkStringForArray(group.substring(0, 1), juniors) -> -30
group.substring(0, 1) == "1" || group.substring(0, 1) == "2" -> {
val a = group.substring(1, 2).toInt()
a - (a * 2)
group.substring(0, 2).toIntOrNull() != null -> {
val a = group.substring(0, 2).toInt()
-a
}
else -> -29
checkStringForArray(group.substring(0, 1), juniors) -> -101
else -> -100
}
} catch (e: Exception) {
0
@@ -15,6 +15,10 @@ import java.lang.IllegalStateException
*/
internal class LoginWebViewClient(private val successListener: OnLoginSuccessListener) : WebViewClient() {
private val schoolUrls = arrayOf("https://307.joomla.schule.bremen.de/index.php/component/users/#top",
"https://307.joomla.schule.bremen.de/index.php/component/users/?task=user.login&Itemid=171",
"https://307.joomla.schule.bremen.de/index.php/component/users/profile?Itemid=171")
/**
* onPageStarted has been overridden to prevent users from reaching a domain different from
* the school's login page
@@ -22,9 +26,7 @@ internal class LoginWebViewClient(private val successListener: OnLoginSuccessLis
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
super.onPageStarted(view, url, favicon)
if (url != "https://307.joomla.schule.bremen.de/index.php/component/users/profile?Itemid=171"
&& url != "https://307.joomla.schule.bremen.de/index.php/component/users/#top"
&& url != "https://307.joomla.schule.bremen.de/index.php/component/users/?task=user.login&Itemid=171") {
if (!HelperFunctions.checkStringForArray(url.toString(), schoolUrls)) {
reloadLoginPage(webView = view)
}
}
@@ -39,7 +41,10 @@ internal class LoginWebViewClient(private val successListener: OnLoginSuccessLis
val cookies = CookieManager.getInstance().getCookie(url)
if (cookies.contains("joomla_user_state=logged_in")) {
if (cookies == null) {
reloadLoginPage(webView = view)
successListener.onLoginSucceeded(false)
} else if (cookies.contains("joomla_user_state=logged_in")) {
successListener.onLoginSucceeded(true)
}
}
@@ -54,10 +59,10 @@ internal class LoginWebViewClient(private val successListener: OnLoginSuccessLis
internal interface OnLoginSuccessListener {
/**
* This function can be overridden to execute code when a login has been successful
* This function returns a boolean value depending on the success status of the login process
*
* @param success boolean value that is set to true if the cookie could be found,
* false otherwise
* false if an error occurred
*/
fun onLoginSucceeded(success: Boolean)
}