Archived
Implemented null check for cookies to prevent app crash, tweaked HelperFunctions#assignRanking to prepare for future years
This commit is contained in:
+2
-2
@@ -10,8 +10,8 @@ android {
|
|||||||
applicationId "com.denizd.substitutionplan"
|
applicationId "com.denizd.substitutionplan"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 28
|
targetSdkVersion 28
|
||||||
versionCode 38
|
versionCode 39
|
||||||
versionName "2.3.0"
|
versionName "2.3.1"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
|||||||
@@ -18,11 +18,13 @@ import android.widget.LinearLayout
|
|||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout
|
import androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
|
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
|
||||||
import com.denizd.substitutionplan.R
|
import com.denizd.substitutionplan.R
|
||||||
import com.denizd.substitutionplan.data.HelperFunctions
|
import com.denizd.substitutionplan.data.HelperFunctions
|
||||||
import com.denizd.substitutionplan.data.LoginWebViewClient
|
import com.denizd.substitutionplan.data.LoginWebViewClient
|
||||||
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||||
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import kotlin.math.hypot
|
import kotlin.math.hypot
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,11 +36,13 @@ internal class Login : AppCompatActivity(R.layout.activity_login_webview), Login
|
|||||||
private lateinit var prefs: SharedPreferences
|
private lateinit var prefs: SharedPreferences
|
||||||
private lateinit var parentLayout: ConstraintLayout
|
private lateinit var parentLayout: ConstraintLayout
|
||||||
private lateinit var logInButton: ExtendedFloatingActionButton
|
private lateinit var logInButton: ExtendedFloatingActionButton
|
||||||
|
private lateinit var snackBarLayout: CoordinatorLayout
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setTheme(R.style.AppTheme0)
|
setTheme(R.style.AppTheme0)
|
||||||
parentLayout = findViewById(R.id.constraintLayout)
|
parentLayout = findViewById(R.id.constraintLayout)
|
||||||
|
snackBarLayout = findViewById(R.id.snackBarLayout)
|
||||||
parentLayout.layoutTransition.enableTransitionType(LayoutTransition.CHANGING)
|
parentLayout.layoutTransition.enableTransitionType(LayoutTransition.CHANGING)
|
||||||
val title = findViewById<TextView>(R.id.txtWelcome)
|
val title = findViewById<TextView>(R.id.txtWelcome)
|
||||||
prefs = PreferenceManager.getDefaultSharedPreferences(this)
|
prefs = PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
@@ -65,6 +69,8 @@ internal class Login : AppCompatActivity(R.layout.activity_login_webview), Login
|
|||||||
override fun onLoginSucceeded(success: Boolean) {
|
override fun onLoginSucceeded(success: Boolean) {
|
||||||
if (success) {
|
if (success) {
|
||||||
success()
|
success()
|
||||||
|
} else {
|
||||||
|
Snackbar.make(snackBarLayout, getString(R.string.error_please_try_again), Snackbar.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -323,15 +323,15 @@ internal object HelperFunctions {
|
|||||||
* @return the ranking as an integer
|
* @return the ranking as an integer
|
||||||
*/
|
*/
|
||||||
fun assignRanking(group: String, isPSA: Boolean): Int {
|
fun assignRanking(group: String, isPSA: Boolean): Int {
|
||||||
if (isPSA) return -31
|
if (isPSA) return -102
|
||||||
return try {
|
return try {
|
||||||
when {
|
when {
|
||||||
checkStringForArray(group.substring(0, 1), juniors) -> -30
|
group.substring(0, 2).toIntOrNull() != null -> {
|
||||||
group.substring(0, 1) == "1" || group.substring(0, 1) == "2" -> {
|
val a = group.substring(0, 2).toInt()
|
||||||
val a = group.substring(1, 2).toInt()
|
-a
|
||||||
a - (a * 2)
|
|
||||||
}
|
}
|
||||||
else -> -29
|
checkStringForArray(group.substring(0, 1), juniors) -> -101
|
||||||
|
else -> -100
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
0
|
0
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ import java.lang.IllegalStateException
|
|||||||
*/
|
*/
|
||||||
internal class LoginWebViewClient(private val successListener: OnLoginSuccessListener) : WebViewClient() {
|
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
|
* onPageStarted has been overridden to prevent users from reaching a domain different from
|
||||||
* the school's login page
|
* 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?) {
|
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
|
||||||
super.onPageStarted(view, url, favicon)
|
super.onPageStarted(view, url, favicon)
|
||||||
|
|
||||||
if (url != "https://307.joomla.schule.bremen.de/index.php/component/users/profile?Itemid=171"
|
if (!HelperFunctions.checkStringForArray(url.toString(), schoolUrls)) {
|
||||||
&& 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") {
|
|
||||||
reloadLoginPage(webView = view)
|
reloadLoginPage(webView = view)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,7 +41,10 @@ internal class LoginWebViewClient(private val successListener: OnLoginSuccessLis
|
|||||||
|
|
||||||
val cookies = CookieManager.getInstance().getCookie(url)
|
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)
|
successListener.onLoginSucceeded(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,10 +59,10 @@ internal class LoginWebViewClient(private val successListener: OnLoginSuccessLis
|
|||||||
internal interface OnLoginSuccessListener {
|
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,
|
* @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)
|
fun onLoginSucceeded(success: Boolean)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,4 +74,15 @@
|
|||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"/>
|
app:layout_constraintTop_toTopOf="parent"/>
|
||||||
|
|
||||||
|
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
|
android:id="@+id/snackBarLayout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="top"
|
||||||
|
android:clickable="false"
|
||||||
|
android:focusable="false"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -164,4 +164,5 @@
|
|||||||
<string name="ordering_system_hint">Sortierweise</string>
|
<string name="ordering_system_hint">Sortierweise</string>
|
||||||
<string name="ordering_systems_dialog_title">Informationen über Sortierweisen</string>
|
<string name="ordering_systems_dialog_title">Informationen über Sortierweisen</string>
|
||||||
<string name="ordering_systems_dialog_text">Du kannst zwischen zwei Sortierweisen auswählen, welche die Reihenfolge der Einträge auf dem Vertretungsplan bestimmen.\n\nStandardmäßig ist \'App-spezifisch\' ausgewählt; dies bietet einen konsistenten Plan sortiert nach Klassen, dann nach Stunden.\n\n\'Website-Original\' bietet die Original-Reihenfolge der Website. Diese ist jedoch nicht konsistent, weswegen \'App-spezifisch\' standardmäßig ausgewählt ist.</string>
|
<string name="ordering_systems_dialog_text">Du kannst zwischen zwei Sortierweisen auswählen, welche die Reihenfolge der Einträge auf dem Vertretungsplan bestimmen.\n\nStandardmäßig ist \'App-spezifisch\' ausgewählt; dies bietet einen konsistenten Plan sortiert nach Klassen, dann nach Stunden.\n\n\'Website-Original\' bietet die Original-Reihenfolge der Website. Diese ist jedoch nicht konsistent, weswegen \'App-spezifisch\' standardmäßig ausgewählt ist.</string>
|
||||||
|
<string name="error_please_try_again">Ein Fehler ist aufgetreten, bitte versuche es erneut</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -176,4 +176,5 @@
|
|||||||
<string name="ordering_system_hint">Ordering system</string>
|
<string name="ordering_system_hint">Ordering system</string>
|
||||||
<string name="ordering_systems_dialog_title">Information on ordering systems</string>
|
<string name="ordering_systems_dialog_title">Information on ordering systems</string>
|
||||||
<string name="ordering_systems_dialog_text">You may pick between two ordering systems that dictate the order in which the items on the substitution plan will appear in.\n\nThe default \'app-specific\' is an algorithm implemented in this app that provides a consistently-sorted substitution plan ordered just like the substitution plan on the website used to; sorted by classes, then by time.\n\n\'Website original\' offers the items on the substitution plan just like they\'re presented on the school website, but since these are not guaranteed to be consistent, \'app-specific\' is picked by default.</string>
|
<string name="ordering_systems_dialog_text">You may pick between two ordering systems that dictate the order in which the items on the substitution plan will appear in.\n\nThe default \'app-specific\' is an algorithm implemented in this app that provides a consistently-sorted substitution plan ordered just like the substitution plan on the website used to; sorted by classes, then by time.\n\n\'Website original\' offers the items on the substitution plan just like they\'re presented on the school website, but since these are not guaranteed to be consistent, \'app-specific\' is picked by default.</string>
|
||||||
|
<string name="error_please_try_again">An error occurred, please try again</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user