mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-26 00:29:20 +08:00
Simplify Settings/Config classes
This commit is contained in:
@ -414,8 +414,8 @@ class GitJournalChangeNotifiers extends StatelessWidget {
|
||||
Widget buildMarkdownSettings({required Widget child}) {
|
||||
return Consumer<RepositoryManager>(
|
||||
builder: (_, repoManager, __) {
|
||||
var markdown = MarkdownRendererConfig(repoManager.currentId);
|
||||
markdown.load(pref);
|
||||
var markdown = MarkdownRendererConfig(repoManager.currentId, pref);
|
||||
markdown.load();
|
||||
|
||||
return ChangeNotifierProvider.value(value: markdown, child: child);
|
||||
},
|
||||
|
0
lib/core/file.dart
Normal file
0
lib/core/file.dart
Normal file
@ -8,11 +8,14 @@ import 'package:gitjournal/settings/settings.dart';
|
||||
import 'package:gitjournal/settings/settings_sharedpref.dart';
|
||||
|
||||
class NotesFolderConfig extends ChangeNotifier with SettingsSharedPref {
|
||||
NotesFolderConfig(this.id);
|
||||
NotesFolderConfig(this.id, this.pref);
|
||||
|
||||
@override
|
||||
final String id;
|
||||
|
||||
@override
|
||||
final SharedPreferences pref;
|
||||
|
||||
var sortingField = SortingField.Default;
|
||||
var sortingOrder = SortingOrder.Default;
|
||||
|
||||
@ -34,83 +37,71 @@ class NotesFolderConfig extends ChangeNotifier with SettingsSharedPref {
|
||||
var inlineTagPrefixes = {'#'};
|
||||
var imageLocationSpec = "."; // . means the same folder
|
||||
|
||||
void load(SharedPreferences pref) {
|
||||
fileNameFormat = NoteFileNameFormat.fromInternalString(
|
||||
getString(pref, "noteFileNameFormat"));
|
||||
void load() {
|
||||
fileNameFormat =
|
||||
NoteFileNameFormat.fromInternalString(getString("noteFileNameFormat"));
|
||||
journalFileNameFormat = NoteFileNameFormat.fromInternalString(
|
||||
getString(pref, "journalNoteFileNameFormat"));
|
||||
getString("journalNoteFileNameFormat"));
|
||||
|
||||
yamlModifiedKey = getString(pref, "yamlModifiedKey") ?? yamlModifiedKey;
|
||||
yamlCreatedKey = getString(pref, "yamlCreatedKey") ?? yamlCreatedKey;
|
||||
yamlTagsKey = getString(pref, "yamlTagsKey") ?? yamlTagsKey;
|
||||
yamlModifiedKey = getString("yamlModifiedKey") ?? yamlModifiedKey;
|
||||
yamlCreatedKey = getString("yamlCreatedKey") ?? yamlCreatedKey;
|
||||
yamlTagsKey = getString("yamlTagsKey") ?? yamlTagsKey;
|
||||
|
||||
yamlHeaderEnabled = getBool(pref, "yamlHeaderEnabled") ?? yamlHeaderEnabled;
|
||||
yamlHeaderEnabled = getBool("yamlHeaderEnabled") ?? yamlHeaderEnabled;
|
||||
|
||||
sortingField =
|
||||
SortingField.fromInternalString(getString(pref, "sortingField"));
|
||||
sortingOrder =
|
||||
SortingOrder.fromInternalString(getString(pref, "sortingOrder"));
|
||||
sortingField = SortingField.fromInternalString(getString("sortingField"));
|
||||
sortingOrder = SortingOrder.fromInternalString(getString("sortingOrder"));
|
||||
defaultEditor =
|
||||
SettingsEditorType.fromInternalString(getString(pref, "defaultEditor"));
|
||||
defaultView = SettingsFolderViewType.fromInternalString(
|
||||
getString(pref, "defaultView"));
|
||||
SettingsEditorType.fromInternalString(getString("defaultEditor"));
|
||||
defaultView =
|
||||
SettingsFolderViewType.fromInternalString(getString("defaultView"));
|
||||
|
||||
showNoteSummary = getBool(pref, "showNoteSummary") ?? showNoteSummary;
|
||||
showNoteSummary = getBool("showNoteSummary") ?? showNoteSummary;
|
||||
folderViewHeaderType =
|
||||
getString(pref, "folderViewHeaderType") ?? folderViewHeaderType;
|
||||
getString("folderViewHeaderType") ?? folderViewHeaderType;
|
||||
|
||||
imageLocationSpec =
|
||||
getString(pref, "imageLocationSpec") ?? imageLocationSpec;
|
||||
imageLocationSpec = getString("imageLocationSpec") ?? imageLocationSpec;
|
||||
|
||||
titleSettings =
|
||||
SettingsTitle.fromInternalString(getString(pref, "titleSettings"));
|
||||
SettingsTitle.fromInternalString(getString("titleSettings"));
|
||||
|
||||
inlineTagPrefixes =
|
||||
getStringSet(pref, "inlineTagPrefixes") ?? inlineTagPrefixes;
|
||||
inlineTagPrefixes = getStringSet("inlineTagPrefixes") ?? inlineTagPrefixes;
|
||||
}
|
||||
|
||||
Future<void> save() async {
|
||||
var pref = await SharedPreferences.getInstance();
|
||||
var defaultSet = NotesFolderConfig(id);
|
||||
var def = NotesFolderConfig(id, pref);
|
||||
|
||||
await setString("noteFileNameFormat", fileNameFormat.toInternalString(),
|
||||
def.fileNameFormat.toInternalString());
|
||||
await setString(
|
||||
pref,
|
||||
"noteFileNameFormat",
|
||||
fileNameFormat.toInternalString(),
|
||||
defaultSet.fileNameFormat.toInternalString());
|
||||
await setString(
|
||||
pref,
|
||||
"journalNoteFileNameFormat",
|
||||
journalFileNameFormat.toInternalString(),
|
||||
defaultSet.journalFileNameFormat.toInternalString());
|
||||
def.journalFileNameFormat.toInternalString());
|
||||
|
||||
await setString("sortingField", sortingField.toInternalString(),
|
||||
def.sortingField.toInternalString());
|
||||
await setString("sortingOrder", sortingOrder.toInternalString(),
|
||||
def.sortingOrder.toInternalString());
|
||||
await setString("defaultEditor", defaultEditor.toInternalString(),
|
||||
def.defaultEditor.toInternalString());
|
||||
await setString("defaultView", defaultView.toInternalString(),
|
||||
def.defaultView.toInternalString());
|
||||
await setBool("showNoteSummary", showNoteSummary, def.showNoteSummary);
|
||||
await setString(
|
||||
"folderViewHeaderType", folderViewHeaderType, def.folderViewHeaderType);
|
||||
|
||||
await setString(pref, "sortingField", sortingField.toInternalString(),
|
||||
defaultSet.sortingField.toInternalString());
|
||||
await setString(pref, "sortingOrder", sortingOrder.toInternalString(),
|
||||
defaultSet.sortingOrder.toInternalString());
|
||||
await setString(pref, "defaultEditor", defaultEditor.toInternalString(),
|
||||
defaultSet.defaultEditor.toInternalString());
|
||||
await setString(pref, "defaultView", defaultView.toInternalString(),
|
||||
defaultSet.defaultView.toInternalString());
|
||||
await setBool(
|
||||
pref, "showNoteSummary", showNoteSummary, defaultSet.showNoteSummary);
|
||||
await setString(pref, "folderViewHeaderType", folderViewHeaderType,
|
||||
defaultSet.folderViewHeaderType);
|
||||
"yamlHeaderEnabled", yamlHeaderEnabled, def.yamlHeaderEnabled);
|
||||
await setString("yamlModifiedKey", yamlModifiedKey, def.yamlModifiedKey);
|
||||
await setString("yamlCreatedKey", yamlCreatedKey, def.yamlCreatedKey);
|
||||
await setString("yamlTagsKey", yamlTagsKey, def.yamlTagsKey);
|
||||
await setString("titleSettings", titleSettings.toInternalString(),
|
||||
def.titleSettings.toInternalString());
|
||||
|
||||
await setBool(pref, "yamlHeaderEnabled", yamlHeaderEnabled,
|
||||
defaultSet.yamlHeaderEnabled);
|
||||
await setStringSet(
|
||||
"inlineTagPrefixes", inlineTagPrefixes, def.inlineTagPrefixes);
|
||||
await setString(
|
||||
pref, "yamlModifiedKey", yamlModifiedKey, defaultSet.yamlModifiedKey);
|
||||
await setString(
|
||||
pref, "yamlCreatedKey", yamlCreatedKey, defaultSet.yamlCreatedKey);
|
||||
await setString(pref, "yamlTagsKey", yamlTagsKey, defaultSet.yamlTagsKey);
|
||||
await setString(pref, "titleSettings", titleSettings.toInternalString(),
|
||||
defaultSet.titleSettings.toInternalString());
|
||||
|
||||
await setStringSet(pref, "inlineTagPrefixes", inlineTagPrefixes,
|
||||
defaultSet.inlineTagPrefixes);
|
||||
await setString(pref, "imageLocationSpec", imageLocationSpec,
|
||||
defaultSet.imageLocationSpec);
|
||||
"imageLocationSpec", imageLocationSpec, def.imageLocationSpec);
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
@ -1,13 +1,12 @@
|
||||
import 'package:gitjournal/settings/settings.dart';
|
||||
import 'note.dart';
|
||||
import 'notes_folder.dart';
|
||||
import 'notes_folder_notifier.dart';
|
||||
|
||||
class VirtualNotesFolder with NotesFolderNotifier implements NotesFolder {
|
||||
final List<Note> _notes;
|
||||
final Settings settings;
|
||||
final NotesFolderConfig _config;
|
||||
|
||||
VirtualNotesFolder(this._notes, this.settings);
|
||||
VirtualNotesFolder(this._notes, this._config);
|
||||
|
||||
@override
|
||||
List<Note> get notes => _notes;
|
||||
@ -39,8 +38,5 @@ class VirtualNotesFolder with NotesFolderNotifier implements NotesFolder {
|
||||
}
|
||||
|
||||
@override
|
||||
NotesFolderConfig get config {
|
||||
// FIXME: This isn't expecting null!
|
||||
return NotesFolderConfig('_');
|
||||
}
|
||||
NotesFolderConfig get config => _config;
|
||||
}
|
||||
|
@ -75,17 +75,17 @@ class GitJournalRepo with ChangeNotifier {
|
||||
}) async {
|
||||
await migrateSettings(id, pref, gitBaseDir);
|
||||
|
||||
var storageConfig = StorageConfig(id);
|
||||
storageConfig.load(pref);
|
||||
var storageConfig = StorageConfig(id, pref);
|
||||
storageConfig.load();
|
||||
|
||||
var folderConfig = NotesFolderConfig(id);
|
||||
folderConfig.load(pref);
|
||||
var folderConfig = NotesFolderConfig(id, pref);
|
||||
folderConfig.load();
|
||||
|
||||
var gitConfig = GitConfig(id);
|
||||
gitConfig.load(pref);
|
||||
var gitConfig = GitConfig(id, pref);
|
||||
gitConfig.load();
|
||||
|
||||
var settings = Settings(id);
|
||||
settings.load(pref);
|
||||
var settings = Settings(id, pref);
|
||||
settings.load();
|
||||
|
||||
// logEvent(Event.Settings, parameters: settings.toLoggableMap());
|
||||
|
||||
|
@ -5,37 +5,36 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:gitjournal/settings/settings_sharedpref.dart';
|
||||
|
||||
class GitConfig extends ChangeNotifier with SettingsSharedPref {
|
||||
GitConfig(this.id);
|
||||
GitConfig(this.id, this.pref);
|
||||
|
||||
@override
|
||||
final String id;
|
||||
|
||||
@override
|
||||
final SharedPreferences pref;
|
||||
|
||||
var gitAuthor = "GitJournal";
|
||||
var gitAuthorEmail = "app@gitjournal.io";
|
||||
var sshPublicKey = "";
|
||||
var sshPrivateKey = "";
|
||||
var sshPassword = "";
|
||||
|
||||
void load(SharedPreferences pref) {
|
||||
gitAuthor = getString(pref, "gitAuthor") ?? gitAuthor;
|
||||
gitAuthorEmail = getString(pref, "gitAuthorEmail") ?? gitAuthorEmail;
|
||||
sshPublicKey = getString(pref, "sshPublicKey") ?? sshPublicKey;
|
||||
sshPrivateKey = getString(pref, "sshPrivateKey") ?? sshPrivateKey;
|
||||
sshPassword = getString(pref, "sshPassword") ?? sshPassword;
|
||||
void load() {
|
||||
gitAuthor = getString("gitAuthor") ?? gitAuthor;
|
||||
gitAuthorEmail = getString("gitAuthorEmail") ?? gitAuthorEmail;
|
||||
sshPublicKey = getString("sshPublicKey") ?? sshPublicKey;
|
||||
sshPrivateKey = getString("sshPrivateKey") ?? sshPrivateKey;
|
||||
sshPassword = getString("sshPassword") ?? sshPassword;
|
||||
}
|
||||
|
||||
Future<void> save() async {
|
||||
var pref = await SharedPreferences.getInstance();
|
||||
var defaultSet = GitConfig(id);
|
||||
var def = GitConfig(id, pref);
|
||||
|
||||
await setString(pref, "gitAuthor", gitAuthor, defaultSet.gitAuthor);
|
||||
await setString(
|
||||
pref, "gitAuthorEmail", gitAuthorEmail, defaultSet.gitAuthorEmail);
|
||||
await setString(
|
||||
pref, "sshPublicKey", sshPublicKey, defaultSet.sshPublicKey);
|
||||
await setString(
|
||||
pref, "sshPrivateKey", sshPrivateKey, defaultSet.sshPrivateKey);
|
||||
await setString(pref, "sshPassword", sshPassword, defaultSet.sshPassword);
|
||||
await setString("gitAuthor", gitAuthor, def.gitAuthor);
|
||||
await setString("gitAuthorEmail", gitAuthorEmail, def.gitAuthorEmail);
|
||||
await setString("sshPublicKey", sshPublicKey, def.sshPublicKey);
|
||||
await setString("sshPrivateKey", sshPrivateKey, def.sshPrivateKey);
|
||||
await setString("sshPassword", sshPassword, def.sshPassword);
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
@ -23,11 +23,14 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:gitjournal/settings/settings_sharedpref.dart';
|
||||
|
||||
class MarkdownRendererConfig extends ChangeNotifier with SettingsSharedPref {
|
||||
MarkdownRendererConfig(this.id);
|
||||
MarkdownRendererConfig(this.id, this.pref);
|
||||
|
||||
@override
|
||||
final String id;
|
||||
|
||||
@override
|
||||
final SharedPreferences pref;
|
||||
|
||||
// Display - Image
|
||||
bool rotateImageGestures = false;
|
||||
double maxImageZoom = 10;
|
||||
@ -51,92 +54,78 @@ class MarkdownRendererConfig extends ChangeNotifier with SettingsSharedPref {
|
||||
var doNotCaptionTags = {"nocaption", "!nc"};
|
||||
var doCaptionTags = {"docaption", "!dc"};
|
||||
|
||||
void load(SharedPreferences pref) {
|
||||
void load() {
|
||||
// Display - Image
|
||||
rotateImageGestures =
|
||||
getBool(pref, "rotateImageGestures") ?? rotateImageGestures;
|
||||
maxImageZoom = getDouble(pref, "maxImageZoom") ?? maxImageZoom;
|
||||
rotateImageGestures = getBool("rotateImageGestures") ?? rotateImageGestures;
|
||||
maxImageZoom = getDouble("maxImageZoom") ?? maxImageZoom;
|
||||
|
||||
// Display - Image - Theming
|
||||
themeRasterGraphics =
|
||||
getBool(pref, "themeRasterGraphics") ?? themeRasterGraphics;
|
||||
themeRasterGraphics = getBool("themeRasterGraphics") ?? themeRasterGraphics;
|
||||
themeOverrideTagLocation = SettingsImageTextType.fromInternalString(
|
||||
getString(pref, "themeOverrideTagLocation"));
|
||||
doNotThemeTags = getStringSet(pref, "doNotThemeTags") ?? doNotThemeTags;
|
||||
doThemeTags = getStringSet(pref, "doThemeTags") ?? doThemeTags;
|
||||
getString("themeOverrideTagLocation"));
|
||||
doNotThemeTags = getStringSet("doNotThemeTags") ?? doNotThemeTags;
|
||||
doThemeTags = getStringSet("doThemeTags") ?? doThemeTags;
|
||||
themeVectorGraphics = SettingsThemeVectorGraphics.fromInternalString(
|
||||
getString(pref, "themeVectorGraphics"));
|
||||
getString("themeVectorGraphics"));
|
||||
themeSvgWithBackground =
|
||||
getBool(pref, "themeSvgWithBackground") ?? themeSvgWithBackground;
|
||||
matchCanvasColor = getBool(pref, "matchCanvasColor") ?? matchCanvasColor;
|
||||
getBool("themeSvgWithBackground") ?? themeSvgWithBackground;
|
||||
matchCanvasColor = getBool("matchCanvasColor") ?? matchCanvasColor;
|
||||
vectorGraphicsAdjustColors =
|
||||
SettingsVectorGraphicsAdjustColors.fromInternalString(
|
||||
getString(pref, "vectorGraphicsAdjustColors"));
|
||||
getString("vectorGraphicsAdjustColors"));
|
||||
|
||||
// Display - Image - Caption
|
||||
overlayCaption = getBool(pref, "overlayCaption") ?? overlayCaption;
|
||||
transparentCaption =
|
||||
getBool(pref, "transparentCaption") ?? transparentCaption;
|
||||
blurBehindCaption = getBool(pref, "blurBehindCaption") ?? blurBehindCaption;
|
||||
tooltipFirst = getBool(pref, "tooltipFirst") ?? tooltipFirst;
|
||||
useAsCaption = SettingsImageTextType.fromInternalString(
|
||||
getString(pref, "useAsCaption"));
|
||||
doNotCaptionTags =
|
||||
getStringSet(pref, "doNotCaptionTag") ?? doNotCaptionTags;
|
||||
doCaptionTags = getStringSet(pref, "doCaptionTag") ?? doCaptionTags;
|
||||
overlayCaption = getBool("overlayCaption") ?? overlayCaption;
|
||||
transparentCaption = getBool("transparentCaption") ?? transparentCaption;
|
||||
blurBehindCaption = getBool("blurBehindCaption") ?? blurBehindCaption;
|
||||
tooltipFirst = getBool("tooltipFirst") ?? tooltipFirst;
|
||||
useAsCaption =
|
||||
SettingsImageTextType.fromInternalString(getString("useAsCaption"));
|
||||
doNotCaptionTags = getStringSet("doNotCaptionTag") ?? doNotCaptionTags;
|
||||
doCaptionTags = getStringSet("doCaptionTag") ?? doCaptionTags;
|
||||
}
|
||||
|
||||
Future<void> save() async {
|
||||
var pref = await SharedPreferences.getInstance();
|
||||
var defaultSet = MarkdownRendererConfig(id);
|
||||
var def = MarkdownRendererConfig(id, pref);
|
||||
|
||||
// Display - Image
|
||||
await setBool(pref, "rotateImageGestures", rotateImageGestures,
|
||||
defaultSet.rotateImageGestures);
|
||||
await setDouble(
|
||||
pref, "maxImageZoom", maxImageZoom, defaultSet.maxImageZoom);
|
||||
await setBool(
|
||||
"rotateImageGestures", rotateImageGestures, def.rotateImageGestures);
|
||||
await setDouble("maxImageZoom", maxImageZoom, def.maxImageZoom);
|
||||
|
||||
// Display - Image - Theme
|
||||
await setBool(pref, "themeRasterGraphics", themeRasterGraphics,
|
||||
defaultSet.themeRasterGraphics);
|
||||
await setBool(
|
||||
"themeRasterGraphics", themeRasterGraphics, def.themeRasterGraphics);
|
||||
await setString(
|
||||
pref,
|
||||
"themeOverrideTagLocation",
|
||||
themeOverrideTagLocation.toInternalString(),
|
||||
defaultSet.themeOverrideTagLocation.toInternalString());
|
||||
await setStringSet(
|
||||
pref, "doNotThemeTags", doNotThemeTags, defaultSet.doNotThemeTags);
|
||||
await setStringSet(
|
||||
pref, "doThemeTags", doThemeTags, defaultSet.doThemeTags);
|
||||
def.themeOverrideTagLocation.toInternalString());
|
||||
await setStringSet("doNotThemeTags", doNotThemeTags, def.doNotThemeTags);
|
||||
await setStringSet("doThemeTags", doThemeTags, def.doThemeTags);
|
||||
await setString(
|
||||
pref,
|
||||
"themeVectorGraphics",
|
||||
themeVectorGraphics.toInternalString(),
|
||||
defaultSet.themeVectorGraphics.toInternalString());
|
||||
await setBool(pref, "themeSvgWithBackground", themeSvgWithBackground,
|
||||
defaultSet.themeSvgWithBackground);
|
||||
await setBool(pref, "matchCanvasColor", matchCanvasColor,
|
||||
defaultSet.matchCanvasColor);
|
||||
def.themeVectorGraphics.toInternalString());
|
||||
await setBool("themeSvgWithBackground", themeSvgWithBackground,
|
||||
def.themeSvgWithBackground);
|
||||
await setBool("matchCanvasColor", matchCanvasColor, def.matchCanvasColor);
|
||||
await setString(
|
||||
pref,
|
||||
"vectorGraphicsAdjustColors",
|
||||
vectorGraphicsAdjustColors.toInternalString(),
|
||||
defaultSet.vectorGraphicsAdjustColors.toInternalString());
|
||||
def.vectorGraphicsAdjustColors.toInternalString());
|
||||
|
||||
// Display - Image - Caption
|
||||
await setBool("overlayCaption", overlayCaption, def.overlayCaption);
|
||||
await setBool(
|
||||
pref, "overlayCaption", overlayCaption, defaultSet.overlayCaption);
|
||||
await setBool(pref, "transparentCaption", transparentCaption,
|
||||
defaultSet.transparentCaption);
|
||||
await setBool(pref, "blurBehindCaption", blurBehindCaption,
|
||||
defaultSet.blurBehindCaption);
|
||||
await setBool(pref, "tooltipFirst", tooltipFirst, defaultSet.tooltipFirst);
|
||||
await setString(pref, "useAsCaption", useAsCaption.toInternalString(),
|
||||
defaultSet.useAsCaption.toInternalString());
|
||||
"transparentCaption", transparentCaption, def.transparentCaption);
|
||||
await setBool(
|
||||
"blurBehindCaption", blurBehindCaption, def.blurBehindCaption);
|
||||
await setBool("tooltipFirst", tooltipFirst, def.tooltipFirst);
|
||||
await setString("useAsCaption", useAsCaption.toInternalString(),
|
||||
def.useAsCaption.toInternalString());
|
||||
await setStringSet(
|
||||
pref, "doNotCaptionTag", doNotCaptionTags, defaultSet.doNotCaptionTags);
|
||||
await setStringSet(
|
||||
pref, "doCaptionTag", doCaptionTags, defaultSet.doCaptionTags);
|
||||
"doNotCaptionTag", doNotCaptionTags, def.doNotCaptionTags);
|
||||
await setStringSet("doCaptionTag", doCaptionTags, def.doCaptionTags);
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
8
lib/settings/screens_stories.dart
Normal file
8
lib/settings/screens_stories.dart
Normal file
@ -0,0 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:gitjournal/settings/settings_screen.dart';
|
||||
|
||||
// Need - Settings, AppSettings, Repo, RepoManager
|
||||
// It won't work otherwise!
|
||||
//
|
||||
Widget settingsScreen() => SettingsScreen();
|
@ -29,10 +29,14 @@ const DEFAULT_ID = "0";
|
||||
const SETTINGS_VERSION = 3;
|
||||
|
||||
class Settings extends ChangeNotifier with SettingsSharedPref {
|
||||
Settings(this.id);
|
||||
Settings(this.id, this.pref);
|
||||
|
||||
@override
|
||||
final String id;
|
||||
|
||||
@override
|
||||
final SharedPreferences pref;
|
||||
|
||||
String customMetaData = "";
|
||||
|
||||
String defaultNewNoteFolderSpec = "";
|
||||
@ -60,88 +64,80 @@ class Settings extends ChangeNotifier with SettingsSharedPref {
|
||||
bool confirmDelete = true;
|
||||
bool hardWrap = false;
|
||||
|
||||
void load(SharedPreferences pref) {
|
||||
void load() {
|
||||
defaultNewNoteFolderSpec =
|
||||
getString(pref, "defaultNewNoteFolderSpec") ?? defaultNewNoteFolderSpec;
|
||||
getString("defaultNewNoteFolderSpec") ?? defaultNewNoteFolderSpec;
|
||||
journalEditordefaultNewNoteFolderSpec =
|
||||
getString(pref, "journalEditordefaultNewNoteFolderSpec") ??
|
||||
getString("journalEditordefaultNewNoteFolderSpec") ??
|
||||
journalEditordefaultNewNoteFolderSpec;
|
||||
journalEditorSingleNote =
|
||||
getBool(pref, "journalEditorSingleNote") ?? journalEditorSingleNote;
|
||||
getBool("journalEditorSingleNote") ?? journalEditorSingleNote;
|
||||
|
||||
remoteSyncFrequency = RemoteSyncFrequency.fromInternalString(
|
||||
getString(pref, "remoteSyncFrequency"));
|
||||
getString("remoteSyncFrequency"));
|
||||
|
||||
markdownDefaultView = SettingsMarkdownDefaultView.fromInternalString(
|
||||
getString(pref, "markdownDefaultView"));
|
||||
getString("markdownDefaultView"));
|
||||
markdownLastUsedView = SettingsMarkdownDefaultView.fromInternalString(
|
||||
getString(pref, "markdownLastUsedView"));
|
||||
getString("markdownLastUsedView"));
|
||||
if (markdownLastUsedView == SettingsMarkdownDefaultView.LastUsed) {
|
||||
markdownLastUsedView = SettingsMarkdownDefaultView.Edit;
|
||||
}
|
||||
|
||||
version = getInt(pref, "settingsVersion") ?? version;
|
||||
emojiParser = getBool(pref, "emojiParser") ?? emojiParser;
|
||||
version = getInt("settingsVersion") ?? version;
|
||||
emojiParser = getBool("emojiParser") ?? emojiParser;
|
||||
|
||||
homeScreen =
|
||||
SettingsHomeScreen.fromInternalString(getString(pref, "homeScreen"));
|
||||
theme = SettingsTheme.fromInternalString(getString(pref, "theme"));
|
||||
homeScreen = SettingsHomeScreen.fromInternalString(getString("homeScreen"));
|
||||
theme = SettingsTheme.fromInternalString(getString("theme"));
|
||||
|
||||
zenMode = getBool(pref, "zenMode") ?? zenMode;
|
||||
swipeToDelete = getBool(pref, "swipeToDelete") ?? swipeToDelete;
|
||||
zenMode = getBool("zenMode") ?? zenMode;
|
||||
swipeToDelete = getBool("swipeToDelete") ?? swipeToDelete;
|
||||
|
||||
// From AppState
|
||||
bottomMenuBar = getBool(pref, "bottomMenuBar") ?? bottomMenuBar;
|
||||
confirmDelete = getBool(pref, "confirmDelete") ?? confirmDelete;
|
||||
bottomMenuBar = getBool("bottomMenuBar") ?? bottomMenuBar;
|
||||
confirmDelete = getBool("confirmDelete") ?? confirmDelete;
|
||||
|
||||
hardWrap = getBool(pref, "hardWrap") ?? hardWrap;
|
||||
hardWrap = getBool("hardWrap") ?? hardWrap;
|
||||
}
|
||||
|
||||
Future<void> save() async {
|
||||
var pref = await SharedPreferences.getInstance();
|
||||
var defaultSet = Settings(id);
|
||||
var def = Settings(id, pref);
|
||||
|
||||
await setString(pref, "defaultNewNoteFolderSpec", defaultNewNoteFolderSpec,
|
||||
defaultSet.defaultNewNoteFolderSpec);
|
||||
await setString("defaultNewNoteFolderSpec", defaultNewNoteFolderSpec,
|
||||
def.defaultNewNoteFolderSpec);
|
||||
await setString(
|
||||
pref,
|
||||
"journalEditordefaultNewNoteFolderSpec",
|
||||
journalEditordefaultNewNoteFolderSpec,
|
||||
defaultSet.journalEditordefaultNewNoteFolderSpec);
|
||||
await setBool(pref, "journalEditorSingleNote", journalEditorSingleNote,
|
||||
defaultSet.journalEditorSingleNote);
|
||||
def.journalEditordefaultNewNoteFolderSpec);
|
||||
await setBool("journalEditorSingleNote", journalEditorSingleNote,
|
||||
def.journalEditorSingleNote);
|
||||
await setString(
|
||||
pref,
|
||||
"remoteSyncFrequency",
|
||||
remoteSyncFrequency.toInternalString(),
|
||||
defaultSet.remoteSyncFrequency.toInternalString());
|
||||
def.remoteSyncFrequency.toInternalString());
|
||||
await setString(
|
||||
pref,
|
||||
"markdownDefaultView",
|
||||
markdownDefaultView.toInternalString(),
|
||||
defaultSet.markdownDefaultView.toInternalString());
|
||||
def.markdownDefaultView.toInternalString());
|
||||
await setString(
|
||||
pref,
|
||||
"markdownLastUsedView",
|
||||
markdownLastUsedView.toInternalString(),
|
||||
defaultSet.markdownLastUsedView.toInternalString());
|
||||
await setBool(pref, "emojiParser", emojiParser, defaultSet.emojiParser);
|
||||
await setString(pref, "homeScreen", homeScreen.toInternalString(),
|
||||
defaultSet.homeScreen.toInternalString());
|
||||
await setString(pref, "theme", theme.toInternalString(),
|
||||
defaultSet.theme.toInternalString());
|
||||
def.markdownLastUsedView.toInternalString());
|
||||
await setBool("emojiParser", emojiParser, def.emojiParser);
|
||||
await setString("homeScreen", homeScreen.toInternalString(),
|
||||
def.homeScreen.toInternalString());
|
||||
await setString(
|
||||
"theme", theme.toInternalString(), def.theme.toInternalString());
|
||||
|
||||
await setBool(pref, "zenMode", zenMode, defaultSet.zenMode);
|
||||
await setBool(
|
||||
pref, "swipeToDelete", swipeToDelete, defaultSet.swipeToDelete);
|
||||
await setBool(
|
||||
pref, "bottomMenuBar", bottomMenuBar, defaultSet.bottomMenuBar);
|
||||
await setBool(
|
||||
pref, "confirmDelete", confirmDelete, defaultSet.confirmDelete);
|
||||
await setBool("zenMode", zenMode, def.zenMode);
|
||||
await setBool("swipeToDelete", swipeToDelete, def.swipeToDelete);
|
||||
await setBool("bottomMenuBar", bottomMenuBar, def.bottomMenuBar);
|
||||
await setBool("confirmDelete", confirmDelete, def.confirmDelete);
|
||||
|
||||
await setInt(pref, "settingsVersion", version, defaultSet.version);
|
||||
await setInt("settingsVersion", version, def.version);
|
||||
|
||||
await setBool(pref, "hardWrap", hardWrap, defaultSet.hardWrap);
|
||||
await setBool("hardWrap", hardWrap, def.hardWrap);
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
@ -7,42 +7,40 @@ abstract class SettingsSharedPref {
|
||||
String get id;
|
||||
|
||||
@protected
|
||||
String? getString(SharedPreferences pref, String key) {
|
||||
SharedPreferences get pref;
|
||||
|
||||
@protected
|
||||
String? getString(String key) {
|
||||
return pref.getString(id + '_' + key);
|
||||
}
|
||||
|
||||
@protected
|
||||
bool? getBool(SharedPreferences pref, String key) {
|
||||
bool? getBool(String key) {
|
||||
return pref.getBool(id + '_' + key);
|
||||
}
|
||||
|
||||
@protected
|
||||
List<String>? getStringList(SharedPreferences pref, String key) {
|
||||
List<String>? getStringList(String key) {
|
||||
return pref.getStringList(id + '_' + key);
|
||||
}
|
||||
|
||||
@protected
|
||||
Set<String>? getStringSet(SharedPreferences pref, String key) {
|
||||
return getStringList(pref, key)?.toSet();
|
||||
Set<String>? getStringSet(String key) {
|
||||
return getStringList(key)?.toSet();
|
||||
}
|
||||
|
||||
@protected
|
||||
int? getInt(SharedPreferences pref, String key) {
|
||||
int? getInt(String key) {
|
||||
return pref.getInt(id + '_' + key);
|
||||
}
|
||||
|
||||
@protected
|
||||
double? getDouble(SharedPreferences pref, String key) {
|
||||
double? getDouble(String key) {
|
||||
return pref.getDouble(id + '_' + key);
|
||||
}
|
||||
|
||||
@protected
|
||||
Future<void> setString(
|
||||
SharedPreferences pref,
|
||||
String key,
|
||||
String value,
|
||||
String? defaultValue,
|
||||
) async {
|
||||
Future<void> setString(String key, String value, String? defaultValue) async {
|
||||
key = id + '_' + key;
|
||||
if (value == defaultValue) {
|
||||
await pref.remove(key);
|
||||
@ -52,12 +50,7 @@ abstract class SettingsSharedPref {
|
||||
}
|
||||
|
||||
@protected
|
||||
Future<void> setBool(
|
||||
SharedPreferences pref,
|
||||
String key,
|
||||
bool value,
|
||||
bool defaultValue,
|
||||
) async {
|
||||
Future<void> setBool(String key, bool value, bool defaultValue) async {
|
||||
key = id + '_' + key;
|
||||
if (value == defaultValue) {
|
||||
await pref.remove(key);
|
||||
@ -67,12 +60,7 @@ abstract class SettingsSharedPref {
|
||||
}
|
||||
|
||||
@protected
|
||||
Future<void> setInt(
|
||||
SharedPreferences pref,
|
||||
String key,
|
||||
int value,
|
||||
int defaultValue,
|
||||
) async {
|
||||
Future<void> setInt(String key, int value, int defaultValue) async {
|
||||
key = id + '_' + key;
|
||||
if (value == defaultValue) {
|
||||
await pref.remove(key);
|
||||
@ -82,12 +70,7 @@ abstract class SettingsSharedPref {
|
||||
}
|
||||
|
||||
@protected
|
||||
Future<void> setDouble(
|
||||
SharedPreferences pref,
|
||||
String key,
|
||||
double value,
|
||||
double defaultValue,
|
||||
) async {
|
||||
Future<void> setDouble(String key, double value, double defaultValue) async {
|
||||
key = id + '_' + key;
|
||||
if (value == defaultValue) {
|
||||
await pref.remove(key);
|
||||
@ -98,11 +81,7 @@ abstract class SettingsSharedPref {
|
||||
|
||||
@protected
|
||||
Future<void> setStringSet(
|
||||
SharedPreferences pref,
|
||||
String key,
|
||||
Set<String> value,
|
||||
Set<String> defaultValue,
|
||||
) async {
|
||||
String key, Set<String> value, Set<String> defaultValue) async {
|
||||
key = id + '_' + key;
|
||||
|
||||
final bool Function(Set<dynamic>, Set<dynamic>) eq =
|
||||
|
@ -11,30 +11,30 @@ import 'package:gitjournal/settings/settings_sharedpref.dart';
|
||||
const FOLDER_NAME_KEY = "remoteGitRepoPath";
|
||||
|
||||
class StorageConfig extends ChangeNotifier with SettingsSharedPref {
|
||||
StorageConfig(this.id);
|
||||
StorageConfig(this.id, this.pref);
|
||||
|
||||
@override
|
||||
final String id;
|
||||
|
||||
@override
|
||||
final SharedPreferences pref;
|
||||
|
||||
var folderName = "journal";
|
||||
var storeInternally = true;
|
||||
var storageLocation = "";
|
||||
|
||||
void load(SharedPreferences pref) {
|
||||
folderName = getString(pref, FOLDER_NAME_KEY) ?? folderName;
|
||||
storeInternally = getBool(pref, "storeInternally") ?? storeInternally;
|
||||
storageLocation = getString(pref, "storageLocation") ?? "";
|
||||
void load() {
|
||||
folderName = getString(FOLDER_NAME_KEY) ?? folderName;
|
||||
storeInternally = getBool("storeInternally") ?? storeInternally;
|
||||
storageLocation = getString("storageLocation") ?? "";
|
||||
}
|
||||
|
||||
Future<void> save() async {
|
||||
var pref = await SharedPreferences.getInstance();
|
||||
var defaultSet = StorageConfig(id);
|
||||
var def = StorageConfig(id, pref);
|
||||
|
||||
await setString(pref, FOLDER_NAME_KEY, folderName, defaultSet.folderName);
|
||||
await setBool(
|
||||
pref, "storeInternally", storeInternally, defaultSet.storeInternally);
|
||||
await setString(
|
||||
pref, "storageLocation", storageLocation, defaultSet.storageLocation);
|
||||
await setString(FOLDER_NAME_KEY, folderName, def.folderName);
|
||||
await setBool("storeInternally", storeInternally, def.storeInternally);
|
||||
await setString("storageLocation", storageLocation, def.storageLocation);
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
@ -4,10 +4,10 @@ import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:gitjournal/core/note.dart';
|
||||
import 'package:gitjournal/core/notes_folder.dart';
|
||||
import 'package:gitjournal/core/virtual_notes_folder.dart';
|
||||
import 'package:gitjournal/folder_views/common.dart';
|
||||
import 'package:gitjournal/folder_views/standard_view.dart';
|
||||
import 'package:gitjournal/settings/settings.dart';
|
||||
import 'package:gitjournal/themes.dart';
|
||||
|
||||
class NoteSearchDelegate extends SearchDelegate<Note?> {
|
||||
@ -86,8 +86,8 @@ class NoteSearchDelegate extends SearchDelegate<Note?> {
|
||||
return note.body.toLowerCase().contains(q);
|
||||
}).toList();
|
||||
|
||||
var settings = Provider.of<Settings>(context);
|
||||
var folder = VirtualNotesFolder(filteredNotes, settings);
|
||||
var folderConfig = Provider.of<NotesFolderConfig>(context);
|
||||
var folder = VirtualNotesFolder(filteredNotes, folderConfig);
|
||||
var emptyText = tr('widgets.FolderView.searchFailed');
|
||||
|
||||
return buildFolderView(
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'package:gitjournal/core/checklist.dart';
|
||||
@ -11,9 +12,12 @@ import 'package:gitjournal/core/notes_folder_fs.dart';
|
||||
void main() {
|
||||
group('Note', () {
|
||||
late Directory tempDir;
|
||||
late NotesFolderConfig config;
|
||||
|
||||
setUpAll(() async {
|
||||
tempDir = await Directory.systemTemp.createTemp('__notes_test__');
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
config = NotesFolderConfig('', await SharedPreferences.getInstance());
|
||||
});
|
||||
|
||||
tearDownAll(() async {
|
||||
@ -41,8 +45,7 @@ Booga Wooga
|
||||
var notePath = p.join(tempDir.path, "note.md");
|
||||
await File(notePath).writeAsString(content);
|
||||
|
||||
var parentFolder =
|
||||
NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
var parentFolder = NotesFolderFS(null, tempDir.path, config);
|
||||
var note = Note(parentFolder, notePath);
|
||||
await note.load();
|
||||
|
||||
@ -106,8 +109,7 @@ Booga Wooga
|
||||
var notePath = p.join(tempDir.path, "note2.md");
|
||||
await File(notePath).writeAsString(content);
|
||||
|
||||
var parentFolder =
|
||||
NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
var parentFolder = NotesFolderFS(null, tempDir.path, config);
|
||||
var note = Note(parentFolder, notePath);
|
||||
await note.load();
|
||||
|
||||
@ -122,8 +124,7 @@ Booga Wooga
|
||||
var notePath = p.join(tempDir.path, "note3.md");
|
||||
await File(notePath).writeAsString(content);
|
||||
|
||||
var parentFolder =
|
||||
NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
var parentFolder = NotesFolderFS(null, tempDir.path, config);
|
||||
var note = Note(parentFolder, notePath);
|
||||
await note.load();
|
||||
|
||||
@ -144,8 +145,7 @@ Booga Wooga
|
||||
var notePath = p.join(tempDir.path, "note13.md");
|
||||
await File(notePath).writeAsString(content);
|
||||
|
||||
var parentFolder =
|
||||
NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
var parentFolder = NotesFolderFS(null, tempDir.path, config);
|
||||
var note = Note(parentFolder, notePath);
|
||||
await note.load();
|
||||
|
||||
@ -165,8 +165,7 @@ Booga Wooga
|
||||
var notePath = p.join(tempDir.path, "note4.md");
|
||||
await File(notePath).writeAsString(content);
|
||||
|
||||
var parentFolder =
|
||||
NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
var parentFolder = NotesFolderFS(null, tempDir.path, config);
|
||||
var note = Note(parentFolder, notePath);
|
||||
await note.load();
|
||||
|
||||
@ -186,8 +185,7 @@ Booga Wooga
|
||||
var notePath = p.join(tempDir.path, "note4.md");
|
||||
await File(notePath).writeAsString(content);
|
||||
|
||||
var parentFolder =
|
||||
NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
var parentFolder = NotesFolderFS(null, tempDir.path, config);
|
||||
var note = Note(parentFolder, notePath);
|
||||
await note.load();
|
||||
|
||||
@ -203,8 +201,7 @@ Booga Wooga
|
||||
var notePath = p.join(tempDir.path, "note449.md");
|
||||
await File(notePath).writeAsString(content);
|
||||
|
||||
var parentFolder =
|
||||
NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
var parentFolder = NotesFolderFS(null, tempDir.path, config);
|
||||
var note = Note(parentFolder, notePath);
|
||||
await note.load();
|
||||
|
||||
@ -222,8 +219,7 @@ Booga Wooga
|
||||
var notePath = p.join(tempDir.path, "note448.md");
|
||||
await File(notePath).writeAsString(content);
|
||||
|
||||
var parentFolder =
|
||||
NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
var parentFolder = NotesFolderFS(null, tempDir.path, config);
|
||||
var note = Note(parentFolder, notePath);
|
||||
await note.load();
|
||||
|
||||
@ -239,8 +235,7 @@ Booga Wooga
|
||||
var notePath = p.join(tempDir.path, "note448.md");
|
||||
await File(notePath).writeAsString(content);
|
||||
|
||||
var parentFolder =
|
||||
NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
var parentFolder = NotesFolderFS(null, tempDir.path, config);
|
||||
var note = Note(parentFolder, notePath);
|
||||
await note.load();
|
||||
|
||||
@ -256,8 +251,7 @@ Booga Wooga
|
||||
var notePath = p.join(tempDir.path, "note449.md");
|
||||
await File(notePath).writeAsString(content);
|
||||
|
||||
var parentFolder =
|
||||
NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
var parentFolder = NotesFolderFS(null, tempDir.path, config);
|
||||
var note = Note(parentFolder, notePath);
|
||||
await note.load();
|
||||
|
||||
@ -274,8 +268,7 @@ Booga Wooga
|
||||
var notePath = p.join(tempDir.path, "note429.md");
|
||||
await File(notePath).writeAsString(content);
|
||||
|
||||
var parentFolder =
|
||||
NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
var parentFolder = NotesFolderFS(null, tempDir.path, config);
|
||||
var note = Note(parentFolder, notePath);
|
||||
await note.load();
|
||||
|
||||
|
@ -2,6 +2,7 @@ import 'dart:io';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'package:gitjournal/core/flattened_notes_folder.dart';
|
||||
@ -13,18 +14,20 @@ void main() {
|
||||
group('Flattened Notes Folder Large Test', () {
|
||||
late Directory tempDir;
|
||||
late NotesFolderFS rootFolder;
|
||||
late NotesFolderConfig config;
|
||||
|
||||
setUp(() async {
|
||||
tempDir = await Directory.systemTemp.createTemp('__flat_folder_test__');
|
||||
// print("TempDir: ${tempDir.path}");
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
config = NotesFolderConfig('', await SharedPreferences.getInstance());
|
||||
|
||||
var random = Random();
|
||||
for (var i = 0; i < 300; i++) {
|
||||
// print("Building Note $i");
|
||||
await _writeRandomNote(random, tempDir.path);
|
||||
await _writeRandomNote(random, tempDir.path, config);
|
||||
}
|
||||
|
||||
rootFolder = NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
rootFolder = NotesFolderFS(null, tempDir.path, config);
|
||||
await rootFolder.loadRecursively();
|
||||
});
|
||||
|
||||
@ -38,7 +41,7 @@ void main() {
|
||||
expect(f.notes.length, 300);
|
||||
|
||||
var tempDir = await Directory.systemTemp.createTemp('_test_');
|
||||
await _writeRandomNote(Random(), tempDir.path);
|
||||
await _writeRandomNote(Random(), tempDir.path, config);
|
||||
|
||||
rootFolder.reset(tempDir.path);
|
||||
await rootFolder.loadRecursively();
|
||||
@ -47,7 +50,8 @@ void main() {
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _writeRandomNote(Random random, String dirPath) async {
|
||||
Future<void> _writeRandomNote(
|
||||
Random random, String dirPath, NotesFolderConfig config) async {
|
||||
String path;
|
||||
while (true) {
|
||||
path = p.join(dirPath, "${random.nextInt(10000)}.md");
|
||||
@ -56,7 +60,7 @@ Future<void> _writeRandomNote(Random random, String dirPath) async {
|
||||
}
|
||||
}
|
||||
|
||||
var note = Note(NotesFolderFS(null, dirPath, NotesFolderConfig('')), path);
|
||||
var note = Note(NotesFolderFS(null, dirPath, config), path);
|
||||
note.modified = DateTime(2014, 1, 1 + (random.nextInt(2000)));
|
||||
note.body = "p1";
|
||||
await note.save();
|
||||
|
@ -2,6 +2,7 @@ import 'dart:io';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'package:gitjournal/core/flattened_notes_folder.dart';
|
||||
@ -26,11 +27,14 @@ void main() {
|
||||
group('Flattened Notes Folder Test', () {
|
||||
late Directory tempDir;
|
||||
late NotesFolderFS rootFolder;
|
||||
late NotesFolderConfig config;
|
||||
|
||||
setUp(() async {
|
||||
tempDir = await Directory.systemTemp.createTemp('__sorted_folder_test__');
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
config = NotesFolderConfig('', await SharedPreferences.getInstance());
|
||||
|
||||
rootFolder = NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
rootFolder = NotesFolderFS(null, tempDir.path, config);
|
||||
|
||||
for (var i = 0; i < 3; i++) {
|
||||
var note = Note(rootFolder, _getRandomFilePath(rootFolder.folderPath));
|
||||
@ -43,8 +47,8 @@ void main() {
|
||||
Directory(p.join(tempDir.path, "sub1", "p1")).createSync();
|
||||
Directory(p.join(tempDir.path, "sub2")).createSync();
|
||||
|
||||
var sub1Folder = NotesFolderFS(
|
||||
rootFolder, p.join(tempDir.path, "sub1"), NotesFolderConfig(''));
|
||||
var sub1Folder =
|
||||
NotesFolderFS(rootFolder, p.join(tempDir.path, "sub1"), config);
|
||||
for (var i = 0; i < 2; i++) {
|
||||
var note = Note(
|
||||
sub1Folder,
|
||||
@ -55,8 +59,8 @@ void main() {
|
||||
await note.save();
|
||||
}
|
||||
|
||||
var sub2Folder = NotesFolderFS(
|
||||
rootFolder, p.join(tempDir.path, "sub2"), NotesFolderConfig(''));
|
||||
var sub2Folder =
|
||||
NotesFolderFS(rootFolder, p.join(tempDir.path, "sub2"), config);
|
||||
for (var i = 0; i < 2; i++) {
|
||||
var note = Note(
|
||||
sub2Folder,
|
||||
@ -67,8 +71,8 @@ void main() {
|
||||
await note.save();
|
||||
}
|
||||
|
||||
var p1Folder = NotesFolderFS(sub1Folder,
|
||||
p.join(tempDir.path, "sub1", "p1"), NotesFolderConfig(''));
|
||||
var p1Folder =
|
||||
NotesFolderFS(sub1Folder, p.join(tempDir.path, "sub1", "p1"), config);
|
||||
for (var i = 0; i < 2; i++) {
|
||||
var note = Note(
|
||||
p1Folder,
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'package:gitjournal/core/link.dart';
|
||||
@ -11,11 +12,14 @@ import 'package:gitjournal/utils/link_resolver.dart';
|
||||
void main() {
|
||||
late Directory tempDir;
|
||||
late NotesFolderFS rootFolder;
|
||||
late NotesFolderConfig config;
|
||||
|
||||
setUpAll(() async {
|
||||
tempDir = await Directory.systemTemp.createTemp('__link_resolver__');
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
config = NotesFolderConfig('', await SharedPreferences.getInstance());
|
||||
|
||||
rootFolder = NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
rootFolder = NotesFolderFS(null, tempDir.path, config);
|
||||
|
||||
await generateNote(tempDir.path, "Hello.md");
|
||||
await generateNote(tempDir.path, "Fire.md");
|
||||
|
@ -1,5 +1,6 @@
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'package:gitjournal/core/md_yaml_doc.dart';
|
||||
@ -11,7 +12,14 @@ import 'package:gitjournal/settings/settings.dart';
|
||||
|
||||
void main() {
|
||||
group('Note Serializer Test', () {
|
||||
var parent = NotesFolderFS(null, '/tmp', NotesFolderConfig(''));
|
||||
late NotesFolderConfig config;
|
||||
late NotesFolderFS parent;
|
||||
|
||||
setUpAll(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
config = NotesFolderConfig('', await SharedPreferences.getInstance());
|
||||
parent = NotesFolderFS(null, '/tmp', config);
|
||||
});
|
||||
|
||||
test('Test emojis', () {
|
||||
var props = LinkedHashMap<String, dynamic>.from(
|
||||
|
@ -2,6 +2,7 @@ import 'dart:collection';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'package:gitjournal/core/md_yaml_doc.dart';
|
||||
@ -16,9 +17,12 @@ void main() {
|
||||
late String n1Path;
|
||||
late String n2Path;
|
||||
late Directory tempDir;
|
||||
late NotesFolderConfig config;
|
||||
|
||||
setUpAll(() async {
|
||||
tempDir = await Directory.systemTemp.createTemp('__storage_test__');
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
config = NotesFolderConfig('', await SharedPreferences.getInstance());
|
||||
|
||||
var dt = DateTime(2019, 12, 2, 5, 4, 2);
|
||||
// ignore: prefer_collection_literals
|
||||
@ -28,7 +32,7 @@ void main() {
|
||||
n1Path = p.join(tempDir.path, "1.md");
|
||||
n2Path = p.join(tempDir.path, "2.md");
|
||||
|
||||
var parent = NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
var parent = NotesFolderFS(null, tempDir.path, config);
|
||||
var n1 = Note(parent, n1Path);
|
||||
n1.body = "test\n";
|
||||
n1.created = dt;
|
||||
@ -52,7 +56,7 @@ void main() {
|
||||
expect(File(n2Path).existsSync(), isTrue);
|
||||
|
||||
var loadedNotes = <Note>[];
|
||||
var parent = NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
var parent = NotesFolderFS(null, tempDir.path, config);
|
||||
|
||||
await Future.forEach(notes, (Note origNote) async {
|
||||
var note = Note(parent, origNote.filePath);
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'package:gitjournal/core/note.dart';
|
||||
@ -10,9 +11,12 @@ import 'package:gitjournal/core/notes_folder_fs.dart';
|
||||
void main() {
|
||||
group('Note', () {
|
||||
late Directory tempDir;
|
||||
late NotesFolderConfig config;
|
||||
|
||||
setUpAll(() async {
|
||||
tempDir = await Directory.systemTemp.createTemp('__notes_test__');
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
config = NotesFolderConfig('', await SharedPreferences.getInstance());
|
||||
});
|
||||
|
||||
tearDownAll(() async {
|
||||
@ -31,8 +35,7 @@ Hello
|
||||
var notePath = p.join(tempDir.path, "note.md");
|
||||
await File(notePath).writeAsString(content);
|
||||
|
||||
var parentFolder =
|
||||
NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
var parentFolder = NotesFolderFS(null, tempDir.path, config);
|
||||
var note = Note(parentFolder, notePath);
|
||||
await note.load();
|
||||
|
||||
@ -64,8 +67,7 @@ Hello
|
||||
var notePath = p.join(tempDir.path, "note.md");
|
||||
await File(notePath).writeAsString(content);
|
||||
|
||||
var parentFolder =
|
||||
NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
var parentFolder = NotesFolderFS(null, tempDir.path, config);
|
||||
var note = Note(parentFolder, notePath);
|
||||
await note.load();
|
||||
|
||||
@ -97,8 +99,7 @@ Hello
|
||||
var notePath = p.join(tempDir.path, "note5.md");
|
||||
await File(notePath).writeAsString(content);
|
||||
|
||||
var parentFolder =
|
||||
NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
var parentFolder = NotesFolderFS(null, tempDir.path, config);
|
||||
var note = Note(parentFolder, notePath);
|
||||
await note.load();
|
||||
|
||||
@ -137,8 +138,7 @@ bar: Foo
|
||||
var notePath = p.join(tempDir.path, "note6.md");
|
||||
await File(notePath).writeAsString(content);
|
||||
|
||||
var parentFolder =
|
||||
NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
var parentFolder = NotesFolderFS(null, tempDir.path, config);
|
||||
var note = Note(parentFolder, notePath);
|
||||
await note.load();
|
||||
|
||||
@ -159,8 +159,7 @@ bar: Foo
|
||||
var notePath = p.join(tempDir.path, "note63.md");
|
||||
await File(notePath).writeAsString(content);
|
||||
|
||||
var parentFolder =
|
||||
NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
var parentFolder = NotesFolderFS(null, tempDir.path, config);
|
||||
var note = Note(parentFolder, notePath);
|
||||
await note.load();
|
||||
|
||||
@ -186,8 +185,7 @@ Gee
|
||||
var notePath = p.join(tempDir.path, "note16.md");
|
||||
await File(notePath).writeAsString(content);
|
||||
|
||||
var parentFolder =
|
||||
NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
var parentFolder = NotesFolderFS(null, tempDir.path, config);
|
||||
var note = Note(parentFolder, notePath);
|
||||
await note.load();
|
||||
|
||||
@ -209,8 +207,7 @@ Gee
|
||||
});
|
||||
|
||||
test('New Notes have a file extension', () async {
|
||||
var parentFolder =
|
||||
NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
var parentFolder = NotesFolderFS(null, tempDir.path, config);
|
||||
var note = Note.newNote(parentFolder);
|
||||
var path = note.filePath;
|
||||
expect(path.endsWith('.md'), true);
|
||||
@ -224,8 +221,7 @@ Gee
|
||||
var txtNotePath = p.join(tempDir.path, "note163.txt");
|
||||
await File(txtNotePath).writeAsString(content);
|
||||
|
||||
var parentFolder =
|
||||
NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
var parentFolder = NotesFolderFS(null, tempDir.path, config);
|
||||
var txtNote = Note(parentFolder, txtNotePath);
|
||||
await txtNote.load();
|
||||
|
||||
@ -248,8 +244,7 @@ Hello
|
||||
var notePath = p.join(tempDir.path, "note.md");
|
||||
await File(notePath).writeAsString(content);
|
||||
|
||||
var parentFolder =
|
||||
NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
var parentFolder = NotesFolderFS(null, tempDir.path, config);
|
||||
var note = Note(parentFolder, notePath);
|
||||
await note.load();
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'package:gitjournal/core/notes_cache.dart';
|
||||
@ -18,14 +19,17 @@ void main() {
|
||||
'/base/d1/file.md',
|
||||
];
|
||||
late NotesCache cache;
|
||||
late NotesFolderConfig config;
|
||||
|
||||
setUp(() async {
|
||||
tempDir = await Directory.systemTemp.createTemp('__notes_test__');
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
config = NotesFolderConfig('', await SharedPreferences.getInstance());
|
||||
cacheFilePath = p.join(tempDir.path, "cache.raw");
|
||||
cache = NotesCache(
|
||||
filePath: cacheFilePath,
|
||||
notesBasePath: '/base',
|
||||
folderConfig: NotesFolderConfig(''),
|
||||
folderConfig: config,
|
||||
);
|
||||
});
|
||||
|
||||
@ -45,7 +49,7 @@ void main() {
|
||||
|
||||
test('Should create directory structure accurately', () async {
|
||||
await cache.saveToDisk(fileList);
|
||||
var rootFolder = NotesFolderFS(null, '/base', NotesFolderConfig(''));
|
||||
var rootFolder = NotesFolderFS(null, '/base', config);
|
||||
await cache.load(rootFolder);
|
||||
|
||||
expect(rootFolder.subFolders.length, 2);
|
||||
|
@ -1,3 +1,4 @@
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'package:gitjournal/core/notes_folder_config.dart';
|
||||
@ -5,11 +6,13 @@ import 'package:gitjournal/core/notes_folder_fs.dart';
|
||||
import 'package:gitjournal/core/processors/wiki_links_auto_add.dart';
|
||||
|
||||
void main() {
|
||||
test('Should process body', () {
|
||||
test('Should process body', () async {
|
||||
var body =
|
||||
"GitJournal is the best? And it works quite well with Foam, Foam and Obsidian.";
|
||||
|
||||
var folder = NotesFolderFS(null, '/', NotesFolderConfig(''));
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
var config = NotesFolderConfig('', await SharedPreferences.getInstance());
|
||||
var folder = NotesFolderFS(null, '/', config);
|
||||
var p = WikiLinksAutoAddProcessor(folder);
|
||||
var newBody = p.processBody(body, ['GitJournal', 'Foam', 'Obsidian']);
|
||||
var expectedBody =
|
||||
|
@ -2,6 +2,7 @@ import 'dart:io';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'package:gitjournal/core/note.dart';
|
||||
@ -14,11 +15,14 @@ void main() {
|
||||
group('Sorted Notes Folder Test', () {
|
||||
late Directory tempDir;
|
||||
late NotesFolderFS folder;
|
||||
late NotesFolderConfig config;
|
||||
|
||||
setUp(() async {
|
||||
tempDir = await Directory.systemTemp.createTemp('__sorted_folder_test__');
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
config = NotesFolderConfig('', await SharedPreferences.getInstance());
|
||||
|
||||
folder = NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
folder = NotesFolderFS(null, tempDir.path, config);
|
||||
|
||||
var random = Random();
|
||||
for (var i = 0; i < 5; i++) {
|
||||
@ -122,7 +126,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('If still sorted while loading the notes', () async {
|
||||
var folder = NotesFolderFS(null, tempDir.path, NotesFolderConfig(''));
|
||||
var folder = NotesFolderFS(null, tempDir.path, config);
|
||||
var sf = SortedNotesFolder(
|
||||
folder: folder,
|
||||
sortingMode:
|
||||
|
@ -1,3 +1,4 @@
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'package:gitjournal/core/note.dart';
|
||||
@ -7,8 +8,15 @@ import 'package:gitjournal/core/sorting_mode.dart';
|
||||
|
||||
void main() {
|
||||
group('Sorting Mode', () {
|
||||
late NotesFolderConfig config;
|
||||
|
||||
setUpAll(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
config = NotesFolderConfig('', await SharedPreferences.getInstance());
|
||||
});
|
||||
|
||||
test('Created', () async {
|
||||
var folder = NotesFolderFS(null, '/tmp/', NotesFolderConfig(''));
|
||||
var folder = NotesFolderFS(null, '/tmp/', config);
|
||||
var n1 = Note(folder, '/tmp/1.md');
|
||||
n1.created = DateTime(2020, 10, 01);
|
||||
|
||||
@ -33,7 +41,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('Modified', () async {
|
||||
var folder = NotesFolderFS(null, '/tmp/', NotesFolderConfig(''));
|
||||
var folder = NotesFolderFS(null, '/tmp/', config);
|
||||
var n1 = Note(folder, '/tmp/1.md');
|
||||
n1.modified = DateTime(2020, 10, 01);
|
||||
|
||||
@ -58,7 +66,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('Title', () async {
|
||||
var folder = NotesFolderFS(null, '/tmp/', NotesFolderConfig(''));
|
||||
var folder = NotesFolderFS(null, '/tmp/', config);
|
||||
var n1 = Note(folder, '/tmp/1.md');
|
||||
n1.title = "alpha";
|
||||
|
||||
|
Reference in New Issue
Block a user