Remove some uses of the Settings singleton

It needs to be removed from everywhere.
This commit is contained in:
Vishesh Handa
2020-09-25 00:40:23 +02:00
parent fe08834259
commit eb4d99338b
3 changed files with 30 additions and 25 deletions

View File

@ -6,7 +6,6 @@ import 'package:flutter/foundation.dart';
import 'package:git_bindings/git_bindings.dart'; import 'package:git_bindings/git_bindings.dart';
import 'package:path/path.dart' as p; import 'package:path/path.dart' as p;
import 'package:gitjournal/settings.dart';
import 'package:gitjournal/utils/logger.dart'; import 'package:gitjournal/utils/logger.dart';
// //
@ -16,6 +15,8 @@ Future migrateGitRepo({
@required String gitBasePath, @required String gitBasePath,
@required String fromGitBasePath, @required String fromGitBasePath,
@required String toGitBaseFolder, @required String toGitBaseFolder,
@required String gitAuthor,
@required String gitAuthorEmail,
}) async { }) async {
Log.d("migrateGitRepo $fromGitBasePath $toGitBaseFolder"); Log.d("migrateGitRepo $fromGitBasePath $toGitBaseFolder");
var fromBasePath = p.join(gitBasePath, fromGitBasePath); var fromBasePath = p.join(gitBasePath, fromGitBasePath);
@ -40,8 +41,8 @@ Future migrateGitRepo({
await gitRepo.add(fileName); await gitRepo.add(fileName);
await gitRepo.commit( await gitRepo.commit(
message: "Added Note", message: "Added Note",
authorEmail: Settings.instance.gitAuthorEmail, authorEmail: gitAuthorEmail,
authorName: Settings.instance.gitAuthor, authorName: gitAuthor,
); );
} }
Log.d("migrateGitRepo: Done"); Log.d("migrateGitRepo: Done");

View File

@ -25,9 +25,11 @@ class NoteRepoResult {
class GitNoteRepository { class GitNoteRepository {
final String gitDirPath; final String gitDirPath;
final GitRepo _gitRepo; final GitRepo _gitRepo;
final Settings settings;
GitNoteRepository({ GitNoteRepository({
@required this.gitDirPath, @required this.gitDirPath,
@required this.settings,
}) : _gitRepo = GitRepo(folderPath: gitDirPath); }) : _gitRepo = GitRepo(folderPath: gitDirPath);
Future<NoteRepoResult> addNote(Note note) async { Future<NoteRepoResult> addNote(Note note) async {
@ -38,8 +40,8 @@ class GitNoteRepository {
await _gitRepo.add("."); await _gitRepo.add(".");
await _gitRepo.commit( await _gitRepo.commit(
message: commitMessage, message: commitMessage,
authorEmail: Settings.instance.gitAuthorEmail, authorEmail: settings.gitAuthorEmail,
authorName: Settings.instance.gitAuthor, authorName: settings.gitAuthor,
); );
return NoteRepoResult(noteFilePath: note.filePath, error: false); return NoteRepoResult(noteFilePath: note.filePath, error: false);
@ -49,8 +51,8 @@ class GitNoteRepository {
await _gitRepo.add("."); await _gitRepo.add(".");
await _gitRepo.commit( await _gitRepo.commit(
message: "Created New Folder", message: "Created New Folder",
authorEmail: Settings.instance.gitAuthorEmail, authorEmail: settings.gitAuthorEmail,
authorName: Settings.instance.gitAuthor, authorName: settings.gitAuthor,
); );
return NoteRepoResult(noteFilePath: folder.folderPath, error: false); return NoteRepoResult(noteFilePath: folder.folderPath, error: false);
@ -63,8 +65,8 @@ class GitNoteRepository {
await _gitRepo.add("."); await _gitRepo.add(".");
await _gitRepo.commit( await _gitRepo.commit(
message: "Update folder config for $pathSpec", message: "Update folder config for $pathSpec",
authorEmail: Settings.instance.gitAuthorEmail, authorEmail: settings.gitAuthorEmail,
authorName: Settings.instance.gitAuthor, authorName: settings.gitAuthor,
); );
return NoteRepoResult(noteFilePath: config.folder.folderPath, error: false); return NoteRepoResult(noteFilePath: config.folder.folderPath, error: false);
@ -78,8 +80,8 @@ class GitNoteRepository {
await _gitRepo.add("."); await _gitRepo.add(".");
await _gitRepo.commit( await _gitRepo.commit(
message: "Renamed Folder", message: "Renamed Folder",
authorEmail: Settings.instance.gitAuthorEmail, authorEmail: settings.gitAuthorEmail,
authorName: Settings.instance.gitAuthor, authorName: settings.gitAuthor,
); );
return NoteRepoResult(noteFilePath: newFullPath, error: false); return NoteRepoResult(noteFilePath: newFullPath, error: false);
@ -93,8 +95,8 @@ class GitNoteRepository {
await _gitRepo.add("."); await _gitRepo.add(".");
await _gitRepo.commit( await _gitRepo.commit(
message: "Renamed Note", message: "Renamed Note",
authorEmail: Settings.instance.gitAuthorEmail, authorEmail: settings.gitAuthorEmail,
authorName: Settings.instance.gitAuthor, authorName: settings.gitAuthor,
); );
return NoteRepoResult(noteFilePath: newFullPath, error: false); return NoteRepoResult(noteFilePath: newFullPath, error: false);
@ -108,8 +110,8 @@ class GitNoteRepository {
await _gitRepo.add("."); await _gitRepo.add(".");
await _gitRepo.commit( await _gitRepo.commit(
message: "Renamed File", message: "Renamed File",
authorEmail: Settings.instance.gitAuthorEmail, authorEmail: settings.gitAuthorEmail,
authorName: Settings.instance.gitAuthor, authorName: settings.gitAuthor,
); );
return NoteRepoResult(noteFilePath: newFullPath, error: false); return NoteRepoResult(noteFilePath: newFullPath, error: false);
@ -123,8 +125,8 @@ class GitNoteRepository {
await _gitRepo.add("."); await _gitRepo.add(".");
await _gitRepo.commit( await _gitRepo.commit(
message: "Note Moved", message: "Note Moved",
authorEmail: Settings.instance.gitAuthorEmail, authorEmail: settings.gitAuthorEmail,
authorName: Settings.instance.gitAuthor, authorName: settings.gitAuthor,
); );
return NoteRepoResult(noteFilePath: newFullPath, error: false); return NoteRepoResult(noteFilePath: newFullPath, error: false);
@ -136,8 +138,8 @@ class GitNoteRepository {
await _gitRepo.rm(spec); await _gitRepo.rm(spec);
await _gitRepo.commit( await _gitRepo.commit(
message: "Removed Note " + spec, message: "Removed Note " + spec,
authorEmail: Settings.instance.gitAuthorEmail, authorEmail: settings.gitAuthorEmail,
authorName: Settings.instance.gitAuthor, authorName: settings.gitAuthor,
); );
return NoteRepoResult(noteFilePath: note.filePath, error: false); return NoteRepoResult(noteFilePath: note.filePath, error: false);
@ -148,8 +150,8 @@ class GitNoteRepository {
await _gitRepo.rm(spec); await _gitRepo.rm(spec);
await _gitRepo.commit( await _gitRepo.commit(
message: "Removed Folder " + spec, message: "Removed Folder " + spec,
authorEmail: Settings.instance.gitAuthorEmail, authorEmail: settings.gitAuthorEmail,
authorName: Settings.instance.gitAuthor, authorName: settings.gitAuthor,
); );
await Directory(folder.folderPath).delete(recursive: true); await Directory(folder.folderPath).delete(recursive: true);
@ -169,8 +171,8 @@ class GitNoteRepository {
Future<void> pull() async { Future<void> pull() async {
try { try {
await _gitRepo.pull( await _gitRepo.pull(
authorEmail: Settings.instance.gitAuthorEmail, authorEmail: settings.gitAuthorEmail,
authorName: Settings.instance.gitAuthor, authorName: settings.gitAuthor,
); );
} on GitException catch (ex, stackTrace) { } on GitException catch (ex, stackTrace) {
Log.e("GitPull Failed", ex: ex, stacktrace: stackTrace); Log.e("GitPull Failed", ex: ex, stacktrace: stackTrace);

View File

@ -48,7 +48,7 @@ class StateContainer with ChangeNotifier {
repoPath = p.join(gitBaseDirectory, settings.localGitRepoFolderName); repoPath = p.join(gitBaseDirectory, settings.localGitRepoFolderName);
} }
_gitRepo = GitNoteRepository(gitDirPath: repoPath); _gitRepo = GitNoteRepository(gitDirPath: repoPath, settings: settings);
appState.notesFolder = NotesFolderFS(null, _gitRepo.gitDirPath); appState.notesFolder = NotesFolderFS(null, _gitRepo.gitDirPath);
// Just a fail safe // Just a fail safe
@ -361,11 +361,13 @@ class StateContainer with ChangeNotifier {
fromGitBasePath: settings.localGitRepoFolderName, fromGitBasePath: settings.localGitRepoFolderName,
toGitBaseFolder: settings.remoteGitRepoFolderName, toGitBaseFolder: settings.remoteGitRepoFolderName,
gitBasePath: gitBaseDirectory, gitBasePath: gitBaseDirectory,
gitAuthor: settings.gitAuthor,
gitAuthorEmail: settings.gitAuthorEmail,
); );
} }
var repoPath = p.join(gitBaseDirectory, settings.remoteGitRepoFolderName); var repoPath = p.join(gitBaseDirectory, settings.remoteGitRepoFolderName);
_gitRepo = GitNoteRepository(gitDirPath: repoPath); _gitRepo = GitNoteRepository(gitDirPath: repoPath, settings: settings);
appState.notesFolder.reset(_gitRepo.gitDirPath); appState.notesFolder.reset(_gitRepo.gitDirPath);
await _persistConfig(); await _persistConfig();