mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-18 04:46:44 -06:00
[Refactor] Cleanup most compilation warnings.
This commit is contained in:
parent
59f80c049c
commit
7884bf4077
@ -10,8 +10,9 @@ import pl.szczodrzynski.edziennik.ui.home.HomeCardModel
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||
|
||||
class ConfigGsonUtils {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
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()
|
||||
if (!json.isJsonArray)
|
||||
return list
|
||||
|
@ -44,7 +44,7 @@ class EdudziennikWebAttendance(override val data: DataEdudziennik,
|
||||
return@map Triple(
|
||||
symbol,
|
||||
name,
|
||||
when (name.toLowerCase(Locale.ROOT)) {
|
||||
when (name.lowercase()) {
|
||||
"obecność" -> Attendance.TYPE_PRESENT
|
||||
"nieobecność" -> Attendance.TYPE_ABSENT
|
||||
"spóźnienie" -> Attendance.TYPE_BELATED
|
||||
|
@ -49,7 +49,7 @@ class EdudziennikWebHomework(override val data: DataEdudziennik,
|
||||
val teacherName = homeworkElement.child(2).text()
|
||||
val teacher = data.getTeacherByFirstLast(teacherName)
|
||||
|
||||
val topic = homeworkElement.child(4).text()?.trim()
|
||||
val topic = homeworkElement.child(4).text().trim()
|
||||
|
||||
val eventObject = Event(
|
||||
profileId = profileId,
|
||||
|
@ -26,8 +26,8 @@ class LibrusApiClassrooms(override val data: DataLibrus,
|
||||
|
||||
classrooms?.forEach { classroom ->
|
||||
val id = classroom.getLong("Id") ?: return@forEach
|
||||
val name = classroom.getString("Name")?.toLowerCase(Locale.getDefault()) ?: ""
|
||||
val symbol = classroom.getString("Symbol")?.toLowerCase(Locale.getDefault()) ?: ""
|
||||
val name = classroom.getString("Name")?.lowercase() ?: ""
|
||||
val symbol = classroom.getString("Symbol")?.lowercase() ?: ""
|
||||
val nameShort = name.fixWhiteSpaces().split(" ").onEach { it[0] }.joinToString()
|
||||
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
|
||||
// append the town name and save to student data
|
||||
val schoolNameShort = schoolNameLong?.firstLettersName
|
||||
val schoolTown = school?.getString("Town")?.toLowerCase(Locale.getDefault())
|
||||
val schoolTown = school?.getString("Town")?.lowercase()
|
||||
data.schoolName = schoolId.toString() + schoolNameShort + "_" + schoolTown
|
||||
|
||||
school?.getJsonArray("LessonsRange")?.let { ranges ->
|
||||
|
@ -109,7 +109,7 @@ class LibrusMessagesGetList(override val data: DataLibrus,
|
||||
id
|
||||
)
|
||||
|
||||
element.select("isAnyFileAttached")?.text()?.let {
|
||||
element.select("isAnyFileAttached").text()?.let {
|
||||
if (it == "1")
|
||||
messageObject.hasAttachments = true
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ class LibrusMessagesGetMessage(override val data: DataLibrus,
|
||||
readDate = readDate
|
||||
)
|
||||
|
||||
messageRecipientObject.fullName = profile.accountName ?: profile.studentNameLong ?: ""
|
||||
messageRecipientObject.fullName = profile.accountName ?: profile.studentNameLong
|
||||
|
||||
messageRecipientList.add(messageRecipientObject)
|
||||
}
|
||||
|
@ -29,9 +29,9 @@ class LibrusMessagesGetRecipientList(override val data: DataLibrus,
|
||||
messagesGet(TAG, "Receivers/action/GetTypes", parameters = mapOf(
|
||||
"includeClass" to 1
|
||||
)) { doc ->
|
||||
doc.select("response GetTypes data list ArrayItem")?.forEach {
|
||||
val id = it.getElementsByTag("id")?.firstOrNull()?.ownText() ?: return@forEach
|
||||
val name = it.getElementsByTag("name")?.firstOrNull()?.ownText() ?: return@forEach
|
||||
doc.select("response GetTypes data list ArrayItem").forEach {
|
||||
val id = it.getElementsByTag("id").firstOrNull()?.ownText() ?: return@forEach
|
||||
val name = it.getElementsByTag("name").firstOrNull()?.ownText() ?: return@forEach
|
||||
listTypes += id to name
|
||||
}
|
||||
|
||||
@ -56,7 +56,7 @@ class LibrusMessagesGetRecipientList(override val data: DataLibrus,
|
||||
if (dataEl is JsonObject) {
|
||||
val listEl = dataEl.get("ArrayItem")
|
||||
if (listEl is JsonArray) {
|
||||
listEl.asJsonObjectList()?.forEach { item ->
|
||||
listEl.asJsonObjectList().forEach { item ->
|
||||
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) {
|
||||
val listEl = element.getJsonObject("list")?.get("ArrayItem")
|
||||
if (listEl is JsonArray) {
|
||||
listEl.asJsonObjectList()?.let { list ->
|
||||
listEl.asJsonObjectList().let { list ->
|
||||
val label = element.getString("label") ?: ""
|
||||
list.forEach { item ->
|
||||
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.events.MessageSentEvent
|
||||
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.ext.base64Encode
|
||||
import pl.szczodrzynski.edziennik.ext.getJsonObject
|
||||
@ -42,14 +41,14 @@ class LibrusMessagesSendMessage(override val data: DataLibrus,
|
||||
val id = response.getLong("data")
|
||||
|
||||
if (response.getString("status") != "ok" || id == null) {
|
||||
val message = response.getString("message")
|
||||
// val message = response.getString("message")
|
||||
// TODO error
|
||||
return@messagesGetJson
|
||||
}
|
||||
|
||||
LibrusMessagesGetList(data, type = Message.TYPE_SENT, lastSync = null) {
|
||||
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)
|
||||
|
||||
EventBus.getDefault().postSticky(event)
|
||||
|
@ -42,7 +42,7 @@ class LibrusSynergiaHomework(override val data: DataLibrus,
|
||||
doc.select("table.myHomeworkTable > tbody").firstOrNull()?.also { homeworkTable ->
|
||||
val homeworkElements = homeworkTable.children()
|
||||
|
||||
homeworkElements.forEachIndexed { i, el ->
|
||||
homeworkElements.forEach { el ->
|
||||
val elements = el.children()
|
||||
|
||||
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 id = "/podglad/([0-9]+)'".toRegex().find(
|
||||
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 startTime = lessons.firstOrNull { it.subjectId == subjectId }?.startTime
|
||||
|
@ -63,7 +63,7 @@ class LibrusLoginApi {
|
||||
}
|
||||
|
||||
private fun copyFromLoginStore() {
|
||||
data.loginStore.data?.apply {
|
||||
data.loginStore.data.apply {
|
||||
if (has("accountLogin")) {
|
||||
data.apiLogin = getString("accountLogin")
|
||||
remove("accountLogin")
|
||||
|
@ -84,7 +84,7 @@ class LibrusLoginPortal(val data: DataLibrus, val onSuccess: () -> Unit) {
|
||||
} else {
|
||||
val csrfMatcher = Pattern.compile("name=\"csrf-token\" content=\"([A-z0-9=+/\\-_]+?)\"", Pattern.DOTALL).matcher(text)
|
||||
if (csrfMatcher.find()) {
|
||||
login(csrfMatcher.group(1))
|
||||
login(csrfMatcher.group(1) ?: "")
|
||||
} else {
|
||||
data.error(ApiError(TAG, ERROR_LOGIN_LIBRUS_PORTAL_CSRF_MISSING)
|
||||
.withResponse(response)
|
||||
|
@ -131,11 +131,11 @@ class MobidziennikWebAttendance(override val data: DataMobidziennik,
|
||||
// verify the lesson count is the same as dates & entries
|
||||
if (count != lessonDates.count() || count != entries.count())
|
||||
return@forEach
|
||||
ranges.forEach { range ->
|
||||
ranges.onEach { range ->
|
||||
val lessonDate = dateIterator.next()
|
||||
val entry = entriesIterator.next()
|
||||
if (range == null || entry.isBlank())
|
||||
return@forEach
|
||||
return@onEach
|
||||
val startTime = Time.fromH_m(range[1])
|
||||
|
||||
range[2].split(" / ").mapNotNull {
|
||||
@ -186,7 +186,7 @@ class MobidziennikWebAttendance(override val data: DataMobidziennik,
|
||||
if (entry.startsWith(symbol) && symbol.length > typeSymbol.length)
|
||||
typeSymbol = symbol
|
||||
}
|
||||
entry = entry.removePrefix(typeSymbol)
|
||||
// entry = entry.removePrefix(typeSymbol)
|
||||
|
||||
var isCustom = false
|
||||
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.utils.Utils.crc16
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import java.util.*
|
||||
|
||||
class MobidziennikWebCalendar(override val data: DataMobidziennik,
|
||||
override val lastSync: Long?,
|
||||
@ -30,7 +29,7 @@ class MobidziennikWebCalendar(override val data: DataMobidziennik,
|
||||
MobidziennikLuckyNumberExtractor(data, text)
|
||||
|
||||
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) {
|
||||
val event = eventEl.asJsonObject
|
||||
|
||||
@ -50,7 +49,7 @@ class MobidziennikWebCalendar(override val data: DataMobidziennik,
|
||||
val dateString = event.getString("start") ?: continue
|
||||
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
|
||||
"#ab0001" -> Event.TYPE_EXAM
|
||||
"#008928" -> Event.TYPE_CLASS_EVENT
|
||||
|
@ -26,7 +26,7 @@ class MobidziennikWebGetRecipientList(override val data: DataMobidziennik,
|
||||
init {
|
||||
webGet(TAG, "/mobile/dodajwiadomosc") { text ->
|
||||
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 ->
|
||||
val listType = list.getString("typ")?.toIntOrNull() ?: -1
|
||||
val listName = list.getString("nazwa") ?: ""
|
||||
|
@ -48,8 +48,8 @@ class MobidziennikWebHomework(override val data: DataMobidziennik,
|
||||
|
||||
event.attachmentIds = mutableListOf()
|
||||
event.attachmentNames = mutableListOf()
|
||||
Regexes.MOBIDZIENNIK_MOBILE_HOMEWORK_ATTACHMENT.findAll(tableRow).forEach {
|
||||
event.attachmentIds?.add(it[1].toLongOrNull() ?: return@forEach)
|
||||
Regexes.MOBIDZIENNIK_MOBILE_HOMEWORK_ATTACHMENT.findAll(tableRow).onEach {
|
||||
event.attachmentIds?.add(it[1].toLongOrNull() ?: return@onEach)
|
||||
event.attachmentNames?.add(it[2])
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ class PodlasieApiEvents(val data: DataPodlasie, val rows: List<JsonObject>) {
|
||||
val name = event.getString("Name")?.replace(""", "\"") ?: ""
|
||||
val description = event.getString("Description")?.replace(""", "\"") ?: ""
|
||||
|
||||
val type = when (event.getString("Category")?.toLowerCase(Locale.getDefault())) {
|
||||
val type = when (event.getString("Category")?.lowercase()) {
|
||||
"klasówka" -> Event.TYPE_EXAM
|
||||
"praca domowa" -> Event.TYPE_HOMEWORK
|
||||
"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.
|
||||
* 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) {
|
||||
val json = JsonObject()
|
||||
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.
|
||||
* 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) {
|
||||
val json = JsonObject()
|
||||
json.addProperty("foo", "bar")
|
||||
|
@ -20,7 +20,7 @@ class TemplateApiSample(override val data: DataTemplate,
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
// ================
|
||||
|
@ -21,7 +21,7 @@ class TemplateWebSample(override val data: DataTemplate,
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
// ================
|
||||
|
@ -20,7 +20,7 @@ class TemplateWebSample2(override val data: DataTemplate,
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
// ================
|
||||
|
@ -175,7 +175,7 @@ open class VulcanWebMain(open val data: DataVulcan, open val lastSync: Long?) {
|
||||
count++
|
||||
}
|
||||
schoolSymbols.removeAll {
|
||||
it.toLowerCase() == "default"
|
||||
it.lowercase() == "default"
|
||||
|| !it.matches(Regexes.VULCAN_WEB_SYMBOL_VALIDATE)
|
||||
}
|
||||
|
||||
@ -280,7 +280,7 @@ open class VulcanWebMain(open val data: DataVulcan, open val lastSync: Long?) {
|
||||
return
|
||||
|
||||
try {
|
||||
val json = JsonParser().parse(text).asJsonObject
|
||||
val json = JsonParser.parseString(text).asJsonObject
|
||||
onSuccess(json, response)
|
||||
} catch (e: Exception) {
|
||||
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.events.MessageSentEvent
|
||||
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.ext.*
|
||||
|
||||
@ -89,7 +88,7 @@ class VulcanHebeSendMessage(
|
||||
|
||||
VulcanHebeMessages(data, null) {
|
||||
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)
|
||||
|
||||
EventBus.getDefault().postSticky(event)
|
||||
|
@ -62,7 +62,7 @@ class VulcanWebLuckyNumber(override val data: DataVulcan,
|
||||
profile?.empty ?: false
|
||||
))
|
||||
}
|
||||
} ?: {
|
||||
} ?: run {
|
||||
// no lucky number
|
||||
if (Date.getToday().weekDay <= Week.FRIDAY && Time.getNow().hour >= 22) {
|
||||
// working days, after 10PM
|
||||
@ -77,7 +77,7 @@ class VulcanWebLuckyNumber(override val data: DataVulcan,
|
||||
// weekends
|
||||
nextSync = Week.getNearestWeekDayDate(Week.MONDAY).combineWith(Time(5, 0, 0))
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
data.setSyncNext(ENDPOINT_VULCAN_WEB_LUCKY_NUMBERS, SYNC_ALWAYS)
|
||||
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) {
|
||||
val json = JsonParser().parse(jsonStr).asJsonObject
|
||||
val json = JsonParser.parseString(jsonStr).asJsonObject
|
||||
val teams = app.db.teamDao().allNow
|
||||
// not used, as the server provides a sharing message
|
||||
//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)) {
|
||||
val notification = Notification(
|
||||
id = Notification.buildId(profile.id
|
||||
?: 0, Notification.TYPE_REMOVED_SHARED_EVENT, eventId),
|
||||
id = Notification.buildId(profile.id, Notification.TYPE_REMOVED_SHARED_EVENT, eventId),
|
||||
title = app.getNotificationTitle(Notification.TYPE_REMOVED_SHARED_EVENT),
|
||||
text = message,
|
||||
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")
|
||||
|
||||
/* 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
|
||||
"ocena" -> MainActivity.DRAWER_ITEM_GRADES 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
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <T : Any> Bundle?.get(key: String): T? {
|
||||
return this?.get(key) as? T?
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun Bundle(vararg properties: Pair<String, Any?>): Bundle {
|
||||
return Bundle().apply {
|
||||
for (property in properties) {
|
||||
|
@ -9,7 +9,7 @@ import android.os.Build
|
||||
import java.util.*
|
||||
|
||||
fun Context.setLanguage(language: String) {
|
||||
val locale = Locale(language.toLowerCase(Locale.ROOT))
|
||||
val locale = Locale(language.lowercase())
|
||||
val configuration = resources.configuration
|
||||
Locale.setDefault(locale)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
@ -18,40 +18,3 @@ fun Context.setLanguage(language: String) {
|
||||
configuration.locale = locale
|
||||
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
|
||||
for (aBuffer in this) {
|
||||
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 shl 12 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.PorterDuffColorFilter
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Build
|
||||
import android.util.TypedValue
|
||||
import androidx.annotation.AttrRes
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.ColorRes
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
|
||||
fun colorFromName(name: String?): Int {
|
||||
val i = (name ?: "").crc32()
|
||||
@ -60,20 +60,10 @@ fun @receiver:AttrRes Int.resolveAttr(context: Context?): Int {
|
||||
}
|
||||
@ColorInt
|
||||
fun @receiver:ColorRes Int.resolveColor(context: Context): Int {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
context.resources.getColor(this, context.theme)
|
||||
}
|
||||
else {
|
||||
context.resources.getColor(this)
|
||||
}
|
||||
return ResourcesCompat.getColor(context.resources, this, context.theme)
|
||||
}
|
||||
fun @receiver:DrawableRes Int.resolveDrawable(context: Context): Drawable {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
context.resources.getDrawable(this, context.theme)
|
||||
}
|
||||
else {
|
||||
context.resources.getDrawable(this)
|
||||
}
|
||||
return ResourcesCompat.getDrawable(context.resources, this, context.theme)!!
|
||||
}
|
||||
|
||||
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?.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?.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?.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?.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?.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?.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.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.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.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: 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.isEmpty(): Boolean = this.size() == 0
|
||||
operator fun JsonArray.plusAssign(o: JsonElement) = this.add(o)
|
||||
operator fun JsonArray.plusAssign(o: String) = this.add(o)
|
||||
operator fun JsonArray.plusAssign(o: Char) = this.add(o)
|
||||
|
@ -112,7 +112,7 @@ fun String.getShortName(): String {
|
||||
*/
|
||||
fun String?.getNameInitials(): String {
|
||||
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 {
|
||||
@ -230,7 +230,7 @@ val String.firstLettersName: String
|
||||
this.split(" ").forEach {
|
||||
if (it.isBlank())
|
||||
return@forEach
|
||||
nameShort += it[0].toLowerCase()
|
||||
nameShort += it[0].lowercase()
|
||||
}
|
||||
return nameShort
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ fun Response?.getUnixDate(): Long {
|
||||
val rfcDate = this?.headers()?.get("date") ?: return currentTimeUnix()
|
||||
val pattern = "EEE, dd MMM yyyy HH:mm:ss Z"
|
||||
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)
|
||||
@ -61,7 +61,6 @@ fun Context.timeTill(time: Int, delimiter: String = " ", countInSeconds: Boolean
|
||||
}
|
||||
if (hours == 0 && minutes < 10) {
|
||||
if (!prefixAdded) parts += R.plurals.time_till_text to seconds
|
||||
prefixAdded = true
|
||||
parts += R.plurals.time_till_seconds to seconds
|
||||
}
|
||||
} else {
|
||||
@ -93,7 +92,6 @@ fun Context.timeLeft(time: Int, delimiter: String = " ", countInSeconds: Boolean
|
||||
}
|
||||
if (hours == 0 && minutes < 10) {
|
||||
if (!prefixAdded) parts += R.plurals.time_left_text to seconds
|
||||
prefixAdded = true
|
||||
parts += R.plurals.time_left_seconds to seconds
|
||||
}
|
||||
} else {
|
||||
|
@ -69,7 +69,7 @@ class AttendanceBar : View {
|
||||
override fun onDraw(canvas: Canvas?) {
|
||||
canvas ?: return
|
||||
|
||||
val sum = attendancesList.sumBy { it.count }
|
||||
val sum = attendancesList.sumOf { it.count }
|
||||
if (sum == 0) {
|
||||
return
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ class AttendanceFragment : Fragment(), CoroutineScope {
|
||||
pageSelection = app.config.forProfile().attendance.attendancePageSelection
|
||||
|
||||
val pagerAdapter = FragmentLazyPagerAdapter(
|
||||
fragmentManager ?: return,
|
||||
parentFragmentManager,
|
||||
b.refreshLayout,
|
||||
listOf(
|
||||
AttendanceSummaryFragment() to getString(R.string.attendance_tab_summary),
|
||||
|
@ -179,12 +179,12 @@ class AttendanceListFragment : LazyFragment(), CoroutineScope {
|
||||
.sortedBy { it.first }
|
||||
.toMap()
|
||||
|
||||
val totalCount = month.typeCountMap.entries.sumBy {
|
||||
val totalCount = month.typeCountMap.entries.sumOf {
|
||||
if (!it.key.isCounted || it.key.baseType == Attendance.TYPE_UNKNOWN)
|
||||
0
|
||||
else it.value
|
||||
}
|
||||
val presenceCount = month.typeCountMap.entries.sumBy {
|
||||
val presenceCount = month.typeCountMap.entries.sumOf {
|
||||
when (it.key.baseType) {
|
||||
Attendance.TYPE_PRESENT,
|
||||
Attendance.TYPE_PRESENT_CUSTOM,
|
||||
|
@ -181,7 +181,7 @@ class AttendanceSummaryFragment : LazyFragment(), CoroutineScope {
|
||||
subjectName = it.value.firstOrNull()?.subjectLongName ?: "",
|
||||
items = it.value.toMutableList()
|
||||
) }
|
||||
.sortedBy { it.subjectName.toLowerCase() }
|
||||
.sortedBy { it.subjectName.lowercase() }
|
||||
|
||||
var totalCountSum = 0
|
||||
var presenceCountSum = 0
|
||||
@ -193,12 +193,12 @@ class AttendanceSummaryFragment : LazyFragment(), CoroutineScope {
|
||||
.sortedBy { it.first }
|
||||
.toMap()
|
||||
|
||||
val totalCount = subject.typeCountMap.entries.sumBy {
|
||||
val totalCount = subject.typeCountMap.entries.sumOf {
|
||||
if (!it.key.isCounted || it.key.baseType == Attendance.TYPE_UNKNOWN)
|
||||
0
|
||||
else it.value
|
||||
}
|
||||
val presenceCount = subject.typeCountMap.entries.sumBy {
|
||||
val presenceCount = subject.typeCountMap.entries.sumOf {
|
||||
when (it.key.baseType) {
|
||||
Attendance.TYPE_PRESENT,
|
||||
Attendance.TYPE_PRESENT_CUSTOM,
|
||||
|
@ -7,7 +7,6 @@ package pl.szczodrzynski.edziennik.ui.attendance.viewholder
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.view.ContextThemeWrapper
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
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.grades.models.ExpandableItemModel
|
||||
import pl.szczodrzynski.edziennik.ui.grades.viewholder.BindableViewHolder
|
||||
import pl.szczodrzynski.edziennik.utils.Themes
|
||||
import pl.szczodrzynski.edziennik.utils.models.Week
|
||||
|
||||
class AttendanceViewHolder(
|
||||
@ -34,7 +32,6 @@ class AttendanceViewHolder(
|
||||
|
||||
override fun onBind(activity: AppCompatActivity, app: App, item: AttendanceFull, position: Int, adapter: AttendanceAdapter) {
|
||||
val manager = app.attendanceManager
|
||||
val contextWrapper = ContextThemeWrapper(activity, Themes.appTheme)
|
||||
|
||||
val bullet = " • "
|
||||
|
||||
|
@ -62,7 +62,6 @@ class MonthViewHolder(
|
||||
|
||||
b.previewContainer.removeAllViews()
|
||||
|
||||
val sum = item.typeCountMap.entries.sumBy { it.value }.toFloat()
|
||||
item.typeCountMap.forEach { (type, count) ->
|
||||
val layout = LinearLayout(contextWrapper)
|
||||
val attendance = Attendance(
|
||||
|
@ -7,7 +7,6 @@ package pl.szczodrzynski.edziennik.ui.attendance.viewholder
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.view.ContextThemeWrapper
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
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.models.AttendanceSubject
|
||||
import pl.szczodrzynski.edziennik.ui.grades.viewholder.BindableViewHolder
|
||||
import pl.szczodrzynski.edziennik.utils.Themes
|
||||
|
||||
class SubjectViewHolder(
|
||||
inflater: LayoutInflater,
|
||||
@ -31,7 +29,6 @@ class SubjectViewHolder(
|
||||
|
||||
override fun onBind(activity: AppCompatActivity, app: App, item: AttendanceSubject, position: Int, adapter: AttendanceAdapter) {
|
||||
val manager = app.attendanceManager
|
||||
val contextWrapper = ContextThemeWrapper(activity, Themes.appTheme)
|
||||
|
||||
b.title.text = item.subjectName
|
||||
|
||||
|
@ -7,7 +7,6 @@ package pl.szczodrzynski.edziennik.ui.attendance.viewholder
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.view.ContextThemeWrapper
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
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.models.AttendanceTypeGroup
|
||||
import pl.szczodrzynski.edziennik.ui.grades.viewholder.BindableViewHolder
|
||||
import pl.szczodrzynski.edziennik.utils.Themes
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
|
||||
class TypeViewHolder(
|
||||
@ -32,7 +30,6 @@ class TypeViewHolder(
|
||||
|
||||
override fun onBind(activity: AppCompatActivity, app: App, item: AttendanceTypeGroup, position: Int, adapter: AttendanceAdapter) {
|
||||
val manager = app.attendanceManager
|
||||
val contextWrapper = ContextThemeWrapper(activity, Themes.appTheme)
|
||||
|
||||
val type = item.type
|
||||
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.request.ErrorReportRequest
|
||||
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.html.BetterHtml
|
||||
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()
|
||||
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("\n".toRegex(), "<br>")
|
||||
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 += BuildConfig.VERSION_NAME + " " + BuildConfig.BUILD_TYPE
|
||||
|
@ -49,7 +49,7 @@ class LabFragment : Fragment(), CoroutineScope {
|
||||
if (!isAdded) return
|
||||
|
||||
val pagerAdapter = FragmentLazyPagerAdapter(
|
||||
fragmentManager ?: return,
|
||||
parentFragmentManager,
|
||||
b.refreshLayout,
|
||||
listOf(
|
||||
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.studentData", app.profile.studentData)
|
||||
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.notifyDataSetChanged()
|
||||
|
@ -8,7 +8,6 @@ import android.annotation.SuppressLint
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.view.ContextThemeWrapper
|
||||
import androidx.core.view.isInvisible
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
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.models.LabJsonArray
|
||||
import pl.szczodrzynski.edziennik.ui.grades.viewholder.BindableViewHolder
|
||||
import pl.szczodrzynski.edziennik.utils.Themes
|
||||
|
||||
class JsonArrayViewHolder(
|
||||
inflater: LayoutInflater,
|
||||
@ -31,8 +29,6 @@ class JsonArrayViewHolder(
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
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.type.text = "Array"
|
||||
|
@ -8,7 +8,6 @@ import android.annotation.SuppressLint
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.view.ContextThemeWrapper
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.gson.JsonNull
|
||||
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.models.LabJsonElement
|
||||
import pl.szczodrzynski.edziennik.ui.grades.viewholder.BindableViewHolder
|
||||
import pl.szczodrzynski.edziennik.utils.Themes
|
||||
|
||||
class JsonElementViewHolder(
|
||||
inflater: LayoutInflater,
|
||||
@ -31,8 +29,6 @@ class JsonElementViewHolder(
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
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.type.text = when (item.jsonElement) {
|
||||
|
@ -8,7 +8,6 @@ import android.annotation.SuppressLint
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.view.ContextThemeWrapper
|
||||
import androidx.core.view.isInvisible
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
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.models.LabJsonObject
|
||||
import pl.szczodrzynski.edziennik.ui.grades.viewholder.BindableViewHolder
|
||||
import pl.szczodrzynski.edziennik.utils.Themes
|
||||
|
||||
class JsonObjectViewHolder(
|
||||
inflater: LayoutInflater,
|
||||
@ -31,8 +29,6 @@ class JsonObjectViewHolder(
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
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.type.text = "Object"
|
||||
|
@ -8,7 +8,6 @@ import android.annotation.SuppressLint
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.view.ContextThemeWrapper
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
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.models.LabJsonObject
|
||||
import pl.szczodrzynski.edziennik.ui.grades.viewholder.BindableViewHolder
|
||||
import pl.szczodrzynski.edziennik.utils.Themes
|
||||
|
||||
class JsonSubObjectViewHolder(
|
||||
inflater: LayoutInflater,
|
||||
@ -30,8 +28,6 @@ class JsonSubObjectViewHolder(
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
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.type.text = "Object"
|
||||
|
@ -15,6 +15,7 @@ import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.MainActivity
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.databinding.DialogBellSyncBinding
|
||||
import pl.szczodrzynski.edziennik.ext.resolveDrawable
|
||||
import pl.szczodrzynski.edziennik.ext.startCoroutineTimer
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
@ -86,7 +87,7 @@ class BellSyncDialog(
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -115,7 +115,7 @@ class GradesConfigDialog(
|
||||
b.dontCountGradesText
|
||||
.text
|
||||
?.toString()
|
||||
?.toLowerCase(Locale.getDefault())
|
||||
?.lowercase()
|
||||
?.replace(", ", ",")
|
||||
)
|
||||
profileConfig.dontCountEnabled = b.dontCountGrades.isChecked
|
||||
|
@ -109,7 +109,7 @@ class GradesEditorFragment : Fragment() {
|
||||
continue
|
||||
}
|
||||
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
|
||||
}
|
||||
val value = editorGrade.value * weight
|
||||
@ -174,7 +174,7 @@ class GradesEditorFragment : Fragment() {
|
||||
averageSemester = 0f
|
||||
for (editorGrade in editorGrades) {
|
||||
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
|
||||
}
|
||||
val value = editorGrade.value * weight
|
||||
@ -216,7 +216,7 @@ class GradesEditorFragment : Fragment() {
|
||||
continue
|
||||
}
|
||||
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
|
||||
}
|
||||
val value = grade.value * weight
|
||||
|
@ -138,8 +138,6 @@ class HomeFragment : Fragment(), CoroutineScope {
|
||||
b.refreshLayout.isEnabled = scrollY == 0
|
||||
}
|
||||
|
||||
val showUnified = false
|
||||
|
||||
val cards = app.config.forProfile().ui.homeCards.filter { it.profileId == app.profile.id }.toMutableList()
|
||||
if (cards.isEmpty()) {
|
||||
cards += listOf(
|
||||
|
@ -63,7 +63,7 @@ class HomeLuckyNumberCard(
|
||||
R.string.home_lucky_number_details_click_to_set
|
||||
else
|
||||
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 ->
|
||||
val isYours = luckyNumber?.number == profile.studentNumber
|
||||
@ -104,7 +104,7 @@ class HomeLuckyNumberCard(
|
||||
R.string.home_lucky_number_details_click_to_set
|
||||
else
|
||||
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(
|
||||
fragmentManager ?: return,
|
||||
parentFragmentManager,
|
||||
b.refreshLayout,
|
||||
listOf(
|
||||
HomeworkListFragment().apply {
|
||||
|
@ -175,9 +175,9 @@ class LoginFormFragment : Fragment(), CoroutineScope {
|
||||
text = text.trim()
|
||||
|
||||
if (credential.caseMode == LoginInfo.FormField.CaseMode.UPPER_CASE)
|
||||
text = text.toUpperCase(Locale.getDefault())
|
||||
text = text.uppercase()
|
||||
if (credential.caseMode == LoginInfo.FormField.CaseMode.LOWER_CASE)
|
||||
text = text.toLowerCase(Locale.getDefault())
|
||||
text = text.lowercase()
|
||||
|
||||
credential.stripTextRegex?.let {
|
||||
text = text.replace(it.toRegex(), "")
|
||||
|
@ -52,7 +52,7 @@ class TemplateFragment : Fragment(), CoroutineScope {
|
||||
if (!isAdded) return
|
||||
|
||||
val pagerAdapter = FragmentLazyPagerAdapter(
|
||||
fragmentManager ?: return,
|
||||
parentFragmentManager,
|
||||
b.refreshLayout,
|
||||
listOf(
|
||||
HomeworkListFragment().apply {
|
||||
|
@ -127,7 +127,7 @@ class TimetableFragment : Fragment(), CoroutineScope {
|
||||
return@launch
|
||||
|
||||
val pagerAdapter = TimetablePagerAdapter(
|
||||
fragmentManager ?: return@launch,
|
||||
parentFragmentManager,
|
||||
items,
|
||||
startHour,
|
||||
endHour
|
||||
|
@ -161,7 +161,7 @@ class AttachmentsView @JvmOverloads constructor(
|
||||
// get the download url before updating file name
|
||||
val fileUrl = attachment.name.substringAfter(":", missingDelimiterValue = "")
|
||||
// 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
|
||||
if (fileUrl != "")
|
||||
attachment.name += ":$fileUrl"
|
||||
|
@ -56,7 +56,6 @@ class DateDropdown : TextInputDropDown {
|
||||
|
||||
suspend fun loadItems() {
|
||||
val date = Date.getToday()
|
||||
val today = date.value
|
||||
var weekDay = date.weekDay
|
||||
|
||||
val dates = withContext(Dispatchers.Default) {
|
||||
|
@ -63,14 +63,14 @@ class WebPushFragment : Fragment(), CoroutineScope {
|
||||
b.scanQrCode.onClick {
|
||||
manager.requestCameraPermission(activity, R.string.permissions_qr_scanner) {
|
||||
QrScannerDialog(activity, {
|
||||
b.tokenEditText.setText(it.crc32().toString(36).toUpperCase())
|
||||
b.tokenEditText.setText(it.crc32().toString(36).uppercase())
|
||||
pairBrowser(browserId = it)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
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)) {
|
||||
b.tokenLayout.error = app.getString(R.string.web_push_token_invalid)
|
||||
return@onClick
|
||||
|
@ -42,10 +42,7 @@ class WidgetLuckyNumberProvider : AppWidgetProvider() {
|
||||
val views = getRemoteViews(app, config)
|
||||
|
||||
val today = Date.getToday()
|
||||
val todayValue = today.value
|
||||
|
||||
val tomorrow = Date.getToday().stepForward(0, 0, 1)
|
||||
val tomorrowValue = tomorrow.value
|
||||
|
||||
val profile = app.db.profileDao().getByIdNow(config.profileId)
|
||||
val luckyNumber = app.db.luckyNumberDao().getNearestFutureNow(config.profileId, today)
|
||||
|
@ -56,7 +56,7 @@ class WidgetNotificationsFactory(val app: App, val config: WidgetConfig) : Remot
|
||||
getString("profileName"),
|
||||
getInt("posted") == 1,
|
||||
getInt("viewId"),
|
||||
getString("extras")?.let { JsonParser().parse(it).asJsonObject },
|
||||
getString("extras")?.let { JsonParser.parseString(it).asJsonObject },
|
||||
getLong("addedDate") ?: System.currentTimeMillis()
|
||||
)
|
||||
} ?: return views
|
||||
|
@ -120,7 +120,7 @@ class GradesManager(val app: App) : CoroutineScope {
|
||||
fun getGradeWeight(dontCountEnabled: Boolean, dontCountGrades: List<String>, grade: Grade): Float {
|
||||
if (!dontCountEnabled)
|
||||
return grade.weight
|
||||
if (grade.name.toLowerCase().trim() in dontCountGrades)
|
||||
if (grade.name.lowercase().trim() in dontCountGrades)
|
||||
return 0f
|
||||
return grade.weight
|
||||
}
|
||||
@ -153,7 +153,7 @@ class GradesManager(val app: App) : CoroutineScope {
|
||||
}
|
||||
type == TYPE_NORMAL && defColor -> grade.color and 0xffffff
|
||||
type in TYPE_NORMAL..TYPE_YEAR_FINAL -> {
|
||||
when (grade.name.toLowerCase()) {
|
||||
when (grade.name.lowercase()) {
|
||||
"+", "++", "+++" -> 0x4caf50
|
||||
"0", "-", "-,", "-,-,", "np", "np.", "npnp", "np,", "np,np,", "bs", "nk", "bz" -> 0xff7043
|
||||
"1-", "1", "f", "ng" -> 0xff0000
|
||||
@ -181,7 +181,7 @@ class GradesManager(val app: App) : CoroutineScope {
|
||||
* the specified [name].
|
||||
*/
|
||||
fun getGradeValue(name: String): Float {
|
||||
return when (name.toLowerCase()) {
|
||||
return when (name.lowercase()) {
|
||||
"1-" -> 0.75f
|
||||
"1" -> 1.00f
|
||||
"1+" -> 1.50f
|
||||
@ -211,7 +211,7 @@ class GradesManager(val app: App) : CoroutineScope {
|
||||
}
|
||||
|
||||
fun getGradeNumberName(name: String): String {
|
||||
return when(name.toLowerCase()){
|
||||
return when(name.lowercase()){
|
||||
"niedostateczny", "f" -> "1"
|
||||
"niedostateczny plus", "f+" -> "1+"
|
||||
"niedostateczny minus", "f-" -> "1-"
|
||||
|
Loading…
x
Reference in New Issue
Block a user