1
0
forked from github/szkolny

[Refactor] Cleanup most compilation warnings.

This commit is contained in:
Kuba Szczodrzyński 2021-10-17 23:02:27 +02:00
parent 59f80c049c
commit 7884bf4077
No known key found for this signature in database
GPG Key ID: 70CB8A85BA1633CB
64 changed files with 89 additions and 168 deletions
app/src/main/java/pl/szczodrzynski/edziennik
config/utils
data
ext
ui
utils/managers

@ -10,8 +10,9 @@ import pl.szczodrzynski.edziennik.ui.home.HomeCardModel
import pl.szczodrzynski.edziennik.utils.models.Time import pl.szczodrzynski.edziennik.utils.models.Time
class ConfigGsonUtils { class ConfigGsonUtils {
@Suppress("UNCHECKED_CAST")
fun <T> deserializeList(gson: Gson, str: String?, classOfT: Class<T>): List<T> { fun <T> deserializeList(gson: Gson, str: String?, classOfT: Class<T>): List<T> {
val json = JsonParser().parse(str) val json = JsonParser.parseString(str)
val list: MutableList<T> = mutableListOf() val list: MutableList<T> = mutableListOf()
if (!json.isJsonArray) if (!json.isJsonArray)
return list return list

@ -44,7 +44,7 @@ class EdudziennikWebAttendance(override val data: DataEdudziennik,
return@map Triple( return@map Triple(
symbol, symbol,
name, name,
when (name.toLowerCase(Locale.ROOT)) { when (name.lowercase()) {
"obecność" -> Attendance.TYPE_PRESENT "obecność" -> Attendance.TYPE_PRESENT
"nieobecność" -> Attendance.TYPE_ABSENT "nieobecność" -> Attendance.TYPE_ABSENT
"spóźnienie" -> Attendance.TYPE_BELATED "spóźnienie" -> Attendance.TYPE_BELATED

@ -49,7 +49,7 @@ class EdudziennikWebHomework(override val data: DataEdudziennik,
val teacherName = homeworkElement.child(2).text() val teacherName = homeworkElement.child(2).text()
val teacher = data.getTeacherByFirstLast(teacherName) val teacher = data.getTeacherByFirstLast(teacherName)
val topic = homeworkElement.child(4).text()?.trim() val topic = homeworkElement.child(4).text().trim()
val eventObject = Event( val eventObject = Event(
profileId = profileId, profileId = profileId,

@ -26,8 +26,8 @@ class LibrusApiClassrooms(override val data: DataLibrus,
classrooms?.forEach { classroom -> classrooms?.forEach { classroom ->
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")?.lowercase() ?: ""
val symbol = classroom.getString("Symbol")?.toLowerCase(Locale.getDefault()) ?: "" val symbol = classroom.getString("Symbol")?.lowercase() ?: ""
val nameShort = name.fixWhiteSpaces().split(" ").onEach { it[0] }.joinToString() val nameShort = name.fixWhiteSpaces().split(" ").onEach { it[0] }.joinToString()
val symbolParts = symbol.fixWhiteSpaces().split(" ") val symbolParts = symbol.fixWhiteSpaces().split(" ")

@ -30,7 +30,7 @@ class LibrusApiSchools(override val data: DataLibrus,
// create the school's short name using first letters of each long name's word // create the school's short name using first letters of each long name's word
// append the town name and save to student data // append the town name and save to student data
val schoolNameShort = schoolNameLong?.firstLettersName val schoolNameShort = schoolNameLong?.firstLettersName
val schoolTown = school?.getString("Town")?.toLowerCase(Locale.getDefault()) val schoolTown = school?.getString("Town")?.lowercase()
data.schoolName = schoolId.toString() + schoolNameShort + "_" + schoolTown data.schoolName = schoolId.toString() + schoolNameShort + "_" + schoolTown
school?.getJsonArray("LessonsRange")?.let { ranges -> school?.getJsonArray("LessonsRange")?.let { ranges ->

@ -109,7 +109,7 @@ class LibrusMessagesGetList(override val data: DataLibrus,
id id
) )
element.select("isAnyFileAttached")?.text()?.let { element.select("isAnyFileAttached").text()?.let {
if (it == "1") if (it == "1")
messageObject.hasAttachments = true messageObject.hasAttachments = true
} }

@ -108,7 +108,7 @@ class LibrusMessagesGetMessage(override val data: DataLibrus,
readDate = readDate readDate = readDate
) )
messageRecipientObject.fullName = profile.accountName ?: profile.studentNameLong ?: "" messageRecipientObject.fullName = profile.accountName ?: profile.studentNameLong
messageRecipientList.add(messageRecipientObject) messageRecipientList.add(messageRecipientObject)
} }

@ -29,9 +29,9 @@ class LibrusMessagesGetRecipientList(override val data: DataLibrus,
messagesGet(TAG, "Receivers/action/GetTypes", parameters = mapOf( messagesGet(TAG, "Receivers/action/GetTypes", parameters = mapOf(
"includeClass" to 1 "includeClass" to 1
)) { doc -> )) { doc ->
doc.select("response GetTypes data list ArrayItem")?.forEach { doc.select("response GetTypes data list ArrayItem").forEach {
val id = it.getElementsByTag("id")?.firstOrNull()?.ownText() ?: return@forEach val id = it.getElementsByTag("id").firstOrNull()?.ownText() ?: return@forEach
val name = it.getElementsByTag("name")?.firstOrNull()?.ownText() ?: return@forEach val name = it.getElementsByTag("name").firstOrNull()?.ownText() ?: return@forEach
listTypes += id to name listTypes += id to name
} }
@ -56,7 +56,7 @@ class LibrusMessagesGetRecipientList(override val data: DataLibrus,
if (dataEl is JsonObject) { if (dataEl is JsonObject) {
val listEl = dataEl.get("ArrayItem") val listEl = dataEl.get("ArrayItem")
if (listEl is JsonArray) { if (listEl is JsonArray) {
listEl.asJsonObjectList()?.forEach { item -> listEl.asJsonObjectList().forEach { item ->
processElement(item, type.first, type.second) processElement(item, type.first, type.second)
} }
} }
@ -72,7 +72,7 @@ class LibrusMessagesGetRecipientList(override val data: DataLibrus,
private fun processElement(element: JsonObject, typeId: String, typeName: String, listName: String? = null) { private fun processElement(element: JsonObject, typeId: String, typeName: String, listName: String? = null) {
val listEl = element.getJsonObject("list")?.get("ArrayItem") val listEl = element.getJsonObject("list")?.get("ArrayItem")
if (listEl is JsonArray) { if (listEl is JsonArray) {
listEl.asJsonObjectList()?.let { list -> listEl.asJsonObjectList().let { list ->
val label = element.getString("label") ?: "" val label = element.getString("label") ?: ""
list.forEach { item -> list.forEach { item ->
processElement(item, typeId, typeName, label) processElement(item, typeId, typeName, label)

@ -9,7 +9,6 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusMessages import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusMessages
import pl.szczodrzynski.edziennik.data.api.events.MessageSentEvent import pl.szczodrzynski.edziennik.data.api.events.MessageSentEvent
import pl.szczodrzynski.edziennik.data.db.entity.Message import pl.szczodrzynski.edziennik.data.db.entity.Message
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
import pl.szczodrzynski.edziennik.data.db.entity.Teacher import pl.szczodrzynski.edziennik.data.db.entity.Teacher
import pl.szczodrzynski.edziennik.ext.base64Encode import pl.szczodrzynski.edziennik.ext.base64Encode
import pl.szczodrzynski.edziennik.ext.getJsonObject import pl.szczodrzynski.edziennik.ext.getJsonObject
@ -42,14 +41,14 @@ class LibrusMessagesSendMessage(override val data: DataLibrus,
val id = response.getLong("data") val id = response.getLong("data")
if (response.getString("status") != "ok" || id == null) { if (response.getString("status") != "ok" || id == null) {
val message = response.getString("message") // val message = response.getString("message")
// TODO error // TODO error
return@messagesGetJson return@messagesGetJson
} }
LibrusMessagesGetList(data, type = Message.TYPE_SENT, lastSync = null) { LibrusMessagesGetList(data, type = Message.TYPE_SENT, lastSync = null) {
val message = data.messageList.firstOrNull { it.isSent && it.id == id } val message = data.messageList.firstOrNull { it.isSent && it.id == id }
val metadata = data.metadataList.firstOrNull { it.thingType == Metadata.TYPE_MESSAGE && it.thingId == message?.id } // val metadata = data.metadataList.firstOrNull { it.thingType == Metadata.TYPE_MESSAGE && it.thingId == message?.id }
val event = MessageSentEvent(data.profileId, message, message?.addedDate) val event = MessageSentEvent(data.profileId, message, message?.addedDate)
EventBus.getDefault().postSticky(event) EventBus.getDefault().postSticky(event)

@ -42,7 +42,7 @@ class LibrusSynergiaHomework(override val data: DataLibrus,
doc.select("table.myHomeworkTable > tbody").firstOrNull()?.also { homeworkTable -> doc.select("table.myHomeworkTable > tbody").firstOrNull()?.also { homeworkTable ->
val homeworkElements = homeworkTable.children() val homeworkElements = homeworkTable.children()
homeworkElements.forEachIndexed { i, el -> homeworkElements.forEach { el ->
val elements = el.children() val elements = el.children()
val subjectName = elements[0].text().trim() val subjectName = elements[0].text().trim()
@ -56,7 +56,7 @@ class LibrusSynergiaHomework(override val data: DataLibrus,
val eventDate = Date.fromY_m_d(elements[6].text().trim()) val eventDate = Date.fromY_m_d(elements[6].text().trim())
val id = "/podglad/([0-9]+)'".toRegex().find( val id = "/podglad/([0-9]+)'".toRegex().find(
elements[9].select("input").attr("onclick") elements[9].select("input").attr("onclick")
)?.get(1)?.toLong() ?: return@forEachIndexed )?.get(1)?.toLong() ?: return@forEach
val lessons = data.db.timetableDao().getAllForDateNow(profileId, eventDate) val lessons = data.db.timetableDao().getAllForDateNow(profileId, eventDate)
val startTime = lessons.firstOrNull { it.subjectId == subjectId }?.startTime val startTime = lessons.firstOrNull { it.subjectId == subjectId }?.startTime

@ -63,7 +63,7 @@ class LibrusLoginApi {
} }
private fun copyFromLoginStore() { private fun copyFromLoginStore() {
data.loginStore.data?.apply { data.loginStore.data.apply {
if (has("accountLogin")) { if (has("accountLogin")) {
data.apiLogin = getString("accountLogin") data.apiLogin = getString("accountLogin")
remove("accountLogin") remove("accountLogin")

@ -84,7 +84,7 @@ class LibrusLoginPortal(val data: DataLibrus, val onSuccess: () -> Unit) {
} else { } else {
val csrfMatcher = Pattern.compile("name=\"csrf-token\" content=\"([A-z0-9=+/\\-_]+?)\"", Pattern.DOTALL).matcher(text) val csrfMatcher = Pattern.compile("name=\"csrf-token\" content=\"([A-z0-9=+/\\-_]+?)\"", Pattern.DOTALL).matcher(text)
if (csrfMatcher.find()) { if (csrfMatcher.find()) {
login(csrfMatcher.group(1)) login(csrfMatcher.group(1) ?: "")
} else { } else {
data.error(ApiError(TAG, ERROR_LOGIN_LIBRUS_PORTAL_CSRF_MISSING) data.error(ApiError(TAG, ERROR_LOGIN_LIBRUS_PORTAL_CSRF_MISSING)
.withResponse(response) .withResponse(response)

@ -131,11 +131,11 @@ class MobidziennikWebAttendance(override val data: DataMobidziennik,
// verify the lesson count is the same as dates & entries // verify the lesson count is the same as dates & entries
if (count != lessonDates.count() || count != entries.count()) if (count != lessonDates.count() || count != entries.count())
return@forEach return@forEach
ranges.forEach { range -> ranges.onEach { range ->
val lessonDate = dateIterator.next() val lessonDate = dateIterator.next()
val entry = entriesIterator.next() val entry = entriesIterator.next()
if (range == null || entry.isBlank()) if (range == null || entry.isBlank())
return@forEach return@onEach
val startTime = Time.fromH_m(range[1]) val startTime = Time.fromH_m(range[1])
range[2].split(" / ").mapNotNull { range[2].split(" / ").mapNotNull {
@ -186,7 +186,7 @@ class MobidziennikWebAttendance(override val data: DataMobidziennik,
if (entry.startsWith(symbol) && symbol.length > typeSymbol.length) if (entry.startsWith(symbol) && symbol.length > typeSymbol.length)
typeSymbol = symbol typeSymbol = symbol
} }
entry = entry.removePrefix(typeSymbol) // entry = entry.removePrefix(typeSymbol)
var isCustom = false var isCustom = false
val baseType = when (typeSymbol) { val baseType = when (typeSymbol) {

@ -15,7 +15,6 @@ import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
import pl.szczodrzynski.edziennik.ext.getString import pl.szczodrzynski.edziennik.ext.getString
import pl.szczodrzynski.edziennik.utils.Utils.crc16 import pl.szczodrzynski.edziennik.utils.Utils.crc16
import pl.szczodrzynski.edziennik.utils.models.Date import pl.szczodrzynski.edziennik.utils.models.Date
import java.util.*
class MobidziennikWebCalendar(override val data: DataMobidziennik, class MobidziennikWebCalendar(override val data: DataMobidziennik,
override val lastSync: Long?, override val lastSync: Long?,
@ -30,7 +29,7 @@ class MobidziennikWebCalendar(override val data: DataMobidziennik,
MobidziennikLuckyNumberExtractor(data, text) MobidziennikLuckyNumberExtractor(data, text)
Regexes.MOBIDZIENNIK_CLASS_CALENDAR.find(text)?.let { Regexes.MOBIDZIENNIK_CLASS_CALENDAR.find(text)?.let {
val events = JsonParser().parse(it.groupValues[1]).asJsonArray val events = JsonParser.parseString(it.groupValues[1]).asJsonArray
for (eventEl in events) { for (eventEl in events) {
val event = eventEl.asJsonObject val event = eventEl.asJsonObject
@ -50,7 +49,7 @@ class MobidziennikWebCalendar(override val data: DataMobidziennik,
val dateString = event.getString("start") ?: continue val dateString = event.getString("start") ?: continue
val eventDate = Date.fromY_m_d(dateString) val eventDate = Date.fromY_m_d(dateString)
val eventType = when (event.getString("color")?.toLowerCase(Locale.getDefault())) { val eventType = when (event.getString("color")?.lowercase()) {
"#c54449" -> Event.TYPE_SHORT_QUIZ "#c54449" -> Event.TYPE_SHORT_QUIZ
"#ab0001" -> Event.TYPE_EXAM "#ab0001" -> Event.TYPE_EXAM
"#008928" -> Event.TYPE_CLASS_EVENT "#008928" -> Event.TYPE_CLASS_EVENT

@ -26,7 +26,7 @@ class MobidziennikWebGetRecipientList(override val data: DataMobidziennik,
init { init {
webGet(TAG, "/mobile/dodajwiadomosc") { text -> webGet(TAG, "/mobile/dodajwiadomosc") { text ->
Regexes.MOBIDZIENNIK_MESSAGE_RECIPIENTS_JSON.find(text)?.let { match -> Regexes.MOBIDZIENNIK_MESSAGE_RECIPIENTS_JSON.find(text)?.let { match ->
val recipientLists = JsonParser().parse(match[1]).asJsonArray val recipientLists = JsonParser.parseString(match[1]).asJsonArray
recipientLists?.asJsonObjectList()?.forEach { list -> recipientLists?.asJsonObjectList()?.forEach { list ->
val listType = list.getString("typ")?.toIntOrNull() ?: -1 val listType = list.getString("typ")?.toIntOrNull() ?: -1
val listName = list.getString("nazwa") ?: "" val listName = list.getString("nazwa") ?: ""

@ -48,8 +48,8 @@ class MobidziennikWebHomework(override val data: DataMobidziennik,
event.attachmentIds = mutableListOf() event.attachmentIds = mutableListOf()
event.attachmentNames = mutableListOf() event.attachmentNames = mutableListOf()
Regexes.MOBIDZIENNIK_MOBILE_HOMEWORK_ATTACHMENT.findAll(tableRow).forEach { Regexes.MOBIDZIENNIK_MOBILE_HOMEWORK_ATTACHMENT.findAll(tableRow).onEach {
event.attachmentIds?.add(it[1].toLongOrNull() ?: return@forEach) event.attachmentIds?.add(it[1].toLongOrNull() ?: return@onEach)
event.attachmentNames?.add(it[2]) event.attachmentNames?.add(it[2])
} }

@ -26,7 +26,7 @@ class PodlasieApiEvents(val data: DataPodlasie, val rows: List<JsonObject>) {
val name = event.getString("Name")?.replace("&#34;", "\"") ?: "" val name = event.getString("Name")?.replace("&#34;", "\"") ?: ""
val description = event.getString("Description")?.replace("&#34;", "\"") ?: "" val description = event.getString("Description")?.replace("&#34;", "\"") ?: ""
val type = when (event.getString("Category")?.toLowerCase(Locale.getDefault())) { val type = when (event.getString("Category")?.lowercase()) {
"klasówka" -> Event.TYPE_EXAM "klasówka" -> Event.TYPE_EXAM
"praca domowa" -> Event.TYPE_HOMEWORK "praca domowa" -> Event.TYPE_HOMEWORK
"wycieczka" -> Event.TYPE_EXCURSION "wycieczka" -> Event.TYPE_EXCURSION

@ -28,6 +28,7 @@ open class TemplateApi(open val data: DataTemplate, open val lastSync: Long?) {
* You can customize this method's parameters to best fit the implemented e-register. * You can customize this method's parameters to best fit the implemented e-register.
* Just make sure that [tag] and [onSuccess] is present. * Just make sure that [tag] and [onSuccess] is present.
*/ */
@Suppress("UNUSED_PARAMETER")
fun apiGet(tag: String, endpoint: String, method: Int = GET, payload: JsonObject? = null, onSuccess: (json: JsonObject?) -> Unit) { fun apiGet(tag: String, endpoint: String, method: Int = GET, payload: JsonObject? = null, onSuccess: (json: JsonObject?) -> Unit) {
val json = JsonObject() val json = JsonObject()
json.addProperty("foo", "bar") json.addProperty("foo", "bar")

@ -28,6 +28,7 @@ open class TemplateWeb(open val data: DataTemplate, open val lastSync: Long?) {
* You can customize this method's parameters to best fit the implemented e-register. * You can customize this method's parameters to best fit the implemented e-register.
* Just make sure that [tag] and [onSuccess] is present. * Just make sure that [tag] and [onSuccess] is present.
*/ */
@Suppress("UNUSED_PARAMETER")
fun webGet(tag: String, endpoint: String, method: Int = GET, payload: JsonObject? = null, onSuccess: (json: JsonObject?) -> Unit) { fun webGet(tag: String, endpoint: String, method: Int = GET, payload: JsonObject? = null, onSuccess: (json: JsonObject?) -> Unit) {
val json = JsonObject() val json = JsonObject()
json.addProperty("foo", "bar") json.addProperty("foo", "bar")

@ -20,7 +20,7 @@ class TemplateApiSample(override val data: DataTemplate,
} }
init { init {
apiGet(TAG, "/api/v3/getData.php") { json -> apiGet(TAG, "/api/v3/getData.php") { _ ->
// here you can access and update any fields of the `data` object // here you can access and update any fields of the `data` object
// ================ // ================

@ -21,7 +21,7 @@ class TemplateWebSample(override val data: DataTemplate,
} }
init { init {
webGet(TAG, "/api/v3/getData.php") { json -> webGet(TAG, "/api/v3/getData.php") {
// here you can access and update any fields of the `data` object // here you can access and update any fields of the `data` object
// ================ // ================

@ -20,7 +20,7 @@ class TemplateWebSample2(override val data: DataTemplate,
} }
init { init {
webGet(TAG, "/api/v3/getData.php") { json -> webGet(TAG, "/api/v3/getData.php") {
// here you can access and update any fields of the `data` object // here you can access and update any fields of the `data` object
// ================ // ================

@ -175,7 +175,7 @@ open class VulcanWebMain(open val data: DataVulcan, open val lastSync: Long?) {
count++ count++
} }
schoolSymbols.removeAll { schoolSymbols.removeAll {
it.toLowerCase() == "default" it.lowercase() == "default"
|| !it.matches(Regexes.VULCAN_WEB_SYMBOL_VALIDATE) || !it.matches(Regexes.VULCAN_WEB_SYMBOL_VALIDATE)
} }
@ -280,7 +280,7 @@ open class VulcanWebMain(open val data: DataVulcan, open val lastSync: Long?) {
return return
try { try {
val json = JsonParser().parse(text).asJsonObject val json = JsonParser.parseString(text).asJsonObject
onSuccess(json, response) onSuccess(json, response)
} catch (e: Exception) { } catch (e: Exception) {
data.error(ApiError(tag, EXCEPTION_VULCAN_WEB_REQUEST) data.error(ApiError(tag, EXCEPTION_VULCAN_WEB_REQUEST)

@ -13,7 +13,6 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanHebe import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanHebe
import pl.szczodrzynski.edziennik.data.api.events.MessageSentEvent import pl.szczodrzynski.edziennik.data.api.events.MessageSentEvent
import pl.szczodrzynski.edziennik.data.db.entity.Message import pl.szczodrzynski.edziennik.data.db.entity.Message
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
import pl.szczodrzynski.edziennik.data.db.entity.Teacher import pl.szczodrzynski.edziennik.data.db.entity.Teacher
import pl.szczodrzynski.edziennik.ext.* import pl.szczodrzynski.edziennik.ext.*
@ -89,7 +88,7 @@ class VulcanHebeSendMessage(
VulcanHebeMessages(data, null) { VulcanHebeMessages(data, null) {
val message = data.messageList.firstOrNull { it.isSent && it.subject == subject } val message = data.messageList.firstOrNull { it.isSent && it.subject == subject }
val metadata = data.metadataList.firstOrNull { it.thingType == Metadata.TYPE_MESSAGE && it.thingId == messageId } // val metadata = data.metadataList.firstOrNull { it.thingType == Metadata.TYPE_MESSAGE && it.thingId == messageId }
val event = MessageSentEvent(data.profileId, message, message?.addedDate) val event = MessageSentEvent(data.profileId, message, message?.addedDate)
EventBus.getDefault().postSticky(event) EventBus.getDefault().postSticky(event)

@ -62,7 +62,7 @@ class VulcanWebLuckyNumber(override val data: DataVulcan,
profile?.empty ?: false profile?.empty ?: false
)) ))
} }
} ?: { } ?: run {
// no lucky number // no lucky number
if (Date.getToday().weekDay <= Week.FRIDAY && Time.getNow().hour >= 22) { if (Date.getToday().weekDay <= Week.FRIDAY && Time.getNow().hour >= 22) {
// working days, after 10PM // working days, after 10PM
@ -77,7 +77,7 @@ class VulcanWebLuckyNumber(override val data: DataVulcan,
// weekends // weekends
nextSync = Week.getNearestWeekDayDate(Week.MONDAY).combineWith(Time(5, 0, 0)) nextSync = Week.getNearestWeekDayDate(Week.MONDAY).combineWith(Time(5, 0, 0))
} }
}() }
data.setSyncNext(ENDPOINT_VULCAN_WEB_LUCKY_NUMBERS, SYNC_ALWAYS) data.setSyncNext(ENDPOINT_VULCAN_WEB_LUCKY_NUMBERS, SYNC_ALWAYS)
onSuccess(ENDPOINT_VULCAN_WEB_LUCKY_NUMBERS) onSuccess(ENDPOINT_VULCAN_WEB_LUCKY_NUMBERS)

@ -108,7 +108,7 @@ class SzkolnyAppFirebase(val app: App, val profiles: List<Profile>, val message:
} }
private fun sharedEvent(teamCode: String, jsonStr: String, message: String) { private fun sharedEvent(teamCode: String, jsonStr: String, message: String) {
val json = JsonParser().parse(jsonStr).asJsonObject val json = JsonParser.parseString(jsonStr).asJsonObject
val teams = app.db.teamDao().allNow val teams = app.db.teamDao().allNow
// not used, as the server provides a sharing message // not used, as the server provides a sharing message
//val eventTypes = app.db.eventTypeDao().allNow //val eventTypes = app.db.eventTypeDao().allNow
@ -192,8 +192,7 @@ class SzkolnyAppFirebase(val app: App, val profiles: List<Profile>, val message:
if (!notificationFilter.contains(Notification.TYPE_REMOVED_SHARED_EVENT)) { if (!notificationFilter.contains(Notification.TYPE_REMOVED_SHARED_EVENT)) {
val notification = Notification( val notification = Notification(
id = Notification.buildId(profile.id id = Notification.buildId(profile.id, Notification.TYPE_REMOVED_SHARED_EVENT, eventId),
?: 0, Notification.TYPE_REMOVED_SHARED_EVENT, eventId),
title = app.getNotificationTitle(Notification.TYPE_REMOVED_SHARED_EVENT), title = app.getNotificationTitle(Notification.TYPE_REMOVED_SHARED_EVENT),
text = message, text = message,
type = Notification.TYPE_REMOVED_SHARED_EVENT, type = Notification.TYPE_REMOVED_SHARED_EVENT,

@ -35,7 +35,7 @@ class SzkolnyVulcanFirebase(val app: App, val profiles: List<Profile>, val messa
val loginId = data.getInt("loginid") val loginId = data.getInt("loginid")
/* pl.vulcan.uonetmobile.auxilary.enums.CDCPushEnum */ /* pl.vulcan.uonetmobile.auxilary.enums.CDCPushEnum */
val viewIdPair = when (type.toLowerCase(Locale.ROOT)) { val viewIdPair = when (type.lowercase()) {
"wiadomosc" -> MainActivity.DRAWER_ITEM_MESSAGES to Message.TYPE_RECEIVED "wiadomosc" -> MainActivity.DRAWER_ITEM_MESSAGES to Message.TYPE_RECEIVED
"ocena" -> MainActivity.DRAWER_ITEM_GRADES to 0 "ocena" -> MainActivity.DRAWER_ITEM_GRADES to 0
"uwaga" -> MainActivity.DRAWER_ITEM_BEHAVIOUR to 0 "uwaga" -> MainActivity.DRAWER_ITEM_BEHAVIOUR to 0

@ -27,10 +27,12 @@ fun Bundle?.getIntOrNull(key: String): Int? {
return this?.get(key) as? Int return this?.get(key) as? Int
} }
@Suppress("UNCHECKED_CAST")
fun <T : Any> Bundle?.get(key: String): T? { fun <T : Any> Bundle?.get(key: String): T? {
return this?.get(key) as? T? return this?.get(key) as? T?
} }
@Suppress("UNCHECKED_CAST")
fun Bundle(vararg properties: Pair<String, Any?>): Bundle { fun Bundle(vararg properties: Pair<String, Any?>): Bundle {
return Bundle().apply { return Bundle().apply {
for (property in properties) { for (property in properties) {

@ -9,7 +9,7 @@ import android.os.Build
import java.util.* import java.util.*
fun Context.setLanguage(language: String) { fun Context.setLanguage(language: String) {
val locale = Locale(language.toLowerCase(Locale.ROOT)) val locale = Locale(language.lowercase())
val configuration = resources.configuration val configuration = resources.configuration
Locale.setDefault(locale) Locale.setDefault(locale)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
@ -18,40 +18,3 @@ fun Context.setLanguage(language: String) {
configuration.locale = locale configuration.locale = locale
resources.updateConfiguration(configuration, resources.displayMetrics) resources.updateConfiguration(configuration, resources.displayMetrics)
} }
/*
Code copied from android-28/java.util.Locale.initDefault()
*/
fun initDefaultLocale() {
run {
// user.locale gets priority
/*val languageTag: String? = System.getProperty("user.locale", "")
if (languageTag.isNotNullNorEmpty()) {
return@run Locale(languageTag)
}*/
// user.locale is empty
val language: String? = System.getProperty("user.language", "pl")
val region: String? = System.getProperty("user.region")
val country: String?
val variant: String?
// for compatibility, check for old user.region property
if (region != null) {
// region can be of form country, country_variant, or _variant
val i = region.indexOf('_')
if (i >= 0) {
country = region.substring(0, i)
variant = region.substring(i + 1)
} else {
country = region
variant = ""
}
} else {
country = System.getProperty("user.country", "")
variant = System.getProperty("user.variant", "")
}
return@run Locale(language)
}.let {
Locale.setDefault(it)
}
}

@ -16,7 +16,7 @@ fun String.crc16(): Int {
var crc = 0xFFFF var crc = 0xFFFF
for (aBuffer in this) { for (aBuffer in this) {
crc = crc.ushr(8) or (crc shl 8) and 0xffff crc = crc.ushr(8) or (crc shl 8) and 0xffff
crc = crc xor (aBuffer.toInt() and 0xff) // byte to int, trunc sign crc = crc xor (aBuffer.code and 0xff) // byte to int, trunc sign
crc = crc xor (crc and 0xff shr 4) crc = crc xor (crc and 0xff shr 4)
crc = crc xor (crc shl 12 and 0xffff) crc = crc xor (crc shl 12 and 0xffff)
crc = crc xor (crc and 0xFF shl 5 and 0xffff) crc = crc xor (crc and 0xFF shl 5 and 0xffff)

@ -9,12 +9,12 @@ import android.content.res.ColorStateList
import android.graphics.PorterDuff import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter import android.graphics.PorterDuffColorFilter
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.os.Build
import android.util.TypedValue import android.util.TypedValue
import androidx.annotation.AttrRes import androidx.annotation.AttrRes
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import androidx.annotation.ColorRes import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.core.content.res.ResourcesCompat
fun colorFromName(name: String?): Int { fun colorFromName(name: String?): Int {
val i = (name ?: "").crc32() val i = (name ?: "").crc32()
@ -60,20 +60,10 @@ fun @receiver:AttrRes Int.resolveAttr(context: Context?): Int {
} }
@ColorInt @ColorInt
fun @receiver:ColorRes Int.resolveColor(context: Context): Int { fun @receiver:ColorRes Int.resolveColor(context: Context): Int {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return ResourcesCompat.getColor(context.resources, this, context.theme)
context.resources.getColor(this, context.theme)
}
else {
context.resources.getColor(this)
}
} }
fun @receiver:DrawableRes Int.resolveDrawable(context: Context): Drawable { fun @receiver:DrawableRes Int.resolveDrawable(context: Context): Drawable {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return ResourcesCompat.getDrawable(context.resources, this, context.theme)!!
context.resources.getDrawable(this, context.theme)
}
else {
context.resources.getDrawable(this)
}
} }
fun Int.toColorStateList(): ColorStateList { fun Int.toColorStateList(): ColorStateList {

@ -18,7 +18,7 @@ fun JsonObject?.getString(key: String): String? = get(key)?.let { if (!it.isJson
fun JsonObject?.getInt(key: String): Int? = get(key)?.let { if (!it.isJsonPrimitive) null else it.asInt } fun JsonObject?.getInt(key: String): Int? = get(key)?.let { if (!it.isJsonPrimitive) null else it.asInt }
fun JsonObject?.getLong(key: String): Long? = get(key)?.let { if (!it.isJsonPrimitive) null else it.asLong } fun JsonObject?.getLong(key: String): Long? = get(key)?.let { if (!it.isJsonPrimitive) null else it.asLong }
fun JsonObject?.getFloat(key: String): Float? = get(key)?.let { if(!it.isJsonPrimitive) null else it.asFloat } fun JsonObject?.getFloat(key: String): Float? = get(key)?.let { if(!it.isJsonPrimitive) null else it.asFloat }
fun JsonObject?.getChar(key: String): Char? = get(key)?.let { if(!it.isJsonPrimitive) null else it.asCharacter } fun JsonObject?.getChar(key: String): Char? = get(key)?.let { if(!it.isJsonPrimitive) null else it.asString[0] }
fun JsonObject?.getJsonObject(key: String): JsonObject? = get(key)?.let { if (it.isJsonObject) it.asJsonObject else null } fun JsonObject?.getJsonObject(key: String): JsonObject? = get(key)?.let { if (it.isJsonObject) it.asJsonObject else null }
fun JsonObject?.getJsonArray(key: String): JsonArray? = get(key)?.let { if (it.isJsonArray) it.asJsonArray else null } fun JsonObject?.getJsonArray(key: String): JsonArray? = get(key)?.let { if (it.isJsonArray) it.asJsonArray else null }
@ -27,7 +27,7 @@ fun JsonObject?.getString(key: String, defaultValue: String): String = get(key)?
fun JsonObject?.getInt(key: String, defaultValue: Int): Int = get(key)?.let { if (!it.isJsonPrimitive) defaultValue else it.asInt } ?: defaultValue fun JsonObject?.getInt(key: String, defaultValue: Int): Int = get(key)?.let { if (!it.isJsonPrimitive) defaultValue else it.asInt } ?: defaultValue
fun JsonObject?.getLong(key: String, defaultValue: Long): Long = get(key)?.let { if (!it.isJsonPrimitive) defaultValue else it.asLong } ?: defaultValue fun JsonObject?.getLong(key: String, defaultValue: Long): Long = get(key)?.let { if (!it.isJsonPrimitive) defaultValue else it.asLong } ?: defaultValue
fun JsonObject?.getFloat(key: String, defaultValue: Float): Float = get(key)?.let { if(!it.isJsonPrimitive) defaultValue else it.asFloat } ?: defaultValue fun JsonObject?.getFloat(key: String, defaultValue: Float): Float = get(key)?.let { if(!it.isJsonPrimitive) defaultValue else it.asFloat } ?: defaultValue
fun JsonObject?.getChar(key: String, defaultValue: Char): Char = get(key)?.let { if(!it.isJsonPrimitive) defaultValue else it.asCharacter } ?: defaultValue fun JsonObject?.getChar(key: String, defaultValue: Char): Char = get(key)?.let { if(!it.isJsonPrimitive) defaultValue else it.asString[0] } ?: defaultValue
fun JsonObject?.getJsonObject(key: String, defaultValue: JsonObject): JsonObject = get(key)?.let { if (it.isJsonObject) it.asJsonObject else defaultValue } ?: defaultValue fun JsonObject?.getJsonObject(key: String, defaultValue: JsonObject): JsonObject = get(key)?.let { if (it.isJsonObject) it.asJsonObject else defaultValue } ?: defaultValue
fun JsonObject?.getJsonArray(key: String, defaultValue: JsonArray): JsonArray = get(key)?.let { if (it.isJsonArray) it.asJsonArray else defaultValue } ?: defaultValue fun JsonObject?.getJsonArray(key: String, defaultValue: JsonArray): JsonArray = get(key)?.let { if (it.isJsonArray) it.asJsonArray else defaultValue } ?: defaultValue
@ -36,11 +36,11 @@ fun JsonArray.getString(key: Int): String? = if (key >= size()) null else get(ke
fun JsonArray.getInt(key: Int): Int? = if (key >= size()) null else get(key)?.let { if (!it.isJsonPrimitive) null else it.asInt } fun JsonArray.getInt(key: Int): Int? = if (key >= size()) null else get(key)?.let { if (!it.isJsonPrimitive) null else it.asInt }
fun JsonArray.getLong(key: Int): Long? = if (key >= size()) null else get(key)?.let { if (!it.isJsonPrimitive) null else it.asLong } fun JsonArray.getLong(key: Int): Long? = if (key >= size()) null else get(key)?.let { if (!it.isJsonPrimitive) null else it.asLong }
fun JsonArray.getFloat(key: Int): Float? = if (key >= size()) null else get(key)?.let { if(!it.isJsonPrimitive) null else it.asFloat } fun JsonArray.getFloat(key: Int): Float? = if (key >= size()) null else get(key)?.let { if(!it.isJsonPrimitive) null else it.asFloat }
fun JsonArray.getChar(key: Int): Char? = if (key >= size()) null else get(key)?.let { if(!it.isJsonPrimitive) null else it.asCharacter } fun JsonArray.getChar(key: Int): Char? = if (key >= size()) null else get(key)?.let { if(!it.isJsonPrimitive) null else it.asString[0] }
fun JsonArray.getJsonObject(key: Int): JsonObject? = if (key >= size()) null else get(key)?.let { if (it.isJsonObject) it.asJsonObject else null } fun JsonArray.getJsonObject(key: Int): JsonObject? = if (key >= size()) null else get(key)?.let { if (it.isJsonObject) it.asJsonObject else null }
fun JsonArray.getJsonArray(key: Int): JsonArray? = if (key >= size()) null else get(key)?.let { if (it.isJsonArray) it.asJsonArray else null } fun JsonArray.getJsonArray(key: Int): JsonArray? = if (key >= size()) null else get(key)?.let { if (it.isJsonArray) it.asJsonArray else null }
fun String.toJsonObject(): JsonObject? = try { JsonParser().parse(this).asJsonObject } catch (ignore: Exception) { null } fun String.toJsonObject(): JsonObject? = try { JsonParser.parseString(this).asJsonObject } catch (ignore: Exception) { null }
operator fun JsonObject.set(key: String, value: JsonElement) = this.add(key, value) operator fun JsonObject.set(key: String, value: JsonElement) = this.add(key, value)
operator fun JsonObject.set(key: String, value: Boolean) = this.addProperty(key, value) operator fun JsonObject.set(key: String, value: Boolean) = this.addProperty(key, value)
@ -94,7 +94,6 @@ fun JsonArray(vararg properties: Any?): JsonArray {
} }
fun JsonArray?.isNullOrEmpty(): Boolean = (this?.size() ?: 0) == 0 fun JsonArray?.isNullOrEmpty(): Boolean = (this?.size() ?: 0) == 0
fun JsonArray.isEmpty(): Boolean = this.size() == 0
operator fun JsonArray.plusAssign(o: JsonElement) = this.add(o) operator fun JsonArray.plusAssign(o: JsonElement) = this.add(o)
operator fun JsonArray.plusAssign(o: String) = this.add(o) operator fun JsonArray.plusAssign(o: String) = this.add(o)
operator fun JsonArray.plusAssign(o: Char) = this.add(o) operator fun JsonArray.plusAssign(o: Char) = this.add(o)

@ -112,7 +112,7 @@ fun String.getShortName(): String {
*/ */
fun String?.getNameInitials(): String { fun String?.getNameInitials(): String {
if (this.isNullOrBlank()) return "" if (this.isNullOrBlank()) return ""
return this.toUpperCase().fixWhiteSpaces().split(" ").take(2).map { it[0] }.joinToString("") return this.uppercase().fixWhiteSpaces().split(" ").take(2).map { it[0] }.joinToString("")
} }
operator fun MatchResult.get(group: Int): String { operator fun MatchResult.get(group: Int): String {
@ -230,7 +230,7 @@ val String.firstLettersName: String
this.split(" ").forEach { this.split(" ").forEach {
if (it.isBlank()) if (it.isBlank())
return@forEach return@forEach
nameShort += it[0].toLowerCase() nameShort += it[0].lowercase()
} }
return nameShort return nameShort
} }

@ -25,7 +25,7 @@ fun Response?.getUnixDate(): Long {
val rfcDate = this?.headers()?.get("date") ?: return currentTimeUnix() val rfcDate = this?.headers()?.get("date") ?: return currentTimeUnix()
val pattern = "EEE, dd MMM yyyy HH:mm:ss Z" val pattern = "EEE, dd MMM yyyy HH:mm:ss Z"
val format = SimpleDateFormat(pattern, Locale.ENGLISH) val format = SimpleDateFormat(pattern, Locale.ENGLISH)
return format.parse(rfcDate).time / 1000 return (format.parse(rfcDate)?.time ?: 0) / 1000
} }
fun Long.formatDate(format: String = "yyyy-MM-dd HH:mm:ss"): String = SimpleDateFormat(format).format(this) fun Long.formatDate(format: String = "yyyy-MM-dd HH:mm:ss"): String = SimpleDateFormat(format).format(this)
@ -61,7 +61,6 @@ fun Context.timeTill(time: Int, delimiter: String = " ", countInSeconds: Boolean
} }
if (hours == 0 && minutes < 10) { if (hours == 0 && minutes < 10) {
if (!prefixAdded) parts += R.plurals.time_till_text to seconds if (!prefixAdded) parts += R.plurals.time_till_text to seconds
prefixAdded = true
parts += R.plurals.time_till_seconds to seconds parts += R.plurals.time_till_seconds to seconds
} }
} else { } else {
@ -93,7 +92,6 @@ fun Context.timeLeft(time: Int, delimiter: String = " ", countInSeconds: Boolean
} }
if (hours == 0 && minutes < 10) { if (hours == 0 && minutes < 10) {
if (!prefixAdded) parts += R.plurals.time_left_text to seconds if (!prefixAdded) parts += R.plurals.time_left_text to seconds
prefixAdded = true
parts += R.plurals.time_left_seconds to seconds parts += R.plurals.time_left_seconds to seconds
} }
} else { } else {

@ -69,7 +69,7 @@ class AttendanceBar : View {
override fun onDraw(canvas: Canvas?) { override fun onDraw(canvas: Canvas?) {
canvas ?: return canvas ?: return
val sum = attendancesList.sumBy { it.count } val sum = attendancesList.sumOf { it.count }
if (sum == 0) { if (sum == 0) {
return return
} }

@ -85,7 +85,7 @@ class AttendanceFragment : Fragment(), CoroutineScope {
pageSelection = app.config.forProfile().attendance.attendancePageSelection pageSelection = app.config.forProfile().attendance.attendancePageSelection
val pagerAdapter = FragmentLazyPagerAdapter( val pagerAdapter = FragmentLazyPagerAdapter(
fragmentManager ?: return, parentFragmentManager,
b.refreshLayout, b.refreshLayout,
listOf( listOf(
AttendanceSummaryFragment() to getString(R.string.attendance_tab_summary), AttendanceSummaryFragment() to getString(R.string.attendance_tab_summary),

@ -179,12 +179,12 @@ class AttendanceListFragment : LazyFragment(), CoroutineScope {
.sortedBy { it.first } .sortedBy { it.first }
.toMap() .toMap()
val totalCount = month.typeCountMap.entries.sumBy { val totalCount = month.typeCountMap.entries.sumOf {
if (!it.key.isCounted || it.key.baseType == Attendance.TYPE_UNKNOWN) if (!it.key.isCounted || it.key.baseType == Attendance.TYPE_UNKNOWN)
0 0
else it.value else it.value
} }
val presenceCount = month.typeCountMap.entries.sumBy { val presenceCount = month.typeCountMap.entries.sumOf {
when (it.key.baseType) { when (it.key.baseType) {
Attendance.TYPE_PRESENT, Attendance.TYPE_PRESENT,
Attendance.TYPE_PRESENT_CUSTOM, Attendance.TYPE_PRESENT_CUSTOM,

@ -181,7 +181,7 @@ class AttendanceSummaryFragment : LazyFragment(), CoroutineScope {
subjectName = it.value.firstOrNull()?.subjectLongName ?: "", subjectName = it.value.firstOrNull()?.subjectLongName ?: "",
items = it.value.toMutableList() items = it.value.toMutableList()
) } ) }
.sortedBy { it.subjectName.toLowerCase() } .sortedBy { it.subjectName.lowercase() }
var totalCountSum = 0 var totalCountSum = 0
var presenceCountSum = 0 var presenceCountSum = 0
@ -193,12 +193,12 @@ class AttendanceSummaryFragment : LazyFragment(), CoroutineScope {
.sortedBy { it.first } .sortedBy { it.first }
.toMap() .toMap()
val totalCount = subject.typeCountMap.entries.sumBy { val totalCount = subject.typeCountMap.entries.sumOf {
if (!it.key.isCounted || it.key.baseType == Attendance.TYPE_UNKNOWN) if (!it.key.isCounted || it.key.baseType == Attendance.TYPE_UNKNOWN)
0 0
else it.value else it.value
} }
val presenceCount = subject.typeCountMap.entries.sumBy { val presenceCount = subject.typeCountMap.entries.sumOf {
when (it.key.baseType) { when (it.key.baseType) {
Attendance.TYPE_PRESENT, Attendance.TYPE_PRESENT,
Attendance.TYPE_PRESENT_CUSTOM, Attendance.TYPE_PRESENT_CUSTOM,

@ -7,7 +7,6 @@ package pl.szczodrzynski.edziennik.ui.attendance.viewholder
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.ContextThemeWrapper
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.App
@ -20,7 +19,6 @@ import pl.szczodrzynski.edziennik.ui.attendance.models.AttendanceDayRange
import pl.szczodrzynski.edziennik.ui.attendance.models.AttendanceMonth import pl.szczodrzynski.edziennik.ui.attendance.models.AttendanceMonth
import pl.szczodrzynski.edziennik.ui.grades.models.ExpandableItemModel import pl.szczodrzynski.edziennik.ui.grades.models.ExpandableItemModel
import pl.szczodrzynski.edziennik.ui.grades.viewholder.BindableViewHolder import pl.szczodrzynski.edziennik.ui.grades.viewholder.BindableViewHolder
import pl.szczodrzynski.edziennik.utils.Themes
import pl.szczodrzynski.edziennik.utils.models.Week import pl.szczodrzynski.edziennik.utils.models.Week
class AttendanceViewHolder( class AttendanceViewHolder(
@ -34,7 +32,6 @@ class AttendanceViewHolder(
override fun onBind(activity: AppCompatActivity, app: App, item: AttendanceFull, position: Int, adapter: AttendanceAdapter) { override fun onBind(activity: AppCompatActivity, app: App, item: AttendanceFull, position: Int, adapter: AttendanceAdapter) {
val manager = app.attendanceManager val manager = app.attendanceManager
val contextWrapper = ContextThemeWrapper(activity, Themes.appTheme)
val bullet = "" val bullet = ""

@ -62,7 +62,6 @@ class MonthViewHolder(
b.previewContainer.removeAllViews() b.previewContainer.removeAllViews()
val sum = item.typeCountMap.entries.sumBy { it.value }.toFloat()
item.typeCountMap.forEach { (type, count) -> item.typeCountMap.forEach { (type, count) ->
val layout = LinearLayout(contextWrapper) val layout = LinearLayout(contextWrapper)
val attendance = Attendance( val attendance = Attendance(

@ -7,7 +7,6 @@ package pl.szczodrzynski.edziennik.ui.attendance.viewholder
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.ContextThemeWrapper
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.App
@ -18,7 +17,6 @@ import pl.szczodrzynski.edziennik.ui.attendance.AttendanceAdapter
import pl.szczodrzynski.edziennik.ui.attendance.AttendanceAdapter.Companion.STATE_CLOSED import pl.szczodrzynski.edziennik.ui.attendance.AttendanceAdapter.Companion.STATE_CLOSED
import pl.szczodrzynski.edziennik.ui.attendance.models.AttendanceSubject import pl.szczodrzynski.edziennik.ui.attendance.models.AttendanceSubject
import pl.szczodrzynski.edziennik.ui.grades.viewholder.BindableViewHolder import pl.szczodrzynski.edziennik.ui.grades.viewholder.BindableViewHolder
import pl.szczodrzynski.edziennik.utils.Themes
class SubjectViewHolder( class SubjectViewHolder(
inflater: LayoutInflater, inflater: LayoutInflater,
@ -31,7 +29,6 @@ class SubjectViewHolder(
override fun onBind(activity: AppCompatActivity, app: App, item: AttendanceSubject, position: Int, adapter: AttendanceAdapter) { override fun onBind(activity: AppCompatActivity, app: App, item: AttendanceSubject, position: Int, adapter: AttendanceAdapter) {
val manager = app.attendanceManager val manager = app.attendanceManager
val contextWrapper = ContextThemeWrapper(activity, Themes.appTheme)
b.title.text = item.subjectName b.title.text = item.subjectName

@ -7,7 +7,6 @@ package pl.szczodrzynski.edziennik.ui.attendance.viewholder
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.ContextThemeWrapper
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.App
@ -18,7 +17,6 @@ import pl.szczodrzynski.edziennik.ext.concat
import pl.szczodrzynski.edziennik.ui.attendance.AttendanceAdapter import pl.szczodrzynski.edziennik.ui.attendance.AttendanceAdapter
import pl.szczodrzynski.edziennik.ui.attendance.models.AttendanceTypeGroup import pl.szczodrzynski.edziennik.ui.attendance.models.AttendanceTypeGroup
import pl.szczodrzynski.edziennik.ui.grades.viewholder.BindableViewHolder import pl.szczodrzynski.edziennik.ui.grades.viewholder.BindableViewHolder
import pl.szczodrzynski.edziennik.utils.Themes
import pl.szczodrzynski.edziennik.utils.models.Date import pl.szczodrzynski.edziennik.utils.models.Date
class TypeViewHolder( class TypeViewHolder(
@ -32,7 +30,6 @@ class TypeViewHolder(
override fun onBind(activity: AppCompatActivity, app: App, item: AttendanceTypeGroup, position: Int, adapter: AttendanceAdapter) { override fun onBind(activity: AppCompatActivity, app: App, item: AttendanceTypeGroup, position: Int, adapter: AttendanceAdapter) {
val manager = app.attendanceManager val manager = app.attendanceManager
val contextWrapper = ContextThemeWrapper(activity, Themes.appTheme)
val type = item.type val type = item.type
b.title.text = type.typeName b.title.text = type.typeName

@ -20,6 +20,7 @@ import pl.szczodrzynski.edziennik.data.api.ERROR_APP_CRASH
import pl.szczodrzynski.edziennik.data.api.szkolny.SzkolnyApi import pl.szczodrzynski.edziennik.data.api.szkolny.SzkolnyApi
import pl.szczodrzynski.edziennik.data.api.szkolny.request.ErrorReportRequest import pl.szczodrzynski.edziennik.data.api.szkolny.request.ErrorReportRequest
import pl.szczodrzynski.edziennik.data.db.entity.Profile import pl.szczodrzynski.edziennik.data.db.entity.Profile
import pl.szczodrzynski.edziennik.ext.resolveColor
import pl.szczodrzynski.edziennik.utils.Themes.appTheme import pl.szczodrzynski.edziennik.utils.Themes.appTheme
import pl.szczodrzynski.edziennik.utils.html.BetterHtml import pl.szczodrzynski.edziennik.utils.html.BetterHtml
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
@ -82,7 +83,7 @@ class CrashActivity : AppCompatActivity(), CoroutineScope {
Toast.makeText(app, getString(R.string.crash_report_sent), Toast.LENGTH_SHORT).show() Toast.makeText(app, getString(R.string.crash_report_sent), Toast.LENGTH_SHORT).show()
reportButton.isEnabled = false reportButton.isEnabled = false
reportButton.setTextColor(resources.getColor(android.R.color.darker_gray)) reportButton.setTextColor(android.R.color.darker_gray.resolveColor(this@CrashActivity))
} }
} }
@ -115,7 +116,7 @@ class CrashActivity : AppCompatActivity(), CoroutineScope {
content = content.replace(packageName.toRegex(), "<font color='#4caf50'>$packageName</font>") content = content.replace(packageName.toRegex(), "<font color='#4caf50'>$packageName</font>")
content = content.replace("\n".toRegex(), "<br>") content = content.replace("\n".toRegex(), "<br>")
contentPlain += "\n" + Build.MANUFACTURER + "\n" + Build.BRAND + "\n" + Build.MODEL + "\n" + Build.DEVICE + "\n" contentPlain += "\n" + Build.MANUFACTURER + "\n" + Build.BRAND + "\n" + Build.MODEL + "\n" + Build.DEVICE + "\n"
if (app.profile != null && app.profile.registration == Profile.REGISTRATION_ENABLED) { if (app.profile.registration == Profile.REGISTRATION_ENABLED) {
contentPlain += "U: " + app.profile.userCode + "\nS: " + app.profile.studentNameLong + "\n" contentPlain += "U: " + app.profile.userCode + "\nS: " + app.profile.studentNameLong + "\n"
} }
contentPlain += BuildConfig.VERSION_NAME + " " + BuildConfig.BUILD_TYPE contentPlain += BuildConfig.VERSION_NAME + " " + BuildConfig.BUILD_TYPE

@ -49,7 +49,7 @@ class LabFragment : Fragment(), CoroutineScope {
if (!isAdded) return if (!isAdded) return
val pagerAdapter = FragmentLazyPagerAdapter( val pagerAdapter = FragmentLazyPagerAdapter(
fragmentManager ?: return, parentFragmentManager,
b.refreshLayout, b.refreshLayout,
listOf( listOf(
LabPageFragment() to "click me", LabPageFragment() to "click me",

@ -168,7 +168,7 @@ class LabProfileFragment : LazyFragment(), CoroutineScope {
json.add("App.profile", app.gson.toJsonTree(app.profile)) json.add("App.profile", app.gson.toJsonTree(app.profile))
json.add("App.profile.studentData", app.profile.studentData) json.add("App.profile.studentData", app.profile.studentData)
json.add("App.profile.loginStore", loginStore?.data ?: JsonObject()) json.add("App.profile.loginStore", loginStore?.data ?: JsonObject())
json.add("App.config", JsonParser().parse(app.gson.toJson(app.config.values.toSortedMap()))) json.add("App.config", JsonParser.parseString(app.gson.toJson(app.config.values.toSortedMap())))
} }
adapter.items = LabJsonAdapter.expand(json, 0) adapter.items = LabJsonAdapter.expand(json, 0)
adapter.notifyDataSetChanged() adapter.notifyDataSetChanged()

@ -8,7 +8,6 @@ import android.annotation.SuppressLint
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.ContextThemeWrapper
import androidx.core.view.isInvisible import androidx.core.view.isInvisible
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.App
@ -18,7 +17,6 @@ import pl.szczodrzynski.edziennik.ui.attendance.AttendanceAdapter
import pl.szczodrzynski.edziennik.ui.debug.LabJsonAdapter import pl.szczodrzynski.edziennik.ui.debug.LabJsonAdapter
import pl.szczodrzynski.edziennik.ui.debug.models.LabJsonArray import pl.szczodrzynski.edziennik.ui.debug.models.LabJsonArray
import pl.szczodrzynski.edziennik.ui.grades.viewholder.BindableViewHolder import pl.szczodrzynski.edziennik.ui.grades.viewholder.BindableViewHolder
import pl.szczodrzynski.edziennik.utils.Themes
class JsonArrayViewHolder( class JsonArrayViewHolder(
inflater: LayoutInflater, inflater: LayoutInflater,
@ -31,8 +29,6 @@ class JsonArrayViewHolder(
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun onBind(activity: AppCompatActivity, app: App, item: LabJsonArray, position: Int, adapter: LabJsonAdapter) { override fun onBind(activity: AppCompatActivity, app: App, item: LabJsonArray, position: Int, adapter: LabJsonAdapter) {
val contextWrapper = ContextThemeWrapper(activity, Themes.appTheme)
b.root.setPadding(item.level * 8.dp + 8.dp, 8.dp, 8.dp, 8.dp) b.root.setPadding(item.level * 8.dp + 8.dp, 8.dp, 8.dp, 8.dp)
b.type.text = "Array" b.type.text = "Array"

@ -8,7 +8,6 @@ import android.annotation.SuppressLint
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.ContextThemeWrapper
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.google.gson.JsonNull import com.google.gson.JsonNull
import com.google.gson.JsonPrimitive import com.google.gson.JsonPrimitive
@ -18,7 +17,6 @@ import pl.szczodrzynski.edziennik.ext.*
import pl.szczodrzynski.edziennik.ui.debug.LabJsonAdapter import pl.szczodrzynski.edziennik.ui.debug.LabJsonAdapter
import pl.szczodrzynski.edziennik.ui.debug.models.LabJsonElement import pl.szczodrzynski.edziennik.ui.debug.models.LabJsonElement
import pl.szczodrzynski.edziennik.ui.grades.viewholder.BindableViewHolder import pl.szczodrzynski.edziennik.ui.grades.viewholder.BindableViewHolder
import pl.szczodrzynski.edziennik.utils.Themes
class JsonElementViewHolder( class JsonElementViewHolder(
inflater: LayoutInflater, inflater: LayoutInflater,
@ -31,8 +29,6 @@ class JsonElementViewHolder(
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun onBind(activity: AppCompatActivity, app: App, item: LabJsonElement, position: Int, adapter: LabJsonAdapter) { override fun onBind(activity: AppCompatActivity, app: App, item: LabJsonElement, position: Int, adapter: LabJsonAdapter) {
val contextWrapper = ContextThemeWrapper(activity, Themes.appTheme)
b.root.setPadding(item.level * 8.dp + 8.dp, 8.dp, 8.dp, 8.dp) b.root.setPadding(item.level * 8.dp + 8.dp, 8.dp, 8.dp, 8.dp)
b.type.text = when (item.jsonElement) { b.type.text = when (item.jsonElement) {

@ -8,7 +8,6 @@ import android.annotation.SuppressLint
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.ContextThemeWrapper
import androidx.core.view.isInvisible import androidx.core.view.isInvisible
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.App
@ -18,7 +17,6 @@ import pl.szczodrzynski.edziennik.ui.attendance.AttendanceAdapter
import pl.szczodrzynski.edziennik.ui.debug.LabJsonAdapter import pl.szczodrzynski.edziennik.ui.debug.LabJsonAdapter
import pl.szczodrzynski.edziennik.ui.debug.models.LabJsonObject import pl.szczodrzynski.edziennik.ui.debug.models.LabJsonObject
import pl.szczodrzynski.edziennik.ui.grades.viewholder.BindableViewHolder import pl.szczodrzynski.edziennik.ui.grades.viewholder.BindableViewHolder
import pl.szczodrzynski.edziennik.utils.Themes
class JsonObjectViewHolder( class JsonObjectViewHolder(
inflater: LayoutInflater, inflater: LayoutInflater,
@ -31,8 +29,6 @@ class JsonObjectViewHolder(
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun onBind(activity: AppCompatActivity, app: App, item: LabJsonObject, position: Int, adapter: LabJsonAdapter) { override fun onBind(activity: AppCompatActivity, app: App, item: LabJsonObject, position: Int, adapter: LabJsonAdapter) {
val contextWrapper = ContextThemeWrapper(activity, Themes.appTheme)
b.root.setPadding(item.level * 8.dp + 8.dp, 8.dp, 8.dp, 8.dp) b.root.setPadding(item.level * 8.dp + 8.dp, 8.dp, 8.dp, 8.dp)
b.type.text = "Object" b.type.text = "Object"

@ -8,7 +8,6 @@ import android.annotation.SuppressLint
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.ContextThemeWrapper
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.App
import pl.szczodrzynski.edziennik.databinding.LabItemSubObjectBinding import pl.szczodrzynski.edziennik.databinding.LabItemSubObjectBinding
@ -17,7 +16,6 @@ import pl.szczodrzynski.edziennik.ui.attendance.AttendanceAdapter
import pl.szczodrzynski.edziennik.ui.debug.LabJsonAdapter import pl.szczodrzynski.edziennik.ui.debug.LabJsonAdapter
import pl.szczodrzynski.edziennik.ui.debug.models.LabJsonObject import pl.szczodrzynski.edziennik.ui.debug.models.LabJsonObject
import pl.szczodrzynski.edziennik.ui.grades.viewholder.BindableViewHolder import pl.szczodrzynski.edziennik.ui.grades.viewholder.BindableViewHolder
import pl.szczodrzynski.edziennik.utils.Themes
class JsonSubObjectViewHolder( class JsonSubObjectViewHolder(
inflater: LayoutInflater, inflater: LayoutInflater,
@ -30,8 +28,6 @@ class JsonSubObjectViewHolder(
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun onBind(activity: AppCompatActivity, app: App, item: LabJsonObject, position: Int, adapter: LabJsonAdapter) { override fun onBind(activity: AppCompatActivity, app: App, item: LabJsonObject, position: Int, adapter: LabJsonAdapter) {
val contextWrapper = ContextThemeWrapper(activity, Themes.appTheme)
b.root.setPadding(item.level * 8.dp + 8.dp, 8.dp, 8.dp, 8.dp) b.root.setPadding(item.level * 8.dp + 8.dp, 8.dp, 8.dp, 8.dp)
b.type.text = "Object" b.type.text = "Object"

@ -15,6 +15,7 @@ import pl.szczodrzynski.edziennik.App
import pl.szczodrzynski.edziennik.MainActivity import pl.szczodrzynski.edziennik.MainActivity
import pl.szczodrzynski.edziennik.R import pl.szczodrzynski.edziennik.R
import pl.szczodrzynski.edziennik.databinding.DialogBellSyncBinding import pl.szczodrzynski.edziennik.databinding.DialogBellSyncBinding
import pl.szczodrzynski.edziennik.ext.resolveDrawable
import pl.szczodrzynski.edziennik.ext.startCoroutineTimer import pl.szczodrzynski.edziennik.ext.startCoroutineTimer
import pl.szczodrzynski.edziennik.utils.models.Time import pl.szczodrzynski.edziennik.utils.models.Time
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
@ -86,7 +87,7 @@ class BellSyncDialog(
} }
if (Time.diff(Time.getNow(), bellTime) > Time(2, 0, 0)) { // Easter egg ^^ if (Time.diff(Time.getNow(), bellTime) > Time(2, 0, 0)) { // Easter egg ^^
b.bellSyncButton.setImageDrawable(app.resources.getDrawable(R.drawable.ic_bell_wtf)) // wtf b.bellSyncButton.setImageDrawable(R.drawable.ic_bell_wtf.resolveDrawable(app)) // wtf
} }
launch { launch {

@ -115,7 +115,7 @@ class GradesConfigDialog(
b.dontCountGradesText b.dontCountGradesText
.text .text
?.toString() ?.toString()
?.toLowerCase(Locale.getDefault()) ?.lowercase()
?.replace(", ", ",") ?.replace(", ", ",")
) )
profileConfig.dontCountEnabled = b.dontCountGrades.isChecked profileConfig.dontCountEnabled = b.dontCountGrades.isChecked

@ -109,7 +109,7 @@ class GradesEditorFragment : Fragment() {
continue continue
} }
var weight = editorGrade.weight var weight = editorGrade.weight
if (config.dontCountEnabled && config.dontCountGrades.contains(editorGrade.name.toLowerCase().trim())) { if (config.dontCountEnabled && config.dontCountGrades.contains(editorGrade.name.lowercase().trim())) {
weight = 0f weight = 0f
} }
val value = editorGrade.value * weight val value = editorGrade.value * weight
@ -174,7 +174,7 @@ class GradesEditorFragment : Fragment() {
averageSemester = 0f averageSemester = 0f
for (editorGrade in editorGrades) { for (editorGrade in editorGrades) {
var weight = editorGrade.weight var weight = editorGrade.weight
if (config.dontCountEnabled && config.dontCountGrades.contains(editorGrade.name.toLowerCase().trim())) { if (config.dontCountEnabled && config.dontCountGrades.contains(editorGrade.name.lowercase().trim())) {
weight = 0f weight = 0f
} }
val value = editorGrade.value * weight val value = editorGrade.value * weight
@ -216,7 +216,7 @@ class GradesEditorFragment : Fragment() {
continue continue
} }
var weight = grade.weight var weight = grade.weight
if (config.dontCountEnabled && config.dontCountGrades.contains(grade.name.toLowerCase().trim())) { if (config.dontCountEnabled && config.dontCountGrades.contains(grade.name.lowercase().trim())) {
weight = 0f weight = 0f
} }
val value = grade.value * weight val value = grade.value * weight

@ -138,8 +138,6 @@ class HomeFragment : Fragment(), CoroutineScope {
b.refreshLayout.isEnabled = scrollY == 0 b.refreshLayout.isEnabled = scrollY == 0
} }
val showUnified = false
val cards = app.config.forProfile().ui.homeCards.filter { it.profileId == app.profile.id }.toMutableList() val cards = app.config.forProfile().ui.homeCards.filter { it.profileId == app.profile.id }.toMutableList()
if (cards.isEmpty()) { if (cards.isEmpty()) {
cards += listOf( cards += listOf(

@ -63,7 +63,7 @@ class HomeLuckyNumberCard(
R.string.home_lucky_number_details_click_to_set R.string.home_lucky_number_details_click_to_set
else else
R.string.home_lucky_number_details R.string.home_lucky_number_details
b.subText.setText(subTextRes, profile.name ?: "", profile.studentNumber) b.subText.setText(subTextRes, profile.name, profile.studentNumber)
app.db.luckyNumberDao().getNearestFuture(profile.id, today).observe(fragment, Observer { luckyNumber -> app.db.luckyNumberDao().getNearestFuture(profile.id, today).observe(fragment, Observer { luckyNumber ->
val isYours = luckyNumber?.number == profile.studentNumber val isYours = luckyNumber?.number == profile.studentNumber
@ -104,7 +104,7 @@ class HomeLuckyNumberCard(
R.string.home_lucky_number_details_click_to_set R.string.home_lucky_number_details_click_to_set
else else
R.string.home_lucky_number_details R.string.home_lucky_number_details
b.subText.setText(newSubTextRes, profile.name ?: "", profile.studentNumber) b.subText.setText(newSubTextRes, profile.name, profile.studentNumber)
}) })
} }
}} }}

@ -78,7 +78,7 @@ class HomeworkFragment : Fragment(), CoroutineScope {
})) }))
val pagerAdapter = FragmentLazyPagerAdapter( val pagerAdapter = FragmentLazyPagerAdapter(
fragmentManager ?: return, parentFragmentManager,
b.refreshLayout, b.refreshLayout,
listOf( listOf(
HomeworkListFragment().apply { HomeworkListFragment().apply {

@ -175,9 +175,9 @@ class LoginFormFragment : Fragment(), CoroutineScope {
text = text.trim() text = text.trim()
if (credential.caseMode == LoginInfo.FormField.CaseMode.UPPER_CASE) if (credential.caseMode == LoginInfo.FormField.CaseMode.UPPER_CASE)
text = text.toUpperCase(Locale.getDefault()) text = text.uppercase()
if (credential.caseMode == LoginInfo.FormField.CaseMode.LOWER_CASE) if (credential.caseMode == LoginInfo.FormField.CaseMode.LOWER_CASE)
text = text.toLowerCase(Locale.getDefault()) text = text.lowercase()
credential.stripTextRegex?.let { credential.stripTextRegex?.let {
text = text.replace(it.toRegex(), "") text = text.replace(it.toRegex(), "")

@ -52,7 +52,7 @@ class TemplateFragment : Fragment(), CoroutineScope {
if (!isAdded) return if (!isAdded) return
val pagerAdapter = FragmentLazyPagerAdapter( val pagerAdapter = FragmentLazyPagerAdapter(
fragmentManager ?: return, parentFragmentManager,
b.refreshLayout, b.refreshLayout,
listOf( listOf(
HomeworkListFragment().apply { HomeworkListFragment().apply {

@ -127,7 +127,7 @@ class TimetableFragment : Fragment(), CoroutineScope {
return@launch return@launch
val pagerAdapter = TimetablePagerAdapter( val pagerAdapter = TimetablePagerAdapter(
fragmentManager ?: return@launch, parentFragmentManager,
items, items,
startHour, startHour,
endHour endHour

@ -161,7 +161,7 @@ class AttachmentsView @JvmOverloads constructor(
// get the download url before updating file name // get the download url before updating file name
val fileUrl = attachment.name.substringAfter(":", missingDelimiterValue = "") val fileUrl = attachment.name.substringAfter(":", missingDelimiterValue = "")
// update file name with the downloaded one // update file name with the downloaded one
attachment.name = File(event.fileName).name attachment.name = File(event.fileName ?: return).name
// save the download url back // save the download url back
if (fileUrl != "") if (fileUrl != "")
attachment.name += ":$fileUrl" attachment.name += ":$fileUrl"

@ -56,7 +56,6 @@ class DateDropdown : TextInputDropDown {
suspend fun loadItems() { suspend fun loadItems() {
val date = Date.getToday() val date = Date.getToday()
val today = date.value
var weekDay = date.weekDay var weekDay = date.weekDay
val dates = withContext(Dispatchers.Default) { val dates = withContext(Dispatchers.Default) {

@ -63,14 +63,14 @@ class WebPushFragment : Fragment(), CoroutineScope {
b.scanQrCode.onClick { b.scanQrCode.onClick {
manager.requestCameraPermission(activity, R.string.permissions_qr_scanner) { manager.requestCameraPermission(activity, R.string.permissions_qr_scanner) {
QrScannerDialog(activity, { QrScannerDialog(activity, {
b.tokenEditText.setText(it.crc32().toString(36).toUpperCase()) b.tokenEditText.setText(it.crc32().toString(36).uppercase())
pairBrowser(browserId = it) pairBrowser(browserId = it)
}) })
} }
} }
b.tokenAccept.onClick { b.tokenAccept.onClick {
val pairToken = b.tokenEditText.text.toString().toUpperCase() val pairToken = b.tokenEditText.text.toString().uppercase()
if (!"[0-9A-Z]{3,13}".toRegex().matches(pairToken)) { if (!"[0-9A-Z]{3,13}".toRegex().matches(pairToken)) {
b.tokenLayout.error = app.getString(R.string.web_push_token_invalid) b.tokenLayout.error = app.getString(R.string.web_push_token_invalid)
return@onClick return@onClick

@ -42,10 +42,7 @@ class WidgetLuckyNumberProvider : AppWidgetProvider() {
val views = getRemoteViews(app, config) val views = getRemoteViews(app, config)
val today = Date.getToday() val today = Date.getToday()
val todayValue = today.value
val tomorrow = Date.getToday().stepForward(0, 0, 1) val tomorrow = Date.getToday().stepForward(0, 0, 1)
val tomorrowValue = tomorrow.value
val profile = app.db.profileDao().getByIdNow(config.profileId) val profile = app.db.profileDao().getByIdNow(config.profileId)
val luckyNumber = app.db.luckyNumberDao().getNearestFutureNow(config.profileId, today) val luckyNumber = app.db.luckyNumberDao().getNearestFutureNow(config.profileId, today)

@ -56,7 +56,7 @@ class WidgetNotificationsFactory(val app: App, val config: WidgetConfig) : Remot
getString("profileName"), getString("profileName"),
getInt("posted") == 1, getInt("posted") == 1,
getInt("viewId"), getInt("viewId"),
getString("extras")?.let { JsonParser().parse(it).asJsonObject }, getString("extras")?.let { JsonParser.parseString(it).asJsonObject },
getLong("addedDate") ?: System.currentTimeMillis() getLong("addedDate") ?: System.currentTimeMillis()
) )
} ?: return views } ?: return views

@ -120,7 +120,7 @@ class GradesManager(val app: App) : CoroutineScope {
fun getGradeWeight(dontCountEnabled: Boolean, dontCountGrades: List<String>, grade: Grade): Float { fun getGradeWeight(dontCountEnabled: Boolean, dontCountGrades: List<String>, grade: Grade): Float {
if (!dontCountEnabled) if (!dontCountEnabled)
return grade.weight return grade.weight
if (grade.name.toLowerCase().trim() in dontCountGrades) if (grade.name.lowercase().trim() in dontCountGrades)
return 0f return 0f
return grade.weight return grade.weight
} }
@ -153,7 +153,7 @@ class GradesManager(val app: App) : CoroutineScope {
} }
type == TYPE_NORMAL && defColor -> grade.color and 0xffffff type == TYPE_NORMAL && defColor -> grade.color and 0xffffff
type in TYPE_NORMAL..TYPE_YEAR_FINAL -> { type in TYPE_NORMAL..TYPE_YEAR_FINAL -> {
when (grade.name.toLowerCase()) { when (grade.name.lowercase()) {
"+", "++", "+++" -> 0x4caf50 "+", "++", "+++" -> 0x4caf50
"0", "-", "-,", "-,-,", "np", "np.", "npnp", "np,", "np,np,", "bs", "nk", "bz" -> 0xff7043 "0", "-", "-,", "-,-,", "np", "np.", "npnp", "np,", "np,np,", "bs", "nk", "bz" -> 0xff7043
"1-", "1", "f", "ng" -> 0xff0000 "1-", "1", "f", "ng" -> 0xff0000
@ -181,7 +181,7 @@ class GradesManager(val app: App) : CoroutineScope {
* the specified [name]. * the specified [name].
*/ */
fun getGradeValue(name: String): Float { fun getGradeValue(name: String): Float {
return when (name.toLowerCase()) { return when (name.lowercase()) {
"1-" -> 0.75f "1-" -> 0.75f
"1" -> 1.00f "1" -> 1.00f
"1+" -> 1.50f "1+" -> 1.50f
@ -211,7 +211,7 @@ class GradesManager(val app: App) : CoroutineScope {
} }
fun getGradeNumberName(name: String): String { fun getGradeNumberName(name: String): String {
return when(name.toLowerCase()){ return when(name.lowercase()){
"niedostateczny", "f" -> "1" "niedostateczny", "f" -> "1"
"niedostateczny plus", "f+" -> "1+" "niedostateczny plus", "f+" -> "1+"
"niedostateczny minus", "f-" -> "1-" "niedostateczny minus", "f-" -> "1-"