changed everything from filcnaplo to refilc finally

This commit is contained in:
Kima
2024-02-24 20:12:25 +01:00
parent 0d1c7b7143
commit 1171e3aaaf
655 changed files with 38728 additions and 44967 deletions

View File

@@ -0,0 +1,15 @@
import 'package:flutter/material.dart';
class ColorUtils {
static Color stringToColor(String str) {
int hash = 0;
for (var i = 0; i < str.length; i++) {
hash = str.codeUnitAt(i) + ((hash << 5) - hash);
}
return HSLColor.fromAHSL(1, hash % 360, .8, .75).toColor();
}
static Color foregroundColor(Color color) =>
color.computeLuminance() >= .5 ? Colors.black : Colors.white;
}

View File

@@ -0,0 +1,80 @@
import 'dart:math';
import 'package:refilc_kreta_api/models/week.dart';
import 'package:flutter/widgets.dart';
import 'package:intl/intl.dart';
import 'package:i18n_extension/i18n_widget.dart';
import 'package:html/parser.dart';
import 'format.i18n.dart';
extension StringFormatUtils on String {
String specialChars() => replaceAll("é", "e")
.replaceAll("á", "a")
.replaceAll("ó", "o")
.replaceAll("ő", "o")
.replaceAll("ö", "o")
.replaceAll("ú", "u")
.replaceAll("ű", "u")
.replaceAll("ü", "u")
.replaceAll("í", "i");
String capital() => isNotEmpty ? this[0].toUpperCase() + substring(1) : "";
String capitalize() => split(" ").map((w) => w.capital()).join(" ");
String escapeHtml() {
String htmlString = this;
htmlString = htmlString.replaceAll("\r", "");
htmlString = htmlString.replaceAll(RegExp(r'<br ?/?>'), "\n");
htmlString = htmlString.replaceAll(RegExp(r'<p ?>'), "");
htmlString = htmlString.replaceAll(RegExp(r'</p ?>'), "\n");
var document = parse(htmlString);
return document.body?.text.trim() ?? htmlString;
}
String limit(int max) {
if (length <= max) return this;
return '${substring(0, min(length, 14))}';
}
}
extension DateFormatUtils on DateTime {
String format(BuildContext context,
{bool timeOnly = false, bool forceToday = false, bool weekday = false}) {
// Time only
if (timeOnly) return DateFormat("HH:mm").format(this);
DateTime now = DateTime.now();
if (now.year == year && now.month == month && now.day == day) {
if (hour == 0 && minute == 0 && second == 0 || forceToday)
return "Today".i18n;
return DateFormat("HH:mm").format(this);
}
if (now.year == year &&
now.month == month &&
now.subtract(const Duration(days: 1)).day == day)
return "Yesterday".i18n;
if (now.year == year &&
now.month == month &&
now.add(const Duration(days: 1)).day == day) return "Tomorrow".i18n;
String formatString;
// If date is current week, show only weekday
if (Week.current().start.isBefore(this) &&
Week.current().end.isAfter(this)) {
formatString = "EEEE";
} else {
if (year == now.year) {
formatString = "MMM dd.";
} else {
formatString = "yy/MM/dd";
} // ex. 21/01/01
if (weekday) formatString += " (EEEE)"; // ex. (monday)
}
return DateFormat(formatString, I18n.of(context).locale.toString())
.format(this)
.capital();
}
}

View File

@@ -0,0 +1,27 @@
import 'package:i18n_extension/i18n_extension.dart';
extension Localization on String {
static final _t = Translations.byLocale("hu_hu") +
{
"en_en": {
"Today": "Today",
"Yesterday": "Yesterday",
"Tomorrow": "Tomorrow",
},
"hu_hu": {
"Today": "Ma",
"Yesterday": "Tegnap",
"Tomorrow": "Holnap",
},
"de_de": {
"Today": "Heute",
"Yesterday": "Gestern",
"Tomorrow": "Morgen",
}
};
String get i18n => localize(this, _t);
String fill(List<Object> params) => localizeFill(this, params);
String plural(int value) => localizePlural(value, this, _t);
String version(Object modifier) => localizeVersion(modifier, this, _t);
}

42
refilc/lib/utils/jwt.dart Normal file
View File

@@ -0,0 +1,42 @@
import 'dart:convert';
import 'package:refilc/models/user.dart';
class JwtUtils {
static Map? decodeJwt(String jwt) {
var parts = jwt.split(".");
if (parts.length != 3) return null;
if (parts[1].length % 4 == 2) {
parts[1] += "==";
} else if (parts[1].length % 4 == 3) {
parts[1] += "=";
}
try {
var payload = utf8.decode(base64Url.decode(parts[1]));
return jsonDecode(payload);
} catch (error) {
// ignore: avoid_print
print("ERROR: JwtUtils.decodeJwt: $error");
}
return null;
}
static String? getNameFromJWT(String jwt) {
var jwtData = decodeJwt(jwt);
return jwtData?["name"];
}
static Role? getRoleFromJWT(String jwt) {
var jwtData = decodeJwt(jwt);
switch (jwtData?["role"]) {
case "Tanulo":
return Role.student;
case "Gondviselo":
return Role.parent;
}
return null;
}
}

View File

@@ -0,0 +1,6 @@
import 'dart:io';
class PlatformUtils {
static bool get isDesktop => Platform.isWindows || Platform.isMacOS || Platform.isLinux;
static bool get isMobile => !isDesktop;
}

View File

@@ -0,0 +1,44 @@
import 'dart:developer';
import 'package:refilc_kreta_api/models/absence.dart';
import 'package:refilc_kreta_api/models/lesson.dart';
import 'package:refilc_kreta_api/models/week.dart';
import 'package:refilc_kreta_api/providers/timetable_provider.dart';
import 'package:flutter/cupertino.dart';
import 'package:provider/provider.dart';
class ReverseSearch {
static Future<Lesson?> getLessonByAbsence(
Absence absence, BuildContext context) async {
final timetableProvider =
Provider.of<TimetableProvider>(context, listen: false);
List<Lesson> lessons = [];
final week = Week.fromDate(absence.date);
try {
await timetableProvider.fetch(week: week);
} catch (e) {
log("[ERROR] getLessonByAbsence: $e");
}
lessons = timetableProvider.getWeek(week) ?? [];
// Find absence lesson in timetable
Lesson lesson = lessons.firstWhere(
(l) =>
_sameDate(l.date, absence.date) &&
l.subject.id == absence.subject.id &&
l.lessonIndex == absence.lessonIndex.toString(),
orElse: () => Lesson.fromJson({'isEmpty': true}),
);
if (lesson.isEmpty) {
return null;
} else {
return lesson;
}
}
// difference.inDays is not reliable
static bool _sameDate(DateTime a, DateTime b) =>
(a.year == b.year && a.month == b.month && a.day == b.day);
}