mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-01 04:07:53 +08:00
Settings Screen: Actually save the gitAuthor + email
There is too much code duplication over here, but - meh - I'll clean it up later.
This commit is contained in:
@ -3,7 +3,7 @@ import 'dart:io';
|
|||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:journal/apis/git.dart';
|
import 'package:journal/apis/git.dart';
|
||||||
|
import 'package:journal/settings.dart';
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -34,8 +34,8 @@ Future migrateGitRepo({
|
|||||||
await gitAdd(toGitBasePath, fileName);
|
await gitAdd(toGitBasePath, fileName);
|
||||||
await gitCommit(
|
await gitCommit(
|
||||||
gitFolder: toGitBasePath,
|
gitFolder: toGitBasePath,
|
||||||
authorEmail: "app@gitjournal.io",
|
authorEmail: Settings.instance.gitAuthorEmail,
|
||||||
authorName: "GitJournal",
|
authorName: Settings.instance.gitAuthor,
|
||||||
message: "Migrated Journal Entry",
|
message: "Migrated Journal Entry",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
|
||||||
import 'package:flutter_crashlytics/flutter_crashlytics.dart';
|
import 'package:flutter_crashlytics/flutter_crashlytics.dart';
|
||||||
|
|
||||||
import 'package:journal/app.dart';
|
|
||||||
import 'package:journal/state_container.dart';
|
|
||||||
import 'package:journal/apis/git.dart';
|
import 'package:journal/apis/git.dart';
|
||||||
|
import 'package:journal/app.dart';
|
||||||
|
import 'package:journal/settings.dart';
|
||||||
|
import 'package:journal/state_container.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
bool isInDebugMode = true;
|
bool isInDebugMode = true;
|
||||||
@ -58,6 +58,8 @@ Future runJournalApp() async {
|
|||||||
|
|
||||||
var dir = await getGitBaseDirectory();
|
var dir = await getGitBaseDirectory();
|
||||||
|
|
||||||
|
await Settings.instance.load();
|
||||||
|
|
||||||
runApp(new StateContainer(
|
runApp(new StateContainer(
|
||||||
localGitRepoConfigured: localGitRepoConfigured,
|
localGitRepoConfigured: localGitRepoConfigured,
|
||||||
remoteGitRepoConfigured: remoteGitRepoConfigured,
|
remoteGitRepoConfigured: remoteGitRepoConfigured,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:package_info/package_info.dart';
|
|
||||||
|
|
||||||
import 'package:journal/app.dart';
|
import 'package:journal/app.dart';
|
||||||
|
import 'package:journal/settings.dart';
|
||||||
|
import 'package:package_info/package_info.dart';
|
||||||
|
|
||||||
class SettingsScreen extends StatelessWidget {
|
class SettingsScreen extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
@ -29,10 +29,14 @@ class SettingsList extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class SettingsListState extends State<SettingsList> {
|
class SettingsListState extends State<SettingsList> {
|
||||||
|
final gitAuthorKey = GlobalKey<FormFieldState<String>>();
|
||||||
|
final gitAuthorEmailKey = GlobalKey<FormFieldState<String>>();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var gitAuthorForm = Form(
|
var gitAuthorForm = Form(
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
|
key: gitAuthorKey,
|
||||||
style: Theme.of(context).textTheme.title,
|
style: Theme.of(context).textTheme.title,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
icon: Icon(Icons.person),
|
icon: Icon(Icons.person),
|
||||||
@ -46,14 +50,27 @@ class SettingsListState extends State<SettingsList> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
textInputAction: TextInputAction.done,
|
textInputAction: TextInputAction.done,
|
||||||
onFieldSubmitted: (String _) {},
|
onFieldSubmitted: (String gitAuthor) {
|
||||||
initialValue:
|
Settings.instance.gitAuthor = gitAuthor;
|
||||||
JournalApp.preferences.getString("gitAuthor") ?? "GitJournal",
|
Settings.instance.save();
|
||||||
|
},
|
||||||
|
onSaved: (String gitAuthor) {
|
||||||
|
Settings.instance.gitAuthor = gitAuthor;
|
||||||
|
Settings.instance.save();
|
||||||
|
},
|
||||||
|
initialValue: Settings.instance.gitAuthor,
|
||||||
),
|
),
|
||||||
|
onChanged: () {
|
||||||
|
if (!gitAuthorKey.currentState.validate()) return;
|
||||||
|
var gitAuthor = gitAuthorKey.currentState.value;
|
||||||
|
Settings.instance.gitAuthor = gitAuthor;
|
||||||
|
Settings.instance.save();
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
var gitAuthorEmailForm = Form(
|
var gitAuthorEmailForm = Form(
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
|
key: gitAuthorEmailKey,
|
||||||
style: Theme.of(context).textTheme.title,
|
style: Theme.of(context).textTheme.title,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
icon: Icon(Icons.email),
|
icon: Icon(Icons.email),
|
||||||
@ -65,12 +82,30 @@ class SettingsListState extends State<SettingsList> {
|
|||||||
if (value.isEmpty) {
|
if (value.isEmpty) {
|
||||||
return 'Please enter an email';
|
return 'Please enter an email';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool emailValid =
|
||||||
|
RegExp(r"^[a-zA-Z0-9.]+@[a-zA-Z0-9]+\.[a-zA-Z]+").hasMatch(value);
|
||||||
|
if (!emailValid) {
|
||||||
|
return 'Please enter a valid email';
|
||||||
|
}
|
||||||
},
|
},
|
||||||
textInputAction: TextInputAction.done,
|
textInputAction: TextInputAction.done,
|
||||||
onFieldSubmitted: (String _) {},
|
onFieldSubmitted: (String gitAuthorEmail) {
|
||||||
initialValue: JournalApp.preferences.getString("gitAuthorEmail") ??
|
Settings.instance.gitAuthorEmail = gitAuthorEmail;
|
||||||
"app@gitjournal.io",
|
Settings.instance.save();
|
||||||
|
},
|
||||||
|
onSaved: (String gitAuthorEmail) {
|
||||||
|
Settings.instance.gitAuthorEmail = gitAuthorEmail;
|
||||||
|
Settings.instance.save();
|
||||||
|
},
|
||||||
|
initialValue: Settings.instance.gitAuthorEmail,
|
||||||
),
|
),
|
||||||
|
onChanged: () {
|
||||||
|
if (!gitAuthorEmailKey.currentState.validate()) return;
|
||||||
|
var gitAuthorEmail = gitAuthorEmailKey.currentState.value;
|
||||||
|
Settings.instance.gitAuthorEmail = gitAuthorEmail;
|
||||||
|
Settings.instance.save();
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
var listView = ListView(children: <Widget>[
|
var listView = ListView(children: <Widget>[
|
||||||
|
24
lib/settings.dart
Normal file
24
lib/settings.dart
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
class Settings {
|
||||||
|
// singleton
|
||||||
|
static final Settings _singleton = Settings._internal();
|
||||||
|
factory Settings() => _singleton;
|
||||||
|
Settings._internal();
|
||||||
|
static Settings get instance => _singleton;
|
||||||
|
|
||||||
|
Future load() async {
|
||||||
|
var pref = await SharedPreferences.getInstance();
|
||||||
|
gitAuthor = pref.getString("gitAuthor") ?? gitAuthor;
|
||||||
|
gitAuthorEmail = pref.getString("gitAuthorEmail") ?? gitAuthorEmail;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future save() async {
|
||||||
|
var pref = await SharedPreferences.getInstance();
|
||||||
|
pref.setString("gitAuthor", gitAuthor);
|
||||||
|
pref.setString("gitAuthorEmail", gitAuthorEmail);
|
||||||
|
}
|
||||||
|
|
||||||
|
String gitAuthor = "GitJournal";
|
||||||
|
String gitAuthorEmail = "app@gitjournal.io";
|
||||||
|
}
|
@ -1,17 +1,16 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:path/path.dart' as p;
|
|
||||||
|
|
||||||
import 'package:journal/note.dart';
|
|
||||||
import 'package:journal/apis/git.dart';
|
import 'package:journal/apis/git.dart';
|
||||||
import 'package:journal/storage/serializers.dart';
|
import 'package:journal/note.dart';
|
||||||
|
import 'package:journal/settings.dart';
|
||||||
import 'package:journal/storage/file_storage.dart';
|
import 'package:journal/storage/file_storage.dart';
|
||||||
import 'package:journal/storage/notes_repository.dart';
|
import 'package:journal/storage/notes_repository.dart';
|
||||||
|
import 'package:journal/storage/serializers.dart';
|
||||||
|
import 'package:path/path.dart' as p;
|
||||||
|
|
||||||
class GitNoteRepository implements NoteRepository {
|
class GitNoteRepository implements NoteRepository {
|
||||||
final FileStorage _fileStorage;
|
final FileStorage _fileStorage;
|
||||||
//final String gitCloneUrl = "";
|
|
||||||
final String dirName;
|
final String dirName;
|
||||||
|
|
||||||
bool cloned = false;
|
bool cloned = false;
|
||||||
@ -42,8 +41,8 @@ class GitNoteRepository implements NoteRepository {
|
|||||||
await gitAdd(this.dirName, filePath);
|
await gitAdd(this.dirName, filePath);
|
||||||
await gitCommit(
|
await gitCommit(
|
||||||
gitFolder: this.dirName,
|
gitFolder: this.dirName,
|
||||||
authorEmail: "app@gitjournal.io",
|
authorEmail: Settings.instance.gitAuthorEmail,
|
||||||
authorName: "GitJournal",
|
authorName: Settings.instance.gitAuthor,
|
||||||
message: commitMessage,
|
message: commitMessage,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -64,8 +63,8 @@ class GitNoteRepository implements NoteRepository {
|
|||||||
await gitRm(this.dirName, filePath);
|
await gitRm(this.dirName, filePath);
|
||||||
await gitCommit(
|
await gitCommit(
|
||||||
gitFolder: this.dirName,
|
gitFolder: this.dirName,
|
||||||
authorEmail: "app@gitjournal.io",
|
authorEmail: Settings.instance.gitAuthorEmail,
|
||||||
authorName: "GitJournal",
|
authorName: Settings.instance.gitAuthor,
|
||||||
message: "Removed Journal entry",
|
message: "Removed Journal entry",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user