[API/Librus] Fix classrooms name short extraction when name contains two spaces.

This commit is contained in:
Kuba Szczodrzyński 2020-01-19 20:22:41 +01:00
parent 621dbd459c
commit d097fcc973
2 changed files with 11 additions and 2 deletions

View File

@ -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
}

View File

@ -25,9 +25,10 @@ class LibrusApiClassrooms(override val data: DataLibrus,
val id = classroom.getLong("Id") ?: return@forEach
val name = classroom.getString("Name")?.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")
}
else {