Compare commits

...

4 Commits

5 changed files with 103 additions and 41 deletions

View File

@@ -11,12 +11,16 @@ class SyncResult {
final bool isOnline; final bool isOnline;
final int changesSynced; final int changesSynced;
final int annotationsSynced; final int annotationsSynced;
final int changesUnsynced;
final int annotationsUnsynced;
SyncResult({ SyncResult({
required this.sheets, required this.sheets,
required this.isOnline, required this.isOnline,
this.changesSynced = 0, required this.changesSynced,
this.annotationsSynced = 0, required this.annotationsSynced,
required this.changesUnsynced,
required this.annotationsUnsynced,
}); });
} }
@@ -35,8 +39,8 @@ class SyncService {
SyncService({ SyncService({
required ApiClient apiClient, required ApiClient apiClient,
required StorageService storageService, required StorageService storageService,
}) : _apiClient = apiClient, }) : _apiClient = apiClient,
_storageService = storageService; _storageService = storageService;
/// Performs a full sync operation. /// Performs a full sync operation.
/// ///
@@ -80,6 +84,8 @@ class SyncService {
// 3. Upload pending annotations // 3. Upload pending annotations
annotationsSynced = await _uploadPendingAnnotations(); annotationsSynced = await _uploadPendingAnnotations();
final remainingAnnotations = await _storageService
.readPendingAnnotationUploads();
// 4. Apply any remaining local changes (in case some failed to upload) // 4. Apply any remaining local changes (in case some failed to upload)
final changeQueue = await _storageService.readChangeQueue(); final changeQueue = await _storageService.readChangeQueue();
@@ -102,6 +108,8 @@ class SyncService {
isOnline: true, isOnline: true,
changesSynced: changesSynced, changesSynced: changesSynced,
annotationsSynced: annotationsSynced, annotationsSynced: annotationsSynced,
changesUnsynced: changeQueue.length,
annotationsUnsynced: remainingAnnotations.length,
); );
} }
@@ -127,9 +135,16 @@ class SyncService {
} }
} }
final remainingAnnotations = await _storageService
.readPendingAnnotationUploads();
return SyncResult( return SyncResult(
sheets: sheets, sheets: sheets,
isOnline: false, isOnline: false,
changesSynced: 0,
annotationsSynced: 0,
changesUnsynced: changeQueue.length,
annotationsUnsynced: remainingAnnotations.length,
); );
} }

View File

@@ -48,7 +48,9 @@ class _HomePageState extends State<HomePage> with RouteAware {
super.initState(); super.initState();
// Exit fullscreen when entering home page // Exit fullscreen when entering home page
FullScreen.setFullScreen(false); if (FullScreen.isFullScreen) {
FullScreen.setFullScreen(false);
}
// Subscribe to route changes // Subscribe to route changes
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
@@ -71,14 +73,19 @@ class _HomePageState extends State<HomePage> with RouteAware {
@override @override
void didPush() { void didPush() {
FullScreen.setFullScreen(false); // Exit fullscreen when entering home page
if (FullScreen.isFullScreen) {
FullScreen.setFullScreen(false);
}
super.didPush(); super.didPush();
} }
@override @override
void didPopNext() { void didPopNext() {
// Exit fullscreen when returning to home page // Exit fullscreen when returning to home page
FullScreen.setFullScreen(false); if (FullScreen.isFullScreen) {
FullScreen.setFullScreen(false);
}
super.didPopNext(); super.didPopNext();
} }
@@ -212,6 +219,7 @@ class _HomePageState extends State<HomePage> with RouteAware {
onLogout: _handleLogout, onLogout: _handleLogout,
appName: _appName, appName: _appName,
appVersion: _appVersion, appVersion: _appVersion,
syncFuture: _syncFuture,
), ),
body: RefreshIndicator(onRefresh: _refreshSheets, child: _buildBody()), body: RefreshIndicator(onRefresh: _refreshSheets, child: _buildBody()),
); );

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:sheetless/core/services/sync_service.dart';
/// Callback for shuffle state changes. /// Callback for shuffle state changes.
typedef ShuffleCallback = void Function(bool enabled); typedef ShuffleCallback = void Function(bool enabled);
@@ -12,12 +13,14 @@ class AppDrawer extends StatelessWidget {
final VoidCallback onLogout; final VoidCallback onLogout;
final String? appName; final String? appName;
final String? appVersion; final String? appVersion;
final Future<SyncResult> syncFuture;
const AppDrawer({ const AppDrawer({
super.key, super.key,
required this.isShuffling, required this.isShuffling,
required this.onShuffleChanged, required this.onShuffleChanged,
required this.onLogout, required this.onLogout,
required this.syncFuture,
this.appName, this.appName,
this.appVersion, this.appVersion,
}); });
@@ -32,7 +35,7 @@ class AppDrawer extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
_buildActions(), _buildActions(),
_buildAppInfo(), Column(children: [_buildSyncStatus(), _buildAppInfo()]),
], ],
), ),
), ),
@@ -44,10 +47,7 @@ class AppDrawer extends StatelessWidget {
return Column( return Column(
children: [ children: [
ListTile( ListTile(
leading: Icon( leading: Icon(Icons.shuffle, color: isShuffling ? Colors.blue : null),
Icons.shuffle,
color: isShuffling ? Colors.blue : null,
),
title: const Text('Shuffle'), title: const Text('Shuffle'),
onTap: () => onShuffleChanged(!isShuffling), onTap: () => onShuffleChanged(!isShuffling),
), ),
@@ -60,6 +60,47 @@ class AppDrawer extends StatelessWidget {
); );
} }
Widget _buildSyncStatus() {
return Center(
// padding: const EdgeInsets.all(5.0),
child: FutureBuilder<SyncResult>(
future: syncFuture,
builder: (context, snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
return const Center(child: CircularProgressIndicator());
}
if (snapshot.hasError) {
return Text(
"Error: ${snapshot.error.toString()}",
style: const TextStyle(color: Colors.red),
textAlign: TextAlign.center,
);
}
if (snapshot.hasData) {
final changes = snapshot.data!.changesUnsynced;
final annotations = snapshot.data!.annotationsUnsynced;
if (changes == 0 && annotations == 0) {
return Text(
"All synced!",
style: const TextStyle(color: Colors.black),
textAlign: TextAlign.center,
);
}
return Text(
"$changes changes and $annotations annotations unsynchronized!",
style: const TextStyle(color: Colors.red),
textAlign: TextAlign.center,
);
}
return const Center(child: CircularProgressIndicator());
},
),
);
}
Widget _buildAppInfo() { Widget _buildAppInfo() {
final versionText = appName != null && appVersion != null final versionText = appName != null && appVersion != null
? '$appName v$appVersion' ? '$appName v$appVersion'
@@ -67,10 +108,7 @@ class AppDrawer extends StatelessWidget {
return Padding( return Padding(
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(16.0),
child: Text( child: Text(versionText, style: const TextStyle(color: Colors.grey)),
versionText,
style: const TextStyle(color: Colors.grey),
),
); );
} }
} }

View File

@@ -65,7 +65,9 @@ class _SheetViewerPageState extends State<SheetViewerPage>
_rightDrawingController = DrawingController(maxHistorySteps: 50); _rightDrawingController = DrawingController(maxHistorySteps: 50);
FullScreen.addListener(this); FullScreen.addListener(this);
FullScreen.setFullScreen(widget.config.fullscreen); if (FullScreen.isFullScreen != widget.config.fullscreen) {
FullScreen.setFullScreen(widget.config.fullscreen);
}
_documentLoaded = _loadPdf(); _documentLoaded = _loadPdf();
} }
@@ -161,14 +163,12 @@ class _SheetViewerPageState extends State<SheetViewerPage>
); );
// Upload left page to server // Upload left page to server
if (leftHasContent) { _syncService.uploadAnnotation(
_syncService.uploadAnnotation( sheetUuid: widget.sheet.uuid,
sheetUuid: widget.sheet.uuid, page: _currentPage,
page: _currentPage, annotationsJson: leftJson,
annotationsJson: leftJson, lastModified: now,
lastModified: now, );
);
}
_leftDrawingController.markSaved(); _leftDrawingController.markSaved();
} }
@@ -188,14 +188,12 @@ class _SheetViewerPageState extends State<SheetViewerPage>
); );
// Upload right page to server // Upload right page to server
if (rightHasContent) { _syncService.uploadAnnotation(
_syncService.uploadAnnotation( sheetUuid: widget.sheet.uuid,
sheetUuid: widget.sheet.uuid, page: _currentPage + 1,
page: _currentPage + 1, annotationsJson: rightJson,
annotationsJson: rightJson, lastModified: now,
lastModified: now, );
);
}
_rightDrawingController.markSaved(); _rightDrawingController.markSaved();
} }
@@ -214,7 +212,7 @@ class _SheetViewerPageState extends State<SheetViewerPage>
} }
void _toggleFullscreen() { void _toggleFullscreen() {
FullScreen.setFullScreen(!widget.config.fullscreen); FullScreen.setFullScreen(!FullScreen.isFullScreen);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@@ -300,8 +298,9 @@ class _SheetViewerPageState extends State<SheetViewerPage>
icon: Icon( icon: Icon(
widget.config.fullscreen ? Icons.fullscreen_exit : Icons.fullscreen, widget.config.fullscreen ? Icons.fullscreen_exit : Icons.fullscreen,
), ),
tooltip: tooltip: widget.config.fullscreen
widget.config.fullscreen ? 'Exit Fullscreen' : 'Enter Fullscreen', ? 'Exit Fullscreen'
: 'Enter Fullscreen',
onPressed: _toggleFullscreen, onPressed: _toggleFullscreen,
), ),
IconButton( IconButton(
@@ -313,8 +312,9 @@ class _SheetViewerPageState extends State<SheetViewerPage>
icon: Icon( icon: Icon(
widget.config.twoPageMode ? Icons.filter_1 : Icons.filter_2, widget.config.twoPageMode ? Icons.filter_1 : Icons.filter_2,
), ),
tooltip: tooltip: widget.config.twoPageMode
widget.config.twoPageMode ? 'Single Page Mode' : 'Two Page Mode', ? 'Single Page Mode'
: 'Two Page Mode',
onPressed: _toggleTwoPageMode, onPressed: _toggleTwoPageMode,
), ),
], ],
@@ -346,8 +346,9 @@ class _SheetViewerPageState extends State<SheetViewerPage>
currentPageNumber: _currentPage, currentPageNumber: _currentPage,
config: widget.config, config: widget.config,
leftDrawingController: _leftDrawingController, leftDrawingController: _leftDrawingController,
rightDrawingController: rightDrawingController: widget.config.twoPageMode
widget.config.twoPageMode ? _rightDrawingController : null, ? _rightDrawingController
: null,
drawingEnabled: _isPaintMode, drawingEnabled: _isPaintMode,
); );

View File

@@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts # In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix. # of the product and file versions while build-number is used as the build suffix.
version: 0.1.2 version: 0.2.0
environment: environment:
sdk: ^3.0.0 sdk: ^3.0.0