mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 09:47:35 +08:00
Allow remote sync frequency to be controller
For now the only 2 options are - automaitic and manual. I rather name it "Automatic" instead of "After each change" as that way I can choose to do it more frequently, if desired. Fixes #8
This commit is contained in:
@ -6,6 +6,8 @@ import 'package:fimber/fimber.dart';
|
||||
|
||||
import 'package:git_bindings/git_bindings.dart';
|
||||
import 'package:gitjournal/screens/githostsetup_sshkey.dart';
|
||||
import 'package:gitjournal/screens/settings_widgets.dart';
|
||||
import 'package:gitjournal/settings.dart';
|
||||
import 'package:gitjournal/utils.dart';
|
||||
|
||||
class GitRemoteSettingsScreen extends StatefulWidget {
|
||||
@ -30,6 +32,7 @@ class _GitRemoteSettingsScreenState extends State<GitRemoteSettingsScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var textTheme = Theme.of(context).textTheme;
|
||||
var settings = Settings.instance;
|
||||
|
||||
var body = Column(
|
||||
children: <Widget>[
|
||||
@ -50,6 +53,19 @@ class _GitRemoteSettingsScreenState extends State<GitRemoteSettingsScreen> {
|
||||
text: "Regnerate Key",
|
||||
onPressed: () => _generateSshKey(context),
|
||||
),
|
||||
ListPreference(
|
||||
title: "Sync Frequency",
|
||||
currentOption: settings.remoteSyncFrequency.toPublicString(),
|
||||
options: RemoteSyncFrequency.options
|
||||
.map((f) => f.toPublicString())
|
||||
.toList(),
|
||||
onChange: (String publicStr) {
|
||||
var val = RemoteSyncFrequency.fromPublicString(publicStr);
|
||||
Settings.instance.remoteSyncFrequency = val;
|
||||
Settings.instance.save();
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
],
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
);
|
||||
|
@ -43,7 +43,6 @@ class ListPreference extends StatelessWidget {
|
||||
children: children,
|
||||
),
|
||||
),
|
||||
contentPadding: const EdgeInsets.all(0.0),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
child: const Text('CANCEL'),
|
||||
|
@ -19,6 +19,8 @@ class Settings {
|
||||
|
||||
String yamlModifiedKey = "modified";
|
||||
String defaultNewNoteFolder = "journal";
|
||||
|
||||
RemoteSyncFrequency remoteSyncFrequency = RemoteSyncFrequency.Default;
|
||||
int version = 0;
|
||||
|
||||
void load(SharedPreferences pref) {
|
||||
@ -36,6 +38,10 @@ class Settings {
|
||||
yamlModifiedKey = pref.getString("yamlModifiedKey") ?? yamlModifiedKey;
|
||||
defaultNewNoteFolder =
|
||||
pref.getString("defaultNewNoteFolder") ?? defaultNewNoteFolder;
|
||||
|
||||
remoteSyncFrequency = RemoteSyncFrequency.fromInternalString(
|
||||
pref.getString("remoteSyncFrequency"));
|
||||
|
||||
version = pref.getInt("settingsVersion") ?? version;
|
||||
}
|
||||
|
||||
@ -48,6 +54,8 @@ class Settings {
|
||||
pref.setBool("collectCrashReports", collectCrashReports);
|
||||
pref.setString("yamlModifiedKey", yamlModifiedKey);
|
||||
pref.setString("defaultNewNoteFolder", defaultNewNoteFolder);
|
||||
pref.setString(
|
||||
"remoteSyncFrequency", remoteSyncFrequency.toInternalString());
|
||||
pref.setInt("settingsVersion", version);
|
||||
|
||||
// Shouldn't we check if something has actually changed?
|
||||
@ -132,3 +140,43 @@ class NoteFileNameFormat {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
class RemoteSyncFrequency {
|
||||
static const Automatic = RemoteSyncFrequency("Automatic");
|
||||
static const Manual = RemoteSyncFrequency("Manual");
|
||||
static const Default = Automatic;
|
||||
|
||||
final String _str;
|
||||
const RemoteSyncFrequency(this._str);
|
||||
|
||||
String toInternalString() {
|
||||
return _str;
|
||||
}
|
||||
|
||||
String toPublicString() {
|
||||
return _str;
|
||||
}
|
||||
|
||||
static const options = <RemoteSyncFrequency>[
|
||||
Automatic,
|
||||
Manual,
|
||||
];
|
||||
|
||||
static RemoteSyncFrequency fromInternalString(String str) {
|
||||
for (var opt in options) {
|
||||
if (opt.toInternalString() == str) {
|
||||
return opt;
|
||||
}
|
||||
}
|
||||
return Default;
|
||||
}
|
||||
|
||||
static RemoteSyncFrequency fromPublicString(String str) {
|
||||
for (var opt in options) {
|
||||
if (opt.toPublicString() == str) {
|
||||
return opt;
|
||||
}
|
||||
}
|
||||
return Default;
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import 'package:gitjournal/appstate.dart';
|
||||
import 'package:gitjournal/core/note.dart';
|
||||
import 'package:gitjournal/core/notes_folder.dart';
|
||||
import 'package:gitjournal/core/git_repo.dart';
|
||||
import 'package:gitjournal/settings.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:flutter_crashlytics/flutter_crashlytics.dart';
|
||||
@ -116,7 +117,11 @@ class StateContainerState extends State<StateContainer> {
|
||||
await _loadNotes();
|
||||
}
|
||||
|
||||
Future<void> _syncNotes() {
|
||||
Future<void> _syncNotes() async {
|
||||
var freq = Settings.instance.remoteSyncFrequency;
|
||||
if (freq != RemoteSyncFrequency.Automatic) {
|
||||
return;
|
||||
}
|
||||
return syncNotes(doNotThrow: true);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user