diff --git a/firka/lib/helpers/settings/setting.dart b/firka/lib/helpers/settings/setting.dart index 94374cf2..623814ee 100644 --- a/firka/lib/helpers/settings/setting.dart +++ b/firka/lib/helpers/settings/setting.dart @@ -120,6 +120,7 @@ class SettingsStore { bundle: FirkaBundle(), child: HomeScreen( initData, + false, key: ValueKey('homeScreen'), ))), ); diff --git a/firka/lib/helpers/ui/firka_card.dart b/firka/lib/helpers/ui/firka_card.dart index e3de9011..dd6e2ef0 100644 --- a/firka/lib/helpers/ui/firka_card.dart +++ b/firka/lib/helpers/ui/firka_card.dart @@ -6,6 +6,7 @@ enum Attach { none, bottom, top } class FirkaCard extends StatelessWidget { final List left; + final List? center; final List? right; final Widget? extra; final Attach? attached; @@ -13,6 +14,7 @@ class FirkaCard extends StatelessWidget { const FirkaCard( {required this.left, + this.center, this.right, this.extra, this.attached, @@ -55,6 +57,7 @@ class FirkaCard extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row(children: left), + Row(children: center ?? []), Row(children: right), ], ), @@ -90,6 +93,7 @@ class FirkaCard extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row(children: left), + Row(children: center ?? []), Row(children: right), ], ), diff --git a/firka/lib/l10n b/firka/lib/l10n index 868bd395..54dc9e43 160000 --- a/firka/lib/l10n +++ b/firka/lib/l10n @@ -1 +1 @@ -Subproject commit 868bd39590f2358c0a4cd776dc99641c3e1f47b1 +Subproject commit 54dc9e43bf9b9593cd15c5dc8fb6a6c5256feb0b diff --git a/firka/lib/main.dart b/firka/lib/main.dart index 724d7ca9..0fb4a612 100644 --- a/firka/lib/main.dart +++ b/firka/lib/main.dart @@ -18,7 +18,6 @@ import 'package:firka/ui/phone/pages/error/error_page.dart'; import 'package:firka/ui/phone/screens/debug/debug_screen.dart'; import 'package:firka/ui/phone/screens/home/home_screen.dart'; import 'package:firka/ui/phone/screens/login/login_screen.dart'; -import 'package:firka/ui/phone/screens/wear_login/wear_login_screen.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -259,13 +258,16 @@ class InitializationScreen extends StatelessWidget { switch (msg["id"]) { case "ping": - debugPrint("[Phone -> Watch]: pong"); - watch.sendMessage({"id": "pong"}); - navigatorKey.currentState?.push( - MaterialPageRoute( - builder: (context) => WearLoginScreen(initData), - ), - ); + if (initData.tokenCount > 0) { + debugPrint("[Phone -> Watch]: pong"); + watch.sendMessage({"id": "pong"}); + navigatorKey.currentState?.push( + MaterialPageRoute( + builder: (context) => HomeScreen(initData, true, + model: msg["model"] as String), + ), + ); + } } }); } @@ -278,6 +280,7 @@ class InitializationScreen extends StatelessWidget { } else { screen = HomeScreen( initData, + false, key: ValueKey('homeScreen'), ); } diff --git a/firka/lib/ui/phone/pages/extras/main_wear_pair.dart b/firka/lib/ui/phone/pages/extras/main_wear_pair.dart index e69de29b..9ffb5129 100644 --- a/firka/lib/ui/phone/pages/extras/main_wear_pair.dart +++ b/firka/lib/ui/phone/pages/extras/main_wear_pair.dart @@ -0,0 +1,142 @@ +import 'package:firka/helpers/debug_helper.dart'; +import 'package:firka/helpers/ui/firka_card.dart'; +import 'package:firka/main.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_svg/flutter_svg.dart'; +import 'package:watch_connectivity/watch_connectivity.dart'; + +import '../../../model/style.dart'; + +void showWearBottomSheet( + BuildContext context, AppInitialization data, String model) async { + final watch = WatchConnectivity(); + final timetable = await data.client + .getTimeTable(timeNow(), timeNow().add(Duration(days: 7))); + + if (timetable.err != null) { + return; + } + + List> timetableArray = List.empty(growable: true); + + for (var l in timetable.response!) { + timetableArray.add(l.toJson()); + } + + showModalBottomSheet( + context: context, + elevation: 100, + isScrollControlled: true, + enableDrag: false, + isDismissible: false, + backgroundColor: Colors.transparent, + barrierColor: Colors.transparent, + constraints: BoxConstraints( + maxHeight: MediaQuery.of(context).size.height * 0.47, + ), + builder: (BuildContext context) { + return Stack( + children: [ + Positioned.fill( + child: GestureDetector( + onTap: () => Navigator.pop(context), + behavior: HitTestBehavior.opaque, + child: Container(color: Colors.transparent), + ), + ), + Align( + alignment: Alignment.bottomCenter, + child: Container( + decoration: BoxDecoration( + color: appStyle.colors.card, + borderRadius: BorderRadius.vertical(top: Radius.circular(16)), + ), + child: Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + children: [ + SvgPicture.asset("assets/images/wear_pair.svg"), + SizedBox(height: 32), + Center( + child: Text(data.l10n.pairing, + style: appStyle.fonts.H_14px + .apply(color: appStyle.colors.secondary)), + ), + Center( + child: Text(model, + style: appStyle.fonts.H_H2 + .apply(color: appStyle.colors.textPrimary)), + ), + Center( + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 6), + child: Text( + data.l10n.pairing_description, + style: appStyle.fonts.B_14R + .apply(color: appStyle.colors.textPrimary), + textAlign: TextAlign.center, + ), + ), + ), + SizedBox(height: 32), + SizedBox( + width: MediaQuery.of(context).size.width / 1.1, + child: GestureDetector( + child: FirkaCard( + left: [], + center: [ + Text( + data.l10n.pair, + style: appStyle.fonts.B_14R + .apply(color: appStyle.colors.textSecondary), + ) + ], + color: appStyle.colors.accent, + ), + onTap: () { + watch.sendMessage({ + "id": "init_data", + // "timetable": timetableArray, + "auth": { + "studentId": data.client.model.studentId, + "iss": data.client.model.iss, + "idToken": data.client.model.idToken, + "accessToken": data.client.model.accessToken, + "refreshToken": data.client.model.refreshToken, + "expiryDate": data.client.model.expiryDate! + .millisecondsSinceEpoch, + }, + }); + }, + ), + ), + SizedBox(height: 8), + SizedBox( + width: MediaQuery.of(context).size.width / 1.1, + child: GestureDetector( + child: FirkaCard( + left: [], + center: [ + Text( + data.l10n.cancel, + style: appStyle.fonts.B_14R + .apply(color: appStyle.colors.textSecondary), + ) + ], + color: appStyle.colors.buttonSecondaryFill, + ), + onTap: () { + Navigator.pop(context); + }, + ), + ), + ], + ), + ), + ), + ), + ], + ); + }, + ); +} diff --git a/firka/lib/ui/phone/screens/home/home_screen.dart b/firka/lib/ui/phone/screens/home/home_screen.dart index 63e3707e..906a35a7 100644 --- a/firka/lib/ui/phone/screens/home/home_screen.dart +++ b/firka/lib/ui/phone/screens/home/home_screen.dart @@ -5,6 +5,7 @@ import 'package:firka/helpers/api/client/kreta_client.dart'; import 'package:firka/helpers/api/exceptions/token.dart'; import 'package:firka/main.dart'; import 'package:firka/ui/model/style.dart'; +import 'package:firka/ui/phone/pages/extras/main_wear_pair.dart'; import 'package:firka/ui/phone/pages/home/home_grades.dart'; import 'package:firka/ui/phone/pages/home/home_main.dart'; import 'package:firka/ui/phone/pages/home/home_timetable_mo.dart'; @@ -27,8 +28,10 @@ import '../login/login_screen.dart'; class HomeScreen extends StatefulWidget { final AppInitialization data; + final bool watchPair; + final String? model; - const HomeScreen(this.data, {super.key}); + const HomeScreen(this.data, this.watchPair, {this.model, super.key}); @override State createState() => _HomeScreenState(); @@ -64,6 +67,7 @@ class _HomeScreenState extends State { List previousPages = List.empty(growable: true); Widget? toast; + bool pairingDone = false; ActiveToastType activeToast = ActiveToastType.none; @@ -250,6 +254,14 @@ class _HomeScreenState extends State { Widget build(BuildContext context) { _updateSystemUI(); // Update system UI on every build, to compensate for the android system being dumb + if (widget.watchPair && !pairingDone) { + Timer.run(() { + showWearBottomSheet(context, widget.data, widget.model!); + + // pairingDone = true; + }); + } + if (_fetching) { setState(() { activeToast = ActiveToastType.fetching; diff --git a/firka/lib/ui/phone/screens/login/login_screen.dart b/firka/lib/ui/phone/screens/login/login_screen.dart index 84afa46b..db2f8286 100644 --- a/firka/lib/ui/phone/screens/login/login_screen.dart +++ b/firka/lib/ui/phone/screens/login/login_screen.dart @@ -68,7 +68,7 @@ class _LoginScreenState extends State { if (!mounted) return NavigationDecision.prevent; Navigator.of(context).pushAndRemoveUntil( - MaterialPageRoute(builder: (context) => HomeScreen(widget.data)), + MaterialPageRoute(builder: (context) => HomeScreen(widget.data, false)), (route) => false, // Remove all previous routes ); } catch (ex) { diff --git a/firka/lib/ui/phone/screens/wear_login/wear_login_screen.dart b/firka/lib/ui/phone/screens/wear_login/wear_login_screen.dart index 3eab020e..a18b232a 100644 --- a/firka/lib/ui/phone/screens/wear_login/wear_login_screen.dart +++ b/firka/lib/ui/phone/screens/wear_login/wear_login_screen.dart @@ -72,7 +72,7 @@ class _WearLoginScreenState extends State { if (widget.data.tokenCount > 0) { Navigator.of(context).pushAndRemoveUntil( MaterialPageRoute( - builder: (context) => HomeScreen(widget.data)), + builder: (context) => HomeScreen(widget.data, false)), (route) => false, // Remove all previous routes ); } else { diff --git a/firka/pubspec.yaml b/firka/pubspec.yaml index cb13e0d1..96e13829 100644 --- a/firka/pubspec.yaml +++ b/firka/pubspec.yaml @@ -91,6 +91,7 @@ flutter: - assets/images/carousel/ - assets/images/icons/ - assets/images/background.png + - assets/images/wear_pair.svg - assets/icons/ - assets/majesticons/ - assets/firka.i