|
@@ -1,8 +1,10 @@
|
|
|
import 'dart:async';
|
|
|
+import 'dart:developer';
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
import 'package:photos/core/event_bus.dart';
|
|
|
import 'package:photos/events/photo_upload_event.dart';
|
|
|
+import 'package:photos/photo_sync_manager.dart';
|
|
|
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
|
|
|
|
|
class SyncIndicator extends StatefulWidget {
|
|
@@ -17,6 +19,7 @@ class SyncIndicator extends StatefulWidget {
|
|
|
class _SyncIndicatorState extends State<SyncIndicator> {
|
|
|
PhotoUploadEvent _event;
|
|
|
StreamSubscription<PhotoUploadEvent> _subscription;
|
|
|
+ String _completeText = "Sync completed.";
|
|
|
|
|
|
@override
|
|
|
void initState() {
|
|
@@ -40,10 +43,58 @@ class _SyncIndicatorState extends State<SyncIndicator> {
|
|
|
idleText: "Pull down to sync.",
|
|
|
refreshingText: _getRefreshingText(),
|
|
|
releaseText: "Release to sync.",
|
|
|
- completeText: "Sync completed.",
|
|
|
+ completeText: _completeText,
|
|
|
failedText: "Sync unsuccessful.",
|
|
|
completeDuration: const Duration(milliseconds: 1000),
|
|
|
refreshStyle: RefreshStyle.UnFollow,
|
|
|
+ refreshingIcon: Container(
|
|
|
+ width: 24,
|
|
|
+ height: 24,
|
|
|
+ child: GestureDetector(
|
|
|
+ onTap: () {
|
|
|
+ AlertDialog alert = AlertDialog(
|
|
|
+ title: Text("Pause?"),
|
|
|
+ content: Text(
|
|
|
+ "Are you sure that you want to pause backing up your memories?"),
|
|
|
+ actions: [
|
|
|
+ FlatButton(
|
|
|
+ child: Text("NO"),
|
|
|
+ onPressed: () {
|
|
|
+ Navigator.of(context).pop();
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ FlatButton(
|
|
|
+ child: Text("YES"),
|
|
|
+ onPressed: () {
|
|
|
+ Navigator.of(context).pop();
|
|
|
+ PhotoSyncManager.instance.stopSync();
|
|
|
+ _completeText = "Sync stopped.";
|
|
|
+ setState(() {});
|
|
|
+ widget.refreshController.refreshCompleted();
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ );
|
|
|
+
|
|
|
+ showDialog(
|
|
|
+ context: context,
|
|
|
+ builder: (BuildContext context) {
|
|
|
+ return alert;
|
|
|
+ },
|
|
|
+ );
|
|
|
+ },
|
|
|
+ child: Stack(
|
|
|
+ children: [
|
|
|
+ Icon(
|
|
|
+ Icons.pause_circle_outline,
|
|
|
+ size: 24,
|
|
|
+ color: Colors.pink,
|
|
|
+ ),
|
|
|
+ CircularProgressIndicator(strokeWidth: 2),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -55,6 +106,8 @@ class _SyncIndicatorState extends State<SyncIndicator> {
|
|
|
if (_event.hasError) {
|
|
|
widget.refreshController.refreshFailed();
|
|
|
s = "Upload failed.";
|
|
|
+ } else if (_event.wasStopped) {
|
|
|
+ s = "Sync stopped.";
|
|
|
} else {
|
|
|
s = "Backing up " +
|
|
|
_event.completed.toString() +
|