mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-18 12:56:45 -06:00
[APIv2] Add Grades. Update Firebase push receivers.
This commit is contained in:
parent
7b3e2a9ea0
commit
ed8ca00a85
@ -204,6 +204,14 @@
|
||||
<action android:name="com.google.firebase.MESSAGING_EVENT" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
<receiver
|
||||
android:name=".sync.FirebaseBroadcastReceiver"
|
||||
android:exported="true"
|
||||
android:permission="com.google.android.c2dm.permission.SEND">
|
||||
<intent-filter>
|
||||
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<service
|
||||
android:name=".widgets.timetable.WidgetTimetableService"
|
||||
android:permission="android.permission.BIND_REMOTEVIEWS" />
|
||||
|
@ -86,6 +86,7 @@ import pl.szczodrzynski.edziennik.utils.PermissionChecker;
|
||||
import pl.szczodrzynski.edziennik.utils.Themes;
|
||||
import pl.szczodrzynski.edziennik.utils.Utils;
|
||||
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore.LOGIN_TYPE_LIBRUS;
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore.LOGIN_TYPE_MOBIDZIENNIK;
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore.LOGIN_TYPE_VULCAN;
|
||||
|
||||
@ -409,20 +410,20 @@ public class App extends androidx.multidex.MultiDexApplication {
|
||||
FirebaseApp pushMobidziennikApp = FirebaseApp.initializeApp(
|
||||
this,
|
||||
new FirebaseOptions.Builder()
|
||||
.setApplicationId("1:1029629079999:android:58bb378dab031f42")
|
||||
.setGcmSenderId("1029629079999")
|
||||
.setApiKey("AIzaSyCi5LmsZ5BBCQnGtrdvWnp1bWLCNP8OWQE")
|
||||
.setApplicationId("1:747285019373:android:f6341bf7b158621d")
|
||||
.build(),
|
||||
"Mobidziennik"
|
||||
"Mobidziennik2"
|
||||
);
|
||||
|
||||
/*FirebaseApp pushLibrusApp = FirebaseApp.initializeApp(
|
||||
FirebaseApp pushLibrusApp = FirebaseApp.initializeApp(
|
||||
this,
|
||||
new FirebaseOptions.Builder()
|
||||
.setApiKey("AIzaSyDfTuEoYPKdv4aceEws1CO3n0-HvTndz-o")
|
||||
.setApplicationId("1:513056078587:android:1e29083b760af544")
|
||||
.build(),
|
||||
"Librus"
|
||||
);*/
|
||||
);
|
||||
|
||||
FirebaseApp pushVulcanApp = FirebaseApp.initializeApp(
|
||||
this,
|
||||
@ -443,10 +444,10 @@ public class App extends androidx.multidex.MultiDexApplication {
|
||||
Log.d(TAG, "Token for Mobidziennik is " + instanceIdResult.getToken() + ", ID is " + instanceIdResult.getId());
|
||||
appConfig.fcmTokens.put(LOGIN_TYPE_MOBIDZIENNIK, new Pair<>(instanceIdResult.getToken(), new ArrayList<>()));
|
||||
});
|
||||
/*FirebaseInstanceId.getInstance(pushLibrusApp).getInstanceId().addOnSuccessListener(instanceIdResult -> {
|
||||
FirebaseInstanceId.getInstance(pushLibrusApp).getInstanceId().addOnSuccessListener(instanceIdResult -> {
|
||||
Log.d(TAG, "Token for Librus is " + instanceIdResult.getToken() + ", ID is " + instanceIdResult.getId());
|
||||
appConfig.fcmTokens.put(LOGIN_TYPE_LIBRUS, new Pair<>(instanceIdResult.getToken(), new ArrayList<>()));
|
||||
});*/
|
||||
});
|
||||
FirebaseInstanceId.getInstance(pushVulcanApp).getInstanceId().addOnSuccessListener(instanceIdResult -> {
|
||||
Log.d(TAG, "Token for Vulcan is " + instanceIdResult.getToken() + ", ID is " + instanceIdResult.getId());
|
||||
Pair<String, List<Integer>> pair = appConfig.fcmTokens.get(LOGIN_TYPE_VULCAN);
|
||||
|
@ -218,4 +218,10 @@ fun LongSparseArray<Team>.getById(id: Long): Team? {
|
||||
return value
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
operator fun MatchResult.get(group: Int): String {
|
||||
if (group >= groupValues.size)
|
||||
return ""
|
||||
return groupValues[group]
|
||||
}
|
@ -37,6 +37,7 @@ const val FEATURE_LUCKY_NUMBER = 105
|
||||
const val FEATURE_TEACHERS = 106
|
||||
const val FEATURE_SUBJECTS = 107
|
||||
const val FEATURE_CLASSROOMS = 108
|
||||
const val FEATURE_PUSH_CONFIG = 120
|
||||
|
||||
const val FEATURE_MESSAGE_GET = 201
|
||||
|
||||
|
@ -83,7 +83,11 @@ const val LOGIN_METHOD_MOBIDZIENNIK_API2 = 300
|
||||
val mobidziennikLoginMethods = listOf(
|
||||
LoginMethod(LOGIN_TYPE_MOBIDZIENNIK, LOGIN_METHOD_MOBIDZIENNIK_WEB, MobidziennikLoginWeb::class.java)
|
||||
.withIsPossible { _, _ -> true }
|
||||
.withRequiredLoginMethod { _, _ -> LOGIN_METHOD_NOT_NEEDED }
|
||||
.withRequiredLoginMethod { _, _ -> LOGIN_METHOD_NOT_NEEDED }/*,
|
||||
|
||||
LoginMethod(LOGIN_TYPE_MOBIDZIENNIK, LOGIN_METHOD_MOBIDZIENNIK_API2, MobidziennikLoginApi2::class.java)
|
||||
.withIsPossible { _, loginStore -> loginStore.hasLoginData("email") }
|
||||
.withRequiredLoginMethod { _, _ -> LOGIN_METHOD_NOT_NEEDED }*/
|
||||
)
|
||||
|
||||
const val LOGIN_TYPE_VULCAN = 4
|
||||
|
@ -6,15 +6,34 @@ package pl.szczodrzynski.edziennik.api.v2
|
||||
|
||||
object Regexes {
|
||||
val MOBIDZIENNIK_GRADES_SUBJECT_NAME by lazy {
|
||||
"<div.*?>\\n*\\s*(.+?)\\s*\\n*(?:<.*?)??</div>".toRegex(RegexOption.DOT_MATCHES_ALL)
|
||||
"""<div.*?>\n*\s*(.+?)\s*\n*(?:<.*?)??</div>""".toRegex(RegexOption.DOT_MATCHES_ALL)
|
||||
}
|
||||
val MOBIDZIENNIK_GRADES_COLOR by lazy {
|
||||
"""background-color:([#A-Fa-f0-9]+);""".toRegex(RegexOption.DOT_MATCHES_ALL)
|
||||
}
|
||||
val MOBIDZIENNIK_GRADES_CATEGORY by lazy {
|
||||
"""> (.+?):</span>""".toRegex(RegexOption.DOT_MATCHES_ALL)
|
||||
}
|
||||
val MOBIDZIENNIK_GRADES_CLASS_AVERAGE by lazy {
|
||||
"""Średnia ocen:.*<strong>([0-9]*\.?[0-9]*)</strong>""".toRegex(RegexOption.DOT_MATCHES_ALL)
|
||||
}
|
||||
val MOBIDZIENNIK_GRADES_ADDED_DATE by lazy {
|
||||
"""Wpisano:.*<strong>.+?,\s([0-9]+)\s(.+?)\s([0-9]{4}),\sgodzina\s([0-9:]+)</strong>""".toRegex(RegexOption.DOT_MATCHES_ALL)
|
||||
}
|
||||
val MOBIDZIENNIK_GRADES_COUNT_TO_AVG by lazy {
|
||||
"""Liczona do średniej:.*?<strong>nie<br/?></strong>""".toRegex(RegexOption.DOT_MATCHES_ALL)
|
||||
}
|
||||
val MOBIDZIENNIK_GRADES_DETAILS by lazy {
|
||||
"""<strong.*?>(.+?)</strong>.*?<sup>.+?</sup>.*?<small>\((.+?)\)</small>.*?<span>.*?Wartość oceny:.*?<strong>([0-9.]+)</strong>.*?Wpisał\(a\):.*?<strong>(.+?)</strong>""".toRegex(RegexOption.DOT_MATCHES_ALL)
|
||||
}
|
||||
|
||||
val MOBIDZIENNIK_EVENT_TYPE by lazy {
|
||||
"\\(([0-9A-ząęóżźńśłć]*?)\\)$".toRegex(RegexOption.DOT_MATCHES_ALL)
|
||||
"""\(([0-9A-ząęóżźńśłć]*?)\)$""".toRegex(RegexOption.DOT_MATCHES_ALL)
|
||||
}
|
||||
val MOBIDZIENNIK_LUCKY_NUMBER by lazy {
|
||||
"class=\"szczesliwy_numerek\".*>0*([0-9]+)(?:/0*[0-9]+)*</a>".toRegex(RegexOption.DOT_MATCHES_ALL)
|
||||
"""class="szczesliwy_numerek".*>0*([0-9]+)(?:/0*[0-9]+)*</a>""".toRegex(RegexOption.DOT_MATCHES_ALL)
|
||||
}
|
||||
val MOBIDZIENNIK_CLASS_CALENDAR by lazy {
|
||||
"events: (.+),$".toRegex(RegexOption.DOT_MATCHES_ALL)
|
||||
"""events: (.+),$""".toRegex(RegexOption.MULTILINE)
|
||||
}
|
||||
}
|
||||
|
@ -77,8 +77,7 @@ open class LibrusApi(open val data: DataLibrus) {
|
||||
data.error(ApiError(tag, EXCEPTION_LIBRUS_API_REQUEST)
|
||||
.withResponse(response)
|
||||
.withThrowable(e)
|
||||
.withApiResponse(json)
|
||||
.setCritical(false))
|
||||
.withApiResponse(json))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ package pl.szczodrzynski.edziennik.api.v2.mobidziennik
|
||||
import android.util.LongSparseArray
|
||||
import android.util.SparseArray
|
||||
import android.util.SparseIntArray
|
||||
import androidx.core.util.isNotEmpty
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.api.v2.LOGIN_METHOD_MOBIDZIENNIK_WEB
|
||||
import pl.szczodrzynski.edziennik.api.v2.models.Data
|
||||
@ -34,15 +35,20 @@ class DataMobidziennik(app: App, profile: Profile?, loginStore: LoginStore) : Da
|
||||
val teachersMap = LongSparseArray<String>()
|
||||
val subjectsMap = LongSparseArray<String>()
|
||||
|
||||
val gradeAddedDates = SparseArray<Long>()
|
||||
val gradeAverages = SparseArray<Float>()
|
||||
val gradeColors = SparseIntArray()
|
||||
val gradeAddedDates = LongSparseArray<Long>()
|
||||
val gradeAverages = LongSparseArray<Float>()
|
||||
val gradeColors = LongSparseArray<Int>()
|
||||
|
||||
private var mLoginServerName: String? = null
|
||||
var loginServerName: String?
|
||||
get() { mLoginServerName = mLoginServerName ?: loginStore.getLoginData("serverName", null); return mLoginServerName }
|
||||
set(value) { loginStore.putLoginData("serverName", value); mLoginServerName = value }
|
||||
|
||||
private var mLoginEmail: String? = null
|
||||
var loginEmail: String?
|
||||
get() { mLoginEmail = mLoginEmail ?: loginStore.getLoginData("email", null); return mLoginEmail }
|
||||
set(value) { loginStore.putLoginData("email", value); mLoginEmail = value }
|
||||
|
||||
private var mLoginUsername: String? = null
|
||||
var loginUsername: String?
|
||||
get() { mLoginUsername = mLoginUsername ?: loginStore.getLoginData("username", null); return mLoginUsername }
|
||||
@ -85,6 +91,13 @@ class DataMobidziennik(app: App, profile: Profile?, loginStore: LoginStore) : Da
|
||||
set(value) { loginStore.putLoginData("sessionIDTime", value); mWebSessionIdExpiryTime = value }
|
||||
|
||||
|
||||
override fun saveData() {
|
||||
super.saveData()
|
||||
if (gradeAddedDates.isNotEmpty()) {
|
||||
app.db.gradeDao().updateDetails(profileId, gradeAverages, gradeAddedDates, gradeColors)
|
||||
}
|
||||
}
|
||||
|
||||
val mobiLessons = mutableListOf<MobiLesson>()
|
||||
|
||||
data class MobiLesson(
|
||||
|
@ -7,7 +7,7 @@ package pl.szczodrzynski.edziennik.api.v2.mobidziennik
|
||||
import pl.szczodrzynski.edziennik.api.v2.*
|
||||
import pl.szczodrzynski.edziennik.api.v2.models.Feature
|
||||
|
||||
const val ENDPOINT_MOBIDZIENNIK_API_MAIN = 1000
|
||||
const val ENDPOINT_MOBIDZIENNIK_API_MAIN = 1000
|
||||
const val ENDPOINT_MOBIDZIENNIK_WEB_MESSAGES_INBOX = 2011
|
||||
const val ENDPOINT_MOBIDZIENNIK_WEB_MESSAGES_SENT = 2012
|
||||
const val ENDPOINT_MOBIDZIENNIK_WEB_MESSAGES_ALL = 2019
|
||||
@ -16,7 +16,8 @@ const val ENDPOINT_MOBIDZIENNIK_WEB_GRADES = 2030
|
||||
const val ENDPOINT_MOBIDZIENNIK_WEB_NOTICES = 2040
|
||||
const val ENDPOINT_MOBIDZIENNIK_WEB_ATTENDANCE = 2050
|
||||
const val ENDPOINT_MOBIDZIENNIK_WEB_MANUALS = 2100
|
||||
const val ENDPOINT_MOBIDZIENNIK_API2 = 3000
|
||||
const val ENDPOINT_MOBIDZIENNIK_WEB_ACCOUNT_EMAIL = 2200
|
||||
const val ENDPOINT_MOBIDZIENNIK_API2_MAIN = 3000
|
||||
|
||||
val MobidziennikFeatures = listOf(
|
||||
// timetable
|
||||
@ -55,8 +56,13 @@ val MobidziennikFeatures = listOf(
|
||||
), listOf(LOGIN_METHOD_MOBIDZIENNIK_WEB)),
|
||||
|
||||
Feature(LOGIN_TYPE_MOBIDZIENNIK, FEATURE_ALWAYS_NEEDED, listOf(
|
||||
ENDPOINT_MOBIDZIENNIK_API_MAIN to LOGIN_METHOD_MOBIDZIENNIK_WEB
|
||||
ENDPOINT_MOBIDZIENNIK_API_MAIN to LOGIN_METHOD_MOBIDZIENNIK_WEB,
|
||||
ENDPOINT_MOBIDZIENNIK_WEB_ACCOUNT_EMAIL to LOGIN_METHOD_MOBIDZIENNIK_WEB
|
||||
), listOf(LOGIN_METHOD_MOBIDZIENNIK_WEB)),
|
||||
|
||||
Feature(LOGIN_TYPE_MOBIDZIENNIK, FEATURE_PUSH_CONFIG, listOf(
|
||||
ENDPOINT_MOBIDZIENNIK_API2_MAIN to LOGIN_METHOD_MOBIDZIENNIK_API2
|
||||
), listOf(LOGIN_METHOD_MOBIDZIENNIK_API2)),
|
||||
/*Feature(LOGIN_TYPE_MOBIDZIENNIK, FEATURE_STUDENT_INFO, listOf(
|
||||
ENDPOINT_MOBIDZIENNIK_API_MAIN to LOGIN_METHOD_MOBIDZIENNIK_WEB
|
||||
), listOf(LOGIN_METHOD_MOBIDZIENNIK_WEB)),
|
||||
|
@ -8,6 +8,7 @@ import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.*
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.data.web.MobidziennikApi
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.data.web.MobidziennikWebCalendar
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.data.web.MobidziennikWebGrades
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
|
||||
class MobidziennikData(val data: DataMobidziennik, val onSuccess: () -> Unit) {
|
||||
@ -51,11 +52,11 @@ class MobidziennikData(val data: DataMobidziennik, val onSuccess: () -> Unit) {
|
||||
ENDPOINT_MOBIDZIENNIK_WEB_CALENDAR -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_calendar)
|
||||
MobidziennikWebCalendar(data) { onSuccess() }
|
||||
}/*
|
||||
}
|
||||
ENDPOINT_MOBIDZIENNIK_WEB_GRADES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_grades)
|
||||
MobidziennikWebGrades(data) { onSuccess() }
|
||||
}
|
||||
}/*
|
||||
ENDPOINT_MOBIDZIENNIK_WEB_NOTICES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_behaviour)
|
||||
MobidziennikWebNotices(data) { onSuccess() }
|
||||
|
@ -62,8 +62,7 @@ open class MobidziennikWeb(open val data: DataMobidziennik) {
|
||||
data.error(ApiError(tag, EXCEPTION_MOBIDZIENNIK_WEB_REQUEST)
|
||||
.withResponse(response)
|
||||
.withThrowable(e)
|
||||
.withApiResponse(text)
|
||||
.setCritical(false))
|
||||
.withApiResponse(text))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,11 +4,15 @@
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.mobidziennik.data.web
|
||||
|
||||
import pl.szczodrzynski.edziennik.DAY
|
||||
import pl.szczodrzynski.edziennik.api.v2.ENDPOINT_LIBRUS_API_ME
|
||||
import pl.szczodrzynski.edziennik.api.v2.ERROR_MOBIDZIENNIK_WEB_INVALID_RESPONSE
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.DataMobidziennik
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.ENDPOINT_MOBIDZIENNIK_API_MAIN
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.data.MobidziennikWeb
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.data.web.apidata.*
|
||||
import pl.szczodrzynski.edziennik.api.v2.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||
|
||||
class MobidziennikApi(override val data: DataMobidziennik,
|
||||
val onSuccess: () -> Unit) : MobidziennikWeb(data) {
|
||||
@ -45,6 +49,7 @@ class MobidziennikApi(override val data: DataMobidziennik,
|
||||
}
|
||||
}
|
||||
|
||||
data.setSyncNext(ENDPOINT_MOBIDZIENNIK_API_MAIN, SYNC_ALWAYS)
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,12 @@
|
||||
package pl.szczodrzynski.edziennik.api.v2.mobidziennik.data.web
|
||||
|
||||
import com.google.gson.JsonParser
|
||||
import pl.szczodrzynski.edziennik.api.v2.ENDPOINT_LIBRUS_API_ME
|
||||
import pl.szczodrzynski.edziennik.api.v2.Regexes
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.DataMobidziennik
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.ENDPOINT_MOBIDZIENNIK_WEB_CALENDAR
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.data.MobidziennikWeb
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.events.Event
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
import pl.szczodrzynski.edziennik.getString
|
||||
@ -91,6 +94,8 @@ class MobidziennikWebCalendar(override val data: DataMobidziennik,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
data.setSyncNext(ENDPOINT_MOBIDZIENNIK_WEB_CALENDAR, SYNC_ALWAYS)
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-10-10.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.mobidziennik.data.web
|
||||
|
||||
import android.graphics.Color
|
||||
import com.google.gson.JsonParser
|
||||
import org.jsoup.Jsoup
|
||||
import pl.szczodrzynski.edziennik.api.v2.ENDPOINT_LIBRUS_API_ME
|
||||
import pl.szczodrzynski.edziennik.api.v2.Regexes
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.DataMobidziennik
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.ENDPOINT_MOBIDZIENNIK_WEB_GRADES
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.data.MobidziennikWeb
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.events.Event
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.Grade
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
import pl.szczodrzynski.edziennik.fixWhiteSpaces
|
||||
import pl.szczodrzynski.edziennik.get
|
||||
import pl.szczodrzynski.edziennik.getString
|
||||
import pl.szczodrzynski.edziennik.singleOrNull
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.strToInt
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||
import java.util.*
|
||||
import java.util.regex.Pattern
|
||||
|
||||
class MobidziennikWebGrades(override val data: DataMobidziennik,
|
||||
val onSuccess: () -> Unit) : MobidziennikWeb(data) {
|
||||
companion object {
|
||||
private const val TAG = "MobidziennikWebGrades"
|
||||
}
|
||||
|
||||
init {
|
||||
webGet(TAG, "/dziennik/oceny?semestr=${profile?.currentSemester ?: 1}") { text ->
|
||||
MobidziennikLuckyNumberExtractor(data, text)
|
||||
|
||||
val doc = Jsoup.parse(text)
|
||||
|
||||
val grades = doc.select("table.spis a, table.spis span, table.spis div")
|
||||
|
||||
var gradeCategory = ""
|
||||
var gradeColor = -1
|
||||
var subjectName = ""
|
||||
|
||||
for (e in grades) {
|
||||
when (e.tagName()) {
|
||||
"div" -> {
|
||||
Regexes.MOBIDZIENNIK_GRADES_SUBJECT_NAME.find(e.outerHtml())?.let {
|
||||
subjectName = it[1]
|
||||
}
|
||||
}
|
||||
"span" -> {
|
||||
val css = e.attr("style")
|
||||
Regexes.MOBIDZIENNIK_GRADES_COLOR.find(css)?.let {
|
||||
// (#2196f3)
|
||||
gradeColor = Color.parseColor(it[1])
|
||||
}
|
||||
Regexes.MOBIDZIENNIK_GRADES_CATEGORY.find(e.outerHtml())?.let {
|
||||
// (category)
|
||||
gradeCategory = it[1]
|
||||
}
|
||||
}
|
||||
"a" -> {
|
||||
val gradeId = e.attr("rel").toLong()
|
||||
var gradeAddedDateMillis: Long = -1
|
||||
var gradeSemester = 1
|
||||
|
||||
val html = e.html()
|
||||
val gradeClassAverage = Regexes.MOBIDZIENNIK_GRADES_CLASS_AVERAGE.find(html)?.let {
|
||||
// (4.75)
|
||||
it[1].toFloatOrNull()
|
||||
} ?: -1f
|
||||
|
||||
Regexes.MOBIDZIENNIK_GRADES_ADDED_DATE.find(html)?.let {
|
||||
// (2) (stycznia) (2019), (12:34:56)
|
||||
val month = when (it[2]) {
|
||||
"stycznia" -> 1
|
||||
"lutego" -> 2
|
||||
"marca" -> 3
|
||||
"kwietnia" -> 4
|
||||
"maja" -> 5
|
||||
"czerwca" -> 6
|
||||
"lipca" -> 7
|
||||
"sierpnia" -> 8
|
||||
"września" -> 9
|
||||
"października" -> 10
|
||||
"listopada" -> 11
|
||||
"grudnia" -> 12
|
||||
else -> 1
|
||||
}
|
||||
val gradeAddedDate = Date(
|
||||
it[3].toInt(),
|
||||
month,
|
||||
it[1].toInt()
|
||||
)
|
||||
val time = Time.fromH_m_s(it[4])
|
||||
gradeAddedDateMillis = gradeAddedDate.combineWith(time)
|
||||
gradeSemester = profile?.dateToSemester(gradeAddedDate) ?: 1
|
||||
}
|
||||
|
||||
if (Regexes.MOBIDZIENNIK_GRADES_COUNT_TO_AVG.containsMatchIn(html)) {
|
||||
Regexes.MOBIDZIENNIK_GRADES_DETAILS.find(html)?.let { match ->
|
||||
val gradeName = match[1]
|
||||
val gradeDescription = match[2]
|
||||
val gradeValue = match[3].toFloatOrNull() ?: 0.0f
|
||||
val teacherName = match[4].fixWhiteSpaces()
|
||||
|
||||
val teacherId = data.teacherList.singleOrNull { it.fullNameLastFirst == teacherName }?.id ?: -1
|
||||
val subjectId = data.subjectList.singleOrNull { it.longName == subjectName }?.id ?: -1
|
||||
|
||||
val gradeObject = Grade(
|
||||
profileId,
|
||||
gradeId,
|
||||
gradeCategory,
|
||||
gradeColor,
|
||||
"NLDŚR, $gradeDescription",
|
||||
gradeName,
|
||||
gradeValue,
|
||||
0f,
|
||||
gradeSemester,
|
||||
teacherId,
|
||||
subjectId
|
||||
)
|
||||
|
||||
gradeObject.classAverage = gradeClassAverage
|
||||
|
||||
data.gradeList.add(gradeObject)
|
||||
data.metadataList.add(
|
||||
Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_GRADE,
|
||||
gradeObject.id,
|
||||
profile?.empty ?: false,
|
||||
profile?.empty ?: false,
|
||||
gradeAddedDateMillis
|
||||
))
|
||||
}
|
||||
} else {
|
||||
data.gradeAverages.put(gradeId, gradeClassAverage)
|
||||
data.gradeAddedDates.put(gradeId, gradeAddedDateMillis)
|
||||
data.gradeColors.put(gradeId, gradeColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data.setSyncNext(ENDPOINT_MOBIDZIENNIK_WEB_GRADES, SYNC_ALWAYS)
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
}
|
@ -23,7 +23,7 @@ class MobidziennikApiGrades(val data: DataMobidziennik, rows: List<String>) {
|
||||
continue
|
||||
val cols = row.split("|")
|
||||
|
||||
val studentId = cols[2].toInt()
|
||||
val studentId = cols[1].toInt()
|
||||
if (studentId != data.studentId)
|
||||
return@run
|
||||
|
||||
@ -35,7 +35,7 @@ class MobidziennikApiGrades(val data: DataMobidziennik, rows: List<String>) {
|
||||
val semester = cols[5].toInt()
|
||||
val teacherId = cols[2].toLong()
|
||||
val subjectId = cols[3].toLong()
|
||||
var type = when (cols[8]) {
|
||||
val type = when (cols[8]) {
|
||||
"3" -> if (semester == 1) TYPE_SEMESTER1_PROPOSED else TYPE_SEMESTER2_PROPOSED
|
||||
"1" -> if (semester == 1) TYPE_SEMESTER1_FINAL else TYPE_SEMESTER2_FINAL
|
||||
"4" -> TYPE_YEAR_PROPOSED
|
||||
@ -70,7 +70,7 @@ class MobidziennikApiGrades(val data: DataMobidziennik, rows: List<String>) {
|
||||
weight,
|
||||
semester,
|
||||
teacherId,
|
||||
subjectId)
|
||||
subjectId);gradeObject.type = type
|
||||
|
||||
data.gradeList.add(gradeObject)
|
||||
data.metadataList.add(
|
||||
|
@ -29,6 +29,7 @@ class MobidziennikApiNotices(val data: DataMobidziennik, rows: List<String>) {
|
||||
val type = when (cols[3]) {
|
||||
"0" -> Notice.TYPE_NEGATIVE
|
||||
"1" -> Notice.TYPE_POSITIVE
|
||||
"3" -> Notice.TYPE_NEUTRAL
|
||||
else -> Notice.TYPE_NEUTRAL
|
||||
}
|
||||
val teacherId = cols[5].toLong()
|
||||
|
@ -5,6 +5,7 @@
|
||||
package pl.szczodrzynski.edziennik.api.v2.mobidziennik.login
|
||||
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.api.v2.LOGIN_METHOD_MOBIDZIENNIK_API2
|
||||
import pl.szczodrzynski.edziennik.api.v2.LOGIN_METHOD_MOBIDZIENNIK_WEB
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.DataMobidziennik
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
@ -48,6 +49,10 @@ class MobidziennikLogin(val data: DataMobidziennik, val onSuccess: () -> Unit) {
|
||||
data.startProgress(R.string.edziennik_progress_login_mobidziennik_web)
|
||||
MobidziennikLoginWeb(data) { onSuccess(loginMethodId) }
|
||||
}
|
||||
LOGIN_METHOD_MOBIDZIENNIK_API2 -> {
|
||||
data.startProgress(R.string.edziennik_progress_login_mobidziennik_api2)
|
||||
//MobidziennikLoginApi2(data) { onSuccess(loginMethodId) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -190,7 +190,7 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
|
||||
messageMetadataList.clear()
|
||||
}
|
||||
|
||||
fun saveData() {
|
||||
open fun saveData() {
|
||||
if (profile == null)
|
||||
return
|
||||
|
||||
|
@ -5,6 +5,7 @@ import android.graphics.Color;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Handler;
|
||||
import android.text.Html;
|
||||
import android.util.LongSparseArray;
|
||||
import android.util.Pair;
|
||||
import android.util.SparseArray;
|
||||
import android.util.SparseIntArray;
|
||||
@ -128,9 +129,9 @@ public class Mobidziennik implements EdziennikInterface {
|
||||
private List<Subject> subjectList;
|
||||
private List<Lesson> lessonList;
|
||||
private List<LessonChange> lessonChangeList;
|
||||
private SparseArray<Long> gradeAddedDates;
|
||||
private SparseArray<Float> gradeAverages;
|
||||
private SparseIntArray gradeColors;
|
||||
private LongSparseArray<Long> gradeAddedDates;
|
||||
private LongSparseArray<Float> gradeAverages;
|
||||
private LongSparseArray<Integer> gradeColors;
|
||||
private List<Grade> gradeList;
|
||||
private List<Event> eventList;
|
||||
private List<Notice> noticeList;
|
||||
@ -179,9 +180,9 @@ public class Mobidziennik implements EdziennikInterface {
|
||||
subjectList = new ArrayList<>();
|
||||
lessonList = new ArrayList<>();
|
||||
lessonChangeList = new ArrayList<>();
|
||||
gradeAddedDates = new SparseArray<>();
|
||||
gradeAverages = new SparseArray<>();
|
||||
gradeColors = new SparseIntArray();
|
||||
gradeAddedDates = new LongSparseArray<>();
|
||||
gradeAverages = new LongSparseArray<>();
|
||||
gradeColors = new LongSparseArray<>();
|
||||
gradeList = new ArrayList<>();
|
||||
eventList = new ArrayList<>();
|
||||
noticeList = new ArrayList<>();
|
||||
|
@ -9,6 +9,8 @@ import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.RawQuery;
|
||||
import androidx.room.Transaction;
|
||||
|
||||
import android.util.LongSparseArray;
|
||||
import android.util.SparseArray;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
@ -88,15 +90,15 @@ public abstract class GradeDao {
|
||||
}
|
||||
|
||||
@Query("UPDATE grades SET gradeClassAverage = :classAverage, gradeColor = :color WHERE profileId = :profileId AND gradeId = :gradeId")
|
||||
public abstract void updateDetailsById(int profileId, int gradeId, float classAverage, int color);
|
||||
public abstract void updateDetailsById(int profileId, long gradeId, float classAverage, int color);
|
||||
|
||||
@Query("UPDATE metadata SET addedDate = :addedDate WHERE profileId = :profileId AND thingType = "+TYPE_GRADE+" AND thingId = :gradeId")
|
||||
public abstract void updateAddedDateById(int profileId, int gradeId, long addedDate);
|
||||
public abstract void updateAddedDateById(int profileId, long gradeId, long addedDate);
|
||||
|
||||
@Transaction
|
||||
public void updateDetails(int profileId, SparseArray<Float> gradeAverages, SparseArray<Long> gradeAddedDates, SparseIntArray gradeColors) {
|
||||
public void updateDetails(int profileId, LongSparseArray<Float> gradeAverages, LongSparseArray<Long> gradeAddedDates, LongSparseArray<Integer> gradeColors) {
|
||||
for (int i = 0; i < gradeAverages.size(); i++) {
|
||||
int gradeId = gradeAverages.keyAt(i);
|
||||
long gradeId = gradeAverages.keyAt(i);
|
||||
float classAverage = gradeAverages.valueAt(i);
|
||||
long addedDate = gradeAddedDates.valueAt(i);
|
||||
int color = gradeColors.valueAt(i);
|
||||
@ -114,7 +116,7 @@ public abstract class GradeDao {
|
||||
@Query("SELECT addedDate FROM metadata WHERE profileId = :profileId AND thingType = "+TYPE_GRADE+" ORDER BY thingId")
|
||||
public abstract List<Long> getAddedDates(int profileId);
|
||||
@Transaction
|
||||
public void getDetails(int profileId, SparseArray<Long> gradeAddedDates, SparseArray<Float> gradeAverages, SparseIntArray gradeColors) {
|
||||
public void getDetails(int profileId, LongSparseArray<Long> gradeAddedDates, LongSparseArray<Float> gradeAverages, LongSparseArray<Integer> gradeColors) {
|
||||
List<Integer> ids = getIds(profileId);
|
||||
List<Float> classAverages = getClassAverages(profileId);
|
||||
List<Integer> colors = getColors(profileId);
|
||||
|
@ -63,6 +63,11 @@ public class LoginStore {
|
||||
}
|
||||
}
|
||||
}
|
||||
public boolean hasLoginData(String key) {
|
||||
if (data == null)
|
||||
return false;
|
||||
return data.has(key);
|
||||
}
|
||||
@Nullable
|
||||
public String getLoginData(String key, @Nullable String defaultValue) {
|
||||
if (data == null)
|
||||
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-10-11.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.sync
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import androidx.legacy.content.WakefulBroadcastReceiver
|
||||
import com.google.firebase.messaging.RemoteMessage
|
||||
import com.google.gson.JsonObject
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
|
||||
class FirebaseBroadcastReceiver : WakefulBroadcastReceiver() {
|
||||
|
||||
val TAG: String = FirebaseBroadcastReceiver::class.java.simpleName
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
|
||||
val json = JsonObject()
|
||||
|
||||
val dataBundle = intent.extras
|
||||
if (dataBundle != null)
|
||||
for (key in dataBundle.keySet()) {
|
||||
dataBundle.get(key)?.let {
|
||||
when (it) {
|
||||
is String -> json.addProperty(key, it)
|
||||
is Int -> json.addProperty(key, it)
|
||||
is Long -> json.addProperty(key, it)
|
||||
is Float -> json.addProperty(key, it)
|
||||
is Boolean -> json.addProperty(key, it)
|
||||
else -> json.addProperty(key, it.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Log.d(TAG, "Firebase got push from Librus Broadcast ${json}")
|
||||
|
||||
val sharedPreferences = context.getSharedPreferences("pushtest_broadcast", Context.MODE_PRIVATE)
|
||||
sharedPreferences.edit().putString(
|
||||
System.currentTimeMillis().toString(),
|
||||
json.toString()
|
||||
).apply()
|
||||
}
|
||||
}
|
@ -61,7 +61,7 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
|
||||
//processAppPush
|
||||
processAppPush(app, remoteMessage);
|
||||
break;
|
||||
case "1029629079999":
|
||||
case "747285019373":
|
||||
app.debugLog("Firebase got push from Mobidziennik "+remoteMessage.getData().toString());
|
||||
processMobidziennikPush(app, remoteMessage);
|
||||
break;
|
||||
|
@ -938,4 +938,5 @@
|
||||
<string name="edziennik_progress_endpoint_behaviour">Pobieram uwagi ucznia...</string>
|
||||
<string name="edziennik_progress_endpoint_attendance">Pobieram frekwencję ucznia...</string>
|
||||
<string name="edziennik_progress_login_vulcan_api">Logowanie do Vulcan API...</string>
|
||||
<string name="edziennik_progress_login_mobidziennik_api2">Logowanie do API MobiDziennika...</string>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user