forked from github/szkolny
[API/Librus] Fix classrooms name short extraction when name contains two spaces.
This commit is contained in:
parent
621dbd459c
commit
d097fcc973
@ -1024,3 +1024,11 @@ fun OkHttpClient.Builder.installHttpsSupport(context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun CharSequence.containsAll(list: List<CharSequence>, ignoreCase: Boolean = false): Boolean {
|
||||||
|
for (i in list) {
|
||||||
|
if (!contains(i, ignoreCase))
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
@ -25,9 +25,10 @@ class LibrusApiClassrooms(override val data: DataLibrus,
|
|||||||
val id = classroom.getLong("Id") ?: return@forEach
|
val id = classroom.getLong("Id") ?: return@forEach
|
||||||
val name = classroom.getString("Name")?.toLowerCase(Locale.getDefault()) ?: ""
|
val name = classroom.getString("Name")?.toLowerCase(Locale.getDefault()) ?: ""
|
||||||
val symbol = classroom.getString("Symbol")?.toLowerCase(Locale.getDefault()) ?: ""
|
val symbol = classroom.getString("Symbol")?.toLowerCase(Locale.getDefault()) ?: ""
|
||||||
val nameShort = name.split(" ").onEach { it[0] }.joinToString()
|
val nameShort = name.fixWhiteSpaces().split(" ").onEach { it[0] }.joinToString()
|
||||||
|
val symbolParts = symbol.fixWhiteSpaces().split(" ")
|
||||||
|
|
||||||
val friendlyName = if (name != symbol && !name.contains(symbol) && !nameShort.contains(symbol)) {
|
val friendlyName = if (name != symbol && !name.contains(symbol) && !name.containsAll(symbolParts) && !nameShort.contains(symbol)) {
|
||||||
classroom.getString("Symbol") + " " + classroom.getString("Name")
|
classroom.getString("Symbol") + " " + classroom.getString("Name")
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user