forked from firka/firka
fix(wear): sync lessons and grades to the watch
This commit is contained in:
@@ -15,7 +15,7 @@ import 'package:firka/core/bloc/settings_cubit.dart';
|
||||
import 'package:firka/core/bloc/theme_cubit.dart';
|
||||
import 'package:firka/core/firka_bundle.dart';
|
||||
import 'package:firka/routing/app_router.dart';
|
||||
import 'package:firka/services/watch_sync_helper.dart';
|
||||
import 'package:firka/services/wear_sync_helper.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
import 'package:firka/ui/phone/pages/extras/main_wear_pair.dart';
|
||||
import 'package:firka/l10n/app_localizations.dart';
|
||||
|
||||
@@ -7,7 +7,7 @@ import "package:firka/app/initialization.dart";
|
||||
import "package:firka/services/fcm_service.dart";
|
||||
import "package:firka/services/notification_delivery_service.dart";
|
||||
import "package:firka/services/progress_notification_service.dart";
|
||||
import "package:firka/services/watch_sync_helper.dart";
|
||||
import "package:firka/services/wear_sync_helper.dart";
|
||||
import "package:firka/ui/phone/screens/themes/builtin_theme_id.dart";
|
||||
import "package:firka_common/ui/theme/core_theme.dart";
|
||||
|
||||
|
||||
Submodule firka/lib/l10n updated: e01d6c090d...4756fdfddc
@@ -1,114 +0,0 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:watch_connectivity/watch_connectivity.dart';
|
||||
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/services/wear_sync_cache.dart';
|
||||
import 'package:firka/api/client/kreta_client.dart';
|
||||
|
||||
/// Helper class for Wear OS sync (Android).
|
||||
class WatchSyncHelper {
|
||||
static const _wearSyncChannel = MethodChannel('app.firka/wear_sync');
|
||||
static WatchConnectivity? _androidWatchConnectivity;
|
||||
static WatchConnectivity get _watchConnectivityAndroid {
|
||||
_androidWatchConnectivity ??= WatchConnectivity();
|
||||
return _androidWatchConnectivity!;
|
||||
}
|
||||
|
||||
/// Callback for Watch pairing message events (Android Wear OS pairing flow).
|
||||
/// Set by initialization_screen.dart to handle "ping" messages for Watch pairing.
|
||||
static void Function(Map<String, dynamic> message)? onWatchMessage;
|
||||
|
||||
/// Send a fire-and-forget message to Watch via watch_connectivity (Android).
|
||||
/// The payload is sent as a JSON string for reliable transport.
|
||||
static Future<void> sendMessageToWatch(Map<String, dynamic> message) async {
|
||||
if (!Platform.isAndroid) return;
|
||||
await _watchConnectivityAndroid.sendMessage(<String, dynamic>{
|
||||
'data': jsonEncode(message),
|
||||
});
|
||||
}
|
||||
|
||||
/// Starts the Wear sync foreground service (Android only). Call after writing initial cache.
|
||||
/// [appDirPath] is the application documents directory path (for the background isolate).
|
||||
static Future<void> startWearSyncService(
|
||||
String cachePath,
|
||||
String appDirPath,
|
||||
) async {
|
||||
if (!Platform.isAndroid) return;
|
||||
await _wearSyncChannel.invokeMethod<void>(
|
||||
'startWearSyncService',
|
||||
<String, dynamic>{'cachePath': cachePath, 'appDirPath': appDirPath},
|
||||
);
|
||||
}
|
||||
|
||||
/// Builds fresh sync payload, writes cache, and starts the Wear sync service (Android only).
|
||||
/// Use when enabling Wear OS support or on app launch when support is already enabled.
|
||||
static Future<void> startWearSyncServiceWithFreshCache(
|
||||
KretaClient client,
|
||||
String appDirPath,
|
||||
) async {
|
||||
if (!Platform.isAndroid) return;
|
||||
final payload = await buildWearSyncPayload(client);
|
||||
if (payload == null) return;
|
||||
final path = await getWearSyncCachePath();
|
||||
await writeWearSyncCache(path, payload);
|
||||
await startWearSyncService(path, appDirPath);
|
||||
}
|
||||
|
||||
/// Sets the method call handler for getLocalizedString (Android). Call once when initData is ready.
|
||||
static void setWearSyncMethodCallHandler() {
|
||||
if (!Platform.isAndroid) return;
|
||||
_wearSyncChannel.setMethodCallHandler((MethodCall call) async {
|
||||
if (call.method == 'getLocalizedString') {
|
||||
final key = call.arguments as String?;
|
||||
return getLocalizedString(key);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/// Returns the localized string for [key] from l10n. Used by Kotlin for notification title/text.
|
||||
static String? getLocalizedString(String? key) {
|
||||
if (key == null || !initDone) return null;
|
||||
switch (key) {
|
||||
case 'wearSyncNotificationTitle':
|
||||
return initData.l10n.wearSyncNotificationTitle;
|
||||
case 'wearSyncNotificationText':
|
||||
return initData.l10n.wearSyncNotificationText;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Stops the Wear sync foreground service (Android only).
|
||||
static Future<void> stopWearSyncService() async {
|
||||
if (!Platform.isAndroid) return;
|
||||
await _wearSyncChannel.invokeMethod<void>('stopWearSyncService');
|
||||
}
|
||||
|
||||
/// Runs sync in foreground: fetches timetable + grades, writes cache, sends sync_data to watch.
|
||||
/// Used when app is in foreground and watch sends request_sync (Android) or equivalent.
|
||||
static Future<void> runWearSyncInForeground(KretaClient client) async {
|
||||
final payload = await buildWearSyncPayload(client);
|
||||
if (payload == null) return;
|
||||
final path = await getWearSyncCachePath();
|
||||
await writeWearSyncCache(path, payload);
|
||||
await sendMessageToWatch(<String, dynamic>{'id': 'sync_data', ...payload});
|
||||
}
|
||||
|
||||
/// Stream of messages from the watch (Android: watch_connectivity). Use for request_sync etc.
|
||||
static Stream<Map<String, dynamic>> get watchMessageStream {
|
||||
if (!Platform.isAndroid) return const Stream.empty();
|
||||
return _watchConnectivityAndroid.messageStream.map((m) {
|
||||
final map = Map<String, dynamic>.from(m);
|
||||
final data = map['data'];
|
||||
if (data is String) {
|
||||
return jsonDecode(data) as Map<String, dynamic>;
|
||||
}
|
||||
return map;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import 'package:path_provider/path_provider.dart'
|
||||
show getApplicationDocumentsDirectory;
|
||||
|
||||
import 'package:firka/api/client/kreta_client.dart';
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
import 'package:firka/core/debug_helper.dart';
|
||||
|
||||
/// File name for the Wear OS sync cache written by the phone (Dart isolate or main).
|
||||
@@ -28,15 +27,15 @@ const String wearSyncCacheFileName = 'wear_sync_cache.json';
|
||||
/// Builds the sync payload (same shape as init_data / sync_data): timetable (2 weeks), grades, lastSyncAt.
|
||||
Future<Map<String, dynamic>?> buildWearSyncPayload(KretaClient client) async {
|
||||
final (start, end) = getWearSyncTimetableRange();
|
||||
await client.getLessons(start, end);
|
||||
await client.getGrades();
|
||||
final lessons = await client.getLessons(start, end);
|
||||
final grades = await client.getGrades();
|
||||
final now = timeNow();
|
||||
final timetable = (<Lesson>[]).map((l) => l.toJson()).toList();
|
||||
final grades = (<Grade>[]).map((g) => g.toJson()).toList();
|
||||
final timetable = lessons.map((l) => l.toJson()).toList();
|
||||
final gradesJson = grades.map((g) => g.toJson()).toList();
|
||||
return {
|
||||
'lastSyncAt': now.toUtc().toIso8601String(),
|
||||
'timetable': timetable,
|
||||
'grades': grades,
|
||||
'grades': gradesJson,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
@@ -5,30 +6,33 @@ import 'package:flutter/services.dart';
|
||||
import 'package:watch_connectivity/watch_connectivity.dart';
|
||||
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/api/client/kreta_client.dart';
|
||||
import 'package:firka/services/wear_sync_cache.dart';
|
||||
import 'package:firka/api/client/kreta_client.dart';
|
||||
|
||||
/// Helper for Wear OS ↔ phone communication (Android only).
|
||||
/// Handles sync service, watch_connectivity messages, and sending data to the watch.
|
||||
class WearSyncHelper {
|
||||
WearSyncHelper._();
|
||||
|
||||
/// Helper class for Wear OS sync (Android).
|
||||
class WatchSyncHelper {
|
||||
static const _wearSyncChannel = MethodChannel('app.firka/wear_sync');
|
||||
static WatchConnectivity? _watchConnectivity;
|
||||
static WatchConnectivity get _watchConnectivityInstance {
|
||||
_watchConnectivity ??= WatchConnectivity();
|
||||
return _watchConnectivity!;
|
||||
static WatchConnectivity? _androidWatchConnectivity;
|
||||
static WatchConnectivity get _watchConnectivityAndroid {
|
||||
_androidWatchConnectivity ??= WatchConnectivity();
|
||||
return _androidWatchConnectivity!;
|
||||
}
|
||||
|
||||
/// Sends a fire-and-forget message to the Wear OS watch (payload sent as JSON string).
|
||||
/// Callback for Watch pairing message events (Android Wear OS pairing flow).
|
||||
/// Set by initialization_screen.dart to handle "ping" messages for Watch pairing.
|
||||
static void Function(Map<String, dynamic> message)? onWatchMessage;
|
||||
|
||||
/// Send a fire-and-forget message to Watch via watch_connectivity (Android).
|
||||
/// The payload is sent as a JSON string for reliable transport.
|
||||
static Future<void> sendMessageToWatch(Map<String, dynamic> message) async {
|
||||
if (!Platform.isAndroid) return;
|
||||
await _watchConnectivityInstance.sendMessage(<String, dynamic>{
|
||||
await _watchConnectivityAndroid.sendMessage(<String, dynamic>{
|
||||
'data': jsonEncode(message),
|
||||
});
|
||||
}
|
||||
|
||||
/// Starts the Wear sync foreground service (Android only).
|
||||
/// Starts the Wear sync foreground service (Android only). Call after writing initial cache.
|
||||
/// [appDirPath] is the application documents directory path (for the background isolate).
|
||||
static Future<void> startWearSyncService(
|
||||
String cachePath,
|
||||
String appDirPath,
|
||||
@@ -41,6 +45,7 @@ class WearSyncHelper {
|
||||
}
|
||||
|
||||
/// Builds fresh sync payload, writes cache, and starts the Wear sync service (Android only).
|
||||
/// Use when enabling Wear OS support or on app launch when support is already enabled.
|
||||
static Future<void> startWearSyncServiceWithFreshCache(
|
||||
KretaClient client,
|
||||
String appDirPath,
|
||||
@@ -85,8 +90,8 @@ class WearSyncHelper {
|
||||
}
|
||||
|
||||
/// Runs sync in foreground: fetches timetable + grades, writes cache, sends sync_data to watch.
|
||||
/// Used when app is in foreground and watch sends request_sync (Android) or equivalent.
|
||||
static Future<void> runWearSyncInForeground(KretaClient client) async {
|
||||
if (!Platform.isAndroid) return;
|
||||
final payload = await buildWearSyncPayload(client);
|
||||
if (payload == null) return;
|
||||
final path = await getWearSyncCachePath();
|
||||
@@ -94,10 +99,10 @@ class WearSyncHelper {
|
||||
await sendMessageToWatch(<String, dynamic>{'id': 'sync_data', ...payload});
|
||||
}
|
||||
|
||||
/// Stream of messages from the Wear OS watch. Empty when not on Android.
|
||||
/// Stream of messages from the watch (Android: watch_connectivity). Use for request_sync etc.
|
||||
static Stream<Map<String, dynamic>> get watchMessageStream {
|
||||
if (!Platform.isAndroid) return const Stream.empty();
|
||||
return _watchConnectivityInstance.messageStream.map((m) {
|
||||
return _watchConnectivityAndroid.messageStream.map((m) {
|
||||
final map = Map<String, dynamic>.from(m);
|
||||
final data = map['data'];
|
||||
if (data is String) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/services/watch_sync_helper.dart';
|
||||
import 'package:firka/services/wear_sync_helper.dart';
|
||||
import 'package:firka/services/wear_sync_cache.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
|
||||
@@ -10,6 +10,8 @@ part 'grade_cache_model.g.dart';
|
||||
|
||||
@collection
|
||||
class GradeCacheModel extends GenericCacheModel<Grade> {
|
||||
GradeCacheModel();
|
||||
|
||||
String? mode;
|
||||
String? topic;
|
||||
late String type;
|
||||
@@ -49,4 +51,32 @@ class GradeCacheModel extends GenericCacheModel<Grade> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Plain-field JSON representation (no Isar links) for cross-process sync, e.g. Wear OS.
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'mode': mode,
|
||||
'topic': topic,
|
||||
'type': type,
|
||||
'valueType': valueType,
|
||||
'writtenAt': writtenAt.toIso8601String(),
|
||||
'numericValue': numericValue,
|
||||
'weightPercentage': weightPercentage,
|
||||
'textValue': textValue,
|
||||
'teacherName': teacherName,
|
||||
};
|
||||
}
|
||||
|
||||
factory GradeCacheModel.fromJson(Map<String, dynamic> json) {
|
||||
return GradeCacheModel()
|
||||
..mode = json['mode'] as String?
|
||||
..topic = json['topic'] as String?
|
||||
..type = json['type'] as String
|
||||
..valueType = json['valueType'] as String
|
||||
..writtenAt = DateTime.parse(json['writtenAt'] as String)
|
||||
..numericValue = json['numericValue'] as int?
|
||||
..weightPercentage = json['weightPercentage'] as int?
|
||||
..textValue = json['textValue'] as String
|
||||
..teacherName = json['teacherName'] as String;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ part 'lesson_cache_model.g.dart';
|
||||
|
||||
@collection
|
||||
class LessonCacheModel extends GenericCacheModel<Lesson> {
|
||||
LessonCacheModel();
|
||||
|
||||
String? uid;
|
||||
@Index()
|
||||
late DateTime start;
|
||||
@@ -91,6 +93,40 @@ class LessonCacheModel extends GenericCacheModel<Lesson> {
|
||||
bool isEvent() {
|
||||
return type == TimetableConsts.event;
|
||||
}
|
||||
|
||||
/// Plain-field JSON representation (no Isar links) for cross-process sync, e.g. Wear OS.
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'uid': uid,
|
||||
'start': start.toIso8601String(),
|
||||
'end': end.toIso8601String(),
|
||||
'dailyNth': dailyNth,
|
||||
'yearlyNth': yearlyNth,
|
||||
'name': name,
|
||||
'topic': topic,
|
||||
'roomName': roomName,
|
||||
'state': state,
|
||||
'type': type,
|
||||
'teacher': teacher,
|
||||
'substituteTeacher': substituteTeacher,
|
||||
};
|
||||
}
|
||||
|
||||
factory LessonCacheModel.fromJson(Map<String, dynamic> json) {
|
||||
return LessonCacheModel()
|
||||
..uid = json['uid'] as String?
|
||||
..start = DateTime.parse(json['start'] as String)
|
||||
..end = DateTime.parse(json['end'] as String)
|
||||
..dailyNth = json['dailyNth'] as int?
|
||||
..yearlyNth = json['yearlyNth'] as int?
|
||||
..name = json['name'] as String
|
||||
..topic = json['topic'] as String?
|
||||
..roomName = json['roomName'] as String?
|
||||
..state = json['state'] as String
|
||||
..type = json['type'] as String
|
||||
..teacher = json['teacher'] as String?
|
||||
..substituteTeacher = json['substituteTeacher'] as String?;
|
||||
}
|
||||
}
|
||||
|
||||
typedef AfterQBFilter<OBJ> = QueryBuilder<OBJ, OBJ, QAfterFilterCondition>;
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
|
||||
# The following line activates a set of recommended lints for Flutter apps,
|
||||
# packages, and plugins designed to encourage good coding practices.
|
||||
analyzer:
|
||||
exclude:
|
||||
- build/**
|
||||
- android/**
|
||||
include: package:flutter_lints/flutter.yaml
|
||||
|
||||
linter:
|
||||
|
||||
@@ -4,7 +4,7 @@ import 'package:intl/intl.dart';
|
||||
import 'package:firka_wear/core/debug_helper.dart';
|
||||
import 'package:firka_wear/l10n/app_localizations.dart';
|
||||
import 'package:firka_common/core/extensions.dart';
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
import 'package:firka_common/data/models/lesson_cache_model.dart';
|
||||
|
||||
export 'package:firka_common/core/extensions.dart';
|
||||
|
||||
@@ -166,24 +166,24 @@ extension DateGrouper<T> on Iterable<T> {
|
||||
}
|
||||
}
|
||||
|
||||
extension LessonExtension on List<Lesson> {
|
||||
int getLessonNo(Lesson lesson) {
|
||||
return lesson.lessonNumber ?? indexOf(lesson);
|
||||
extension LessonExtension on List<LessonCacheModel> {
|
||||
int getLessonNo(LessonCacheModel lesson) {
|
||||
return lesson.dailyNth ?? indexOf(lesson);
|
||||
}
|
||||
|
||||
Lesson? getCurrentLesson(DateTime now) {
|
||||
LessonCacheModel? getCurrentLesson(DateTime now) {
|
||||
return firstWhereOrNull(
|
||||
(lesson) => now.isAfter(lesson.start) && now.isBefore(lesson.end),
|
||||
);
|
||||
}
|
||||
|
||||
Lesson? getPrevLesson(DateTime now) {
|
||||
LessonCacheModel? getPrevLesson(DateTime now) {
|
||||
return firstWhereOrNull(
|
||||
(lesson) => lesson.end.isBefore(now.add(Duration(milliseconds: 1))),
|
||||
);
|
||||
}
|
||||
|
||||
Lesson? getNextLesson(DateTime now) {
|
||||
LessonCacheModel? getNextLesson(DateTime now) {
|
||||
return firstWhereOrNull(
|
||||
(lesson) => lesson.start.isAfter(now.add(Duration(milliseconds: 1))),
|
||||
);
|
||||
|
||||
@@ -3,7 +3,8 @@ import 'dart:math';
|
||||
|
||||
import 'package:isar_community/isar.dart';
|
||||
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
import 'package:firka_common/data/models/lesson_cache_model.dart';
|
||||
import 'package:firka_common/data/models/grade_cache_model.dart';
|
||||
|
||||
import 'package:firka_wear/data/models/generic_cache_model.dart';
|
||||
import 'package:firka_wear/data/models/token_model.dart';
|
||||
@@ -15,12 +16,12 @@ class WearSyncStore {
|
||||
|
||||
final Isar isar;
|
||||
|
||||
List<Lesson> _timetable = [];
|
||||
List<Grade> _grades = [];
|
||||
List<LessonCacheModel> _timetable = [];
|
||||
List<GradeCacheModel> _grades = [];
|
||||
DateTime? _lastSyncAt;
|
||||
|
||||
List<Lesson> get timetable => List.unmodifiable(_timetable);
|
||||
List<Grade> get grades => List.unmodifiable(_grades);
|
||||
List<LessonCacheModel> get timetable => List.unmodifiable(_timetable);
|
||||
List<GradeCacheModel> get grades => List.unmodifiable(_grades);
|
||||
DateTime? get lastSyncAt => _lastSyncAt;
|
||||
|
||||
/// True if we have no data or data is older than 1 hour.
|
||||
@@ -64,7 +65,9 @@ class WearSyncStore {
|
||||
if (timetableCache?.cacheData != null) {
|
||||
final raw = jsonDecode(timetableCache!.cacheData!) as List<dynamic>;
|
||||
_timetable = raw
|
||||
.map((e) => Lesson.fromJson(Map<String, dynamic>.from(e as Map)))
|
||||
.map(
|
||||
(e) => LessonCacheModel.fromJson(Map<String, dynamic>.from(e as Map)),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@@ -73,7 +76,9 @@ class WearSyncStore {
|
||||
if (gradesCache?.cacheData != null) {
|
||||
final raw = jsonDecode(gradesCache!.cacheData!) as List<dynamic>;
|
||||
_grades = raw
|
||||
.map((e) => Grade.fromJson(Map<String, dynamic>.from(e as Map)))
|
||||
.map(
|
||||
(e) => GradeCacheModel.fromJson(Map<String, dynamic>.from(e as Map)),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
} catch (_) {}
|
||||
@@ -81,8 +86,8 @@ class WearSyncStore {
|
||||
|
||||
Future<void> save({
|
||||
required DateTime? lastSyncAt,
|
||||
required List<Lesson> timetable,
|
||||
required List<Grade> grades,
|
||||
required List<LessonCacheModel> timetable,
|
||||
required List<GradeCacheModel> grades,
|
||||
}) async {
|
||||
final studentIdNorm = await _getStudentIdNorm();
|
||||
if (studentIdNorm == null) return;
|
||||
@@ -124,7 +129,7 @@ class WearSyncStore {
|
||||
}
|
||||
|
||||
/// Returns lessons that fall on [date] (compare by calendar day via lesson start).
|
||||
List<Lesson> getLessonsForDate(DateTime date) {
|
||||
List<LessonCacheModel> getLessonsForDate(DateTime date) {
|
||||
final y = date.year;
|
||||
final m = date.month;
|
||||
final d = date.day;
|
||||
|
||||
@@ -3,12 +3,13 @@ import 'dart:convert';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:firka_common/data/models/subject_cache_model.dart';
|
||||
import 'package:firka_common/data/models/lesson_cache_model.dart';
|
||||
import 'package:firka_common/data/models/grade_cache_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_arc_text/flutter_arc_text.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
import 'package:watch_connectivity/watch_connectivity.dart';
|
||||
import 'package:wearable_rotary/wearable_rotary.dart';
|
||||
import 'package:wear_plus/wear_plus.dart';
|
||||
@@ -38,7 +39,7 @@ class _WearHomeScreenState extends State<WearHomeScreen> {
|
||||
WearAppInitialization get data => widget.data;
|
||||
|
||||
int? currentLessonNo;
|
||||
List<Lesson> today = List.empty(growable: true);
|
||||
List<LessonCacheModel> today = List.empty(growable: true);
|
||||
String apiError = "";
|
||||
DateTime now = timeNow();
|
||||
Timer? timer;
|
||||
@@ -113,11 +114,15 @@ class _WearHomeScreenState extends State<WearHomeScreen> {
|
||||
: null;
|
||||
final rawTimetable = msg['timetable'] as List<dynamic>? ?? [];
|
||||
final timetable = rawTimetable
|
||||
.map((e) => Lesson.fromJson(Map<String, dynamic>.from(e as Map)))
|
||||
.map(
|
||||
(e) => LessonCacheModel.fromJson(Map<String, dynamic>.from(e as Map)),
|
||||
)
|
||||
.toList();
|
||||
final rawGrades = msg['grades'] as List<dynamic>? ?? [];
|
||||
final grades = rawGrades
|
||||
.map((e) => Grade.fromJson(Map<String, dynamic>.from(e as Map)))
|
||||
.map(
|
||||
(e) => GradeCacheModel.fromJson(Map<String, dynamic>.from(e as Map)),
|
||||
)
|
||||
.toList();
|
||||
await data.syncStore.save(
|
||||
lastSyncAt: lastSyncAt,
|
||||
@@ -222,9 +227,9 @@ class _WearHomeScreenState extends State<WearHomeScreen> {
|
||||
}
|
||||
currentLessonNo = null;
|
||||
if (now.isAfter(today.first.start) && now.isBefore(today.last.end)) {
|
||||
Lesson? currentLesson = today.getCurrentLesson(now);
|
||||
Lesson? lastLesson = today.getPrevLesson(now);
|
||||
Lesson? nextLesson = today.getNextLesson(now);
|
||||
LessonCacheModel? currentLesson = today.getCurrentLesson(now);
|
||||
LessonCacheModel? lastLesson = today.getPrevLesson(now);
|
||||
LessonCacheModel? nextLesson = today.getNextLesson(now);
|
||||
|
||||
if (currentLesson != null) {
|
||||
currentLessonNo = today.getLessonNo(currentLesson);
|
||||
|
||||
@@ -27,7 +27,7 @@ class _HomeScreenBodyPage extends StatelessWidget {
|
||||
}
|
||||
|
||||
class _LessonCardPage extends StatelessWidget {
|
||||
final Lesson? lesson;
|
||||
final LessonCacheModel? lesson;
|
||||
final double viewportHeight;
|
||||
|
||||
const _LessonCardPage({
|
||||
|
||||
@@ -3,7 +3,8 @@ import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
import 'package:firka_common/data/models/lesson_cache_model.dart';
|
||||
import 'package:firka_common/data/models/grade_cache_model.dart';
|
||||
import 'package:watch_connectivity/watch_connectivity.dart';
|
||||
import 'package:wear_plus/wear_plus.dart';
|
||||
|
||||
@@ -79,13 +80,17 @@ class _WearLoginScreen extends State<WearLoginScreen> {
|
||||
final rawTimetable = msg["timetable"] as List<dynamic>? ?? [];
|
||||
final timetable = rawTimetable
|
||||
.map(
|
||||
(e) => Lesson.fromJson(Map<String, dynamic>.from(e as Map)),
|
||||
(e) => LessonCacheModel.fromJson(
|
||||
Map<String, dynamic>.from(e as Map),
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
final rawGrades = msg["grades"] as List<dynamic>? ?? [];
|
||||
final grades = rawGrades
|
||||
.map(
|
||||
(e) => Grade.fromJson(Map<String, dynamic>.from(e as Map)),
|
||||
(e) => GradeCacheModel.fromJson(
|
||||
Map<String, dynamic>.from(e as Map),
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
await initData.syncStore.save(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:firka_common/data/models/subject_cache_model.dart';
|
||||
import 'package:firka_common/data/models/lesson_cache_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
|
||||
import 'package:firka_wear/ui/components/firka_shadow.dart';
|
||||
import 'package:firka_wear/ui/shared/class_icon.dart';
|
||||
@@ -27,16 +27,16 @@ class LessonCardSmall extends StatelessWidget {
|
||||
});
|
||||
|
||||
factory LessonCardSmall.fromLesson(
|
||||
Lesson lesson, {
|
||||
LessonCacheModel lesson, {
|
||||
VoidCallback? onTap,
|
||||
Color? iconColor,
|
||||
bool shadow = true,
|
||||
Key? key,
|
||||
}) {
|
||||
return LessonCardSmall(
|
||||
uid: lesson.uid,
|
||||
uid: lesson.uid ?? lesson.name,
|
||||
subjectName: lesson.name,
|
||||
category: lesson.subject?.name ?? '',
|
||||
category: '',
|
||||
roomName: lesson.roomName,
|
||||
onTap: onTap,
|
||||
iconColor: iconColor,
|
||||
|
||||
Reference in New Issue
Block a user