icon packs

This commit is contained in:
55nknown 2022-11-14 10:08:05 +01:00
parent fcb1d8d6d9
commit 5d37de897f
6 changed files with 73 additions and 37 deletions

View File

@ -73,7 +73,7 @@ class LiveCardProvider extends ChangeNotifier {
switch (currentState) { switch (currentState) {
case LiveCardState.duringLesson: case LiveCardState.duringLesson:
return { return {
"icon": currentLesson != null ? SubjectIcon.resolve(subject: currentLesson?.subject).name : "book", "icon": currentLesson != null ? SubjectIcon.resolveName(subject: currentLesson?.subject) : "book",
"index": currentLesson != null ? '${currentLesson!.lessonIndex}. ' : "", "index": currentLesson != null ? '${currentLesson!.lessonIndex}. ' : "",
"title": currentLesson != null ? ShortSubject.resolve(subject: currentLesson?.subject).capital() : "", "title": currentLesson != null ? ShortSubject.resolve(subject: currentLesson?.subject).capital() : "",
"subtitle": currentLesson?.room.replaceAll("_", " ") ?? "", "subtitle": currentLesson?.room.replaceAll("_", " ") ?? "",

View File

@ -15,7 +15,7 @@ const settingsDB = DatabaseStruct("settings", {
"vibration_strength": int, "ab_weeks": int, "swap_ab_weeks": int, "vibration_strength": int, "ab_weeks": int, "swap_ab_weeks": int,
"notifications": int, "notifications_bitfield": int, "notification_poll_interval": int, // notifications "notifications": int, "notifications_bitfield": int, "notification_poll_interval": int, // notifications
"x_filc_id": String, "graph_class_avg": int, "presentation_mode": int, "bell_delay": int, "bell_delay_enabled": int, "x_filc_id": String, "graph_class_avg": int, "presentation_mode": int, "bell_delay": int, "bell_delay_enabled": int,
"grade_opening_fun": int, "grade_opening_fun": int, "icon_pack": String,
}); });
const usersDB = DatabaseStruct( const usersDB = DatabaseStruct(
"users", {"id": String, "name": String, "username": String, "password": String, "institute_code": String, "student": String, "role": int}); "users", {"id": String, "name": String, "username": String, "password": String, "institute_code": String, "student": String, "role": int});

View File

@ -1,20 +1,40 @@
import 'package:filcnaplo/icons/filc_icons.dart'; import 'package:filcnaplo/icons/filc_icons.dart';
import 'package:filcnaplo/models/icon_pack.dart';
import 'package:filcnaplo/models/settings.dart';
import 'package:filcnaplo/utils/format.dart'; import 'package:filcnaplo/utils/format.dart';
import 'package:filcnaplo_kreta_api/models/subject.dart'; import 'package:filcnaplo_kreta_api/models/subject.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
typedef SubjectIconVariants = Map<IconPack, IconData>;
class SubjectIconData { class SubjectIconData {
final IconData data; final SubjectIconVariants data;
final String name; // for iOS live activities compatibilty final String name; // for iOS live activities compatibilty
SubjectIconData({ SubjectIconData({
this.data = CupertinoIcons.rectangle_grid_2x2, this.data = const {
IconPack.material: Icons.widgets_outlined,
IconPack.cupertino: CupertinoIcons.rectangle_grid_2x2,
},
this.name = "square.grid.2x2", this.name = "square.grid.2x2",
}); });
} }
SubjectIconVariants createIcon({required IconData material, required IconData cupertino}) {
return {
IconPack.material: material,
IconPack.cupertino: cupertino,
};
}
class SubjectIcon { class SubjectIcon {
static SubjectIconData resolve({Subject? subject, String? subjectName}) { static String resolveName({Subject? subject, String? subjectName}) => _resolve(subject: subject, subjectName: subjectName).name;
static IconData resolveVariant({Subject? subject, String? subjectName, required BuildContext context}) =>
_resolve(subject: subject, subjectName: subjectName).data[Provider.of<SettingsProvider>(context, listen: false).iconPack]!;
static SubjectIconData _resolve({Subject? subject, String? subjectName}) {
assert(!(subject == null && subjectName == null)); assert(!(subject == null && subjectName == null));
String name = (subject?.name ?? subjectName ?? "").toLowerCase().specialChars().trim(); String name = (subject?.name ?? subjectName ?? "").toLowerCase().specialChars().trim();
@ -22,65 +42,70 @@ class SubjectIcon {
// todo: check for categories // todo: check for categories
if (RegExp("mate(k|matika)").hasMatch(name) || category == "matematika") { if (RegExp("mate(k|matika)").hasMatch(name) || category == "matematika") {
return SubjectIconData(data: CupertinoIcons.function, name: "function"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.function, material: Icons.calculate_outlined), name: "function");
} else if (RegExp("magyar nyelv|nyelvtan").hasMatch(name)) { } else if (RegExp("magyar nyelv|nyelvtan").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.textformat_alt, name: "textformat.alt"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.textformat_alt, material: Icons.spellcheck_outlined), name: "textformat.alt");
} else if (RegExp("irodalom").hasMatch(name)) { } else if (RegExp("irodalom").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.book, name: "book"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.book, material: Icons.menu_book_outlined), name: "book");
} else if (RegExp("tor(i|tenelem)").hasMatch(name)) { } else if (RegExp("tor(i|tenelem)").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.compass, name: "safari"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.compass, material: Icons.hourglass_empty_outlined), name: "safari");
} else if (RegExp("foldrajz").hasMatch(name)) { } else if (RegExp("foldrajz").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.map, name: "map"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.map, material: Icons.public_outlined), name: "map");
} else if (RegExp("rajz|muvtori|muveszet|vizualis").hasMatch(name)) { } else if (RegExp("rajz|muvtori|muveszet|vizualis").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.paintbrush, name: "paintbrush"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.paintbrush, material: Icons.palette_outlined), name: "paintbrush");
} else if (RegExp("fizika").hasMatch(name)) { } else if (RegExp("fizika").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.lightbulb, name: "lightbulb"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.lightbulb, material: Icons.emoji_objects_outlined), name: "lightbulb");
} else if (RegExp("^enek|zene|szolfezs|zongora|korus").hasMatch(name)) { } else if (RegExp("^enek|zene|szolfezs|zongora|korus").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.music_note, name: "music.note"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.music_note, material: Icons.music_note_outlined), name: "music.note");
} else if (RegExp("^tes(i|tneveles)|sport").hasMatch(name)) { } else if (RegExp("^tes(i|tneveles)|sport").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.sportscourt, name: "sportscourt"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.sportscourt, material: Icons.sports_soccer_outlined), name: "sportscourt");
} else if (RegExp("kemia").hasMatch(name)) { } else if (RegExp("kemia").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.lab_flask, name: "testtube.2"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.lab_flask, material: Icons.science_outlined), name: "testtube.2");
} else if (RegExp("biologia").hasMatch(name)) { } else if (RegExp("biologia").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.paw, name: "pawprint"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.paw, material: Icons.pets_outlined), name: "pawprint");
} else if (RegExp("kornyezet|termeszet ?(tudomany|ismeret)|hon( es nep)?ismeret").hasMatch(name)) { } else if (RegExp("kornyezet|termeszet ?(tudomany|ismeret)|hon( es nep)?ismeret").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.arrow_3_trianglepath, name: "arrow.3.trianglepath"); return SubjectIconData(
data: createIcon(cupertino: CupertinoIcons.arrow_3_trianglepath, material: Icons.eco_outlined), name: "arrow.3.trianglepath");
} else if (RegExp("(hit|erkolcs)tan|vallas|etika").hasMatch(name)) { } else if (RegExp("(hit|erkolcs)tan|vallas|etika").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.heart, name: "heart"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.heart, material: Icons.favorite_border_outlined), name: "heart");
} else if (RegExp("penzugy").hasMatch(name)) { } else if (RegExp("penzugy").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.money_dollar, name: "dollarsign"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.money_dollar, material: Icons.savings_outlined), name: "dollarsign");
} else if (RegExp("informatika|szoftver|iroda|digitalis").hasMatch(name)) { } else if (RegExp("informatika|szoftver|iroda|digitalis").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.device_laptop, name: "laptopcomputer"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.device_laptop, material: Icons.computer_outlined), name: "laptopcomputer");
} else if (RegExp("prog").hasMatch(name)) { } else if (RegExp("prog").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.chevron_left_slash_chevron_right, name: "chevron.left.forwardslash.chevron.right"); return SubjectIconData(
data: createIcon(cupertino: CupertinoIcons.chevron_left_slash_chevron_right, material: Icons.code_outlined),
name: "chevron.left.forwardslash.chevron.right");
} else if (RegExp("halozat").hasMatch(name)) { } else if (RegExp("halozat").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.antenna_radiowaves_left_right, name: "antenna.radiowaves.left.and.right"); return SubjectIconData(
data: createIcon(cupertino: CupertinoIcons.antenna_radiowaves_left_right, material: Icons.wifi_tethering_outlined),
name: "antenna.radiowaves.left.and.right");
} else if (RegExp("szinhaz").hasMatch(name)) { } else if (RegExp("szinhaz").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.hifispeaker, name: "hifispeaker"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.hifispeaker, material: Icons.theater_comedy_outlined), name: "hifispeaker");
} else if (RegExp("film|media").hasMatch(name)) { } else if (RegExp("film|media").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.film, name: "film"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.film, material: Icons.theaters_outlined), name: "film");
} else if (RegExp("elektro(tech)?nika").hasMatch(name)) { } else if (RegExp("elektro(tech)?nika").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.bolt, name: "bolt"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.bolt, material: Icons.electrical_services_outlined), name: "bolt");
} else if (RegExp("gepesz|mernok|ipar").hasMatch(name)) { } else if (RegExp("gepesz|mernok|ipar").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.wrench, name: "wrench"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.wrench, material: Icons.precision_manufacturing_outlined), name: "wrench");
} else if (RegExp("technika").hasMatch(name)) { } else if (RegExp("technika").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.hammer, name: "hammer"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.hammer, material: Icons.build_outlined), name: "hammer");
} else if (RegExp("tanc").hasMatch(name)) { } else if (RegExp("tanc").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.music_mic, name: "music.mic"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.music_mic, material: Icons.speaker_outlined), name: "music.mic");
} else if (RegExp("filozofia").hasMatch(name)) { } else if (RegExp("filozofia").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.bubble_left, name: "bubble.left"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.bubble_left, material: Icons.psychology_outlined), name: "bubble.left");
} else if (RegExp("osztaly(fonoki|kozosseg)").hasMatch(name) || name == "ofo") { } else if (RegExp("osztaly(fonoki|kozosseg)").hasMatch(name) || name == "ofo") {
return SubjectIconData(data: CupertinoIcons.group, name: "person.3"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.group, material: Icons.groups_outlined), name: "person.3");
} else if (RegExp("gazdasag").hasMatch(name)) { } else if (RegExp("gazdasag").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.chart_pie, name: "chart.pie"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.chart_pie, material: Icons.account_balance_outlined), name: "chart.pie");
} else if (RegExp("szorgalom").hasMatch(name)) { } else if (RegExp("szorgalom").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.checkmark_seal, name: "checkmark.seal"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.checkmark_seal, material: Icons.verified_outlined), name: "checkmark.seal");
} else if (RegExp("magatartas").hasMatch(name)) { } else if (RegExp("magatartas").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.smiley, name: "face.smiling"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.smiley, material: Icons.emoji_people_outlined), name: "face.smiling");
} else if (RegExp("angol|nemet|francia|olasz|orosz|spanyol|latin|kinai|nyelv").hasMatch(name)) { } else if (RegExp("angol|nemet|francia|olasz|orosz|spanyol|latin|kinai|nyelv").hasMatch(name)) {
return SubjectIconData(data: CupertinoIcons.globe, name: "globe"); return SubjectIconData(data: createIcon(cupertino: CupertinoIcons.globe, material: Icons.translate_outlined), name: "globe");
} else if (RegExp("linux").hasMatch(name)) { } else if (RegExp("linux").hasMatch(name)) {
return SubjectIconData(data: FilcIcons.linux); return SubjectIconData(data: createIcon(material: FilcIcons.linux, cupertino: FilcIcons.linux));
} }
return SubjectIconData(); return SubjectIconData();

View File

@ -0,0 +1 @@
enum IconPack { material, cupertino }

View File

@ -3,6 +3,7 @@ import 'dart:developer';
import 'package:filcnaplo/api/providers/database_provider.dart'; import 'package:filcnaplo/api/providers/database_provider.dart';
import 'package:filcnaplo/models/config.dart'; import 'package:filcnaplo/models/config.dart';
import 'package:filcnaplo/models/icon_pack.dart';
import 'package:filcnaplo/theme/colors/accent.dart'; import 'package:filcnaplo/theme/colors/accent.dart';
import 'package:filcnaplo/theme/colors/dark_mobile.dart'; import 'package:filcnaplo/theme/colors/dark_mobile.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -56,6 +57,7 @@ class SettingsProvider extends ChangeNotifier {
bool _bellDelayEnabled; bool _bellDelayEnabled;
int _bellDelay; int _bellDelay;
bool _gradeOpeningFun; bool _gradeOpeningFun;
IconPack _iconPack;
SettingsProvider({ SettingsProvider({
required String language, required String language,
@ -82,6 +84,7 @@ class SettingsProvider extends ChangeNotifier {
required bool bellDelayEnabled, required bool bellDelayEnabled,
required int bellDelay, required int bellDelay,
required bool gradeOpeningFun, required bool gradeOpeningFun,
required IconPack iconPack,
}) : _language = language, }) : _language = language,
_startPage = startPage, _startPage = startPage,
_rounding = rounding, _rounding = rounding,
@ -105,7 +108,8 @@ class SettingsProvider extends ChangeNotifier {
_presentationMode = presentationMode, _presentationMode = presentationMode,
_bellDelayEnabled = bellDelayEnabled, _bellDelayEnabled = bellDelayEnabled,
_bellDelay = bellDelay, _bellDelay = bellDelay,
_gradeOpeningFun = gradeOpeningFun; _gradeOpeningFun = gradeOpeningFun,
_iconPack = iconPack;
factory SettingsProvider.fromMap(Map map) { factory SettingsProvider.fromMap(Map map) {
Map<String, Object?>? configMap; Map<String, Object?>? configMap;
@ -147,6 +151,7 @@ class SettingsProvider extends ChangeNotifier {
bellDelayEnabled: map["bell_delay_enabled"] == 1, bellDelayEnabled: map["bell_delay_enabled"] == 1,
bellDelay: map["bell_delay"], bellDelay: map["bell_delay"],
gradeOpeningFun: map["grade_opening_fun"] == 1, gradeOpeningFun: map["grade_opening_fun"] == 1,
iconPack: Map.fromEntries(IconPack.values.map((e) => MapEntry(e.name, e)))[map["icon_pack"]]!,
); );
} }
@ -179,6 +184,7 @@ class SettingsProvider extends ChangeNotifier {
"bell_delay_enabled": _bellDelayEnabled ? 1 : 0, "bell_delay_enabled": _bellDelayEnabled ? 1 : 0,
"bell_delay": _bellDelay, "bell_delay": _bellDelay,
"grade_opening_fun": _gradeOpeningFun ? 1 : 0, "grade_opening_fun": _gradeOpeningFun ? 1 : 0,
"icon_pack": _iconPack.name,
}; };
} }
@ -214,6 +220,7 @@ class SettingsProvider extends ChangeNotifier {
bellDelayEnabled: false, bellDelayEnabled: false,
bellDelay: 0, bellDelay: 0,
gradeOpeningFun: true, gradeOpeningFun: true,
iconPack: IconPack.cupertino,
); );
} }
@ -242,6 +249,7 @@ class SettingsProvider extends ChangeNotifier {
bool get bellDelayEnabled => _bellDelayEnabled; bool get bellDelayEnabled => _bellDelayEnabled;
int get bellDelay => _bellDelay; int get bellDelay => _bellDelay;
bool get gradeOpeningFun => _gradeOpeningFun; bool get gradeOpeningFun => _gradeOpeningFun;
IconPack get iconPack => _iconPack;
Future<void> update( Future<void> update(
BuildContext context, { BuildContext context, {
@ -271,6 +279,7 @@ class SettingsProvider extends ChangeNotifier {
bool? bellDelayEnabled, bool? bellDelayEnabled,
int? bellDelay, int? bellDelay,
bool? gradeOpeningFun, bool? gradeOpeningFun,
IconPack? iconPack,
}) async { }) async {
if (language != null && language != _language) _language = language; if (language != null && language != _language) _language = language;
if (startPage != null && startPage != _startPage) _startPage = startPage; if (startPage != null && startPage != _startPage) _startPage = startPage;
@ -298,6 +307,7 @@ class SettingsProvider extends ChangeNotifier {
if (bellDelay != null && bellDelay != _bellDelay) _bellDelay = bellDelay; if (bellDelay != null && bellDelay != _bellDelay) _bellDelay = bellDelay;
if (bellDelayEnabled != null && bellDelayEnabled != _bellDelayEnabled) _bellDelayEnabled = bellDelayEnabled; if (bellDelayEnabled != null && bellDelayEnabled != _bellDelayEnabled) _bellDelayEnabled = bellDelayEnabled;
if (gradeOpeningFun != null && gradeOpeningFun != _gradeOpeningFun) _gradeOpeningFun = gradeOpeningFun; if (gradeOpeningFun != null && gradeOpeningFun != _gradeOpeningFun) _gradeOpeningFun = gradeOpeningFun;
if (iconPack != null && iconPack != _iconPack) _iconPack = iconPack;
database ??= Provider.of<DatabaseProvider>(context, listen: false); database ??= Provider.of<DatabaseProvider>(context, listen: false);
if (store) await database.store.storeSettings(this); if (store) await database.store.storeSettings(this);

View File

@ -80,7 +80,7 @@ class GradeTile extends StatelessWidget {
child: Padding( child: Padding(
padding: leadingPadding, padding: leadingPadding,
child: Icon( child: Icon(
SubjectIcon.resolve(subject: grade.subject).data, SubjectIcon.resolveVariant(subject: grade.subject, context: context),
size: 28.0, size: 28.0,
color: AppColors.of(context).text.withOpacity(.75), color: AppColors.of(context).text.withOpacity(.75),
), ),