Skip to content

Commit

Permalink
support show contest problems
Browse files Browse the repository at this point in the history
  • Loading branch information
YuiHrsw committed Mar 25, 2024
1 parent 5be5437 commit 802b947
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 75 deletions.
1 change: 1 addition & 0 deletions lib/pages/exercises.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class ExercisesState extends State<Exercises> {
MaterialPageRoute(
builder: (context) => ListDetail(
listItem: AppStorage().problemlists[index],
online: false,
),
),
);
Expand Down
154 changes: 92 additions & 62 deletions lib/pages/explore.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:cf_partner/backend/cfapi/cf_helper.dart';
import 'package:cf_partner/backend/cfapi/models/contest.dart';
import 'package:cf_partner/backend/list_item.dart';
import 'package:cf_partner/pages/list_detail.dart';
import 'package:flutter/material.dart';

class ExplorePage extends StatefulWidget {
Expand Down Expand Up @@ -29,11 +31,12 @@ class ExplorePageState extends State<ExplorePage> {
@override
Widget build(BuildContext context) {
late final colorScheme = Theme.of(context).colorScheme;

late final backgroundColor = Color.alphaBlend(
colorScheme.primary.withOpacity(0.08), colorScheme.surface);
return Scaffold(
appBar: AppBar(
title: const Text(
'Explore',
'Contests',
style: TextStyle(fontWeight: FontWeight.w500, fontSize: 26),
),
actions: [
Expand Down Expand Up @@ -66,73 +69,100 @@ class ExplorePageState extends State<ExplorePage> {
itemBuilder: (context, index) {
return SizedBox(
height: 50,
child: Card(
child: Row(
children: [
const SizedBox(
width: 4,
),
Ink(
decoration: BoxDecoration(
color: colorScheme.primaryContainer,
borderRadius: BorderRadius.circular(8),
child: Card.outlined(
child: InkWell(
borderRadius: BorderRadius.circular(12),
onTap: contests[index].phase! == 'FINISHED' && !locked
? () async {
setState(() {
locked = true;
});
var problems = await CFHelper.getContestProblems(
contests[index].id!);
if (!context.mounted) return;
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ListDetail(
listItem: ListItem(
items: problems,
title: contests[index].name!,
),
online: true,
),
),
);
setState(() {
locked = false;
});
}
: null,
child: Row(
children: [
const SizedBox(
width: 4,
),
height: 20,
width: 40,
child: Center(
child: Text(
contests[index].id!.toString(),
style: TextStyle(
color: colorScheme.onPrimaryContainer,
fontWeight: FontWeight.w500),
Ink(
decoration: BoxDecoration(
color: colorScheme.primaryContainer,
borderRadius: BorderRadius.circular(8),
),
height: 20,
width: 40,
child: Center(
child: Text(
contests[index].id!.toString(),
style: TextStyle(
color: colorScheme.onPrimaryContainer,
fontWeight: FontWeight.w500),
),
),
),
),
const SizedBox(
width: 4,
),
contests[index].phase! == 'FINISHED'
? Ink(
decoration: BoxDecoration(
color: colorScheme.secondaryContainer,
borderRadius: BorderRadius.circular(8),
),
height: 20,
width: 70,
child: Center(
child: Text(
'Finished',
style: TextStyle(
color: colorScheme.onSecondaryContainer,
fontWeight: FontWeight.w500),
const SizedBox(
width: 4,
),
contests[index].phase! == 'FINISHED'
? Ink(
decoration: BoxDecoration(
color: colorScheme.secondaryContainer,
borderRadius: BorderRadius.circular(8),
),
),
)
: const SizedBox(),
const SizedBox(
width: 4,
),
Ink(
decoration: BoxDecoration(
color: colorScheme.tertiaryContainer,
borderRadius: BorderRadius.circular(8),
height: 20,
width: 70,
child: Center(
child: Text(
'Finished',
style: TextStyle(
color: colorScheme.onSecondaryContainer,
fontWeight: FontWeight.w500),
),
),
)
: const SizedBox(),
const SizedBox(
width: 4,
),
height: 20,
width: 50,
child: Center(
child: Text(
'${contests[index].durationSeconds! ~/ 3600}h${(contests[index].durationSeconds! % 3600) ~/ 60}m',
style: TextStyle(
color: colorScheme.onTertiaryContainer,
fontWeight: FontWeight.w500),
Ink(
decoration: BoxDecoration(
color: colorScheme.tertiaryContainer,
borderRadius: BorderRadius.circular(8),
),
height: 20,
width: 50,
child: Center(
child: Text(
'${contests[index].durationSeconds! ~/ 3600}h${(contests[index].durationSeconds! % 3600) ~/ 60}m',
style: TextStyle(
color: colorScheme.onTertiaryContainer,
fontWeight: FontWeight.w500),
),
),
),
const SizedBox(
width: 4,
),
),
const SizedBox(
width: 4,
),
Text(contests[index].name!)
],
Text(contests[index].name!)
],
),
),
),
);
Expand Down
6 changes: 3 additions & 3 deletions lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ class HomeState extends State<Home> {
label: Text('Exercises'),
),
NavigationRailDestination(
selectedIcon: Icon(Icons.explore),
icon: Icon(Icons.explore_outlined),
label: Text('Explore'),
selectedIcon: Icon(Icons.emoji_events),
icon: Icon(Icons.emoji_events_outlined),
label: Text('Contests'),
),
NavigationRailDestination(
selectedIcon: Icon(Icons.settings),
Expand Down
97 changes: 88 additions & 9 deletions lib/pages/list_detail.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import 'package:cf_partner/backend/cfapi/cf_helper.dart';
import 'package:cf_partner/backend/library_helper.dart';
import 'package:cf_partner/backend/list_item.dart';
import 'package:cf_partner/backend/storage.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

class ListDetail extends StatefulWidget {
const ListDetail({super.key, required this.listItem});
const ListDetail({super.key, required this.listItem, required this.online});
final ListItem listItem;
final bool online;

@override
ListDetailState createState() => ListDetailState();
Expand Down Expand Up @@ -178,20 +180,97 @@ class ListDetailState extends State<ListDetail> {
widget.listItem.items[index].name!,
style: TextStyle(
fontSize: 18,
color: mark[index] ? colorScheme.primary : null,
color: index < mark.length && mark[index]
? colorScheme.primary
: null,
),
),
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
IconButton(
onPressed: () {
LibraryHelper.removeProblemFromList(
widget.listItem, widget.listItem.items[index]);
setState(() {});
},
icon: const Icon(Icons.delete_outline)),
widget.online
? IconButton(
onPressed: () {
showDialog(
barrierColor:
colorScheme.surfaceTint.withOpacity(0.12),
useRootNavigator: false,
context: context,
builder: (BuildContext context) =>
AlertDialog(
surfaceTintColor: Colors.transparent,
title: const Text('Add to list'),
content: SizedBox(
width: 200,
height: 300,
child: ListView.builder(
itemBuilder: (context, indexList) {
return SizedBox(
height: 60,
child: InkWell(
onTap: () {
LibraryHelper.addProblemToList(
AppStorage().problemlists[
indexList],
widget
.listItem.items[index]);
Navigator.pop(context);
},
borderRadius:
BorderRadius.circular(20),
child: Row(
children: [
const SizedBox(
width: 6,
),
Ink(
decoration: BoxDecoration(
color: colorScheme
.primaryContainer,
borderRadius:
BorderRadius.circular(
20),
),
height: 50,
width: 50,
child: Icon(
Icons.star_rounded,
color: colorScheme
.onPrimaryContainer,
),
),
const SizedBox(
width: 6,
),
Text(
AppStorage()
.problemlists[indexList]
.title,
style: const TextStyle(
fontSize: 18),
),
],
),
),
);
},
itemCount:
AppStorage().problemlists.length,
),
),
),
);
},
icon: const Icon(Icons.add_circle_outline))
: IconButton(
onPressed: () {
LibraryHelper.removeProblemFromList(
widget.listItem,
widget.listItem.items[index]);
setState(() {});
},
icon: const Icon(Icons.delete_outline)),
],
)),
const SizedBox(
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class SettingsState extends State<Settings> {
),
title: const Text('CF Partner'),
trailing: const Text(
'v 0.2',
'v 0.3',
style: TextStyle(
fontSize: 16,
),
Expand Down

0 comments on commit 802b947

Please sign in to comment.