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 {
|
||||
Unknown,
|
||||
Done,
|
||||
Loading,
|
||||
Pulling,
|
||||
Pushing,
|
||||
Error,
|
||||
}
|
||||
|
||||
|
@ -126,18 +126,21 @@ class GitNoteRepository {
|
||||
return _addNote(note, "Edited Note");
|
||||
}
|
||||
|
||||
Future<void> sync() async {
|
||||
Future<void> pull() async {
|
||||
try {
|
||||
await _gitRepo.pull();
|
||||
} on GitException catch (ex) {
|
||||
Fimber.d(ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> push() async {
|
||||
try {
|
||||
await _gitRepo.push();
|
||||
} on GitException catch (ex) {
|
||||
if (ex.cause == 'cannot push non-fastforwardable reference') {
|
||||
return sync();
|
||||
await pull();
|
||||
return push();
|
||||
}
|
||||
Fimber.d(ex.toString());
|
||||
rethrow;
|
||||
|
@ -91,11 +91,19 @@ class StateContainer with ChangeNotifier {
|
||||
return true;
|
||||
}
|
||||
|
||||
appState.syncStatus = SyncStatus.Loading;
|
||||
appState.syncStatus = SyncStatus.Pulling;
|
||||
notifyListeners();
|
||||
|
||||
Future noteLoadingFuture;
|
||||
try {
|
||||
await _gitRepo.sync();
|
||||
await _gitRepo.pull();
|
||||
|
||||
appState.syncStatus = SyncStatus.Pushing;
|
||||
notifyListeners();
|
||||
|
||||
noteLoadingFuture = _loadNotes();
|
||||
|
||||
await _gitRepo.push();
|
||||
|
||||
Fimber.d("Synced!");
|
||||
appState.syncStatus = SyncStatus.Done;
|
||||
@ -109,7 +117,8 @@ class StateContainer with ChangeNotifier {
|
||||
}
|
||||
if (!doNotThrow) rethrow;
|
||||
}
|
||||
await _loadNotes();
|
||||
|
||||
await noteLoadingFuture;
|
||||
}
|
||||
|
||||
Future<void> _syncNotes() async {
|
||||
|
@ -47,8 +47,16 @@ class _SyncButtonState extends State<SyncButton> {
|
||||
},
|
||||
);
|
||||
}
|
||||
if (appState.syncStatus == SyncStatus.Loading) {
|
||||
return RotatingIcon();
|
||||
if (appState.syncStatus == SyncStatus.Pulling) {
|
||||
return BlinkingIcon(
|
||||
icon: Icon(Icons.arrow_downward),
|
||||
);
|
||||
}
|
||||
|
||||
if (appState.syncStatus == SyncStatus.Pushing) {
|
||||
return BlinkingIcon(
|
||||
icon: Icon(Icons.arrow_upward),
|
||||
);
|
||||
}
|
||||
|
||||
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
|
||||
_RotatingIconState createState() => _RotatingIconState();
|
||||
_BlinkingIconState createState() => _BlinkingIconState();
|
||||
}
|
||||
|
||||
class _RotatingIconState extends State<RotatingIcon>
|
||||
class _BlinkingIconState extends State<BlinkingIcon>
|
||||
with SingleTickerProviderStateMixin {
|
||||
AnimationController _controller;
|
||||
Animation<double> _animation;
|
||||
@ -98,8 +112,8 @@ class _RotatingIconState extends State<RotatingIcon>
|
||||
super.initState();
|
||||
|
||||
_controller = AnimationController(
|
||||
duration: Duration(milliseconds: widget.interval),
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 1800),
|
||||
);
|
||||
_animation = CurvedAnimation(
|
||||
parent: _controller,
|
||||
@ -117,14 +131,12 @@ class _RotatingIconState extends State<RotatingIcon>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var button = IconButton(
|
||||
icon: const Icon(Icons.loop),
|
||||
return FadeTransition(
|
||||
opacity: _animation,
|
||||
child: IconButton(
|
||||
icon: widget.icon,
|
||||
onPressed: () {},
|
||||
);
|
||||
|
||||
return RotationTransition(
|
||||
child: button,
|
||||
turns: _animation,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user