mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 18:03:14 +08:00
@ -25,6 +25,7 @@ class AppState {
|
||||
bool onBoardingCompleted = false;
|
||||
|
||||
SyncStatus syncStatus = SyncStatus.Unknown;
|
||||
int numChanges = 0;
|
||||
|
||||
//
|
||||
// Temporary
|
||||
|
@ -169,6 +169,14 @@ class GitNoteRepository {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> numChanges() async {
|
||||
try {
|
||||
var repo = await git.GitRepository.load(gitDirPath);
|
||||
return repo.numChangesToPush();
|
||||
} catch (_) {}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
const ignoredMessages = [
|
||||
|
@ -87,6 +87,9 @@ class StateContainer with ChangeNotifier {
|
||||
return _loadLock.synchronized(() async {
|
||||
await appState.notesFolder.loadRecursively();
|
||||
await _notesCache.buildCache(appState.notesFolder);
|
||||
|
||||
appState.numChanges = await _gitRepo.numChanges();
|
||||
notifyListeners();
|
||||
});
|
||||
}
|
||||
|
||||
@ -113,6 +116,7 @@ class StateContainer with ChangeNotifier {
|
||||
|
||||
Log.d("Synced!");
|
||||
appState.syncStatus = SyncStatus.Done;
|
||||
appState.numChanges = 0;
|
||||
notifyListeners();
|
||||
} catch (e, stacktrace) {
|
||||
Log.d("Failed to Sync");
|
||||
@ -148,6 +152,8 @@ class StateContainer with ChangeNotifier {
|
||||
|
||||
_gitRepo.addFolder(newFolder).then((NoteRepoResult _) {
|
||||
_syncNotes();
|
||||
appState.numChanges += 1;
|
||||
notifyListeners();
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -161,6 +167,8 @@ class StateContainer with ChangeNotifier {
|
||||
folder.parentFS.removeFolder(folder);
|
||||
_gitRepo.removeFolder(folder).then((NoteRepoResult _) {
|
||||
_syncNotes();
|
||||
appState.numChanges += 1;
|
||||
notifyListeners();
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -177,6 +185,8 @@ class StateContainer with ChangeNotifier {
|
||||
.renameFolder(oldFolderPath, folder.folderPath)
|
||||
.then((NoteRepoResult _) {
|
||||
_syncNotes();
|
||||
appState.numChanges += 1;
|
||||
notifyListeners();
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -190,6 +200,8 @@ class StateContainer with ChangeNotifier {
|
||||
|
||||
_gitRepo.renameNote(oldNotePath, note.filePath).then((NoteRepoResult _) {
|
||||
_syncNotes();
|
||||
appState.numChanges += 1;
|
||||
notifyListeners();
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -206,6 +218,8 @@ class StateContainer with ChangeNotifier {
|
||||
|
||||
_gitRepo.moveNote(oldNotePath, note.filePath).then((NoteRepoResult _) {
|
||||
_syncNotes();
|
||||
appState.numChanges += 1;
|
||||
notifyListeners();
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -219,6 +233,8 @@ class StateContainer with ChangeNotifier {
|
||||
note.updateModified();
|
||||
_gitRepo.addNote(note).then((NoteRepoResult _) {
|
||||
_syncNotes();
|
||||
appState.numChanges += 1;
|
||||
notifyListeners();
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -230,6 +246,8 @@ class StateContainer with ChangeNotifier {
|
||||
// FIXME: What if the Note hasn't yet been saved?
|
||||
note.parent.remove(note);
|
||||
_gitRepo.removeNote(note).then((NoteRepoResult _) async {
|
||||
appState.numChanges += 1;
|
||||
notifyListeners();
|
||||
// FIXME: Is there a way of figuring this amount dynamically?
|
||||
// The '4 seconds' is taken from snack_bar.dart -> _kSnackBarDisplayDuration
|
||||
// We wait an aritfical amount of time, so that the user has a change to undo
|
||||
@ -247,6 +265,8 @@ class StateContainer with ChangeNotifier {
|
||||
note.parent.add(note);
|
||||
_gitRepo.resetLastCommit().then((NoteRepoResult _) {
|
||||
_syncNotes();
|
||||
appState.numChanges -= 1;
|
||||
notifyListeners();
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -259,6 +279,8 @@ class StateContainer with ChangeNotifier {
|
||||
note.updateModified();
|
||||
_gitRepo.updateNote(note).then((NoteRepoResult _) {
|
||||
_syncNotes();
|
||||
appState.numChanges += 1;
|
||||
notifyListeners();
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -274,6 +296,8 @@ class StateContainer with ChangeNotifier {
|
||||
await config.saveToFS();
|
||||
_gitRepo.addFolderConfig(config).then((NoteRepoResult _) {
|
||||
_syncNotes();
|
||||
appState.numChanges += 1;
|
||||
notifyListeners();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:connectivity/connectivity.dart';
|
||||
import 'package:git_bindings/git_bindings.dart';
|
||||
import 'package:badges/badges.dart';
|
||||
|
||||
import 'package:gitjournal/appstate.dart';
|
||||
import 'package:gitjournal/state_container.dart';
|
||||
@ -60,11 +61,24 @@ class _SyncButtonState extends State<SyncButton> {
|
||||
);
|
||||
}
|
||||
|
||||
return IconButton(
|
||||
icon: Icon(_syncStatusIcon()),
|
||||
onPressed: () async {
|
||||
_syncRepo();
|
||||
},
|
||||
var theme = Theme.of(context);
|
||||
var darkMode = theme.brightness == Brightness.dark;
|
||||
var style = theme.textTheme.caption.copyWith(
|
||||
fontSize: 6.0,
|
||||
color: darkMode ? Colors.black : Colors.white,
|
||||
);
|
||||
|
||||
return Badge(
|
||||
badgeContent: Text(appState.numChanges.toString(), style: style),
|
||||
showBadge: appState.numChanges != 0,
|
||||
badgeColor: theme.iconTheme.color,
|
||||
position: BadgePosition.topRight(top: 10.0, right: 4.0),
|
||||
child: IconButton(
|
||||
icon: Icon(_syncStatusIcon()),
|
||||
onPressed: () async {
|
||||
_syncRepo();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ packages:
|
||||
name: badges
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.0.6"
|
||||
version: "1.1.1"
|
||||
benchmark_harness:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
@ -146,7 +146,7 @@ packages:
|
||||
description:
|
||||
path: "."
|
||||
ref: HEAD
|
||||
resolved-ref: "4c530f3a63b0de22d62ce854da22f2db8f0209ce"
|
||||
resolved-ref: "27fe7ee9b5713c72dd7a3db3018ff16e6b06945b"
|
||||
url: "https://github.com/GitJournal/dart_git.git"
|
||||
source: git
|
||||
version: "0.0.1"
|
||||
|
@ -16,7 +16,7 @@ dependencies:
|
||||
dots_indicator: ^0.0.3
|
||||
package_info: ^0.4.0+13
|
||||
http: ^0.12.0+1
|
||||
badges: ^0.0.6
|
||||
badges: ^1.1.1
|
||||
share: ^0.6.3+5
|
||||
launch_review: ^2.0.0
|
||||
device_info: ^0.4.1+4
|
||||
|
Reference in New Issue
Block a user