diff --git a/refilc_kreta_api/lib/demo/demo_data.dart b/refilc_kreta_api/lib/demo/demo_data.dart new file mode 100644 index 00000000..7e050d3a --- /dev/null +++ b/refilc_kreta_api/lib/demo/demo_data.dart @@ -0,0 +1,381 @@ +import 'package:refilc/models/user.dart'; +import 'package:refilc_kreta_api/models/absence.dart'; +import 'package:refilc_kreta_api/models/category.dart'; +import 'package:refilc_kreta_api/models/exam.dart'; +import 'package:refilc_kreta_api/models/grade.dart'; +import 'package:refilc_kreta_api/models/homework.dart'; +import 'package:refilc_kreta_api/models/lesson.dart'; +import 'package:refilc_kreta_api/models/message.dart'; +import 'package:refilc_kreta_api/models/recipient.dart'; +import 'package:refilc_kreta_api/models/subject.dart'; +import 'package:refilc_kreta_api/models/teacher.dart'; +import 'package:refilc_kreta_api/models/week.dart'; + +class DemoData { + static final _subjectMath = GradeSubject( + id: 'demo-subject-math', + category: Category(id: 'matematika', name: 'matematika'), + name: 'Matematika', + ); + static final _subjectHun = GradeSubject( + id: 'demo-subject-hun', + category: Category(id: 'magyar_nyelv_es_irodalom', name: 'magyar_nyelv_es_irodalom'), + name: 'Magyar nyelv és irodalom', + ); + static final _subjectHist = GradeSubject( + id: 'demo-subject-hist', + category: Category(id: 'tortenelem_es_allampolgari_ismeretek', name: 'tortenelem_es_allampolgari_ismeretek'), + name: 'Történelem', + ); + static final _subjectEng = GradeSubject( + id: 'demo-subject-eng', + category: Category(id: 'angol_nyelv', name: 'angol_nyelv'), + name: 'Angol nyelv', + ); + static final _subjectPhy = GradeSubject( + id: 'demo-subject-phy', + category: Category(id: 'fizika', name: 'fizika'), + name: 'Fizika', + ); + static final _subjectBio = GradeSubject( + id: 'demo-subject-bio', + category: Category(id: 'biologia_egeszsegtan', name: 'biologia_egeszsegtan'), + name: 'Biológia', + ); + static final _subjectChem = GradeSubject( + id: 'demo-subject-chem', + category: Category(id: 'kemia', name: 'kemia'), + name: 'Kémia', + ); + static final _subjectPE = GradeSubject( + id: 'demo-subject-pe', + category: Category(id: 'testnevelés_és_sport', name: 'testnevelés_és_sport'), + name: 'Testnevelés', + ); + static final _subjectIT = GradeSubject( + id: 'demo-subject-it', + category: Category(id: 'informatika', name: 'informatika'), + name: 'Informatika', + ); + + static final _teacherNagy = Teacher.fromString('Nagy Katalin'); + static final _teacherSzabo = Teacher.fromString('Szabó Péter'); + static final _teacherKovacs = Teacher.fromString('Kovács Mária'); + static final _teacherToth = Teacher.fromString('Tóth László'); + static final _teacherVarga = Teacher.fromString('Varga Erzsébet'); + static final _teacherFekete = Teacher.fromString('Fekete Gábor'); + + static final _modeOral = Category(id: '1,SzobaliVizsga', name: 'Szóbeli vizsga', description: 'Szóbeli vizsga'); + static final _modeWritten = Category(id: '2,IrasbaliVizsga', name: 'Írásbeli vizsga', description: 'Írásbeli vizsga'); + static final _modePractical = Category(id: '3,Gyakorlati', name: 'Gyakorlati', description: 'Gyakorlati'); + + static List get grades { + final now = DateTime.now(); + return [ + _makeGrade('demo-g-1', 5, 'Jeles', 'Ötös', 100, _subjectMath, _teacherNagy, 'Függvények', now.subtract(const Duration(days: 3)), _modeWritten, GradeType.midYear), + _makeGrade('demo-g-2', 4, 'Jó', 'Négyes', 100, _subjectMath, _teacherNagy, 'Egyenletek', now.subtract(const Duration(days: 14)), _modeWritten, GradeType.midYear), + _makeGrade('demo-g-3', 5, 'Jeles', 'Ötös', 100, _subjectHun, _teacherKovacs, 'Arany János költészete', now.subtract(const Duration(days: 5)), _modeOral, GradeType.midYear), + _makeGrade('demo-g-4', 4, 'Jó', 'Négyes', 100, _subjectHun, _teacherKovacs, 'Fogalmazás', now.subtract(const Duration(days: 20)), _modeWritten, GradeType.midYear), + _makeGrade('demo-g-5', 5, 'Jeles', 'Ötös', 100, _subjectEng, _teacherSzabo, 'Grammar test', now.subtract(const Duration(days: 7)), _modeWritten, GradeType.midYear), + _makeGrade('demo-g-6', 5, 'Jeles', 'Ötös', 100, _subjectEng, _teacherSzabo, 'Speaking', now.subtract(const Duration(days: 18)), _modeOral, GradeType.midYear), + _makeGrade('demo-g-7', 4, 'Jó', 'Négyes', 100, _subjectHist, _teacherToth, 'Az első világháború', now.subtract(const Duration(days: 10)), _modeOral, GradeType.midYear), + _makeGrade('demo-g-8', 3, 'Közepes', 'Hármas', 100, _subjectHist, _teacherToth, 'Témazáró', now.subtract(const Duration(days: 25)), _modeWritten, GradeType.midYear), + _makeGrade('demo-g-9', 5, 'Jeles', 'Ötös', 100, _subjectPhy, _teacherVarga, 'Mechanika', now.subtract(const Duration(days: 8)), _modeWritten, GradeType.midYear), + _makeGrade('demo-g-10', 4, 'Jó', 'Négyes', 100, _subjectBio, _teacherFekete, 'Sejtbiológia', now.subtract(const Duration(days: 12)), _modeOral, GradeType.midYear), + _makeGrade('demo-g-11', 5, 'Jeles', 'Ötös', 100, _subjectChem, _teacherVarga, 'Kémiai kötések', now.subtract(const Duration(days: 6)), _modeWritten, GradeType.midYear), + _makeGrade('demo-g-12', 5, 'Jeles', 'Ötös', 100, _subjectIT, _teacherSzabo, 'Programozás alapjai', now.subtract(const Duration(days: 4)), _modePractical, GradeType.midYear), + _makeGrade('demo-g-13', 4, 'Jó', 'Négyes', 100, _subjectMath, _teacherNagy, 'Statisztika', now.subtract(const Duration(days: 30)), _modeWritten, GradeType.halfYear), + _makeGrade('demo-g-14', 5, 'Jeles', 'Ötös', 100, _subjectHun, _teacherKovacs, 'Félévzáró', now.subtract(const Duration(days: 60)), _modeWritten, GradeType.halfYear), + _makeGrade('demo-g-15', 4, 'Jó', 'Négyes', 100, _subjectEng, _teacherSzabo, 'Mid-year exam', now.subtract(const Duration(days: 60)), _modeWritten, GradeType.halfYear), + ]; + } + + static Grade _makeGrade( + String id, + int value, + String valueName, + String shortName, + int weight, + GradeSubject subject, + Teacher teacher, + String description, + DateTime date, + Category mode, + GradeType type, + ) { + return Grade( + id: id, + date: date, + value: GradeValue(value, valueName, shortName, weight), + teacher: teacher, + description: description, + type: type, + groupId: 'demo-group', + subject: subject, + mode: mode, + writeDate: date, + seenDate: date, + form: '', + json: { + 'SzamErtek': value, + 'SzovegesErtek': valueName, + 'SzovegesErtekelesRovidNev': shortName, + 'SulySzazalekErteke': weight, + 'ErtekFajta': null, + }, + ); + } + + static Map> get timetable { + final week = Week.current(); + return {week: _lessonsForWeek(week)}; + } + + static List _lessonsForWeek(Week week) { + final monday = week.start; + List lessons = []; + + // Monday + lessons.addAll(_dayLessons(monday, [ + _LessonDef('Matematika', _subjectMath, _teacherNagy, '101', '9A'), + _LessonDef('Magyar nyelv és irodalom', _subjectHun, _teacherKovacs, '203', '9A'), + _LessonDef('Történelem', _subjectHist, _teacherToth, '105', '9A'), + _LessonDef('Angol nyelv', _subjectEng, _teacherSzabo, '102', '9A'), + _LessonDef('Testnevelés', _subjectPE, _teacherFekete, 'Tornaterem', '9A'), + ])); + + // Tuesday + lessons.addAll(_dayLessons(monday.add(const Duration(days: 1)), [ + _LessonDef('Fizika', _subjectPhy, _teacherVarga, '204', '9A'), + _LessonDef('Biológia', _subjectBio, _teacherFekete, '205', '9A'), + _LessonDef('Matematika', _subjectMath, _teacherNagy, '101', '9A'), + _LessonDef('Informatika', _subjectIT, _teacherSzabo, 'Számítóterem', '9A'), + ])); + + // Wednesday + lessons.addAll(_dayLessons(monday.add(const Duration(days: 2)), [ + _LessonDef('Magyar nyelv és irodalom', _subjectHun, _teacherKovacs, '203', '9A'), + _LessonDef('Kémia', _subjectChem, _teacherVarga, '206', '9A'), + _LessonDef('Angol nyelv', _subjectEng, _teacherSzabo, '102', '9A'), + _LessonDef('Történelem', _subjectHist, _teacherToth, '105', '9A'), + _LessonDef('Testnevelés', _subjectPE, _teacherFekete, 'Tornaterem', '9A'), + ])); + + // Thursday + lessons.addAll(_dayLessons(monday.add(const Duration(days: 3)), [ + _LessonDef('Matematika', _subjectMath, _teacherNagy, '101', '9A'), + _LessonDef('Biológia', _subjectBio, _teacherFekete, '205', '9A'), + _LessonDef('Fizika', _subjectPhy, _teacherVarga, '204', '9A'), + _LessonDef('Informatika', _subjectIT, _teacherSzabo, 'Számítóterem', '9A'), + ])); + + // Friday + lessons.addAll(_dayLessons(monday.add(const Duration(days: 4)), [ + _LessonDef('Magyar nyelv és irodalom', _subjectHun, _teacherKovacs, '203', '9A'), + _LessonDef('Kémia', _subjectChem, _teacherVarga, '206', '9A'), + _LessonDef('Matematika', _subjectMath, _teacherNagy, '101', '9A'), + _LessonDef('Angol nyelv', _subjectEng, _teacherSzabo, '102', '9A'), + ])); + + return lessons; + } + + static List _dayLessons(DateTime day, List<_LessonDef> defs) { + final List result = []; + // School starts at 8:00, each lesson is 45 min, 15 min break + DateTime time = DateTime(day.year, day.month, day.day, 8, 0); + for (int i = 0; i < defs.length; i++) { + final def = defs[i]; + final start = time; + final end = time.add(const Duration(minutes: 45)); + result.add(Lesson( + id: 'demo-lesson-${day.weekday}-$i', + date: day, + subject: def.subject, + lessonIndex: '${i + 1}', + teacher: def.teacher, + start: start, + end: end, + homeworkId: '', + description: '', + room: def.room, + groupName: def.group, + name: def.name, + )); + time = end.add(const Duration(minutes: 15)); + } + return result; + } + + static List get absences { + final now = DateTime.now(); + return [ + _makeAbsence('demo-abs-1', _subjectMath, _teacherNagy, now.subtract(const Duration(days: 15)), Justification.excused), + _makeAbsence('demo-abs-2', _subjectMath, _teacherNagy, now.subtract(const Duration(days: 15)), Justification.excused), + _makeAbsence('demo-abs-3', _subjectHun, _teacherKovacs, now.subtract(const Duration(days: 15)), Justification.excused), + _makeAbsence('demo-abs-4', _subjectEng, _teacherSzabo, now.subtract(const Duration(days: 8)), Justification.pending), + _makeAbsence('demo-abs-5', _subjectHist, _teacherToth, now.subtract(const Duration(days: 8)), Justification.pending), + _makeAbsence('demo-abs-6', _subjectPhy, _teacherVarga, now.subtract(const Duration(days: 2)), Justification.unexcused), + ]; + } + + static Absence _makeAbsence( + String id, + GradeSubject subject, + Teacher teacher, + DateTime date, + Justification state, + ) { + final start = DateTime(date.year, date.month, date.day, 8, 0); + final end = start.add(const Duration(minutes: 45)); + return Absence( + id: id, + date: date, + delay: 0, + submitDate: date, + teacher: teacher, + state: state, + subject: subject, + lessonStart: start, + lessonEnd: end, + group: 'demo-group', + ); + } + + static List get exams { + final now = DateTime.now(); + return [ + Exam( + id: 'demo-exam-1', + date: now.subtract(const Duration(days: 3)), + writeDate: now.add(const Duration(days: 7)), + subject: _subjectMath, + teacher: _teacherNagy, + description: 'Trigonometria témazáró', + group: 'demo-group', + ), + Exam( + id: 'demo-exam-2', + date: now.subtract(const Duration(days: 5)), + writeDate: now.add(const Duration(days: 12)), + subject: _subjectHun, + teacher: _teacherKovacs, + description: 'Petőfi Sándor életmű dolgozat', + group: 'demo-group', + ), + Exam( + id: 'demo-exam-3', + date: now.subtract(const Duration(days: 1)), + writeDate: now.add(const Duration(days: 5)), + subject: _subjectPhy, + teacher: _teacherVarga, + description: 'Elektromosságtan', + group: 'demo-group', + ), + ]; + } + + static List get homework { + final now = DateTime.now(); + return [ + Homework( + id: 'demo-hw-1', + date: now.subtract(const Duration(days: 2)), + lessonDate: now.subtract(const Duration(days: 2)), + deadline: now.add(const Duration(days: 5)), + byTeacher: true, + homeworkEnabled: true, + teacher: _teacherNagy, + content: 'Oldjátok meg a tankönyv 84-85. oldalán lévő feladatokat (1-15).', + subject: _subjectMath, + group: 'demo-group', + attachments: [], + ), + Homework( + id: 'demo-hw-2', + date: now.subtract(const Duration(days: 4)), + lessonDate: now.subtract(const Duration(days: 4)), + deadline: now.add(const Duration(days: 3)), + byTeacher: true, + homeworkEnabled: true, + teacher: _teacherKovacs, + content: 'Írjatok egy 1-2 oldalas elemzést Petőfi Sándor "Szeptember végén" c. verséről.', + subject: _subjectHun, + group: 'demo-group', + attachments: [], + ), + Homework( + id: 'demo-hw-3', + date: now.subtract(const Duration(days: 1)), + lessonDate: now.subtract(const Duration(days: 1)), + deadline: now.add(const Duration(days: 6)), + byTeacher: true, + homeworkEnabled: true, + teacher: _teacherSzabo, + content: 'Complete exercises 3-7 on page 42 of the workbook.', + subject: _subjectEng, + group: 'demo-group', + attachments: [], + ), + ]; + } + + static List get messages { + final now = DateTime.now(); + return [ + Message( + id: 10001, + messageId: 10001, + seen: true, + deleted: false, + date: now.subtract(const Duration(days: 1)), + author: 'Nagy Katalin', + content: 'Kedves Szülők!\n\nTájékoztatjuk Önöket, hogy jövő héten pótdolgozatot írunk matematikából. Kérem, segítsenek gyermeküknek a felkészülésben.\n\nÜdvözlettel,\nNagy Katalin', + subject: 'Pótdolgozat - Matematika', + type: MessageType.inbox, + recipients: [Recipient(id: 1, name: 'Demo Diák', kretaId: 1)], + attachments: [], + isSeen: true, + ), + Message( + id: 10002, + messageId: 10002, + seen: false, + deleted: false, + date: now.subtract(const Duration(days: 3)), + author: 'Kovács Mária', + content: 'Kedves Diákok!\n\nEmlékeztetem Önöket, hogy a fogalmazást péntekig be kell adni. Kérem, ne felejtsék el!\n\nÜdvözlettel,\nKovács Mária', + subject: 'Fogalmazás határideje', + type: MessageType.inbox, + recipients: [Recipient(id: 1, name: 'Demo Diák', kretaId: 1)], + attachments: [], + isSeen: false, + ), + Message( + id: 10003, + messageId: 10003, + seen: true, + deleted: false, + date: now.subtract(const Duration(days: 7)), + author: 'Tóth László', + content: 'Kedves Szülők!\n\nAz osztálykirándulás időpontja: március 20. Kérem, hogy a beleegyező nyilatkozatot hozzák vissza aláírva.\n\nÜdvözlettel,\nTóth László\nosztályfőnök', + subject: 'Osztálykirándulás', + type: MessageType.inbox, + recipients: [Recipient(id: 1, name: 'Demo Diák', kretaId: 1)], + attachments: [], + isSeen: true, + ), + ]; + } + + static bool isDemo(String? userId) => userId == demoUserId; +} + +class _LessonDef { + final String name; + final GradeSubject subject; + final Teacher teacher; + final String room; + final String group; + const _LessonDef(this.name, this.subject, this.teacher, this.room, this.group); +} diff --git a/refilc_kreta_api/lib/providers/absence_provider.dart b/refilc_kreta_api/lib/providers/absence_provider.dart index fcf4d044..05544c21 100644 --- a/refilc_kreta_api/lib/providers/absence_provider.dart +++ b/refilc_kreta_api/lib/providers/absence_provider.dart @@ -5,6 +5,7 @@ import 'package:refilc/api/providers/database_provider.dart'; import 'package:refilc/models/user.dart'; import 'package:refilc_kreta_api/client/api.dart'; import 'package:refilc_kreta_api/client/client.dart'; +import 'package:refilc_kreta_api/demo/demo_data.dart'; import 'package:refilc_kreta_api/models/absence.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; @@ -81,6 +82,12 @@ class AbsenceProvider with ChangeNotifier { Future fetch() async { User? user = Provider.of(_context, listen: false).user; if (user == null) throw "Cannot fetch Absences for User null"; + + if (DemoData.isDemo(user.id)) { + await store(DemoData.absences); + return; + } + String iss = user.instituteCode; List? absencesJson = await Provider.of(_context, listen: false) diff --git a/refilc_kreta_api/lib/providers/event_provider.dart b/refilc_kreta_api/lib/providers/event_provider.dart index 63836be2..c361150e 100644 --- a/refilc_kreta_api/lib/providers/event_provider.dart +++ b/refilc_kreta_api/lib/providers/event_provider.dart @@ -3,6 +3,7 @@ import 'package:refilc/api/providers/database_provider.dart'; import 'package:refilc/models/user.dart'; import 'package:refilc_kreta_api/client/api.dart'; import 'package:refilc_kreta_api/client/client.dart'; +import 'package:refilc_kreta_api/demo/demo_data.dart'; import 'package:refilc_kreta_api/models/event.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; @@ -40,6 +41,7 @@ class EventProvider with ChangeNotifier { Future fetch() async { User? user = Provider.of(_context, listen: false).user; if (user == null) throw "Cannot fetch Events for User null"; + if (DemoData.isDemo(user.id)) return; String iss = user.instituteCode; List? eventsJson = await Provider.of(_context, listen: false) diff --git a/refilc_kreta_api/lib/providers/exam_provider.dart b/refilc_kreta_api/lib/providers/exam_provider.dart index 65d8f43c..5c3c58fc 100644 --- a/refilc_kreta_api/lib/providers/exam_provider.dart +++ b/refilc_kreta_api/lib/providers/exam_provider.dart @@ -3,6 +3,7 @@ import 'package:refilc/api/providers/database_provider.dart'; import 'package:refilc/models/user.dart'; import 'package:refilc_kreta_api/client/api.dart'; import 'package:refilc_kreta_api/client/client.dart'; +import 'package:refilc_kreta_api/demo/demo_data.dart'; import 'package:refilc_kreta_api/models/exam.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; @@ -68,6 +69,12 @@ class ExamProvider with ChangeNotifier { Future fetch() async { User? user = Provider.of(_context, listen: false).user; if (user == null) throw "Cannot fetch Exams for User null"; + + if (DemoData.isDemo(user.id)) { + await store(DemoData.exams); + return; + } + String iss = user.instituteCode; List? examsJson = await Provider.of(_context, listen: false) diff --git a/refilc_kreta_api/lib/providers/grade_provider.dart b/refilc_kreta_api/lib/providers/grade_provider.dart index e35f46ab..01da001b 100644 --- a/refilc_kreta_api/lib/providers/grade_provider.dart +++ b/refilc_kreta_api/lib/providers/grade_provider.dart @@ -5,6 +5,7 @@ import 'package:refilc/models/settings.dart'; import 'package:refilc/models/user.dart'; import 'package:refilc_kreta_api/client/api.dart'; import 'package:refilc_kreta_api/client/client.dart'; +import 'package:refilc_kreta_api/demo/demo_data.dart'; import 'package:refilc_kreta_api/models/grade.dart'; import 'package:refilc_kreta_api/models/group_average.dart'; import 'package:refilc_kreta_api/providers/grade_provider.i18n.dart'; @@ -164,11 +165,14 @@ Future unseenAll() async { // Fetches Grades from the Kreta API then stores them in the database Future fetch() async { - // test cucc - // unseenAll(); - User? user = _user.user; if (user == null) throw "Cannot fetch Grades for User null"; + + if (DemoData.isDemo(user.id)) { + await store(DemoData.grades); + return; + } + String iss = user.instituteCode; List? gradesJson = await _kreta.getAPI(KretaAPI.grades(iss)); diff --git a/refilc_kreta_api/lib/providers/homework_provider.dart b/refilc_kreta_api/lib/providers/homework_provider.dart index 182692dc..7a135f44 100644 --- a/refilc_kreta_api/lib/providers/homework_provider.dart +++ b/refilc_kreta_api/lib/providers/homework_provider.dart @@ -4,6 +4,7 @@ import 'package:refilc/api/providers/database_provider.dart'; import 'package:refilc/models/user.dart'; import 'package:refilc_kreta_api/client/api.dart'; import 'package:refilc_kreta_api/client/client.dart'; +import 'package:refilc_kreta_api/demo/demo_data.dart'; import 'package:refilc_kreta_api/models/homework.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -75,6 +76,12 @@ class HomeworkProvider with ChangeNotifier { User? user = Provider.of(_context, listen: false).user; if (user == null) throw "Cannot fetch Homework for User null"; + if (DemoData.isDemo(user.id)) { + _homework = DemoData.homework; + notifyListeners(); + return; + } + String iss = user.instituteCode; List? homeworkJson = []; diff --git a/refilc_kreta_api/lib/providers/message_provider.dart b/refilc_kreta_api/lib/providers/message_provider.dart index cf592cba..87b5fe5b 100644 --- a/refilc_kreta_api/lib/providers/message_provider.dart +++ b/refilc_kreta_api/lib/providers/message_provider.dart @@ -7,6 +7,7 @@ import 'package:refilc/api/providers/database_provider.dart'; import 'package:refilc/models/user.dart'; import 'package:refilc_kreta_api/client/api.dart'; import 'package:refilc_kreta_api/client/client.dart'; +import 'package:refilc_kreta_api/demo/demo_data.dart'; import 'package:refilc_kreta_api/models/message.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; @@ -53,13 +54,21 @@ class MessageProvider with ChangeNotifier { Future fetch({MessageType type = MessageType.inbox}) async { // Check Message Type if (type == MessageType.draft) return; - String messageType = - ["beerkezett", "elkuldott", "torolt"].elementAt(type.index); // Check User User? user = Provider.of(_context, listen: false).user; if (user == null) throw "Cannot fetch Messages for User null"; + if (DemoData.isDemo(user.id)) { + if (type == MessageType.inbox) { + await store(DemoData.messages, type); + } + return; + } + + String messageType = + ["beerkezett", "elkuldott", "torolt"].elementAt(type.index); + // Get messages List? messagesJson = await Provider.of(_context, listen: false) .getAPI(KretaAPI.messages(messageType)); @@ -127,6 +136,8 @@ class MessageProvider with ChangeNotifier { User? user = Provider.of(_context, listen: false).user; if (user == null) throw "Cannot fetch Messages for User null"; + if (DemoData.isDemo(user.id)) return; + // get categories List? availableCategoriesJson = await Provider.of(_context, listen: false) diff --git a/refilc_kreta_api/lib/providers/note_provider.dart b/refilc_kreta_api/lib/providers/note_provider.dart index 42a232b2..11954671 100644 --- a/refilc_kreta_api/lib/providers/note_provider.dart +++ b/refilc_kreta_api/lib/providers/note_provider.dart @@ -3,6 +3,7 @@ import 'package:refilc/api/providers/database_provider.dart'; import 'package:refilc/models/user.dart'; import 'package:refilc_kreta_api/client/api.dart'; import 'package:refilc_kreta_api/client/client.dart'; +import 'package:refilc_kreta_api/demo/demo_data.dart'; import 'package:refilc_kreta_api/models/note.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; @@ -39,6 +40,7 @@ class NoteProvider with ChangeNotifier { Future fetch() async { User? user = Provider.of(_context, listen: false).user; if (user == null) throw "Cannot fetch Notes for User null"; + if (DemoData.isDemo(user.id)) return; String iss = user.instituteCode; List? notesJson = await Provider.of(_context, listen: false) diff --git a/refilc_kreta_api/lib/providers/timetable_provider.dart b/refilc_kreta_api/lib/providers/timetable_provider.dart index 932acbab..4363fae7 100644 --- a/refilc_kreta_api/lib/providers/timetable_provider.dart +++ b/refilc_kreta_api/lib/providers/timetable_provider.dart @@ -3,6 +3,7 @@ import 'package:refilc/api/providers/database_provider.dart'; import 'package:refilc/models/user.dart'; import 'package:refilc_kreta_api/client/api.dart'; import 'package:refilc_kreta_api/client/client.dart'; +import 'package:refilc_kreta_api/demo/demo_data.dart'; import 'package:refilc_kreta_api/models/lesson.dart'; import 'package:refilc_kreta_api/models/week.dart'; import 'package:flutter/foundation.dart'; @@ -73,6 +74,13 @@ class TimetableProvider with ChangeNotifier { if (week == null) return; User? user = _user.user; if (user == null) throw "Cannot fetch Lessons for User null"; + + if (DemoData.isDemo(user.id)) { + lessons = DemoData.timetable; + notifyListeners(); + return; + } + String iss = user.instituteCode; List? lessonsJson; diff --git a/refilc_mobile_ui/lib/screens/login/login_screen.dart b/refilc_mobile_ui/lib/screens/login/login_screen.dart index c40204d4..94336a44 100644 --- a/refilc_mobile_ui/lib/screens/login/login_screen.dart +++ b/refilc_mobile_ui/lib/screens/login/login_screen.dart @@ -383,6 +383,25 @@ class LoginScreenState extends State { ), ), const SizedBox(height: 19), + GestureDetector( + onTap: () { + final userProvider = Provider.of(context, listen: false); + final demoUser = User.demo(); + userProvider.addUser(demoUser); + userProvider.setUser(demoUser.id); + setSystemChrome(context); + Navigator.of(context).pushReplacementNamed('login_to_navigation'); + }, + child: Text( + 'demo_login'.i18n, + style: TextStyle( + color: AppColors.of(context).loginSecondary, + fontWeight: FontWeight.w500, + fontSize: 14.0, + ), + ), + ), + const SizedBox(height: 12), // privacy policy GestureDetector( onTap: () => PrivacyView.show(context), diff --git a/refilc_mobile_ui/lib/screens/login/login_screen.i18n.dart b/refilc_mobile_ui/lib/screens/login/login_screen.i18n.dart index da6b0e38..4363b692 100644 --- a/refilc_mobile_ui/lib/screens/login/login_screen.i18n.dart +++ b/refilc_mobile_ui/lib/screens/login/login_screen.i18n.dart @@ -34,6 +34,7 @@ extension Localization on String { "welcome_text_4": "You can also organise your notes by lesson in the built-in notebook, so you can find everything in one app.", "login_w_kreta_acc": "Log in with your e-KRÉTA account", + "demo_login": "Try demo mode", }, "hu_hu": { "username": "Felhasználónév", @@ -66,6 +67,7 @@ extension Localization on String { "welcome_text_4": "A beépített jegyzetfüzetbe órák szerint is rendezheted a jegyzeteidet, így mindent megtalálsz egy appban.", "login_w_kreta_acc": "Bejelentkezés e-KRÉTA fiókkal", + "demo_login": "Demo mód kipróbálása", }, "de_de": { "username": "Benutzername", @@ -98,6 +100,7 @@ extension Localization on String { "welcome_text_4": "You can also organise your notes by lesson in the built-in notebook, so you can find everything in one app.", "login_w_kreta_acc": "Mit e-KRÉTA-Konto anmelden", + "demo_login": "Demo-Modus ausprobieren", }, };