Skip to content

Commit

Permalink
Merge pull request #68 from univerx/dev
Browse files Browse the repository at this point in the history
0.4.3
  • Loading branch information
31b4 authored Aug 27, 2024
2 parents 1614433 + a18ae97 commit 3a5e6d6
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 55 deletions.
12 changes: 6 additions & 6 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 8;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_TEAM = S4AJ4WBQ76;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
Expand All @@ -480,7 +480,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.3.2;
MARKETING_VERSION = 0.4.2;
PRODUCT_BUNDLE_IDENTIFIER = com.31b4.univerx;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -659,7 +659,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 8;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_TEAM = S4AJ4WBQ76;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
Expand All @@ -668,7 +668,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.3.2;
MARKETING_VERSION = 0.4.2;
MTL_ENABLE_DEBUG_INFO = NO;
PRODUCT_BUNDLE_IDENTIFIER = com.31b4.univerx;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -688,7 +688,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 8;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_TEAM = S4AJ4WBQ76;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
Expand All @@ -697,7 +697,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.3.2;
MARKETING_VERSION = 0.4.2;
MTL_ENABLE_DEBUG_INFO = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.31b4.univerx;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
4 changes: 2 additions & 2 deletions lib/database/database_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DatabaseHelper {
Future<Database> get database async {
if (_database != null) return _database!;

_database = await _initDB('test_11.db');
_database = await _initDB('test_12.db');

return _database!;
}
Expand Down Expand Up @@ -60,7 +60,7 @@ class DatabaseHelper {

await db.execute('''
CREATE TABLE Exam (
exam_id INTEGER PRIMARY KEY AUTOINCREMENT,
exam_id INTEGER,
class_id INTEGER,
title TEXT,
description TEXT,
Expand Down
2 changes: 1 addition & 1 deletion lib/features/common/widgets/profile_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class DrawerMenu extends StatelessWidget {
),
SizedBox(height: 10.0),
const Text(
'v0.4.2 beta',
'v0.4.3 beta',
style: TextStyle(
color: Colors.white,
fontSize: 12.0,
Expand Down
11 changes: 4 additions & 7 deletions lib/features/home/homePage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,16 @@ class _HomeState extends State<Home> with RouteAware {

Map<String, List<Widget>> _groupEventsByDate(List<Exam> exams, List<Assignment> assignments) {
final Map<String, List<Widget>> groupedEvents = {};
final now = DateTime(2000, 1, 1, 1, 1);
final now = DateTime.now();
//print exams
for (final exam in exams) {
print(exam.title);
}

for (final exam in exams) {
if (exam.startTime.isAfter(now) || exam.startTime.isAtSameMomentAs(now)) {
final String date = DateFormat('yyyy MMM d').format(exam.startTime);
if (groupedEvents.containsKey(date)) {
groupedEvents[date]!.add(UpcomingContainer(
homeContext: context,
title: Exam.getFormattedTitle(exam.title),
title: Exam.formatText(30,exam.title),
date: date,
isExam: true,
onDelete: () => _deleteExam(exam),
Expand All @@ -153,7 +150,7 @@ class _HomeState extends State<Home> with RouteAware {
groupedEvents[date] = [
UpcomingContainer(
homeContext: context,
title: Exam.getFormattedTitle(exam.title),
title: Exam.formatText(40,exam.title),
date: date,
isExam: true,
onDelete: () => _deleteExam(exam),
Expand Down Expand Up @@ -245,7 +242,7 @@ class _HomeState extends State<Home> with RouteAware {
// remove events from sorted entries that are in the past
sortedEntries.removeWhere((entry) {
final date = DateFormat('yyyy MMM d').parse(entry.key);
return date.isBefore(DateTime(2022));
return date.isBefore(DateTime.now());
});

return sortedEntries.map((entry) {
Expand Down
2 changes: 1 addition & 1 deletion lib/features/neptun_login/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class _LoginPageState extends State<LoginPage> {
right: 0,
child: Center(
child: Text(
'v0.4.2 beta',
'v0.4.3 beta',
style: TextStyle(
color: Colors.grey,
fontSize: 12.0,
Expand Down
16 changes: 15 additions & 1 deletion lib/models/class.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:intl/intl.dart';
import 'package:univerx/models/exam.dart';

class Class {
final int id;
Expand Down Expand Up @@ -41,7 +42,7 @@ class Class {
}

// ------------------ Helper functions ------------------
factory Class.fromICS(String icsData) {
static Object fromICS(String icsData) {
final lines = icsData.split('\n');
DateTime? startTime;
DateTime? endTime;
Expand All @@ -59,6 +60,19 @@ class Class {
location = line.split(':')[1];
}
}
//if title starts with vizsga return with Exam()
if (title!.contains('Vizsga')) {
return Exam(
id: -1,
classId: -1,
title: title!,
description: "",
startTime: startTime!,
endTime: endTime!,
location: location!,
isUserCreated: false,
);
}

return Class(
id: -1,
Expand Down
38 changes: 24 additions & 14 deletions lib/models/exam.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,7 @@ class Exam {
return formatter.format(startTime);
}

static String getFormattedTitle(String title) {
if (title.startsWith('[Óra]')) {
title = title.substring(title.indexOf(']') + 2, title.length);
var sv = title.split(" ");
title = sv[0] + " " + sv[1];
}
else if (title.startsWith('[Vizsga]')) {
var sv = title.split(" ");
title = sv[0] + " " + sv[1] + " " +sv[2];
}


return title;
}

Class convertExamToClass() {
return Class(
id: classId,
Expand All @@ -71,4 +58,27 @@ class Exam {
isUserCreated: isUserCreated,
);
}
static String formatText(int limit, String text) {
var words = text.split(' ');
var result = '';

if (words[0].length > limit){
return words[0].substring(0,limit-3) + "...";
}


for (var word in words) {
if (result.length + word.length <= limit) {
result += word + ' ';
} else {
//result += '...';
break;
}
}
//if last character is a comma, remove it
if (result[result.length - 2] == ',') {
result = result.substring(0, result.length - 2);
}
return result;
}
}
79 changes: 56 additions & 23 deletions lib/services/neptun_ICS_fetching.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import 'dart:convert';
import 'dart:math';
import 'package:http/http.dart' as http;
import 'package:univerx/database/database_helper.dart';
import 'package:univerx/models/class.dart';
import 'package:univerx/models/exam.dart';
import 'package:univerx/services/neptun_API_fetching.dart';

class ParsedData {
final List<Class> classes;
final List<Exam> exams;

ParsedData({required this.classes, required this.exams});
}

class EventService {
final String url;
Expand All @@ -11,50 +21,70 @@ class EventService {

Future<void> fetchAndUpdateIcs() async {

// Fetch events from .ics file
List<Class> newEvents = await fetchEvents();
if (newEvents.isEmpty) {
return;
}
// Fetch events from .ics file
ParsedData newEvents = await fetchEvents();
if (newEvents.classes.isEmpty && newEvents.exams.isEmpty) {
return;
}

//classes and exams
List<Class> newClasses = newEvents.classes;
List<Exam> newExams = newEvents.exams;
print(newExams);
print(newClasses);

// Fetch existing events from database
DatabaseHelper dbHelper = DatabaseHelper.instance;
// Fetch existing events from database
DatabaseHelper dbHelper = DatabaseHelper.instance;


// Clear the existing events in the database
await dbHelper.deleteNeptunClasses();
// Clear the existing events in the database
await dbHelper.deleteNeptunClasses();
await dbHelper.deleteNeptunExams();

// Save new events to the database
for (Class newEvent in newEvents) {
await dbHelper.insertClass(newEvent);
// Save new events to the database
for (Class newEvent in newClasses) {
await dbHelper.insertClass(newEvent);
}
for (Exam newExam in newExams) {
await dbHelper.insertExam(newExam);
}
}
}

Future<List<Class>> fetchEvents() async {
Future<ParsedData> fetchEvents() async {
try {
final response = await http.get(Uri.parse(url));
if (response.statusCode == 200) {
final icsData = response.body;
final events = parseICS(icsData);
events.sort((a, b) => a.startTime.compareTo(b.startTime)); // Sort events by start time
return events;
ParsedData parsed = parseICS(icsData);
parsed.exams.sort((a, b) => a.startTime.compareTo(b.startTime)); // Sort events by start time
parsed.classes.sort((a, b) => a.startTime.compareTo(b.startTime)); // Sort events by start time


return parsed;
} else {
throw Exception('Failed to load events');
}
} catch (e) {
print('Error fetching events: $e');
return [];
return null!;
}
}

List<Class> parseICS(String icsData) {
ParsedData parseICS(String icsData) {
try {
final events = <Class>[];
ParsedData parsedData = ParsedData(classes: [], exams: []);
final eventStrings = icsData.split('BEGIN:VEVENT');
for (var eventString in eventStrings.skip(1)) {
events.add(Class.fromICS(eventString));
// if object type exam add to exam else add to event
final event = Class.fromICS(eventString);
if (event.runtimeType == Exam) {
parsedData.exams.add(event as Exam);
}
else if (event.runtimeType == Class) {
parsedData.classes.add(event as Class);
}
}
return events;
return parsedData;
} catch (e) {
print('Error parsing ICS data: $e');
rethrow;
Expand Down Expand Up @@ -100,7 +130,10 @@ class EventService {
break;
}
}

//if last character is a comma, remove it
if (result[result.length - 2] == ',') {
result = result.substring(0, result.length - 2);
}
return result;
}

Expand Down

0 comments on commit 3a5e6d6

Please sign in to comment.