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