Skip to content

Commit

Permalink
Timetable week view [material]
Browse files Browse the repository at this point in the history
  • Loading branch information
KimihikoAkayasaki committed Sep 1, 2024
1 parent d425d99 commit 28b2140
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 68 deletions.
2 changes: 1 addition & 1 deletion assets/resources/strings/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -1884,7 +1884,7 @@
},
{
"id": "3A9D76DA-A971-48BB-B6F6-24D6A749D1F9",
"translation": "Dzisiaj nie ma lekcji!"
"translation": "Dzisiaj bez lekcji!"
},
{
"id": "F2A3AB37-ED80-478A-AF17-76BF541CE3D2",
Expand Down
64 changes: 46 additions & 18 deletions lib/interface/components/material/data_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables
import 'package:autoscale_tabbarview/autoscale_tabbarview.dart';
import 'package:darq/darq.dart';
import 'package:dynamic_color/dynamic_color.dart';
import 'package:enum_flag/enum_flag.dart';
Expand Down Expand Up @@ -203,7 +204,26 @@ class DataPageState extends State<DataPage> with TickerProviderStateMixin {
tabAlignment:
(widget.segmentController?.scrollable ?? false) ? TabAlignment.center : TabAlignment.fill,
labelPadding: EdgeInsets.symmetric(horizontal: 20),
tabs: widget.segments!.values.select((x, _) => Tab(text: x)).toList(),
tabs: widget.segments!.values
.select((x, index) => Tab(
text: (!Share.settings.appSettings.useCupertino &&
isHorizontalPhoneMode(context) &&
widget.pageBuilder != null)
? null
: x,
child: (!Share.settings.appSettings.useCupertino &&
isHorizontalPhoneMode(context) &&
widget.pageBuilder != null)
? Text(x,
style: TextStyle(
color: tabController.index == index
? Theme.of(context).colorScheme.primary
: ((tabController.index - index).abs() < 4
? Theme.of(context).colorScheme.secondary
: Theme.of(context).colorScheme.onSurfaceVariant)))
: null,
))
.toList(),
controller: tabController,
)
: null,
Expand All @@ -214,23 +234,27 @@ class DataPageState extends State<DataPage> with TickerProviderStateMixin {
),
if (widget.pageFlags.hasFlag(DataPageType.segmented) && widget.pageBuilder != null)
SliverFillRemaining(
child: TabBarView(
controller: tabController,
viewportFraction: MediaQuery.of(context).size.width >= 640 ? (1 / 3) : 1.0,
children: List.generate(widget.segments!.length,
(index) => widget.pageBuilder!(context, widget.segments!.keys.elementAt(index))),
),
// hasScrollBody: false,
// child: Column(
// children: [
// AutoScaleTabBarView(
// controller: tabController,
// // viewportFraction: MediaQuery.of(context).size.width >= 640 ? (1 / 3) : 1.0,
// children: List.generate(widget.segments!.length,
// (index) => widget.pageBuilder!(context, widget.segments!.keys.elementAt(index))),
// ),
// ],
// ),
hasScrollBody: false,
child: isHorizontalPhoneMode(context)
? SizedBox(
height: 2000,
child: TabBarView(
controller: tabController,
viewportFraction: isHorizontalPhoneMode(context) ? (1 / 7) : 1.0,
children: List.generate(widget.segments!.length,
(index) => widget.pageBuilder!(context, widget.segments!.keys.elementAt(index))),
),
)
: Column(
children: [
AutoScaleTabBarView(
controller: tabController,
// viewportFraction: MediaQuery.of(context).size.width >= 640 ? (1 / 3) : 1.0,
children: List.generate(widget.segments!.length,
(index) => widget.pageBuilder!(context, widget.segments!.keys.elementAt(index))),
),
],
),
),
],
);
Expand Down Expand Up @@ -263,3 +287,7 @@ class DataPageState extends State<DataPage> with TickerProviderStateMixin {
});
}
}

bool isHorizontalPhoneMode(BuildContext context) {
return MediaQuery.of(context).size.width >= 640 && MediaQuery.of(context).size.height < MediaQuery.of(context).size.width;
}
14 changes: 11 additions & 3 deletions lib/interface/components/material/elements/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:format/format.dart';
import 'package:intl/intl.dart';
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
import 'package:oshi/interface/components/cupertino/application.dart';
import 'package:oshi/interface/components/material/data_page.dart';
import 'package:oshi/interface/shared/containers.dart';
import 'package:oshi/interface/shared/input.dart';
import 'package:oshi/interface/shared/pages/home.dart';
Expand Down Expand Up @@ -373,7 +374,9 @@ extension EventWidgetExtension on Event {
timeTo != null && timeTo?.hour != 0))
]))
.toList()))),
margin: EdgeInsets.only(left: 15, top: 5, bottom: 5, right: 20),
margin: !Share.settings.appSettings.useCupertino && isHorizontalPhoneMode(context)
? EdgeInsets.only(left: 5, right: 5)
: EdgeInsets.only(left: 15, top: 5, bottom: 5, right: 20),
child: ConstrainedBox(
constraints: BoxConstraints(
maxHeight: (animation?.value ?? 0) < CupertinoContextMenu.animationOpensAt ? double.infinity : 100,
Expand Down Expand Up @@ -418,7 +421,10 @@ extension EventWidgetExtension on Event {
flex: 2,
child: Text(
titleString,
maxLines: 1,
maxLines:
!Share.settings.appSettings.useCupertino && isHorizontalPhoneMode(context)
? 3
: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 17,
Expand Down Expand Up @@ -740,7 +746,9 @@ extension LessonWidgetExtension on TimetableLesson {
isCanceled && !isMovedLesson))
]),
true)))),
margin: EdgeInsets.only(left: 15, top: 3, bottom: 3, right: 20),
margin: !Share.settings.appSettings.useCupertino && isHorizontalPhoneMode(context)
? EdgeInsets.only(left: 5, right: 5)
: EdgeInsets.only(left: 15, top: 3, bottom: 3, right: 20),
child: Opacity(
opacity: (isCanceled ||
(date == DateTime.now().asDate() &&
Expand Down
98 changes: 52 additions & 46 deletions lib/interface/shared/pages/timetable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:flutter/material.dart';
import 'package:format/format.dart';
import 'package:intl/intl.dart';
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
import 'package:oshi/interface/components/material/data_page.dart';
import 'package:oshi/interface/components/shim/elements/event.dart';
import 'package:oshi/interface/components/shim/page_routes.dart';
import 'package:oshi/interface/shared/containers.dart';
Expand Down Expand Up @@ -167,52 +168,57 @@ class _TimetablePageState extends VisibilityAwareState<TimetablePage> {
.toList(),
);

return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
(searchController.text.isEmpty ? lessonsWidget : Container()),
if (!Share.settings.appSettings.useCupertino &&
(homeworksToday.isNotEmpty || eventsToday.isNotEmpty || teachersAbsentToday.isNotEmpty))
Padding(
padding: const EdgeInsets.only(bottom: 10),
child: Divider(indent: 23, endIndent: 23),
),
// Homeworks for today
Visibility(
visible: homeworksToday.isNotEmpty,
child: Container(
margin: EdgeInsets.only(top: Share.settings.appSettings.useCupertino ? 20 : 0),
child: CardContainer(
filled: false,
regularOverride: true,
additionalDividerMargin: 5,
children: homeworksToday.isNotEmpty ? homeworksToday : [Text('')],
))),
// Events for today
Visibility(
visible: eventsToday.isNotEmpty,
child: Container(
margin: EdgeInsets.only(top: Share.settings.appSettings.useCupertino ? 20 : 0),
child: CardContainer(
filled: false,
regularOverride: true,
additionalDividerMargin: 5,
children: eventsToday.isNotEmpty ? eventsToday : [Text('')],
))),
// Teachers absent today
Visibility(
visible: teachersAbsentToday.isNotEmpty,
child: Container(
margin: EdgeInsets.only(top: Share.settings.appSettings.useCupertino ? 20 : 0),
child: CardContainer(
filled: false,
regularOverride: true,
additionalDividerMargin: 5,
children: teachersAbsentToday.isNotEmpty ? teachersAbsentToday : [Text('')],
))),
],
return MediaQuery(
data: MediaQuery.of(context).copyWith(
textScaler:
TextScaler.linear(!Share.settings.appSettings.useCupertino && isHorizontalPhoneMode(context) ? 0.7 : 1.0)),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
(searchController.text.isEmpty ? lessonsWidget : Container()),
if (!Share.settings.appSettings.useCupertino &&
(homeworksToday.isNotEmpty || eventsToday.isNotEmpty || teachersAbsentToday.isNotEmpty))
Padding(
padding: const EdgeInsets.only(bottom: 10),
child: Divider(indent: 23, endIndent: 23),
),
// Homeworks for today
Visibility(
visible: homeworksToday.isNotEmpty,
child: Container(
margin: EdgeInsets.only(top: Share.settings.appSettings.useCupertino ? 20 : 0),
child: CardContainer(
filled: false,
regularOverride: true,
additionalDividerMargin: 5,
children: homeworksToday.isNotEmpty ? homeworksToday : [Text('')],
))),
// Events for today
Visibility(
visible: eventsToday.isNotEmpty,
child: Container(
margin: EdgeInsets.only(top: Share.settings.appSettings.useCupertino ? 20 : 0),
child: CardContainer(
filled: false,
regularOverride: true,
additionalDividerMargin: 5,
children: eventsToday.isNotEmpty ? eventsToday : [Text('')],
))),
// Teachers absent today
Visibility(
visible: teachersAbsentToday.isNotEmpty,
child: Container(
margin: EdgeInsets.only(top: Share.settings.appSettings.useCupertino ? 20 : 0),
child: CardContainer(
filled: false,
regularOverride: true,
additionalDividerMargin: 5,
children: teachersAbsentToday.isNotEmpty ? teachersAbsentToday : [Text('')],
))),
],
),
);
}

Expand Down

0 comments on commit 28b2140

Please sign in to comment.