Skip to content
This repository has been archived by the owner on Apr 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #110 from CCXXXI/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
CCXXXI authored Oct 8, 2021
2 parents 9c9528a + 98f56f9 commit ce9e4e1
Show file tree
Hide file tree
Showing 21 changed files with 358 additions and 89 deletions.
20 changes: 20 additions & 0 deletions lib/dev/cheater_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:flutter/material.dart';

import '../toolbox/cheater.dart';

class CheaterPage extends StatelessWidget {
const CheaterPage({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: ListView(
children: ListTile.divideTiles(
context: context,
tiles: cheaters.map((e) => Text(e)),
).toList(),
),
);
}
}
36 changes: 33 additions & 3 deletions lib/dev/dev_logic.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,42 @@
import 'package:flutter_loggy/flutter_loggy.dart';
import 'package:get/get.dart';
import 'package:open_file/open_file.dart';
import 'package:path_provider/path_provider.dart';

import '../utils/gu.dart';
import '../utils/loading.dart';
import '../utils/log.dart';
import 'cheater_view.dart';
import 'trivia_view.dart';

class DevLogic extends GetxController {
void triviaOnTap() => Get.to(() => const TriviaPage());

class DevLogic extends GetxController with L {
void updateLog(_) => Get.snackbar('日志设置已更新', '重启后生效');

void logOnTap() => Get.to(() => const LoggyStreamScreen());

void triviaOnTap() => Get.to(() => const TriviaPage());

void cheaterOnTap() => Get.to(() => const CheaterPage());

void guOnTap() => gu();

void loadingOnTap() => Get.defaultDialog(
title: 'Loading',
content: Loading(),
);

final jsonFile = ''.obs;

@override
void onInit() async {
if (GetPlatform.isDesktop && !GetPlatform.isWeb) {
final baseDir = (await getApplicationSupportDirectory()).path;
l.info(jsonFile.value = '$baseDir\\shared_preferences.json');
}
super.onInit();
}

void jsonOnTap() async {
l.info((await OpenFile.open(jsonFile.value)).message);
}
}
35 changes: 29 additions & 6 deletions lib/dev/dev_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,35 @@ class DevPage extends StatelessWidget {
),
SettingsGroup(
title: '杂项',
children: [
ListTile(
title: const Text('trivia'),
onTap: logic.triviaOnTap,
),
],
children: ListTile.divideTiles(
context: context,
tiles: [
ListTile(
title: const Text('trivia'),
onTap: logic.triviaOnTap,
),
ListTile(
title: const Text('cheater'),
onTap: logic.cheaterOnTap,
),
ListTile(
title: const Text('gu'),
onTap: logic.guOnTap,
),
ListTile(
title: const Text('loading'),
onTap: logic.loadingOnTap,
),
Obx(
() => ListTile(
title: const Text('shared_preferences.json'),
subtitle: Text(logic.jsonFile.value),
enabled: logic.jsonFile.value.isNotEmpty,
onTap: logic.jsonOnTap,
),
),
],
).toList(),
),
],
),
Expand Down
7 changes: 6 additions & 1 deletion lib/dev/trivia_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ class TriviaPage extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: ListView.builder(itemBuilder: (_, idx) => getTrivia(idx)),
body: ListView(
children: ListTile.divideTiles(
context: context,
tiles: trivia,
).toList(),
),
);
}
}
13 changes: 11 additions & 2 deletions lib/home/home_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter_settings_screens/flutter_settings_screens.dart';
import 'package:get/get.dart';

import '../dev/dev_view.dart';
import '../timetable/timetable_logic.dart';
import '../utils/log.dart';

class HomeLogic extends GetxController with L {
Expand Down Expand Up @@ -36,7 +37,11 @@ class HomeLogic extends GetxController with L {
}
}

void onDestinationSelected(int idx_) => _toPage(idxMap[idx_], false);
void onDestinationSelected(int idx_) {
var realIdx = idxMap[idx_];
if (realIdx == 1 && idx.value == 1) TimetableLogic.openMenu();
_toPage(realIdx, false);
}

void onItemSelected(int idx_) {
if (isAnimating.isFalse) _toPage(idx_, true);
Expand All @@ -46,9 +51,13 @@ class HomeLogic extends GetxController with L {
if (isAnimating.isFalse) idx.value = idx_;
}

final railExtended = false.obs;

void ecnuLongPress() => Get.to(() => DevPage());

void ecnuOnPressed() => railExtended.toggle();
}

// NavigationRail: Timetable, Toolbox, Settings
// actual: Toolbox, Timetable, Settings
// NavigationRail: Timetable, Toolbox, Settings
final idxMap = [1, 0, 2];
69 changes: 51 additions & 18 deletions lib/home/home_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get/get.dart';

import '../settings/settings_view.dart';
import '../timetable/timetable_logic.dart';
import '../timetable/timetable_view.dart';
import '../toolbox/toolbox_view.dart';
import '../utils/messages.dart';
Expand All @@ -23,30 +24,55 @@ class HomePage extends StatelessWidget {
'求实创造 为人师表',
style: TextStyle(fontFamily: notoSerif),
),
leading: ecnuButton,
leading: ecnuButton(Get.theme.colorScheme.onPrimary),
actions: [
Obx(
() => Visibility(
visible: logic.idx.value == 1,
child: IconButton(
onPressed: TimetableLogic.openMenu,
icon: _labelIconsAlt[1].icon,
),
),
),
],
backgroundColor: Get.theme.colorScheme.primary,
foregroundColor: Get.theme.colorScheme.onPrimary,
)
: null,
body: Row(
children: [
if (context.isLandscape)
Obx(() {
return NavigationRail(
Obx(
() => NavigationRail(
selectedIndex: idxMap[logic.idx.value],
onDestinationSelected: logic.onDestinationSelected,
destinations: [
for (final i in idxMap)
NavigationRailDestination(
label: _labelIcons[i].label,
icon: _labelIcons[i].icon,
label: (logic.idx.value == 1
? _labelIconsAlt
: _labelIcons)[i]
.label,
icon: (logic.idx.value == 1
? _labelIconsAlt
: _labelIcons)[i]
.icon,
),
],
selectedIconTheme:
IconTheme.of(context).copyWith(color: Colors.white),
unselectedIconTheme: IconTheme.of(context)
.copyWith(color: Colors.white, opacity: .5),
leading: ecnuButton,
);
}),
selectedIconTheme: IconTheme.of(context).copyWith(
color: Get.theme.colorScheme.onSurface,
),
selectedLabelTextStyle: TextStyle(
color: Get.theme.colorScheme.onSurface,
),
extended: logic.railExtended.value,
leading: ecnuButton(
Get.theme.colorScheme.onSurface,
onPressed: logic.ecnuOnPressed,
),
),
),
Expanded(
child: context.isPortrait
? Obx(() {
Expand Down Expand Up @@ -78,7 +104,7 @@ class HomePage extends StatelessWidget {
BottomNavyBarItem(
title: labelIcon.label,
icon: labelIcon.icon,
activeColor: Colors.white,
activeColor: Get.theme.colorScheme.onSurface,
),
],
);
Expand All @@ -87,7 +113,8 @@ class HomePage extends StatelessWidget {
);
}

Widget get ecnuButton => GestureDetector(
Widget ecnuButton(Color color, {void Function()? onPressed}) =>
GestureDetector(
child: IconButton(
iconSize: 42,
icon: const ImageIcon(
Expand All @@ -96,8 +123,8 @@ class HomePage extends StatelessWidget {
width: 42,
),
),
color: Colors.white,
onPressed: () {},
color: color,
onPressed: onPressed ?? () {},
),
onLongPress: logic.ecnuLongPress,
);
Expand All @@ -112,8 +139,14 @@ class _LabelIcon {

final _labelIcons = [
_LabelIcon('工具箱', const FaIcon(FontAwesomeIcons.toolbox)),
_LabelIcon('课程表', const Icon(Icons.calendar_view_month)),
_LabelIcon('设置', const Icon(Icons.settings)),
_LabelIcon('课程表', const FaIcon(FontAwesomeIcons.th)),
_LabelIcon('设置', const FaIcon(FontAwesomeIcons.cog)),
];

final _labelIconsAlt = [
_labelIcons.first,
_LabelIcon('课程表', const FaIcon(FontAwesomeIcons.edit)),
_labelIcons.last,
];

final _pages = [ToolboxPage(), TimetablePage(), SettingsPage()];
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void initDesktop() {
setWindowTitle(appName);

logDebug('setWindowMinSize');
setWindowMinSize(const Size(300, 400));
setWindowMinSize(const Size(512, 512));

logInfo('initDesktop end.');
}
Expand Down
16 changes: 8 additions & 8 deletions lib/settings/settings_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ class SettingsPage extends StatelessWidget {
// region user
Widget get user => logic.loggedIn
? ListTile(
leading: const Icon(Icons.person),
trailing: const Icon(Icons.logout),
leading: const FaIcon(FontAwesomeIcons.user),
trailing: const FaIcon(FontAwesomeIcons.signOutAlt),
title: Text(logic.username!),
subtitle: Text(logic.id!),
)
: ListTile(
leading: const FaIcon(FontAwesomeIcons.userSecret),
trailing: const Icon(Icons.login),
trailing: const FaIcon(FontAwesomeIcons.signInAlt),
title: const Text('无名者'),
subtitle: const Text('点击以登录'),
onTap: logic.login,
Expand Down Expand Up @@ -125,14 +125,14 @@ class SettingsPage extends StatelessWidget {
: logic.latestVer.value!.isEmpty
? IconButton(
onPressed: logic.updateVerInfo,
icon: const Icon(Icons.refresh),
icon: const FaIcon(FontAwesomeIcons.redo),
)
: Badge(
child: Text(logic.latestVer.value!),
badgeContent: Icon(
badgeContent: FaIcon(
logic.updateAvailable
? Icons.new_releases_outlined
: Icons.check,
? FontAwesomeIcons.exclamation
: FontAwesomeIcons.check,
size: 16,
),
badgeColor:
Expand Down Expand Up @@ -164,7 +164,7 @@ class SettingsPage extends StatelessWidget {
// endregion

Widget get trivia => ListTile(
leading: const Icon(Icons.lightbulb),
leading: const FaIcon(FontAwesomeIcons.lightbulb),
title: randomTrivia,
);
}
6 changes: 6 additions & 0 deletions lib/settings/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ Color _c(String key) => Settings.getValue('theme.overrideColor', false)
Settings.getValue('theme.color.$key', _ecnuColorStr))
: ecnuColor;

Color _on(Color color) =>
color.computeLuminance() > .5 ? Colors.black : Colors.white;

ColorScheme get _colorScheme => (_dark ? ColorScheme.dark : ColorScheme.light)(
primary: _c('primary'),
secondary: _c('secondary'),
surface: _c('surface'),
onPrimary: _on(_c('primary')),
onSecondary: _on(_c('secondary')),
onSurface: _on(_c('surface')),
);
// endregion

Expand Down
19 changes: 10 additions & 9 deletions lib/settings/trivia.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import 'dart:math';

import 'package:dart_random_choice/dart_random_choice.dart';
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';

import '../utils/messages.dart';

final _trivia = [
final _triviaStr = [
'GitHub的仓库名通常使用分隔符`ecnu-timetable`,但为了让Dart开心,本仓库使用了下划线`ecnu_timetable`。'.s,
'此项目最初是受ECNU-class2ics启发的。'.s,
'长按校徽可以打开开发者选项。',
Expand All @@ -17,7 +18,8 @@ final _trivia = [
'由于某人不喜欢苹果严格的审核机制,此应用没有macOS或iOS版本。'.s,
'由于构建过程比较痛苦,此应用没有Linux版本。'.s,
'虽然一些字体会在用到时从Google Fonts下载,但考虑到部分用户的网络环境,常用字体文件直接打包进了应用。'.s,
r'Windows的配置文件位于`%AppData%\io.github.ccxxxi\ecnu_timetable`。'.s,
r'Windows的配置文件位于`%AppData%\io.github.ccxxxi\ecnu_timetable\shared_preferences.json`。'
.s,
'竖屏状态下,上方校训的字体固定为思源宋体,不会受字体设置影响。',
'最新版本信息需要从GitHub获取,在某些网络环境下可能会失败。'.s,
'此应用为开源项目,使用MIT许可协议。'.s,
Expand All @@ -29,13 +31,12 @@ final _trivia = [
'舔狗语录刷新后会关闭是有意为之,以此避免连点导致API请求过于频繁。'.s,
'cheater语录刷新后会关闭是因为复用了舔狗语录的代码。'.s,
'由于跨域资源共享(CORS)问题,部分功能在Web端不可用。'.s,
'点击加载动画可以换一个,虽然对实际加载速度不会有任何影响。',
'字体与图标颜色会随背景色自动调整。',
'横屏状态下,点击校徽可以展开/收起侧栏。'.s,
];

final _r = Random();
final trivia =
_triviaStr.map((e) => MarkdownBody(data: e)).toList(growable: false);

Widget getTrivia(int idx) => SizedBox(
height: 42 * 2,
child: Markdown(data: _trivia[idx % _trivia.length]),
);

Widget get randomTrivia => getTrivia(_r.nextInt(_trivia.length));
Widget get randomTrivia => randomChoice(trivia);
Loading

0 comments on commit ce9e4e1

Please sign in to comment.