Archived
Added custom sorting algorithm to restore the old sorting system of the school's substitution plan that ordered by group first, then time, instead of the other way around
This commit is contained in:
@@ -50,7 +50,6 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
|
||||
private var mContext = WeakReference(context)
|
||||
private var mApplication = application
|
||||
private var mView = WeakReference(parentView)
|
||||
private var priority = 200
|
||||
private var notificationText = ""
|
||||
private var informational = ""
|
||||
private val prefs = PreferenceManager.getDefaultSharedPreferences(mContext.get())
|
||||
@@ -91,6 +90,7 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
mView.get()?.let { v: View ->
|
||||
val snackBarView = v.findViewById<View>(R.id.coordination)
|
||||
Snackbar.make(snackBarView, mContext.get()?.getString(R.string.no_internet_connection) ?: "", Snackbar.LENGTH_LONG).setBackgroundTint(ContextCompat.getColor(mContext.get()!!,
|
||||
@@ -169,20 +169,22 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
|
||||
val row = rows[i]
|
||||
val cols = row.select("th")
|
||||
|
||||
val group = cols[0].text()
|
||||
val date = cols[1].text()
|
||||
val subst = Substitution(
|
||||
group = cols[0].text(),
|
||||
date = cols[1].text(),
|
||||
group = group,
|
||||
date = date,
|
||||
time = cols[2].text(),
|
||||
course = cols[3].text(),
|
||||
room = cols[4].text(),
|
||||
additional = cols[5].text(),
|
||||
teacher = cols[6].text(),
|
||||
type = cols[7].text(),
|
||||
priority = priority
|
||||
priority = HelperFunctions.assignRanking(group, date.substring(0, 3) == "psa"),
|
||||
date_priority = HelperFunctions.assignDatePriority(date)
|
||||
)
|
||||
substArray.add(subst)
|
||||
substRepo.insert(subst)
|
||||
priority--
|
||||
}
|
||||
var countOfNotificationItems = 0
|
||||
var countOfMoreNotificationItems = 0
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.*
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.OutputStreamWriter
|
||||
import java.lang.NumberFormatException
|
||||
import javax.xml.parsers.DocumentBuilderFactory
|
||||
|
||||
/**
|
||||
@@ -309,6 +310,52 @@ internal object HelperFunctions {
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns an integer to a given group used to sort the substitution plan in SQL.
|
||||
* The ranking is stored as 'priority' in the database
|
||||
*
|
||||
* @param group the group string that should be assigned a ranking
|
||||
* @param isPSA used to determine a PSA, assigns lowest value if true, therefore putting
|
||||
* the PSA at the top
|
||||
*
|
||||
* @return the ranking as an integer
|
||||
*/
|
||||
fun assignRanking(group: String, isPSA: Boolean): Int {
|
||||
val juniors = arrayOf("5", "6", "7", "8", "9")
|
||||
if (isPSA) return -31
|
||||
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)
|
||||
}
|
||||
else -> -29
|
||||
}
|
||||
} catch (e: StringIndexOutOfBoundsException) {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns a date priority to circumvent the event of the 1.12. being shown before the
|
||||
* 31.11., essentially
|
||||
*
|
||||
* @param date the date to be analysed
|
||||
*
|
||||
* @return an integer value to determine the ranking in the database
|
||||
*/
|
||||
fun assignDatePriority(date: String): Int {
|
||||
val periodIndex = date.indexOf('.', 0, true)
|
||||
return try {
|
||||
date.substring(periodIndex + 1, date.length - 1).toInt()
|
||||
} catch (e: StringIndexOutOfBoundsException) {
|
||||
0
|
||||
} catch (n: NumberFormatException) {
|
||||
-1
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The code below is used for saving and restoring user settings. However, it is currently
|
||||
* inaccessible to the end user without entering a code in the hidden settings menu,
|
||||
|
||||
Reference in New Issue
Block a user