app: update wear pairing

This commit is contained in:
2025-08-27 17:02:37 +02:00
parent ad90b8baa0
commit 479122df7b
9 changed files with 175 additions and 12 deletions

View File

@@ -120,6 +120,7 @@ class SettingsStore {
bundle: FirkaBundle(),
child: HomeScreen(
initData,
false,
key: ValueKey('homeScreen'),
))),
);

View File

@@ -6,6 +6,7 @@ enum Attach { none, bottom, top }
class FirkaCard extends StatelessWidget {
final List<Widget> left;
final List<Widget>? center;
final List<Widget>? 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),
],
),

View File

@@ -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'),
);
}

View File

@@ -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<Map<String, dynamic>> 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);
},
),
),
],
),
),
),
),
],
);
},
);
}

View File

@@ -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<HomeScreen> createState() => _HomeScreenState();
@@ -64,6 +67,7 @@ class _HomeScreenState extends State<HomeScreen> {
List<ActiveHomePage> previousPages = List.empty(growable: true);
Widget? toast;
bool pairingDone = false;
ActiveToastType activeToast = ActiveToastType.none;
@@ -250,6 +254,14 @@ class _HomeScreenState extends State<HomeScreen> {
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;

View File

@@ -68,7 +68,7 @@ class _LoginScreenState extends State<LoginScreen> {
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) {

View File

@@ -72,7 +72,7 @@ class _WearLoginScreenState extends State<WearLoginScreen> {
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 {

View File

@@ -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