mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-01 20:43:20 +08:00
Hookup onBoarding screen to app
* I should probably stop calling in an onboarding screen, since it's now just a way to setup sync. * It overall feels quite ugly, and unpolished.
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:journal/screens/home_screen.dart';
|
||||
import 'package:journal/screens/settings_screen.dart';
|
||||
import 'package:journal/screens/onboarding_screens.dart';
|
||||
import 'package:journal/state_container.dart';
|
||||
|
||||
import 'package:firebase_analytics/firebase_analytics.dart';
|
||||
import 'package:firebase_analytics/observer.dart';
|
||||
@ -18,6 +20,11 @@ class JournalApp extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var stateContainer = StateContainer.of(context);
|
||||
var onCompleted = () {
|
||||
stateContainer.completeOnBoarding();
|
||||
};
|
||||
|
||||
return new MaterialApp(
|
||||
title: 'GitJournal',
|
||||
theme: new ThemeData(
|
||||
@ -32,6 +39,7 @@ class JournalApp extends StatelessWidget {
|
||||
routes: {
|
||||
'/': (context) => HomeScreen(),
|
||||
'/settings': (context) => SettingsScreen(),
|
||||
'/setupRemoteGit': (context) => OnBoardingScreen(onCompleted),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -134,7 +134,8 @@ class OnBoardingScreenState extends State<OnBoardingScreen> {
|
||||
curve: Curves.easeIn,
|
||||
);
|
||||
|
||||
_startGitClone();
|
||||
var appState = StateContainer.of(context).appState;
|
||||
_startGitClone(appState.gitBaseDirectory);
|
||||
|
||||
getAnalytics().logEvent(
|
||||
name: "onboarding_public_key_copied",
|
||||
@ -275,9 +276,9 @@ class OnBoardingScreenState extends State<OnBoardingScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
void _startGitClone() async {
|
||||
void _startGitClone(String basePath) async {
|
||||
// Just in case it was half cloned because of an error
|
||||
await _removeExistingClone();
|
||||
await _removeExistingClone(basePath);
|
||||
|
||||
String error = await gitClone(_gitCloneUrl, "journal");
|
||||
if (error != null && error.isNotEmpty) {
|
||||
@ -299,17 +300,14 @@ class OnBoardingScreenState extends State<OnBoardingScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
Future _removeExistingClone() async {
|
||||
// FIXME: Implement this
|
||||
/*
|
||||
var baseDir = await getNotesDir();
|
||||
var dotGitDir = new Directory(p.join(baseDir.path, ".git"));
|
||||
Future _removeExistingClone(String baseDirPath) async {
|
||||
var baseDir = new Directory(baseDirPath);
|
||||
var dotGitDir = new Directory(p.join(baseDir.path, "journal", ".git"));
|
||||
bool exists = await dotGitDir.exists();
|
||||
if (exists) {
|
||||
await baseDir.delete(recursive: true);
|
||||
await baseDir.create();
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,9 +10,10 @@ import 'package:journal/appstate.dart';
|
||||
import 'package:journal/note.dart';
|
||||
import 'package:journal/storage/notes_repository.dart';
|
||||
import 'package:journal/storage/git_storage.dart';
|
||||
import 'package:journal/apis/git.dart';
|
||||
import 'package:journal/datetime_utils.dart';
|
||||
|
||||
import 'package:journal/apis/git_migration.dart';
|
||||
|
||||
class StateContainer extends StatefulWidget {
|
||||
final Widget child;
|
||||
final bool localGitRepoConfigured;
|
||||
@ -185,20 +186,27 @@ class StateContainerState extends State<StateContainer> {
|
||||
}
|
||||
|
||||
void completeOnBoarding() {
|
||||
setState(() {
|
||||
//this.appState.onBoardingCompleted = true;
|
||||
setState(() async {
|
||||
this.appState.remoteGitRepoConfigured = true;
|
||||
this.appState.remoteGitRepoPath = "journal";
|
||||
|
||||
_persistOnBoardingCompleted();
|
||||
await migrateGitRepo(
|
||||
fromGitBasePath: appState.localGitRepoPath,
|
||||
toGitBasePath: appState.localGitRepoPath,
|
||||
gitBasePath: appState.gitBaseDirectory,
|
||||
);
|
||||
|
||||
noteRepo = new GitNoteRepository(
|
||||
baseDirectory: appState.gitBaseDirectory,
|
||||
dirName: appState.remoteGitRepoPath,
|
||||
);
|
||||
|
||||
_persistConfig();
|
||||
_loadNotesFromDisk();
|
||||
_syncNotes();
|
||||
});
|
||||
}
|
||||
|
||||
void _persistOnBoardingCompleted() async {
|
||||
var pref = await SharedPreferences.getInstance();
|
||||
pref.setBool("onBoardingCompleted", true);
|
||||
}
|
||||
|
||||
Future _persistConfig() async {
|
||||
var pref = await SharedPreferences.getInstance();
|
||||
await pref.setBool(
|
||||
|
Reference in New Issue
Block a user