mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 18:03:14 +08:00
SyncButton: Seperate pulling and pushing
This way we also refresh the view after the pulling, as we don't need to wait for a push for that.
This commit is contained in:
@ -6,7 +6,8 @@ import 'package:gitjournal/core/notes_folder_fs.dart';
|
|||||||
enum SyncStatus {
|
enum SyncStatus {
|
||||||
Unknown,
|
Unknown,
|
||||||
Done,
|
Done,
|
||||||
Loading,
|
Pulling,
|
||||||
|
Pushing,
|
||||||
Error,
|
Error,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,18 +126,21 @@ class GitNoteRepository {
|
|||||||
return _addNote(note, "Edited Note");
|
return _addNote(note, "Edited Note");
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> sync() async {
|
Future<void> pull() async {
|
||||||
try {
|
try {
|
||||||
await _gitRepo.pull();
|
await _gitRepo.pull();
|
||||||
} on GitException catch (ex) {
|
} on GitException catch (ex) {
|
||||||
Fimber.d(ex.toString());
|
Fimber.d(ex.toString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> push() async {
|
||||||
try {
|
try {
|
||||||
await _gitRepo.push();
|
await _gitRepo.push();
|
||||||
} on GitException catch (ex) {
|
} on GitException catch (ex) {
|
||||||
if (ex.cause == 'cannot push non-fastforwardable reference') {
|
if (ex.cause == 'cannot push non-fastforwardable reference') {
|
||||||
return sync();
|
await pull();
|
||||||
|
return push();
|
||||||
}
|
}
|
||||||
Fimber.d(ex.toString());
|
Fimber.d(ex.toString());
|
||||||
rethrow;
|
rethrow;
|
||||||
|
@ -91,11 +91,19 @@ class StateContainer with ChangeNotifier {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
appState.syncStatus = SyncStatus.Loading;
|
appState.syncStatus = SyncStatus.Pulling;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
||||||
|
Future noteLoadingFuture;
|
||||||
try {
|
try {
|
||||||
await _gitRepo.sync();
|
await _gitRepo.pull();
|
||||||
|
|
||||||
|
appState.syncStatus = SyncStatus.Pushing;
|
||||||
|
notifyListeners();
|
||||||
|
|
||||||
|
noteLoadingFuture = _loadNotes();
|
||||||
|
|
||||||
|
await _gitRepo.push();
|
||||||
|
|
||||||
Fimber.d("Synced!");
|
Fimber.d("Synced!");
|
||||||
appState.syncStatus = SyncStatus.Done;
|
appState.syncStatus = SyncStatus.Done;
|
||||||
@ -109,7 +117,8 @@ class StateContainer with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
if (!doNotThrow) rethrow;
|
if (!doNotThrow) rethrow;
|
||||||
}
|
}
|
||||||
await _loadNotes();
|
|
||||||
|
await noteLoadingFuture;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _syncNotes() async {
|
Future<void> _syncNotes() async {
|
||||||
|
@ -47,8 +47,16 @@ class _SyncButtonState extends State<SyncButton> {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (appState.syncStatus == SyncStatus.Loading) {
|
if (appState.syncStatus == SyncStatus.Pulling) {
|
||||||
return RotatingIcon();
|
return BlinkingIcon(
|
||||||
|
icon: Icon(Icons.arrow_downward),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (appState.syncStatus == SyncStatus.Pushing) {
|
||||||
|
return BlinkingIcon(
|
||||||
|
icon: Icon(Icons.arrow_upward),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return IconButton(
|
return IconButton(
|
||||||
@ -83,12 +91,18 @@ class _SyncButtonState extends State<SyncButton> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class RotatingIcon extends StatefulWidget {
|
class BlinkingIcon extends StatefulWidget {
|
||||||
|
final Icon icon;
|
||||||
|
final int interval;
|
||||||
|
|
||||||
|
BlinkingIcon({@required this.icon, this.interval = 500, Key key})
|
||||||
|
: super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_RotatingIconState createState() => _RotatingIconState();
|
_BlinkingIconState createState() => _BlinkingIconState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _RotatingIconState extends State<RotatingIcon>
|
class _BlinkingIconState extends State<BlinkingIcon>
|
||||||
with SingleTickerProviderStateMixin {
|
with SingleTickerProviderStateMixin {
|
||||||
AnimationController _controller;
|
AnimationController _controller;
|
||||||
Animation<double> _animation;
|
Animation<double> _animation;
|
||||||
@ -98,8 +112,8 @@ class _RotatingIconState extends State<RotatingIcon>
|
|||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
_controller = AnimationController(
|
_controller = AnimationController(
|
||||||
|
duration: Duration(milliseconds: widget.interval),
|
||||||
vsync: this,
|
vsync: this,
|
||||||
duration: const Duration(milliseconds: 1800),
|
|
||||||
);
|
);
|
||||||
_animation = CurvedAnimation(
|
_animation = CurvedAnimation(
|
||||||
parent: _controller,
|
parent: _controller,
|
||||||
@ -117,14 +131,12 @@ class _RotatingIconState extends State<RotatingIcon>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var button = IconButton(
|
return FadeTransition(
|
||||||
icon: const Icon(Icons.loop),
|
opacity: _animation,
|
||||||
onPressed: () {},
|
child: IconButton(
|
||||||
);
|
icon: widget.icon,
|
||||||
|
onPressed: () {},
|
||||||
return RotationTransition(
|
),
|
||||||
child: button,
|
|
||||||
turns: _animation,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user