feat: Android

This commit is contained in:
2026-06-21 14:28:07 +02:00
parent edb1d5fe82
commit af06bc2b5c
13 changed files with 879 additions and 1258 deletions
+19
View File
@@ -1,6 +1,7 @@
plugins {
id 'com.android.library'
id 'expo-module-gradle-plugin'
id 'org.jetbrains.kotlin.android'
}
group = 'cz.jzitnik.jecnaapireactnative'
@@ -8,11 +9,29 @@ version = '0.1.0'
android {
namespace "cz.jzitnik.jecnaapireactnative"
compileSdk = 36
defaultConfig {
versionCode 1
versionName "0.1.0"
minSdk = 26
}
lintOptions {
abortOnError false
}
kotlinOptions {
freeCompilerArgs += [
'-Xskip-metadata-version-check'
]
}
}
repositories {
mavenCentral()
}
dependencies {
implementation "io.github.tomhula:jecnaapi-jecna:10.3.5"
implementation "io.github.tomhula:jecnaapi-canteen:10.3.5"
implementation "com.google.code.gson:gson:2.14.0"
}
@@ -1,10 +1,222 @@
package cz.jzitnik.jecnaapireactnative
import com.google.gson.Gson
import expo.modules.kotlin.functions.Coroutine
import expo.modules.kotlin.modules.Module
import expo.modules.kotlin.modules.ModuleDefinition
import io.github.tomhula.jecnaapi.CanteenClient
import io.github.tomhula.jecnaapi.JecnaClient
import io.github.tomhula.jecnaapi.data.canteen.ExchangeItem
import io.github.tomhula.jecnaapi.data.canteen.MenuItem
import io.github.tomhula.jecnaapi.data.notification.NotificationReference
import io.github.tomhula.jecnaapi.data.notification.NotificationReference.NotificationType
import io.github.tomhula.jecnaapi.util.SchoolYear
import io.github.tomhula.jecnaapi.util.SchoolYearHalf
import kotlinx.datetime.LocalDate
import kotlinx.datetime.Month
class JecnaapiReactNativeModule : Module() {
override fun definition() = ModuleDefinition {
Name("JecnaapiReactNative")
}
private var client: JecnaClient = JecnaClient(autoLogin = true)
private var canteenClient: CanteenClient = CanteenClient(autoLogin = true)
private val gson = Gson()
override fun definition() = ModuleDefinition {
Name("JecnaapiReactNative")
// ==========================================
// JecnaClient Functions
// ==========================================
AsyncFunction("login") Coroutine { username: String, pass: String ->
return@Coroutine client.login(username, pass)
}
AsyncFunction("logout") Coroutine { ->
client.logout()
}
AsyncFunction("isLoggedIn") Coroutine { ->
return@Coroutine client.isLoggedIn()
}
AsyncFunction("getNewsPage") Coroutine { ->
val news = client.getNewsPage()
return@Coroutine gson.toJson(news)
}
AsyncFunction("getGradesPage") Coroutine { ->
val grades = client.getGradesPage()
return@Coroutine gson.toJson(grades)
}
AsyncFunction("getGradesPageByYear") Coroutine { firstCalendarYear: Int, half: String ->
val schoolYear = SchoolYear(firstCalendarYear)
val schoolYearHalf = SchoolYearHalf.valueOf(half.uppercase())
val grades = client.getGradesPage(schoolYear, schoolYearHalf)
return@Coroutine gson.toJson(grades)
}
AsyncFunction("getTimetablePage") Coroutine { ->
val timetable = client.getTimetablePage()
return@Coroutine gson.toJson(timetable)
}
AsyncFunction("getTimetablePageByYear") Coroutine { firstCalendarYear: Int, periodId: Int? ->
val schoolYear = SchoolYear(firstCalendarYear)
val timetable = client.getTimetablePage(schoolYear, periodId)
return@Coroutine gson.toJson(timetable)
}
AsyncFunction("getAttendancesPage") Coroutine { ->
val attendance = client.getAttendancesPage()
return@Coroutine gson.toJson(attendance)
}
AsyncFunction("getAttendancesPageByMonth") Coroutine { firstCalendarYear: Int, monthName: String ->
val schoolYear = SchoolYear(firstCalendarYear)
val month = Month.valueOf(monthName.uppercase())
val attendance = client.getAttendancesPage(schoolYear, month)
return@Coroutine gson.toJson(attendance)
}
AsyncFunction("getAbsencesPage") Coroutine { ->
val absences = client.getAbsencesPage()
return@Coroutine gson.toJson(absences)
}
AsyncFunction("getAbsencesPageByYear") Coroutine { firstCalendarYear: Int ->
val schoolYear = SchoolYear(firstCalendarYear)
val absences = client.getAbsencesPage(schoolYear)
return@Coroutine gson.toJson(absences)
}
AsyncFunction("getTeachersPage") Coroutine { ->
val teachers = client.getTeachersPage()
return@Coroutine gson.toJson(teachers)
}
AsyncFunction("getTeacher") Coroutine { teacherTag: String ->
val teacher = client.getTeacher(teacherTag)
return@Coroutine gson.toJson(teacher)
}
AsyncFunction("getRoomsPage") Coroutine { ->
val rooms = client.getRoomsPage()
return@Coroutine gson.toJson(rooms)
}
AsyncFunction("getRoom") Coroutine { roomCode: String ->
val room = client.getRoom(roomCode)
return@Coroutine gson.toJson(room)
}
AsyncFunction("getLocker") Coroutine { ->
val locker = client.getLocker()
return@Coroutine gson.toJson(locker)
}
AsyncFunction("getStudentProfile") Coroutine { ->
val profile = client.getStudentProfile()
return@Coroutine gson.toJson(profile)
}
AsyncFunction("getStudentProfileByUsername") Coroutine { username: String ->
val profile = client.getStudentProfile(username)
return@Coroutine gson.toJson(profile)
}
AsyncFunction("getNotifications") Coroutine { ->
val notifications = client.getNotifications()
return@Coroutine gson.toJson(notifications)
}
AsyncFunction("getNotification") Coroutine { type: String, message: String, recordId: Int ->
val notificationType = NotificationType.valueOf(type.uppercase())
val notificationRef = NotificationReference(notificationType, message, recordId)
val notification = client.getNotification(notificationRef)
return@Coroutine gson.toJson(notification)
}
AsyncFunction("getStudentCertificates") Coroutine { ->
val certificates = client.getStudentCertificates()
return@Coroutine gson.toJson(certificates)
}
AsyncFunction("getDocumentsPage") Coroutine { path: String ->
val documents = client.getDocumentsPage(path)
return@Coroutine gson.toJson(documents)
}
AsyncFunction("getDocumentsPageDefault") Coroutine { ->
val documents = client.getDocumentsPage()
return@Coroutine gson.toJson(documents)
}
// ==========================================
// CanteenClient Functions
// ==========================================
AsyncFunction("canteenLogin") Coroutine { username: String, pass: String ->
return@Coroutine canteenClient.login(username, pass)
}
AsyncFunction("canteenLogout") Coroutine { ->
canteenClient.logout()
}
AsyncFunction("canteenIsLoggedIn") Coroutine { ->
return@Coroutine canteenClient.isLoggedIn()
}
AsyncFunction("canteenGetMenuPage") Coroutine { ->
val menuPage = canteenClient.getMenuPage()
return@Coroutine gson.toJson(menuPage)
}
AsyncFunction("canteenGetMenuAsync") Coroutine { daysStrings: List<String> ->
val localDates = daysStrings.map { LocalDate.parse(it) }
val dayMenusList = mutableListOf<io.github.tomhula.jecnaapi.data.canteen.DayMenu>()
canteenClient.getMenuAsync(localDates).collect { dayMenu ->
dayMenusList.add(dayMenu)
}
return@Coroutine gson.toJson(dayMenusList)
}
AsyncFunction("canteenGetDayMenu") Coroutine { dayString: String ->
val day = LocalDate.parse(dayString)
val dayMenu = canteenClient.getDayMenu(day)
return@Coroutine gson.toJson(dayMenu)
}
AsyncFunction("canteenGetExchange") Coroutine { ->
val exchange = canteenClient.getExchange()
return@Coroutine gson.toJson(exchange)
}
AsyncFunction("canteenGetCredit") Coroutine { ->
return@Coroutine canteenClient.getCredit()
}
AsyncFunction("canteenOrderMenuItem") Coroutine { menuItemJson: String ->
val menuItem = gson.fromJson(menuItemJson, MenuItem::class.java)
return@Coroutine canteenClient.order(menuItem)
}
AsyncFunction("canteenOrderExchangeItem") Coroutine { number: Int, orderPath: String, dayString: String, amount: Int ->
val day = LocalDate.parse(dayString)
val exchangeItem = ExchangeItem(
number = number,
description = null,
amount = amount,
orderPath = orderPath,
day = day
)
return@Coroutine canteenClient.order(exchangeItem)
}
AsyncFunction("canteenPutOnExchange") Coroutine { menuItemJson: String ->
val menuItem = gson.fromJson(menuItemJson, MenuItem::class.java)
return@Coroutine canteenClient.putOnExchange(menuItem)
}
}
}