141 lines
5.2 KiB
Dart
141 lines
5.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:persistent_bottom_nav_bar_v2/persistent_bottom_nav_bar_v2.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../../../api/mhsl/breaker/getBreakers/getBreakersResponse.dart';
|
|
import '../../../model/breakers/Breaker.dart';
|
|
import '../../../model/chatList/chatListProps.dart';
|
|
import '../../../storage/base/settingsProvider.dart';
|
|
import '../../../view/pages/files/files.dart';
|
|
import '../../../view/pages/more/roomplan/roomplan.dart';
|
|
import '../../../view/pages/talk/chatList.dart';
|
|
import '../../../view/pages/timetable/timetable.dart';
|
|
import '../../../widget/centeredLeading.dart';
|
|
import 'gradeAverages/view/grade_averages_view.dart';
|
|
import 'holidays/view/holidays_view.dart';
|
|
import 'marianumMessage/view/marianum_message_list_view.dart';
|
|
|
|
import 'package:badges/badges.dart' as badges;
|
|
|
|
class AppModule {
|
|
Modules module;
|
|
String name;
|
|
Widget Function() icon;
|
|
BreakerArea breakerArea;
|
|
Widget Function() create;
|
|
|
|
AppModule(this.module, {required this.name, required this.icon, this.breakerArea = BreakerArea.global, required this.create});
|
|
|
|
static Map<Modules, AppModule> modules(BuildContext context, { showFiltered = false }) {
|
|
var settings = Provider.of<SettingsProvider>(context, listen: false);
|
|
var available = {
|
|
Modules.timetable: AppModule(
|
|
Modules.timetable,
|
|
name: 'Vertretung',
|
|
icon: () => Icon(Icons.calendar_month),
|
|
breakerArea: BreakerArea.timetable,
|
|
create: Timetable.new,
|
|
),
|
|
Modules.talk: AppModule(
|
|
Modules.talk,
|
|
name: 'Talk',
|
|
icon: () => Consumer<ChatListProps>(
|
|
builder: (context, value, child) {
|
|
if(value.primaryLoading()) return Icon(Icons.chat);
|
|
var messages = value.getRoomsResponse.data.map((e) => e.unreadMessages).reduce((a, b) => a+b);
|
|
return badges.Badge(
|
|
showBadge: messages > 0,
|
|
position: badges.BadgePosition.topEnd(top: -3, end: -3),
|
|
stackFit: StackFit.loose,
|
|
badgeStyle: badges.BadgeStyle(
|
|
padding: const EdgeInsets.all(3),
|
|
badgeColor: Theme.of(context).primaryColor,
|
|
elevation: 1,
|
|
),
|
|
badgeContent: Text('$messages', style: const TextStyle(color: Colors.white, fontSize: 10, fontWeight: FontWeight.bold)),
|
|
child: Icon(Icons.chat),
|
|
);
|
|
},
|
|
),
|
|
breakerArea: BreakerArea.talk,
|
|
create: ChatList.new,
|
|
),
|
|
Modules.files: AppModule(
|
|
Modules.files,
|
|
name: 'Files',
|
|
icon: () => Icon(Icons.folder),
|
|
breakerArea: BreakerArea.files,
|
|
create: Files.new,
|
|
),
|
|
Modules.marianumMessage: AppModule(
|
|
Modules.marianumMessage,
|
|
name: 'Marianum Message',
|
|
icon: () => Icon(Icons.newspaper),
|
|
breakerArea: BreakerArea.more,
|
|
create: MarianumMessageListView.new,
|
|
),
|
|
Modules.roomPlan: AppModule(
|
|
Modules.roomPlan,
|
|
name: 'Raumplan',
|
|
icon: () => Icon(Icons.location_pin),
|
|
breakerArea: BreakerArea.more,
|
|
create: Roomplan.new,
|
|
),
|
|
Modules.gradeAveragesCalculator: AppModule(
|
|
Modules.gradeAveragesCalculator,
|
|
name: 'Notendurschnittsrechner',
|
|
icon: () => Icon(Icons.calculate),
|
|
breakerArea: BreakerArea.more,
|
|
create: GradeAveragesView.new,
|
|
),
|
|
Modules.holidays: AppModule(
|
|
Modules.holidays,
|
|
name: 'Schulferien',
|
|
icon: () => Icon(Icons.flight),
|
|
breakerArea: BreakerArea.more,
|
|
create: HolidaysView.new,
|
|
),
|
|
};
|
|
|
|
if(!showFiltered) available.removeWhere((key, value) => settings.val().modulesSettings.hiddenModules.contains(key));
|
|
|
|
return { for (var element in settings.val().modulesSettings.moduleOrder.where((element) => available.containsKey(element))) element : available[element]! };
|
|
}
|
|
|
|
static List<AppModule> getBottomBarModules(BuildContext context) => modules(context).values.toList().getRange(0, 3).toList();
|
|
static List<AppModule> getOverhangModules(BuildContext context) => modules(context).values.skip(3).toList();
|
|
|
|
Widget toListTile(BuildContext context, {Key? key, bool isReorder = false, Function()? onVisibleChange, bool isVisible = true}) => ListTile(
|
|
key: key,
|
|
leading: CenteredLeading(icon()),
|
|
title: Text(name),
|
|
onTap: isReorder ? null : () => pushScreen(context, withNavBar: false, screen: create()),
|
|
trailing: isReorder
|
|
? Row(mainAxisSize: MainAxisSize.min, children: [
|
|
IconButton(onPressed: onVisibleChange, icon: Icon(isVisible ? Icons.visibility_outlined : Icons.visibility_off_outlined)),
|
|
Icon(Icons.drag_handle_outlined)
|
|
])
|
|
: const Icon(Icons.arrow_right),
|
|
);
|
|
|
|
PersistentTabConfig toBottomTab(BuildContext context, {Widget Function(IconData icon)? iconBuilder}) => PersistentTabConfig(
|
|
screen: Breaker(breaker: breakerArea, child: create()),
|
|
item: ItemConfig(
|
|
activeForegroundColor: Theme.of(context).primaryColor,
|
|
inactiveForegroundColor: Theme.of(context).colorScheme.secondary,
|
|
icon: icon(),
|
|
title: name
|
|
),
|
|
);
|
|
}
|
|
|
|
enum Modules {
|
|
timetable,
|
|
talk,
|
|
files,
|
|
marianumMessage,
|
|
roomPlan,
|
|
gradeAveragesCalculator,
|
|
holidays,
|
|
}
|