Move all persistent state from AppState to Settings

This way all the persistant state of the app is managed from the same
place. It makes everything much easier. Also, it's required for when
GitJournal supports multiple repositories.
This commit is contained in:
Vishesh Handa
2020-09-24 23:44:32 +02:00
parent 1f32a3c10e
commit f30c52f595
11 changed files with 79 additions and 108 deletions

View File

@ -1,7 +1,4 @@
import 'package:shared_preferences/shared_preferences.dart';
import 'package:gitjournal/core/notes_folder_fs.dart';
import 'package:gitjournal/utils/logger.dart';
enum SyncStatus {
Unknown,
@ -12,54 +9,12 @@ enum SyncStatus {
}
class AppState {
//
// Saved on Disk
//
// FIXME: These should be figured out by querying the 'git remotes'
String localGitRepoFolderName = "";
bool localGitRepoConfigured = false;
String remoteGitRepoFolderName = "";
bool remoteGitRepoConfigured = false;
SyncStatus syncStatus = SyncStatus.Unknown;
int numChanges = 0;
//
// Temporary
//
/// This is the directory where all the git repos are stored
String gitBaseDirectory = "";
bool get hasJournalEntries {
return notesFolder.hasNotes;
}
NotesFolderFS notesFolder;
AppState(SharedPreferences pref) {
localGitRepoConfigured = pref.getBool("localGitRepoConfigured") ?? false;
remoteGitRepoConfigured = pref.getBool("remoteGitRepoConfigured") ?? false;
localGitRepoFolderName = pref.getString("localGitRepoPath") ?? "";
remoteGitRepoFolderName = pref.getString("remoteGitRepoPath") ?? "";
gitBaseDirectory = pref.getString("gitBaseDirectory") ?? "";
}
void dumpToLog() {
Log.i(" ---- Settings ---- ");
Log.i("localGitRepoConfigured: $localGitRepoConfigured");
Log.i("remoteGitRepoConfigured: $remoteGitRepoConfigured");
Log.i("localGitRepoFolderName: $localGitRepoFolderName");
Log.i("remoteGitRepoFolderName: $remoteGitRepoFolderName");
Log.i("gitBaseDirectory: $gitBaseDirectory");
Log.i(" ------------------ ");
}
Future save(SharedPreferences pref) async {
await pref.setBool("localGitRepoConfigured", localGitRepoConfigured);
await pref.setBool("remoteGitRepoConfigured", remoteGitRepoConfigured);
await pref.setString("localGitRepoPath", localGitRepoFolderName);
await pref.setString("remoteGitRepoPath", remoteGitRepoFolderName);
await pref.setString("gitBaseDirectory", gitBaseDirectory);
}
}