StateContainer: noteRepo doesn't need to be public

Also lets call it gitRepo instead
This commit is contained in:
Vishesh Handa
2019-12-08 01:10:03 +01:00
parent 9e2d59f3fa
commit 7dafdaa617

View File

@ -36,7 +36,7 @@ class StateContainer extends StatefulWidget {
class StateContainerState extends State<StateContainer> { class StateContainerState extends State<StateContainer> {
AppState appState; AppState appState;
GitNoteRepository noteRepo; GitNoteRepository _gitRepo;
StateContainerState(this.appState); StateContainerState(this.appState);
@ -47,17 +47,17 @@ class StateContainerState extends State<StateContainer> {
assert(appState.localGitRepoConfigured); assert(appState.localGitRepoConfigured);
if (appState.remoteGitRepoConfigured) { if (appState.remoteGitRepoConfigured) {
noteRepo = GitNoteRepository( _gitRepo = GitNoteRepository(
baseDirectory: appState.gitBaseDirectory, baseDirectory: appState.gitBaseDirectory,
dirName: appState.remoteGitRepoFolderName, dirName: appState.remoteGitRepoFolderName,
); );
} else if (appState.localGitRepoConfigured) { } else if (appState.localGitRepoConfigured) {
noteRepo = GitNoteRepository( _gitRepo = GitNoteRepository(
baseDirectory: appState.gitBaseDirectory, baseDirectory: appState.gitBaseDirectory,
dirName: appState.localGitRepoPath, dirName: appState.localGitRepoPath,
); );
} }
appState.notesFolder = NotesFolder(null, noteRepo.notesBasePath); appState.notesFolder = NotesFolder(null, _gitRepo.notesBasePath);
// Just a fail safe // Just a fail safe
if (!appState.remoteGitRepoConfigured) { if (!appState.remoteGitRepoConfigured) {
@ -112,7 +112,7 @@ class StateContainerState extends State<StateContainer> {
return true; return true;
} }
await noteRepo.sync(); await _gitRepo.sync();
try { try {
await _loadNotes(); await _loadNotes();
@ -136,7 +136,7 @@ class StateContainerState extends State<StateContainer> {
} }
Fimber.d("Starting to syncNotes"); Fimber.d("Starting to syncNotes");
noteRepo.sync().then((loaded) { _gitRepo.sync().then((loaded) {
Fimber.d("NotesRepo Synced: " + loaded.toString()); Fimber.d("NotesRepo Synced: " + loaded.toString());
_loadNotesFromDisk(); _loadNotesFromDisk();
}).catchError((err) { }).catchError((err) {
@ -154,7 +154,7 @@ class StateContainerState extends State<StateContainer> {
setState(() { setState(() {
// Update the git repo // Update the git repo
noteRepo.addFolder(newFolder).then((NoteRepoResult _) { _gitRepo.addFolder(newFolder).then((NoteRepoResult _) {
_syncNotes(); _syncNotes();
}); });
}); });
@ -167,7 +167,7 @@ class StateContainerState extends State<StateContainer> {
folder.rename(newFolderName); folder.rename(newFolderName);
// Update the git repo // Update the git repo
noteRepo _gitRepo
.renameFolder(oldFolderPath, folder.folderPath) .renameFolder(oldFolderPath, folder.folderPath)
.then((NoteRepoResult _) { .then((NoteRepoResult _) {
_syncNotes(); _syncNotes();
@ -182,7 +182,7 @@ class StateContainerState extends State<StateContainer> {
void removeNote(Note note) { void removeNote(Note note) {
setState(() { setState(() {
note.parent.remove(note); note.parent.remove(note);
noteRepo.removeNote(note.filePath).then((NoteRepoResult _) async { _gitRepo.removeNote(note.filePath).then((NoteRepoResult _) async {
// 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
@ -196,7 +196,7 @@ class StateContainerState extends State<StateContainer> {
void undoRemoveNote(Note note, int index) { void undoRemoveNote(Note note, int index) {
setState(() { setState(() {
note.parent.insert(index, note); note.parent.insert(index, note);
noteRepo.resetLastCommit().then((NoteRepoResult _) { _gitRepo.resetLastCommit().then((NoteRepoResult _) {
_syncNotes(); _syncNotes();
}); });
}); });
@ -208,11 +208,11 @@ class StateContainerState extends State<StateContainer> {
if (note.filePath == null || note.filePath.isEmpty) { if (note.filePath == null || note.filePath.isEmpty) {
var parentPath = note.parent != null var parentPath = note.parent != null
? note.parent.folderPath ? note.parent.folderPath
: noteRepo.notesBasePath; : _gitRepo.notesBasePath;
note.filePath = p.join(parentPath, getFileName(note)); note.filePath = p.join(parentPath, getFileName(note));
} }
note.parent.insert(index, note); note.parent.insert(index, note);
noteRepo.addNote(note).then((NoteRepoResult _) { _gitRepo.addNote(note).then((NoteRepoResult _) {
_syncNotes(); _syncNotes();
}); });
}); });
@ -222,7 +222,7 @@ class StateContainerState extends State<StateContainer> {
Fimber.d("State Container updateNote"); Fimber.d("State Container updateNote");
setState(() { setState(() {
// Update the git repo // Update the git repo
noteRepo.updateNote(note).then((NoteRepoResult _) { _gitRepo.updateNote(note).then((NoteRepoResult _) {
_syncNotes(); _syncNotes();
}); });
}); });
@ -239,11 +239,11 @@ class StateContainerState extends State<StateContainer> {
gitBasePath: appState.gitBaseDirectory, gitBasePath: appState.gitBaseDirectory,
); );
noteRepo = GitNoteRepository( _gitRepo = GitNoteRepository(
baseDirectory: appState.gitBaseDirectory, baseDirectory: appState.gitBaseDirectory,
dirName: appState.remoteGitRepoFolderName, dirName: appState.remoteGitRepoFolderName,
); );
appState.notesFolder = NotesFolder(null, noteRepo.notesBasePath); appState.notesFolder = NotesFolder(null, _gitRepo.notesBasePath);
await _persistConfig(); await _persistConfig();
_loadNotesFromDisk(); _loadNotesFromDisk();