Rename everything filcnaplo-related to refilc
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
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;
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:filcnaplo_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();
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
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);
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:filcnaplo/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;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
import 'dart:io';
|
||||
|
||||
class PlatformUtils {
|
||||
static bool get isDesktop => Platform.isWindows || Platform.isMacOS || Platform.isLinux;
|
||||
static bool get isMobile => !isDesktop;
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:filcnaplo_kreta_api/models/absence.dart';
|
||||
import 'package:filcnaplo_kreta_api/models/lesson.dart';
|
||||
import 'package:filcnaplo_kreta_api/models/week.dart';
|
||||
import 'package:filcnaplo_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);
|
||||
}
|
||||
Reference in New Issue
Block a user