Skip to content

Commit

Permalink
Merge pull request #127 from DislikesSchool/build-homepage-update
Browse files Browse the repository at this point in the history
Build homepage update
  • Loading branch information
vyPal authored Sep 20, 2023
2 parents c98a641 + b8545a0 commit b3b1887
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 67 deletions.
177 changes: 118 additions & 59 deletions lib/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ import 'package:url_launcher/url_launcher.dart';
class HomePage extends StatefulWidget {
final SessionManager sessionManager;
final Function reLogin;
final ValueChanged<int> onDestinationSelected;

const HomePage(
{super.key, required this.sessionManager, required this.reLogin});
{super.key,
required this.sessionManager,
required this.reLogin,
required this.onDestinationSelected});

@override
State<HomePage> createState() => HomePageState();
Expand Down Expand Up @@ -317,9 +321,13 @@ class HomePageState extends State<HomePage> {
final response = await dio
.get(
'https://api.github.com/repos/DislikesSchool/EduPage2/releases/latest')
.catchError((r) {
.catchError((obj) {
return Response(
requestOptions: RequestOptions(path: r.path), statusCode: 500);
requestOptions: RequestOptions(
path:
'https://api.github.com/repos/DislikesSchool/EduPage2/releases/latest'),
statusCode: 500,
);
});
if (response.statusCode == 500) {
return;
Expand Down Expand Up @@ -489,30 +497,35 @@ class HomePageState extends State<HomePage> {
children: [
for (Map<String, dynamic> lesson
in apidataTT["lessons"])
Card(
child: Padding(
padding: const EdgeInsets.all(10),
child: Column(
children: [
Text(
lesson["period"]["name"] + ".",
style:
const TextStyle(fontSize: 10),
),
Text(
lesson["subject"]["short"],
style:
const TextStyle(fontSize: 20),
),
Text(
lesson["classrooms"].length > 0
? lesson["classrooms"][0]
["short"]
: "?",
style:
const TextStyle(fontSize: 14),
),
],
GestureDetector(
onTap: () {
widget.onDestinationSelected(1);
},
child: Card(
child: Padding(
padding: const EdgeInsets.all(10),
child: Column(
children: [
Text(
lesson["period"]["name"] + ".",
style:
const TextStyle(fontSize: 10),
),
Text(
lesson["subject"]["short"],
style:
const TextStyle(fontSize: 20),
),
Text(
lesson["classrooms"].length > 0
? lesson["classrooms"][0]
["short"]
: "?",
style:
const TextStyle(fontSize: 14),
),
],
),
),
),
),
Expand Down Expand Up @@ -669,12 +682,72 @@ class HomePageState extends State<HomePage> {
const Padding(
padding: EdgeInsets.only(top: 15),
),
InkWell(
highlightColor: Colors.transparent,
splashColor: Colors.transparent,
child: ListTile(
leading: const Icon(Icons.bolt_rounded),
title: Text(local!.homeQuickstart),
trailing: Transform.scale(
scale: 0.75,
child: Switch(
value: quickstart,
onChanged: (bool value) {
sharedPreferences.setBool('quickstart', value);
setState(() {
quickstart = value;
});
},
),
),
onTap: () {
sharedPreferences.setBool('quickstart', !quickstart);
setState(() {
quickstart = !quickstart;
});
},
),
),
/*
const Divider(),
ListTile(
leading: const Icon(Icons.language),
title: const Text('Language'),
trailing: SizedBox(
height: 32,
child: Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(4),
),
padding: const EdgeInsets.symmetric(horizontal: 8),
child: DropdownButton<Locale>(
value: Localizations.localeOf(context),
onChanged: (Locale? locale) {
if (locale != null) {
// Handle locale selection
}
},
icon: const Icon(Icons.arrow_drop_down),
underline: Container(),
style: Theme.of(context).textTheme.titleMedium,
items: AppLocalizations.supportedLocales
.map((locale) => DropdownMenuItem<Locale>(
value: locale,
child: Text(locale.languageCode),
))
.toList(),
),
),
),
),*/
const Divider(),
InkWell(
highlightColor: Colors.transparent,
splashColor: Colors.transparent,
child: ListTile(
leading: const Icon(Icons.lunch_dining_rounded),
title: Text(local!.homeSetupICanteen),
title: Text(local.homeSetupICanteen),
onTap: () {
Navigator.push(
context,
Expand All @@ -690,37 +763,6 @@ class HomePageState extends State<HomePage> {
},
),
),
InkWell(
highlightColor: Colors.transparent,
splashColor: Colors.transparent,
child: Badge(
label: Text(local.homePreview),
alignment: AlignmentDirectional.topEnd,
child: ListTile(
leading: const Icon(Icons.bolt_rounded),
title: Text(local.homeQuickstart),
trailing: Transform.scale(
scale: 0.75,
child: Switch(
value: quickstart,
onChanged: (bool value) {
sharedPreferences.setBool('quickstart', value);
setState(() {
quickstart = value;
});
},
),
),
onTap: () {
sharedPreferences.setBool('quickstart', !quickstart);
setState(() {
quickstart = !quickstart;
});
},
),
),
),
const Divider(),
InkWell(
highlightColor: Colors.transparent,
splashColor: Colors.transparent,
Expand All @@ -735,6 +777,23 @@ class HomePageState extends State<HomePage> {
},
),
),
const Divider(),
InkWell(
highlightColor: Colors.transparent,
splashColor: Colors.transparent,
child: ListTile(
leading: const Icon(Icons.discord),
title: const Text("EduPage2 Discord"),
onTap: () async {
final url = Uri.parse('https://discord.gg/xy5nqWa2kQ');
if (await canLaunchUrl(url)) {
await launchUrl(url);
} else {
throw 'Could not launch $url';
}
},
),
),
const AboutListTile(
icon: Icon(Icons.info_outline),
applicationName: 'EduPage2',
Expand Down
12 changes: 10 additions & 2 deletions lib/load.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ class LoadingScreenState extends State<LoadingScreen> {
progress = 0.5;
loaderText = local!.loadLoggedIn;
setState(() {});
sessionManager.set('user', response.data);
if (response.data.runtimeType == Map) {
sessionManager.set('user', jsonEncode(response.data));
} else {
sessionManager.set('user', response.data);
}
return loadTimetable();
} else {
failedToken = token;
Expand Down Expand Up @@ -202,7 +206,11 @@ class LoadingScreenState extends State<LoadingScreen> {
progress = 0.6;
loaderText = local!.loadLoggedIn;
setState(() {});
sessionManager.set('user', response.data);
if (response.data.runtimeType == Map) {
sessionManager.set('user', jsonEncode(response.data));
} else {
sessionManager.set('user', response.data);
}
return loadTimetable();
} else {
runningInit = false;
Expand Down
20 changes: 14 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ class PageBaseState extends State<PageBase> {
super.setState(fn);
}

void _onDestinationSelected(int index) {
setState(() {
_selectedIndex = index;
});
}

initRemoteConfig() async {
final remoteConfig = FirebaseRemoteConfig.instance;
await remoteConfig.setConfigSettings(RemoteConfigSettings(
Expand Down Expand Up @@ -165,12 +171,14 @@ class PageBaseState extends State<PageBase> {
index: _selectedIndex,
children: <Widget>[
HomePage(
sessionManager: sessionManager,
reLogin: () {
setState(() {
loaded = false;
});
}),
sessionManager: sessionManager,
reLogin: () {
setState(() {
loaded = false;
});
},
onDestinationSelected: _onDestinationSelected,
),
TimeTablePage(
sessionManager: sessionManager,
),
Expand Down

0 comments on commit b3b1887

Please sign in to comment.